Skip to content

Commit

Permalink
Add load/save config for fbs
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksandr Kuzin committed Nov 19, 2024
1 parent 8665e6c commit 45eb97d
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 8 deletions.
4 changes: 2 additions & 2 deletions asam_cmp_capture_module/src/capture_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ DictPtr<IString, IFunctionBlockType> CaptureModule::onGetAvailableFunctionBlockT
{
auto types = Dict<IString, IFunctionBlockType>();

auto typeStatistics = CaptureModuleFb::CreateType();
types.set(typeStatistics.getId(), typeStatistics);
auto typeCaptureModule = CaptureModuleFb::CreateType();
types.set(typeCaptureModule.getId(), typeCaptureModule);

return types;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class CaptureCommonFbImpl : public FunctionBlockImpl<IFunctionBlock, Interfaces.

static FunctionBlockTypePtr CreateType();

DictPtr<IString, IFunctionBlockType> onGetAvailableFunctionBlockTypes() override;
FunctionBlockPtr onAddFunctionBlock(const StringPtr& typeId, const PropertyObjectPtr& config) override;

protected:
void initDeviceInfoProperties(bool readOnly);
template <class Impl, typename... Params>
Expand Down Expand Up @@ -155,9 +158,8 @@ FunctionBlockPtr CaptureCommonFbImpl<Interfaces...>::addInterfaceWithParams(uint
StringPtr fbId = fmt::format("Interface_{}", createdInterfaces++);
auto newFb = createWithImplementation<IFunctionBlock, Impl>(this->context, this->functionBlocks, fbId, init, std::forward<Params>(params)...);
newFb.setName(fbName);
this->functionBlocks.addItem(newFb);
interfaceIdManager.addId(interfaceId);

addNestedFunctionBlock(newFb);
return newFb;
}

Expand Down Expand Up @@ -248,4 +250,24 @@ void CaptureCommonFbImpl<Interfaces...>::propertyChangedIfNotUpdating()
needsPropertyChanged = true;
}

template <typename... Interfaces>
DictPtr<IString, IFunctionBlockType> CaptureCommonFbImpl<Interfaces...>::onGetAvailableFunctionBlockTypes()
{
auto type = InterfaceCommonFb::CreateType();
return Dict<IString, IFunctionBlockType>({{type.getId(), type}});
}

template <typename... Interfaces>
FunctionBlockPtr CaptureCommonFbImpl<Interfaces...>::onAddFunctionBlock(const StringPtr& typeId, const PropertyObjectPtr& config)
{
if (typeId == InterfaceCommonFb::CreateType().getId())
{
addInterface();
auto interfaceFb = this->functionBlocks.getItems().getItemAt(this->functionBlocks.getItems().getCount() - 1);
return interfaceFb;
}

throw NotFoundException("Function block not found");
}

END_NAMESPACE_ASAM_CMP_COMMON
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class InterfaceCommonFb : public FunctionBlock
~InterfaceCommonFb() override = default;
static FunctionBlockTypePtr CreateType();

DictPtr<IString, IFunctionBlockType> onGetAvailableFunctionBlockTypes() override;
FunctionBlockPtr onAddFunctionBlock(const StringPtr& typeId, const PropertyObjectPtr& config) override;
protected:
template <class Impl, typename... Params>
FunctionBlockPtr addStreamWithParams(uint8_t streamId, Params&&... params);
Expand Down Expand Up @@ -94,9 +96,8 @@ FunctionBlockPtr InterfaceCommonFb::addStreamWithParams(uint8_t streamId, Params
StringPtr fbId = fmt::format("Stream_{}", createdStreams++);
auto newFb = createWithImplementation<IFunctionBlock, Impl>(context, functionBlocks, fbId, init, std::forward<Params>(params)...);
newFb.setName(fbName);
functionBlocks.addItem(newFb);
streamIdManager.addId(streamId);

addNestedFunctionBlock(newFb);
return newFb;
}

Expand Down
19 changes: 19 additions & 0 deletions asam_cmp_common_lib/src/interface_common_fb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,23 @@ void InterfaceCommonFb::propertyChangedIfNotUpdating()
needsPropertyChanged = true;
}


DictPtr<IString, IFunctionBlockType> InterfaceCommonFb::onGetAvailableFunctionBlockTypes()
{
auto type = StreamCommonFb::CreateType();
return Dict<IString, IFunctionBlockType>({{type.getId(), type}});
}

FunctionBlockPtr InterfaceCommonFb::onAddFunctionBlock(const StringPtr& typeId, const PropertyObjectPtr& config)
{
if (typeId == StreamCommonFb::CreateType().getId())
{
addStream();
auto streamFb = this->functionBlocks.getItems().getItemAt(this->functionBlocks.getItems().getCount() - 1);
return streamFb;
}

throw NotFoundException("Function block not found");
}

END_NAMESPACE_ASAM_CMP_COMMON
3 changes: 3 additions & 0 deletions asam_cmp_data_sink/include/asam_cmp_data_sink/data_sink_fb.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class DataSinkFb final : public FunctionBlock

static FunctionBlockTypePtr CreateType();

DictPtr<IString, IFunctionBlockType> onGetAvailableFunctionBlockTypes() override;
FunctionBlockPtr onAddFunctionBlock(const StringPtr& typeId, const PropertyObjectPtr& config) override;

private:
void initProperties();
void addCaptureModuleFromStatus(int index);
Expand Down
24 changes: 22 additions & 2 deletions asam_cmp_data_sink/src/data_sink_fb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ void DataSinkFb::addCaptureModuleFromStatus(int index)
const StringPtr fbId = getFbId(captureModuleId);
const auto newFb = createWithImplementation<IFunctionBlock, CaptureFb>(
context, functionBlocks, fbId, dataPacketsPublisher, capturePacketsPublisher, std::move(deviceStatus));
functionBlocks.addItem(newFb);
//functionBlocks.addItem(newFb);
addNestedFunctionBlock(newFb);
++captureModuleId;
}

Expand All @@ -44,7 +45,8 @@ void DataSinkFb::addCaptureModuleEmpty()
const StringPtr fbId = getFbId(captureModuleId);
const auto newFb =
createWithImplementation<IFunctionBlock, CaptureFb>(context, functionBlocks, fbId, dataPacketsPublisher, capturePacketsPublisher);
functionBlocks.addItem(newFb);
//functionBlocks.addItem(newFb);
addNestedFunctionBlock(newFb);
capturePacketsPublisher.subscribe(newFb.getPropertyValue("DeviceId"), newFb.as<IAsamCmpPacketsSubscriber>(true));
++captureModuleId;
}
Expand Down Expand Up @@ -100,4 +102,22 @@ void DataSinkFb::initProperties()
objPtr.asPtr<IPropertyObjectProtected>().setProtectedPropertyValue(propName, proc);
}

DictPtr<IString, IFunctionBlockType> DataSinkFb::onGetAvailableFunctionBlockTypes()
{
auto type = CaptureFb::CreateType();
return Dict<IString, IFunctionBlockType>({{type.getId(), type}});
}

FunctionBlockPtr DataSinkFb::onAddFunctionBlock(const StringPtr& typeId, const PropertyObjectPtr& config)
{
if (typeId == CaptureFb::CreateType().getId())
{
addCaptureModuleEmpty();
auto captureFb = this->functionBlocks.getItems().getItemAt(this->functionBlocks.getItems().getCount() - 1);
return captureFb;
}

throw NotFoundException("Function block not found");
}

END_NAMESPACE_ASAM_CMP_DATA_SINK_MODULE

0 comments on commit 45eb97d

Please sign in to comment.