Skip to content
Open
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 @@ -62,6 +62,11 @@ class CaptureFb final : public daq::asam_cmp_common_lib::CaptureCommonFb
void startStatusLoop();
void stopStatusLoop();
ASAM::CMP::DataContext createEncoderDataContext() const;
uint64_t getCurrentSystemTime();
static DevicePtr FindParentDevice(const ComponentPtr& parent);

private:
static constexpr Int NanoTicksPerSec{1000000000};

private:
const bool allowJumboFrames;
Expand All @@ -76,6 +81,7 @@ class CaptureFb final : public daq::asam_cmp_common_lib::CaptureCommonFb
bool stopStatusSending;
std::shared_ptr<asam_cmp_common_lib::EthernetPcppItf> ethernetWrapper;
const StringPtr& selectedEthernetDeviceName;
DevicePtr parentDevice;
};

END_NAMESPACE_ASAM_CMP_CAPTURE_MODULE
41 changes: 34 additions & 7 deletions modules/asam_cmp_capture_module/src/capture_fb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@
#include <asam_cmp/cmp_header.h>
#include <asam_cmp_common_lib/ethernet_pcpp_itf.h>

#include <chrono>

BEGIN_NAMESPACE_ASAM_CMP_CAPTURE_MODULE

CaptureFb::CaptureFb(const ModuleInfoPtr& moduleInfo,
const ContextPtr& ctx,
const ComponentPtr& parent,
const StringPtr& localId,
const CaptureFbInit& init)
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)
, parentDevice(FindParentDevice(parent))
{
initProperties();
initEncoders();
Expand Down Expand Up @@ -103,6 +106,25 @@ ASAM::CMP::DataContext CaptureFb::createEncoderDataContext() const
return {64, 1500};
}

uint64_t CaptureFb::getCurrentSystemTime()
{
if (!parentDevice.assigned())
return std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now().time_since_epoch()).count();

DeviceDomainPtr domain = parentDevice.getDomain();
const auto domainResolution = domain.getTickResolution();
return static_cast<Int>(parentDevice.getTicksSinceOrigin()) * (SimplifiedRatioPtr(domainResolution) * NanoTicksPerSec);
}

DevicePtr CaptureFb::FindParentDevice(const ComponentPtr& parent)
{
auto parentDevice = parent;
while (parentDevice.assigned() && !parentDevice.asPtrOrNull<IDevice>().assigned())
parentDevice = parentDevice.getParent();

return parentDevice;
}

void CaptureFb::statusLoop()
{
auto encoderContext = createEncoderDataContext();
Expand All @@ -112,17 +134,22 @@ void CaptureFb::statusLoop()
cv.wait_for(lock, std::chrono::milliseconds(sendingSyncLoopTime));
if (!stopStatusSending)
{
auto encodeAndSend = [&](const ASAM::CMP::Packet& packet) {
auto time = getCurrentSystemTime();
auto encodeAndSend = [&](ASAM::CMP::Packet& packet, uint64_t time) {
packet.setTimestamp(time);
auto encodedData = encoders.encode(1, packet, encoderContext);
for (const auto& e : encodedData)
ethernetWrapper->sendPacket(e);
};


encodeAndSend(captureStatus.getPacket());
encodeAndSend(captureStatus.getPacket(), time);


for (SizeT i = 0; i < captureStatus.getInterfaceStatusCount(); ++i)
{
encodeAndSend(captureStatus.getInterfaceStatus(i).getPacket());
auto packet = captureStatus.getInterfaceStatus(i).getPacket();
encodeAndSend(packet, time);
}
}
}
Expand Down
Loading