From 45eb97d69d0e530634d8f58aa67977bb8d83b341 Mon Sep 17 00:00:00 2001 From: Aleksandr Kuzin Date: Tue, 19 Nov 2024 11:22:18 +0100 Subject: [PATCH] Add load/save config for fbs --- .../src/capture_module.cpp | 4 +-- .../asam_cmp_common_lib/capture_common_fb.h | 26 +++++++++++++++++-- .../asam_cmp_common_lib/interface_common_fb.h | 5 ++-- .../src/interface_common_fb.cpp | 19 ++++++++++++++ .../include/asam_cmp_data_sink/data_sink_fb.h | 3 +++ asam_cmp_data_sink/src/data_sink_fb.cpp | 24 +++++++++++++++-- 6 files changed, 73 insertions(+), 8 deletions(-) diff --git a/asam_cmp_capture_module/src/capture_module.cpp b/asam_cmp_capture_module/src/capture_module.cpp index 95543a2..4e83f19 100644 --- a/asam_cmp_capture_module/src/capture_module.cpp +++ b/asam_cmp_capture_module/src/capture_module.cpp @@ -18,8 +18,8 @@ DictPtr CaptureModule::onGetAvailableFunctionBlockT { auto types = Dict(); - auto typeStatistics = CaptureModuleFb::CreateType(); - types.set(typeStatistics.getId(), typeStatistics); + auto typeCaptureModule = CaptureModuleFb::CreateType(); + types.set(typeCaptureModule.getId(), typeCaptureModule); return types; } diff --git a/asam_cmp_common_lib/include/asam_cmp_common_lib/capture_common_fb.h b/asam_cmp_common_lib/include/asam_cmp_common_lib/capture_common_fb.h index fcd4900..3561a3c 100644 --- a/asam_cmp_common_lib/include/asam_cmp_common_lib/capture_common_fb.h +++ b/asam_cmp_common_lib/include/asam_cmp_common_lib/capture_common_fb.h @@ -34,6 +34,9 @@ class CaptureCommonFbImpl : public FunctionBlockImpl onGetAvailableFunctionBlockTypes() override; + FunctionBlockPtr onAddFunctionBlock(const StringPtr& typeId, const PropertyObjectPtr& config) override; + protected: void initDeviceInfoProperties(bool readOnly); template @@ -155,9 +158,8 @@ FunctionBlockPtr CaptureCommonFbImpl::addInterfaceWithParams(uint StringPtr fbId = fmt::format("Interface_{}", createdInterfaces++); auto newFb = createWithImplementation(this->context, this->functionBlocks, fbId, init, std::forward(params)...); newFb.setName(fbName); - this->functionBlocks.addItem(newFb); interfaceIdManager.addId(interfaceId); - + addNestedFunctionBlock(newFb); return newFb; } @@ -248,4 +250,24 @@ void CaptureCommonFbImpl::propertyChangedIfNotUpdating() needsPropertyChanged = true; } +template +DictPtr CaptureCommonFbImpl::onGetAvailableFunctionBlockTypes() +{ + auto type = InterfaceCommonFb::CreateType(); + return Dict({{type.getId(), type}}); +} + +template +FunctionBlockPtr CaptureCommonFbImpl::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 diff --git a/asam_cmp_common_lib/include/asam_cmp_common_lib/interface_common_fb.h b/asam_cmp_common_lib/include/asam_cmp_common_lib/interface_common_fb.h index 184292b..f3c40b6 100644 --- a/asam_cmp_common_lib/include/asam_cmp_common_lib/interface_common_fb.h +++ b/asam_cmp_common_lib/include/asam_cmp_common_lib/interface_common_fb.h @@ -44,6 +44,8 @@ class InterfaceCommonFb : public FunctionBlock ~InterfaceCommonFb() override = default; static FunctionBlockTypePtr CreateType(); + DictPtr onGetAvailableFunctionBlockTypes() override; + FunctionBlockPtr onAddFunctionBlock(const StringPtr& typeId, const PropertyObjectPtr& config) override; protected: template FunctionBlockPtr addStreamWithParams(uint8_t streamId, Params&&... params); @@ -94,9 +96,8 @@ FunctionBlockPtr InterfaceCommonFb::addStreamWithParams(uint8_t streamId, Params StringPtr fbId = fmt::format("Stream_{}", createdStreams++); auto newFb = createWithImplementation(context, functionBlocks, fbId, init, std::forward(params)...); newFb.setName(fbName); - functionBlocks.addItem(newFb); streamIdManager.addId(streamId); - + addNestedFunctionBlock(newFb); return newFb; } diff --git a/asam_cmp_common_lib/src/interface_common_fb.cpp b/asam_cmp_common_lib/src/interface_common_fb.cpp index 0586376..604f210 100644 --- a/asam_cmp_common_lib/src/interface_common_fb.cpp +++ b/asam_cmp_common_lib/src/interface_common_fb.cpp @@ -151,4 +151,23 @@ void InterfaceCommonFb::propertyChangedIfNotUpdating() needsPropertyChanged = true; } + +DictPtr InterfaceCommonFb::onGetAvailableFunctionBlockTypes() +{ + auto type = StreamCommonFb::CreateType(); + return Dict({{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 diff --git a/asam_cmp_data_sink/include/asam_cmp_data_sink/data_sink_fb.h b/asam_cmp_data_sink/include/asam_cmp_data_sink/data_sink_fb.h index 692faec..fa02b8b 100644 --- a/asam_cmp_data_sink/include/asam_cmp_data_sink/data_sink_fb.h +++ b/asam_cmp_data_sink/include/asam_cmp_data_sink/data_sink_fb.h @@ -38,6 +38,9 @@ class DataSinkFb final : public FunctionBlock static FunctionBlockTypePtr CreateType(); + DictPtr onGetAvailableFunctionBlockTypes() override; + FunctionBlockPtr onAddFunctionBlock(const StringPtr& typeId, const PropertyObjectPtr& config) override; + private: void initProperties(); void addCaptureModuleFromStatus(int index); diff --git a/asam_cmp_data_sink/src/data_sink_fb.cpp b/asam_cmp_data_sink/src/data_sink_fb.cpp index 1d7313b..d5574ea 100644 --- a/asam_cmp_data_sink/src/data_sink_fb.cpp +++ b/asam_cmp_data_sink/src/data_sink_fb.cpp @@ -33,7 +33,8 @@ void DataSinkFb::addCaptureModuleFromStatus(int index) const StringPtr fbId = getFbId(captureModuleId); const auto newFb = createWithImplementation( context, functionBlocks, fbId, dataPacketsPublisher, capturePacketsPublisher, std::move(deviceStatus)); - functionBlocks.addItem(newFb); + //functionBlocks.addItem(newFb); + addNestedFunctionBlock(newFb); ++captureModuleId; } @@ -44,7 +45,8 @@ void DataSinkFb::addCaptureModuleEmpty() const StringPtr fbId = getFbId(captureModuleId); const auto newFb = createWithImplementation(context, functionBlocks, fbId, dataPacketsPublisher, capturePacketsPublisher); - functionBlocks.addItem(newFb); + //functionBlocks.addItem(newFb); + addNestedFunctionBlock(newFb); capturePacketsPublisher.subscribe(newFb.getPropertyValue("DeviceId"), newFb.as(true)); ++captureModuleId; } @@ -100,4 +102,22 @@ void DataSinkFb::initProperties() objPtr.asPtr().setProtectedPropertyValue(propName, proc); } +DictPtr DataSinkFb::onGetAvailableFunctionBlockTypes() +{ + auto type = CaptureFb::CreateType(); + return Dict({{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