diff --git a/asam_cmp_capture_module/include/asam_cmp_capture_module/stream_fb.h b/asam_cmp_capture_module/include/asam_cmp_capture_module/stream_fb.h index 07a316b..c54e0d9 100644 --- a/asam_cmp_capture_module/include/asam_cmp_capture_module/stream_fb.h +++ b/asam_cmp_capture_module/include/asam_cmp_capture_module/stream_fb.h @@ -16,13 +16,13 @@ #pragma once #include +#include #include #include #include #include #include #include -#include #include #include @@ -75,8 +75,8 @@ class StreamFb final : public asam_cmp_common_lib::StreamCommonFb void configure(); void processDataPacket(const DataPacketPtr& packet); + template void processCanPacket(const DataPacketPtr& packet); - void processCanFdPacket(const DataPacketPtr& packet); void processAnalogPacket(const DataPacketPtr& packet); void processEventPacket(const EventPacketPtr& packet); diff --git a/asam_cmp_capture_module/src/stream_fb.cpp b/asam_cmp_capture_module/src/stream_fb.cpp index f4de6ee..0488e85 100644 --- a/asam_cmp_capture_module/src/stream_fb.cpp +++ b/asam_cmp_capture_module/src/stream_fb.cpp @@ -319,8 +319,16 @@ ASAM::CMP::DataContext StreamFb::createEncoderDataContext() const return {minFrameSize, maxFrameSize}; } +template +constexpr size_t maxCanDataSize = 64; +template <> +constexpr size_t maxCanDataSize = 8; + +template void StreamFb::processCanPacket(const DataPacketPtr& packet) { + static_assert(std::is_base_of_v); + #pragma pack(push, 1) struct CANData { @@ -345,9 +353,9 @@ void StreamFb::processCanPacket(const DataPacketPtr& packet) for (size_t i = 0; i < sampleCount; i++) { - if (canData->length <= 8) + if (canData->length <= maxCanDataSize) { - ASAM::CMP::CanPayload payload; + CanPayloadType payload{}; payload.setData(canData->data, canData->length); payload.setId(canData->arbId); @@ -364,46 +372,6 @@ void StreamFb::processCanPacket(const DataPacketPtr& packet) ethernetWrapper->sendPacket(rawFrame); } -void StreamFb::processCanFdPacket(const DataPacketPtr& packet) -{ -#pragma pack(push, 1) - struct CANData - { - uint32_t arbId; - uint8_t length; - uint8_t data[64]; - }; -#pragma pack(pop) - - auto* canData = reinterpret_cast(packet.getData()); - const size_t sampleCount = packet.getSampleCount(); - - uint64_t* rawTimeBuffer = reinterpret_cast(packet.getDomainPacket().getRawData()); - RatioPtr timeResolution = packet.getDomainPacket().getDataDescriptor().getTickResolution(); - size_t timeScale = 1'000'000'000 / timeResolution.getDenominator(); - - std::vector packets; - packets.reserve(sampleCount); - - for (size_t i = 0; i < sampleCount; i++) - { - ASAM::CMP::CanFdPayload payload; - payload.setData(canData->data, canData->length); - payload.setId(canData->arbId); - - packets.emplace_back(); - packets.back().setInterfaceId(interfaceId); - packets.back().setPayload(payload); - packets.back().setTimestamp((*rawTimeBuffer) * timeScale); - - canData++; - rawTimeBuffer++; - } - - for (auto& rawFrame : encoders->encode(streamId, packets.begin(), packets.end(), dataContext)) - ethernetWrapper->sendPacket(rawFrame); -} - template void createAnalogPayloadWithInternalScaling(ASAM::CMP::AnalogPayload& payload, const daq::DataPacketPtr& packet, @@ -505,10 +473,10 @@ void StreamFb::processDataPacket(const DataPacketPtr& packet) switch (payloadType.getType()) { case ASAM::CMP::PayloadType::can: - processCanPacket(packet); + processCanPacket(packet); break; case ASAM::CMP::PayloadType::canFd: - processCanFdPacket(packet); + processCanPacket(packet); break; case ASAM::CMP::PayloadType::analog: processAnalogPacket(packet);