Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add load/save config for fbs #48

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);

this->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);

this->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
22 changes: 20 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,7 @@ 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);
this->addNestedFunctionBlock(newFb);
++captureModuleId;
}

Expand All @@ -44,7 +44,7 @@ void DataSinkFb::addCaptureModuleEmpty()
const StringPtr fbId = getFbId(captureModuleId);
const auto newFb =
createWithImplementation<IFunctionBlock, CaptureFb>(context, functionBlocks, fbId, dataPacketsPublisher, capturePacketsPublisher);
functionBlocks.addItem(newFb);
this->addNestedFunctionBlock(newFb);
capturePacketsPublisher.subscribe(newFb.getPropertyValue("DeviceId"), newFb.as<IAsamCmpPacketsSubscriber>(true));
++captureModuleId;
}
Expand Down Expand Up @@ -100,4 +100,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
14 changes: 14 additions & 0 deletions asam_cmp_data_sink/tests/test_capture_fb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ TEST_F(CaptureFbTest, FunctionBlockType)
ASSERT_EQ(type.getDescription(), "ASAM CMP Capture");
}

TEST_F(CaptureFbTest, AvailableFunctionBlockTypes)
{
auto availableTypes = captureFb.getAvailableFunctionBlockTypes();
ASSERT_EQ(availableTypes.getCount(), 1);
ASSERT_TRUE(availableTypes.hasKey("AsamCmpInterface"));
ASSERT_EQ(availableTypes.get("AsamCmpInterface"), asam_cmp_common_lib::InterfaceCommonFb::CreateType());
}

TEST_F(CaptureFbTest, OnAddFunctionBlocks)
{
EXPECT_NO_THROW(captureFb.addFunctionBlock("AsamCmpInterface"));
EXPECT_THROW(captureFb.addFunctionBlock("AsamCmpStream"), daq::NotFoundException);
}

TEST_F(CaptureFbTest, CaptureModuleProperties)
{
ASSERT_TRUE(captureFb.hasProperty("DeviceId"));
Expand Down
15 changes: 15 additions & 0 deletions asam_cmp_data_sink/tests/test_data_sink_fb.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <asam_cmp_data_sink/data_sink_fb.h>
#include <asam_cmp_data_sink/status_fb_impl.h>
#include <asam_cmp_data_sink/status_handler.h>
#include <asam_cmp_data_sink/capture_fb.h>

#include <asam_cmp/capture_module_payload.h>
#include <asam_cmp/interface_payload.h>
Expand Down Expand Up @@ -81,6 +82,20 @@ TEST_F(DataSinkFbTest, FunctionBlockType)
ASSERT_EQ(type.getDescription(), "ASAM CMP Data Sink");
}

TEST_F(DataSinkFbTest, AvailableFunctionBlockTypes)
{
auto availableTypes = funcBlock.getAvailableFunctionBlockTypes();
ASSERT_EQ(availableTypes.getCount(), 1);
ASSERT_TRUE(availableTypes.hasKey("AsamCmpCapture"));
ASSERT_EQ(availableTypes.get("AsamCmpCapture"), CaptureFb::CreateType());
}

TEST_F(DataSinkFbTest, OnAddFunctionBlocks)
{
EXPECT_NO_THROW(funcBlock.addFunctionBlock("AsamCmpCapture"));
EXPECT_THROW(funcBlock.addFunctionBlock("AsamCmpStream"), daq::NotFoundException);
}

TEST_F(DataSinkFbTest, AddCaptureModuleFromStatusReadOnly)
{
auto proc = daq::Procedure([]() {});
Expand Down
15 changes: 15 additions & 0 deletions asam_cmp_data_sink/tests/test_interface_fb.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <asam_cmp_data_sink/capture_fb.h>
#include <asam_cmp_data_sink/stream_fb.h>
#include <asam_cmp_data_sink/common.h>

#include <gtest/gtest.h>
Expand Down Expand Up @@ -45,6 +46,20 @@ TEST_F(InterfaceFbTest, FunctionBlockType)
ASSERT_EQ(type.getDescription(), "ASAM CMP Interface");
}

TEST_F(InterfaceFbTest, AvailableFunctionBlockTypes)
{
auto availableTypes = interfaceFb.getAvailableFunctionBlockTypes();
ASSERT_EQ(availableTypes.getCount(), 1);
ASSERT_TRUE(availableTypes.hasKey("AsamCmpStream"));
ASSERT_EQ(availableTypes.get("AsamCmpStream"), modules::asam_cmp_data_sink_module::StreamFb::CreateType());
}

TEST_F(InterfaceFbTest, OnAddFunctionBlocks)
{
EXPECT_NO_THROW(interfaceFb.addFunctionBlock("AsamCmpStream"));
EXPECT_THROW(interfaceFb.addFunctionBlock("AsamCmpCapture"), daq::NotFoundException);
}

TEST_F(InterfaceFbTest, CaptureModuleProperties)
{
ASSERT_TRUE(interfaceFb.hasProperty("InterfaceId"));
Expand Down