diff --git a/communication/decoder.cpp b/communication/decoder.cpp index 9acb502..793eba5 100644 --- a/communication/decoder.cpp +++ b/communication/decoder.cpp @@ -159,6 +159,7 @@ bool Decoder::decode(std::shared_ptr& result, const std::shared_ptr(result.get()); msg.network = packet->network; + msg.timestamp *= timestampResolution; return true; } case Network::Type::LIN: { diff --git a/communication/packet/a2bpacket.cpp b/communication/packet/a2bpacket.cpp index 032c2eb..a72bda1 100644 --- a/communication/packet/a2bpacket.cpp +++ b/communication/packet/a2bpacket.cpp @@ -4,20 +4,18 @@ namespace icsneo { -const size_t HardwareA2BPacket::coreMiniMessageHeaderSize = 28; -const size_t HardwareA2BPacket::a2bMessageMaxLength = (size_t)HardwareA2BPacket::coreMiniMessageHeaderSize + 1024; -const size_t HardwareA2BPacket::a2bHeaderSize = 6; +const size_t HardwareA2BPacket::a2bMessageMaxLength = sizeof(HardwareA2BPacket) + 1024; std::shared_ptr HardwareA2BPacket::DecodeToMessage(const std::vector& bytestream) { - if(bytestream.size() < coreMiniMessageHeaderSize) + if(bytestream.size() < sizeof(HardwareA2BPacket)) { return nullptr; } - const HardwareA2BPacket *data = (const HardwareA2BPacket*)bytestream.data(); + const HardwareA2BPacket* data = (const HardwareA2BPacket*)bytestream.data(); - size_t totalPackedLength = static_cast(bytestream.size()) - static_cast(coreMiniMessageHeaderSize); // First 28 bytes are message header. + size_t totalPackedLength = static_cast(bytestream.size()) - sizeof(HardwareA2BPacket); // First 28 bytes are message header. std::shared_ptr msg = std::make_shared( (uint8_t)data->header.channelNum, @@ -30,7 +28,8 @@ std::shared_ptr HardwareA2BPacket::DecodeToMessage(const std::vectorsetErrIndicatorBit(data->header.errIndicator); msg->setSyncFrameBit(data->header.syncFrame); msg->setRFU2(data->header.rfu2); - msg->setAudioBuffer(bytestream.begin() + coreMiniMessageHeaderSize, bytestream.end()); + msg->timestamp = data->timestamp.TS; + msg->setAudioBuffer(bytestream.begin() + sizeof(HardwareA2BPacket), bytestream.end()); return msg; } diff --git a/include/icsneo/communication/packet/a2bpacket.h b/include/icsneo/communication/packet/a2bpacket.h index e18391a..a2e1b09 100644 --- a/include/icsneo/communication/packet/a2bpacket.h +++ b/include/icsneo/communication/packet/a2bpacket.h @@ -13,6 +13,9 @@ namespace icsneo { typedef uint16_t icscm_bitfield; + + +#pragma pack(push, 2) struct HardwareA2BPacket { static std::shared_ptr DecodeToMessage(const std::vector& bytestream); @@ -33,12 +36,21 @@ struct HardwareA2BPacket { icscm_bitfield : 11; icscm_bitfield rfu2; } header; + uint8_t offset[8]; + uint16_t stats; + struct { + uint64_t TS : 60; + uint64_t : 3; // Reserved for future status bits + uint64_t IsExtended : 1; + } timestamp; + uint16_t networkID; + uint16_t length; - static const size_t coreMiniMessageHeaderSize; static const size_t a2bMessageMaxLength; - static const size_t a2bHeaderSize; }; +#pragma pack(pop) + } #endif // __cplusplus