From ffbb5e20c5bf858d84285b283888d6f23c5dffa5 Mon Sep 17 00:00:00 2001 From: Kyle Schwarz Date: Fri, 13 Nov 2020 16:15:04 -0500 Subject: [PATCH] Add description field for messages Closes https://github.com/intrepidcs/libicsneo/issues/28 --- api/icsneolegacy/icsneolegacy.cpp | 2 ++ communication/message/neomessage.cpp | 3 +++ include/icsneo/communication/message/neomessage.h | 11 ++++++++--- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/api/icsneolegacy/icsneolegacy.cpp b/api/icsneolegacy/icsneolegacy.cpp index 5ac676e..041556c 100644 --- a/api/icsneolegacy/icsneolegacy.cpp +++ b/api/icsneolegacy/icsneolegacy.cpp @@ -46,6 +46,7 @@ static void NeoMessageToSpyMessage(const neodevice_t* device, const neomessage_t memcpy(oldmsg.Data, newmsg.data, std::min(newmsg.length, (size_t)8)); oldmsg.ArbIDOrHeader = *(uint32_t*)newmsg.header; oldmsg.NetworkID = (uint8_t)newmsg.netid; // Note: NetID remapping from the original API is not supported + oldmsg.DescriptionID = newmsg.description; oldmsg.StatusBitField = newmsg.status.statusBitfield[0]; oldmsg.StatusBitField2 = newmsg.status.statusBitfield[1]; oldmsg.StatusBitField3 = newmsg.status.statusBitfield[2]; @@ -221,6 +222,7 @@ int icsneoTxMessagesEx(void* hObject, icsSpyMessage* pMsg, unsigned int lNetwork const icsSpyMessage& oldmsg = pMsg[i]; newmsg = {}; newmsg.netid = (uint16_t)lNetworkID; + newmsg.description = oldmsg.DescriptionID; memcpy(newmsg.header, &oldmsg.ArbIDOrHeader, sizeof(newmsg.header)); newmsg.length = oldmsg.NumberBytesData | (oldmsg.NodeID << 8); if (oldmsg.ExtraDataPtr != nullptr) diff --git a/communication/message/neomessage.cpp b/communication/message/neomessage.cpp index 487fb3c..3262e26 100644 --- a/communication/message/neomessage.cpp +++ b/communication/message/neomessage.cpp @@ -11,6 +11,7 @@ neomessage_t icsneo::CreateNeoMessage(const std::shared_ptr message) { neomessage_t neomsg = {}; // Clear out the memory neomsg.netid = (uint32_t)message->network.getNetID(); neomsg.type = (uint8_t)type; + neomsg.description = message->description; neomsg.length = message->data.size(); neomsg.data = message->data.data(); neomsg.timestamp = message->timestamp; @@ -61,6 +62,7 @@ std::shared_ptr icsneo::CreateMessageFromNeoMessage(const neomessage_t* neomessage_can_t& can = *(neomessage_can_t*)neomessage; auto canmsg = std::make_shared(); canmsg->network = network; + canmsg->description = can.description; canmsg->data.insert(canmsg->data.end(), can.data, can.data + can.length); canmsg->arbid = can.arbid; canmsg->isExtended = can.status.extendedFrame; @@ -74,6 +76,7 @@ std::shared_ptr icsneo::CreateMessageFromNeoMessage(const neomessage_t* neomessage_eth_t& eth = *(neomessage_eth_t*)neomessage; auto ethmsg = std::make_shared(); ethmsg->network = network; + ethmsg->description = eth.description; ethmsg->data.insert(ethmsg->data.end(), eth.data, eth.data + eth.length); return ethmsg; } diff --git a/include/icsneo/communication/message/neomessage.h b/include/icsneo/communication/message/neomessage.h index 28892c1..f23884f 100644 --- a/include/icsneo/communication/message/neomessage.h +++ b/include/icsneo/communication/message/neomessage.h @@ -108,7 +108,9 @@ typedef struct { uint8_t header[4]; uint16_t netid; uint8_t type; - uint8_t reserved[17]; + uint8_t reserved0; + uint16_t description; + uint8_t reserved1[14]; } neomessage_t; // 72 bytes total // Any time you add another neomessage_*_t type, make sure to add it to the static_asserts below! @@ -122,7 +124,8 @@ typedef struct { uint16_t netid; uint8_t type; uint8_t dlcOnWire; - uint8_t reserved[16]; + uint16_t description; + uint8_t reserved[14]; } neomessage_can_t; typedef struct { @@ -135,7 +138,9 @@ typedef struct { uint8_t reservedHeader[3]; uint16_t netid; uint8_t type; - uint8_t reserved[17]; + uint8_t reserved0; + uint16_t description; + uint8_t reserved1[14]; } neomessage_eth_t; #pragma pack(pop)