diff --git a/bindings/python/icsneopy/communication/message/ethernetmessage.cpp b/bindings/python/icsneopy/communication/message/ethernetmessage.cpp index 87a9cc6..5904309 100644 --- a/bindings/python/icsneopy/communication/message/ethernetmessage.cpp +++ b/bindings/python/icsneopy/communication/message/ethernetmessage.cpp @@ -15,7 +15,7 @@ void init_ethernetmessage(pybind11::module_& m) { .def(pybind11::init()) .def_readwrite("preemptionEnabled", &EthernetMessage::preemptionEnabled) .def_readwrite("preemptionFlags", &EthernetMessage::preemptionFlags) - .def_readwrite("fcsAvailable", &EthernetMessage::fcsAvailable) + .def_readwrite("fcs", &EthernetMessage::fcs) .def_readwrite("frameTooShort", &EthernetMessage::frameTooShort) .def_readwrite("noPadding", &EthernetMessage::noPadding) .def("get_destination_mac", &EthernetMessage::getDestinationMAC, pybind11::return_value_policy::reference) diff --git a/communication/message/neomessage.cpp b/communication/message/neomessage.cpp index acaab67..bbab488 100644 --- a/communication/message/neomessage.cpp +++ b/communication/message/neomessage.cpp @@ -51,7 +51,7 @@ neomessage_t icsneo::CreateNeoMessage(const std::shared_ptr message) { eth.status.incompleteFrame = ethmsg->frameTooShort; // TODO Fill in extra status bits //eth.status.xyz = ethmsg->preemptionEnabled; - //eth.status.xyz = ethmsg->fcsAvailable; + //eth.status.xyz = ethmsg->fcs; //eth.status.xyz = ethmsg->noPadding; break; } diff --git a/communication/packet/ethernetpacket.cpp b/communication/packet/ethernetpacket.cpp index e3dd59f..e4209c1 100644 --- a/communication/packet/ethernetpacket.cpp +++ b/communication/packet/ethernetpacket.cpp @@ -16,8 +16,8 @@ std::shared_ptr HardwareEthernetPacket::DecodeToMessage(const s if(packet->Length < 4) return nullptr; - const size_t ethernetFrameSize = packet->Length - (sizeof(uint16_t) * 2); - const size_t bytestreamExpectedSize = sizeof(HardwareEthernetPacket) + ethernetFrameSize; + const size_t fcsSize = packet->header.FCS_AVAIL ? 4 : 0; + const size_t bytestreamExpectedSize = sizeof(HardwareEthernetPacket) + packet->Length; const size_t bytestreamActualSize = bytestream.size(); if(bytestreamActualSize < bytestreamExpectedSize) return nullptr; @@ -36,8 +36,6 @@ std::shared_ptr HardwareEthernetPacket::DecodeToMessage(const s message.preemptionEnabled = packet->header.PREEMPTION_ENABLED; if(message.preemptionEnabled) message.preemptionFlags = (uint8_t)((rawWords[0] & 0x03F8) >> 4); - - message.fcsAvailable = packet->header.FCS_AVAIL; message.frameTooShort = packet->header.RUNT_FRAME; if(message.frameTooShort) @@ -47,11 +45,14 @@ std::shared_ptr HardwareEthernetPacket::DecodeToMessage(const s // Decoder will fix as it has information about the timestampResolution increments message.timestamp = packet->timestamp.TS; - // Network ID is also not set, this will be fixed in the Decoder as well - - const std::vector::const_iterator databegin = bytestream.begin() + (sizeof(HardwareEthernetPacket) - (sizeof(uint16_t) * 2)); - const std::vector::const_iterator dataend = databegin + ethernetFrameSize; + const std::vector::const_iterator databegin = bytestream.begin() + sizeof(HardwareEthernetPacket); + const std::vector::const_iterator dataend = databegin + packet->Length - fcsSize; message.data.insert(message.data.begin(), databegin, dataend); + + if(fcsSize) { + uint32_t& fcs = message.fcs.emplace(); + std::copy(dataend, dataend + fcsSize, (uint8_t*)&fcs); + } return messagePtr; } diff --git a/include/icsneo/communication/message/ethernetmessage.h b/include/icsneo/communication/message/ethernetmessage.h index 3c54975..d71d2d4 100644 --- a/include/icsneo/communication/message/ethernetmessage.h +++ b/include/icsneo/communication/message/ethernetmessage.h @@ -35,7 +35,7 @@ class EthernetMessage : public Frame { public: bool preemptionEnabled = false; uint8_t preemptionFlags = 0; - bool fcsAvailable = false; + std::optional fcs; bool frameTooShort = false; bool noPadding = false; diff --git a/include/icsneo/communication/packet/ethernetpacket.h b/include/icsneo/communication/packet/ethernetpacket.h index 3696fa0..dbe338d 100644 --- a/include/icsneo/communication/packet/ethernetpacket.h +++ b/include/icsneo/communication/packet/ethernetpacket.h @@ -10,6 +10,8 @@ namespace icsneo { +#pragma pack(push, 2) + typedef uint16_t icscm_bitfield; struct HardwareEthernetPacket { @@ -42,6 +44,8 @@ struct HardwareEthernetPacket { uint16_t Length; }; +#pragma pack(pop) + } #endif // __cplusplus