Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ struct CaptureFbInit
class CaptureFb final : public daq::asam_cmp_common_lib::CaptureCommonFb
{
public:
explicit CaptureFb(const ContextPtr& ctx, const ComponentPtr& parent, const StringPtr& localId, const CaptureFbInit& init);
explicit CaptureFb(const ModuleInfoPtr& moduleInfo,
const ContextPtr & ctx,
const ComponentPtr& parent,
const StringPtr& localId,
const CaptureFbInit& init);
~CaptureFb() override;

static FunctionBlockTypePtr CreateType();

private:
void initProperties();
void initEncoders();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,18 @@ BEGIN_NAMESPACE_ASAM_CMP_CAPTURE_MODULE
class CaptureModuleFb final : public asam_cmp_common_lib::NetworkManagerFb
{
public:
explicit CaptureModuleFb(const ContextPtr& ctx, const ComponentPtr& parent, const StringPtr& localId, const std::shared_ptr<asam_cmp_common_lib::EthernetPcppItf>& ethernetWrapper);
explicit CaptureModuleFb(const ModuleInfoPtr& moduleInfo,
const ContextPtr& ctx,
const ComponentPtr& parent,
const StringPtr& localId,
const std::shared_ptr<asam_cmp_common_lib::EthernetPcppItf>& ethernetWrapper);
~CaptureModuleFb() override = default;

static FunctionBlockTypePtr CreateType();
static FunctionBlockPtr create(const ContextPtr& ctx, const ComponentPtr& parent, const StringPtr& localId);
static FunctionBlockTypePtr CreateType(const ModuleInfoPtr& moduleInfo);
static FunctionBlockPtr create(const ModuleInfoPtr& moduleInfo,
const ContextPtr& ctx,
const ComponentPtr& parent,
const StringPtr& localId);

private:
void createFbs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ struct InterfaceFbInit
class InterfaceFb final : public asam_cmp_common_lib::InterfaceCommonFb
{
public:
explicit InterfaceFb(const ContextPtr& ctx,
const ComponentPtr& parent,
const StringPtr& localId,
const asam_cmp_common_lib::InterfaceCommonInit& commonInit,
const InterfaceFbInit& internalInit);
explicit InterfaceFb(const ModuleInfoPtr& modulenifo,
const ContextPtr& ctx,
const ComponentPtr& parent,
const StringPtr& localId,
const asam_cmp_common_lib::InterfaceCommonInit& commonInit,
const InterfaceFbInit& internalInit);
~InterfaceFb() override = default;
static FunctionBlockTypePtr CreateType();

private:
void initProperties();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ struct StreamInit
class StreamFb final : public asam_cmp_common_lib::StreamCommonFb
{
public:
explicit StreamFb(const ContextPtr& ctx,
explicit StreamFb(const ModuleInfoPtr& moduleInfo,
const ContextPtr& ctx,
const ComponentPtr& parent,
const StringPtr& localId,
const asam_cmp_common_lib::StreamCommonInit& init,
Expand Down
12 changes: 10 additions & 2 deletions asam_cmp_capture_module/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ project(asam_cmp_capture_module

set(LIB_NAME asam_cmp_capture_module)

set(SRC_Cpp module_dll.cpp
set(SRC_Cpp
module_dll.cpp
capture_module_fb.cpp
capture_module.cpp
interface_fb.cpp
Expand All @@ -14,7 +15,8 @@ set(SRC_Cpp module_dll.cpp
encoder_bank.cpp
)

set(SRC_PublicHeaders module_dll.h
set(SRC_PublicHeaders
module_dll.h
capture_module_fb.h
capture_module.h
interface_fb.h
Expand All @@ -28,6 +30,12 @@ set(SRC_PrivateHeaders
dispatch.h
)

source_group("module" FILES
${SRC_Cpp}
${SRC_PublicHeaders}
${SRC_PrivateHeaders}
)

if (MSVC)
add_compile_options(/bigobj)
endif()
Expand Down
8 changes: 6 additions & 2 deletions asam_cmp_capture_module/src/capture_fb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@

BEGIN_NAMESPACE_ASAM_CMP_CAPTURE_MODULE

CaptureFb::CaptureFb(const ContextPtr& ctx, const ComponentPtr& parent, const StringPtr& localId, const CaptureFbInit& init)
: asam_cmp_common_lib::CaptureCommonFb(ctx, parent, localId)
CaptureFb::CaptureFb(const ModuleInfoPtr& moduleInfo,
const ContextPtr& ctx,
const ComponentPtr& parent,
const StringPtr& localId,
const CaptureFbInit& init)
: asam_cmp_common_lib::CaptureCommonFb(moduleInfo, ctx, parent, localId)
, allowJumboFrames(false)
, ethernetWrapper(init.ethernetWrapper)
, selectedEthernetDeviceName(init.selectedDeviceName)
Expand Down
6 changes: 3 additions & 3 deletions asam_cmp_capture_module/src/capture_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ DictPtr<IString, IFunctionBlockType> CaptureModule::onGetAvailableFunctionBlockT
{
auto types = Dict<IString, IFunctionBlockType>();

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

return types;
Expand All @@ -29,9 +29,9 @@ FunctionBlockPtr CaptureModule::onCreateFunctionBlock(const StringPtr& id,
const StringPtr& localId,
const PropertyObjectPtr& config)
{
if (id == CaptureModuleFb::CreateType().getId())
if (id == CaptureModuleFb::CreateType(moduleInfo).getId())
{
FunctionBlockPtr fb = CaptureModuleFb::create(context, parent, localId);
FunctionBlockPtr fb = CaptureModuleFb::create(moduleInfo,context, parent, localId);
return fb;
}

Expand Down
19 changes: 12 additions & 7 deletions asam_cmp_capture_module/src/capture_module_fb.cpp
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
#include <opendaq/component_type_private.h>

#include <asam_cmp_capture_module/capture_fb.h>
#include <asam_cmp_capture_module/capture_module_fb.h>
#include <asam_cmp_common_lib/ethernet_pcpp_impl.h>

BEGIN_NAMESPACE_ASAM_CMP_CAPTURE_MODULE

CaptureModuleFb::CaptureModuleFb(const ContextPtr& ctx, const ComponentPtr& parent, const StringPtr& localId, const std::shared_ptr<asam_cmp_common_lib::EthernetPcppItf>& ethernetWrapper)
: NetworkManagerFb(CreateType(), ctx, parent, localId, ethernetWrapper)
CaptureModuleFb::CaptureModuleFb(const ModuleInfoPtr& moduleInfo,const ContextPtr& ctx, const ComponentPtr& parent, const StringPtr& localId, const std::shared_ptr<asam_cmp_common_lib::EthernetPcppItf>& ethernetWrapper)
: NetworkManagerFb(CreateType(moduleInfo), ctx, parent, localId, ethernetWrapper)
{
createFbs();
}

FunctionBlockPtr CaptureModuleFb::create(const ContextPtr& ctx, const ComponentPtr& parent, const StringPtr& localId)
FunctionBlockPtr CaptureModuleFb::create(const ModuleInfoPtr& moduleInfo, const ContextPtr& ctx, const ComponentPtr& parent, const StringPtr& localId)
{
std::shared_ptr<asam_cmp_common_lib::EthernetPcppItf> ptr = std::make_shared<asam_cmp_common_lib::EthernetPcppImpl>();
auto fb = createWithImplementation<IFunctionBlock, CaptureModuleFb>(ctx, parent, localId, ptr);
auto fb = createWithImplementation<IFunctionBlock, CaptureModuleFb>(moduleInfo, ctx, parent, localId, ptr);
return fb;
}

FunctionBlockTypePtr CaptureModuleFb::CreateType()
FunctionBlockTypePtr CaptureModuleFb::CreateType(const ModuleInfoPtr& moduleInfo)
{
return FunctionBlockType("AsamCmpCaptureModule", "AsamCmpCaptureModule", "ASAM CMP Capture Module");
auto fbType = FunctionBlockType("AsamCmpCaptureModule", "AsamCmpCaptureModule", "ASAM CMP Capture Module");

checkErrorInfo(fbType.asPtr<IComponentTypePrivate>(true)->setModuleInfo(moduleInfo));
return fbType;
}

void CaptureModuleFb::createFbs()
{
const StringPtr captureModuleId = "Capture";
CaptureFbInit init{ethernetWrapper, selectedEthernetDeviceName};
auto newFb = createWithImplementation<IFunctionBlock, CaptureFb>(
context, functionBlocks, captureModuleId, init);
this->type.getModuleInfo(), context, functionBlocks, captureModuleId, init);
newFb.setName("Capture");
functionBlocks.addItem(newFb);
}
Expand Down
5 changes: 3 additions & 2 deletions asam_cmp_capture_module/src/interface_fb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@

BEGIN_NAMESPACE_ASAM_CMP_CAPTURE_MODULE

InterfaceFb::InterfaceFb(const ContextPtr& ctx,
InterfaceFb::InterfaceFb(const ModuleInfoPtr& moduleInfo,
const ContextPtr& ctx,
const ComponentPtr& parent,
const StringPtr& localId,
const asam_cmp_common_lib::InterfaceCommonInit& init,
const InterfaceFbInit& internalInit)
: InterfaceCommonFb(ctx, parent, localId, init)
: InterfaceCommonFb(moduleInfo, ctx, parent, localId, init)
, statusSync(internalInit.statusSync)
, encoders(internalInit.encoders)
, deviceStatus(internalInit.deviceStatus)
Expand Down
5 changes: 3 additions & 2 deletions asam_cmp_capture_module/src/stream_fb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ constexpr std::string_view InputInvalid{"Invalid"};
constexpr std::string_view IsClientScaling{"$IsConnectedAnalogSignal == true && $IsClientPostScaling == false"};
constexpr std::string_view IsClientRange{"$IsConnectedAnalogSignal == true && $IsClientPostScaling == true"};

StreamFb::StreamFb(const ContextPtr& ctx,
StreamFb::StreamFb(const ModuleInfoPtr& moduleInfo,
const ContextPtr& ctx,
const ComponentPtr& parent,
const StringPtr& localId,
const asam_cmp_common_lib::StreamCommonInit& init,
const StreamInit& internalInit)
: asam_cmp_common_lib::StreamCommonFb(ctx, parent, localId, init)
: asam_cmp_common_lib::StreamCommonFb(moduleInfo, ctx, parent, localId, init)
, interfaceId(internalInit.interfaceId)
, streamIdsList(internalInit.streamIdsList)
, statusSync(internalInit.statusSync)
Expand Down
1 change: 1 addition & 0 deletions asam_cmp_capture_module/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
set(TEST_APP test_capture_module)

set(TEST_SOURCES
test_capture_module_fb.cpp
test_interface.cpp
test_stream.cpp
test_capture_fb.cpp
Expand Down
5 changes: 3 additions & 2 deletions asam_cmp_capture_module/tests/test_analog_messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class AnalogMessagesTest : public testing::Test
const StringPtr captureModuleId = "asam_cmp_capture_fb";
selectedDevice = "device1";
modules::asam_cmp_capture_module::CaptureFbInit init = {ethernetWrapper, selectedDevice};
captureFb =
createWithImplementation<IFunctionBlock, modules::asam_cmp_capture_module::CaptureFb>(context, nullptr, captureModuleId, init);
captureFb = createWithImplementation<IFunctionBlock, modules::asam_cmp_capture_module::CaptureFb>(
moduleInfo, context, nullptr, captureModuleId, init);

ProcedurePtr createProc = captureFb.getPropertyValue("AddInterface");
createProc();
Expand Down Expand Up @@ -86,6 +86,7 @@ class AnalogMessagesTest : public testing::Test
StringPtr selectedDevice;

ContextPtr context;
ModuleInfoPtr moduleInfo;
FunctionBlockPtr captureFb;
FunctionBlockPtr interfaceFb;

Expand Down
6 changes: 3 additions & 3 deletions asam_cmp_capture_module/tests/test_capture_fb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ class CaptureFbTest : public testing::Test
const StringPtr captureModuleId = "asam_cmp_capture_fb";
selectedDevice = "device1";
modules::asam_cmp_capture_module::CaptureFbInit init = {ethernetWrapper, selectedDevice};
captureFb =
createWithImplementation<IFunctionBlock, modules::asam_cmp_capture_module::CaptureFb>(
context, nullptr, captureModuleId, init);
captureFb = createWithImplementation<IFunctionBlock, modules::asam_cmp_capture_module::CaptureFb>(
moduleInfo, context, nullptr, captureModuleId, init);
}

protected:
Expand All @@ -52,6 +51,7 @@ class CaptureFbTest : public testing::Test

StringPtr selectedDevice;
ContextPtr context;
ModuleInfoPtr moduleInfo;
FunctionBlockPtr captureFb;

std::mutex packedReceivedSync;
Expand Down
63 changes: 63 additions & 0 deletions asam_cmp_capture_module/tests/test_capture_module.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include <opendaq/context_factory.h>
#include <opendaq/scheduler_factory.h>
#include <opendaq/module_ptr.h>
#include <gtest/gtest.h>

#include <asam_cmp_common_lib/ethernet_pcpp_mock.h>

#include <asam_cmp_capture_module/capture_module.h>
#include <asam_cmp_capture_module/capture_module_fb.h>
#include <asam_cmp_capture_module/version.h>


using namespace daq;
using namespace testing;
using namespace daq::modules::asam_cmp_capture_module;

class CaptureModuleFbTest : public::testing::Test
{
protected:
CaptureModuleFbTest()
: logger(Logger())
, context(Context(Scheduler(logger), logger, nullptr, nullptr))
, moduleInfo(ModuleInfo(VersionInfo(1,2,3), "", ""))
, names(List<IString>())
, descriptions(List<IString>())
, ethernetWrapper(std::make_shared<asam_cmp_common_lib::EthernetPcppMock>())
{
auto startStub = []() {};
auto stopStub = []() {};

ON_CALL(*ethernetWrapper, startCapture(_)).WillByDefault(startStub);
ON_CALL(*ethernetWrapper, stopCapture()).WillByDefault(stopStub);
ON_CALL(*ethernetWrapper, getEthernetDevicesNamesList()).WillByDefault(Return(names));
ON_CALL(*ethernetWrapper, getEthernetDevicesDescriptionsList()).WillByDefault(Return(descriptions));
ON_CALL(*ethernetWrapper, sendPacket(_))
.WillByDefault(WithArgs<0>(Invoke(
[&](const std::vector<uint8_t>& data) { }
)));

captureModuleFb = createWithImplementation<IFunctionBlock, CaptureModuleFb>(moduleInfo, context, nullptr, "dummy_id", ethernetWrapper);
}

protected:
LoggerPtr logger;
ContextPtr context;
ModuleInfoPtr moduleInfo;

ListPtr<StringPtr> names;
ListPtr<StringPtr> descriptions;
std::shared_ptr<asam_cmp_common_lib::EthernetPcppMock> ethernetWrapper;

FunctionBlockPtr captureModuleFb;
};

TEST_F(CaptureModuleFbTest, VersionScaling)
{
ASSERT_EQ(captureModuleFb.getFunctionBlockType().getModuleInfo().getVersionInfo(), moduleInfo.getVersionInfo());

auto captureFb = captureModuleFb.getFunctionBlocks().getItemAt(0);

ASSERT_EQ(captureFb.getFunctionBlockType().getModuleInfo().getVersionInfo(), moduleInfo.getVersionInfo());
}

71 changes: 71 additions & 0 deletions asam_cmp_capture_module/tests/test_capture_module_fb.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include <opendaq/context_factory.h>
#include <opendaq/scheduler_factory.h>
#include <opendaq/module_info_factory.h>
#include <gtest/gtest.h>

#include <asam_cmp_common_lib/ethernet_pcpp_mock.h>

#include <asam_cmp_capture_module/capture_module.h>
#include <asam_cmp_capture_module/capture_module_fb.h>
#include <asam_cmp_capture_module/version.h>


using namespace daq;
using namespace testing;
using namespace daq::modules::asam_cmp_capture_module;

class CaptureModuleFbTest : public::testing::Test
{
protected:
CaptureModuleFbTest()
: logger(Logger())
, context(Context(Scheduler(logger), logger, nullptr, nullptr))
, moduleInfo(ModuleInfo(VersionInfo(1,2,3), "", ""))
, names(List<IString>())
, descriptions(List<IString>())
, ethernetWrapper(std::make_shared<asam_cmp_common_lib::EthernetPcppMock>())
{
names.pushBack("DummyName");
descriptions.pushBack("DummyDescription");
auto startStub = []() {};
auto stopStub = []() {};

EXPECT_CALL(*ethernetWrapper, setDevice(_)).WillRepeatedly(Return(true));
EXPECT_CALL(*ethernetWrapper, startCapture(_)).WillRepeatedly(startStub);
EXPECT_CALL(*ethernetWrapper, stopCapture()).WillRepeatedly(stopStub);
EXPECT_CALL(*ethernetWrapper, getEthernetDevicesNamesList()).WillRepeatedly(Return(names));
EXPECT_CALL(*ethernetWrapper, getEthernetDevicesDescriptionsList()).WillRepeatedly(Return(descriptions));
EXPECT_CALL(*ethernetWrapper, sendPacket(_))
.WillRepeatedly(WithArgs<0>(Invoke(
[&](const std::vector<uint8_t>& data) { }
)));

captureModuleFb = createWithImplementation<IFunctionBlock, CaptureModuleFb>(moduleInfo, context, nullptr, "dummy_id", ethernetWrapper);
}

protected:
LoggerPtr logger;
ContextPtr context;
ModuleInfoPtr moduleInfo;

ListPtr<StringPtr> names;
ListPtr<StringPtr> descriptions;
std::shared_ptr<asam_cmp_common_lib::EthernetPcppMock> ethernetWrapper;

FunctionBlockPtr captureModuleFb;
};

TEST_F(CaptureModuleFbTest, VersionScaling)
{
ASSERT_EQ(captureModuleFb.getFunctionBlockType().getModuleInfo().getVersionInfo(), moduleInfo.getVersionInfo());

auto captureFb = captureModuleFb.getFunctionBlocks().getItemAt(0);
ASSERT_EQ(captureFb.getFunctionBlockType().getModuleInfo().getVersionInfo(), moduleInfo.getVersionInfo());

auto itfFB = captureFb.addFunctionBlock("AsamCmpInterface");
ASSERT_EQ(itfFB.getFunctionBlockType().getModuleInfo().getVersionInfo(), moduleInfo.getVersionInfo());

auto streamFb = itfFB.addFunctionBlock("AsamCmpStream");
ASSERT_EQ(itfFB.getFunctionBlockType().getModuleInfo().getVersionInfo(), moduleInfo.getVersionInfo());
}

Loading
Loading