diff --git a/communication/include/communication.h b/communication/include/communication.h index 60a89e6..a8d9f3e 100644 --- a/communication/include/communication.h +++ b/communication/include/communication.h @@ -4,7 +4,7 @@ #include "communication/include/icommunication.h" #include "communication/include/command.h" #include "communication/include/network.h" -#include "communication/include/messagecallback.h" +#include "communication/include/packet.h" #include #include #include @@ -40,11 +40,6 @@ public: void setAlign16Bit(bool enable) { align16bit = enable; } - class Packet { - public: - Network network; - std::vector data; - }; protected: std::shared_ptr impl; diff --git a/communication/include/messagedecoder.h b/communication/include/messagedecoder.h index 21b22df..80d5a8f 100644 --- a/communication/include/messagedecoder.h +++ b/communication/include/messagedecoder.h @@ -1,9 +1,9 @@ #ifndef __MESSAGEDECODER_H_ #define __MESSAGEDECODER_H_ -#include "communication/include/communication.h" #include "communication/message/include/message.h" #include "communication/message/include/canmessage.h" +#include "communication/include/packet.h" #include "communication/include/network.h" #include #include @@ -16,7 +16,8 @@ namespace icsneo { class MessageDecoder { public: - std::shared_ptr decodePacket(const std::shared_ptr& message); + static uint64_t GetUInt64FromLEBytes(uint8_t* bytes); + std::shared_ptr decodePacket(const std::shared_ptr& message); private: typedef uint16_t icscm_bitfield; diff --git a/communication/include/packet.h b/communication/include/packet.h new file mode 100644 index 0000000..54188f2 --- /dev/null +++ b/communication/include/packet.h @@ -0,0 +1,18 @@ +#ifndef __PACKET_H_ +#define __PACKET_H_ + +#include "communication/include/network.h" +#include +#include + +namespace icsneo { + +class Packet { +public: + Network network; + std::vector data; +}; + +} + +#endif \ No newline at end of file diff --git a/communication/include/packetizer.h b/communication/include/packetizer.h index b4f7791..ae4cc10 100644 --- a/communication/include/packetizer.h +++ b/communication/include/packetizer.h @@ -11,7 +11,7 @@ namespace icsneo { class Packetizer { public: bool input(const std::vector& bytes); - std::vector> output(); + std::vector> output(); private: enum class ReadState { @@ -27,10 +27,10 @@ private: int headerSize = 0; bool checksum = false; bool gotGoodPackets = false; // Tracks whether we've ever gotten a good packet - Communication::Packet packet; + Packet packet; std::deque bytes; - std::vector> processedPackets; + std::vector> processedPackets; }; } diff --git a/communication/messagedecoder.cpp b/communication/messagedecoder.cpp index 3984346..3819d37 100644 --- a/communication/messagedecoder.cpp +++ b/communication/messagedecoder.cpp @@ -1,35 +1,44 @@ -#include "communication/include/messagedecoder.h" -#include "communication/include/communication.h" -#include - -using namespace icsneo; - -std::shared_ptr MessageDecoder::decodePacket(const std::shared_ptr& packet) { - switch(packet->network.getType()) { - case Network::Type::CAN: { - if(packet->data.size() < 24) - break; // We would read garbage when interpereting the data - - HardwareCANPacket* data = (HardwareCANPacket*)packet->data.data(); - auto msg = std::make_shared(); - msg->network = packet->network; - msg->arbid = data->header.SID; - msg->data.reserve(data->dlc.DLC); - - // Timestamp calculation - msg->timestamp = data->timestamp.TS * 25; // Timestamps are in 25ns increments since 1/1/2007 GMT 00:00:00.0000 - - for(auto i = 0; i < data->dlc.DLC; i++) - msg->data.push_back(data->data[i]); - return msg; - } - default: - // TODO Implement others - break; - } - - auto msg = std::make_shared(); - msg->network = packet->network; - msg->data = packet->data; - return msg; +#include "communication/include/messagedecoder.h" +#include "communication/include/communication.h" +#include "communication/include/command.h" +#include "device/include/device.h" +#include + +using namespace icsneo; + +uint64_t MessageDecoder::GetUInt64FromLEBytes(uint8_t* bytes) { + uint64_t ret = 0; + for(int i = 0; i < 8; i++) + ret |= (bytes[i] << (i * 8)); + return ret; +} + +std::shared_ptr MessageDecoder::decodePacket(const std::shared_ptr& packet) { + switch(packet->network.getType()) { + case Network::Type::CAN: { + if(packet->data.size() < 24) + break; // We would read garbage when interpereting the data + + HardwareCANPacket* data = (HardwareCANPacket*)packet->data.data(); + auto msg = std::make_shared(); + msg->network = packet->network; + msg->arbid = data->header.SID; + msg->data.reserve(data->dlc.DLC); + + // Timestamp calculation + msg->timestamp = data->timestamp.TS * 25; // Timestamps are in 25ns increments since 1/1/2007 GMT 00:00:00.0000 + + for(auto i = 0; i < data->dlc.DLC; i++) + msg->data.push_back(data->data[i]); + return msg; + } + default: + // TODO Implement others + break; + } + + auto msg = std::make_shared(); + msg->network = packet->network; + msg->data = packet->data; + return msg; } \ No newline at end of file diff --git a/communication/packetizer.cpp b/communication/packetizer.cpp index 19ec1e9..3b3d84d 100644 --- a/communication/packetizer.cpp +++ b/communication/packetizer.cpp @@ -103,8 +103,8 @@ bool Packetizer::input(const std::vector& inputBytes) { return processedPackets.size() > 0; } -std::vector> Packetizer::output() { +std::vector> Packetizer::output() { auto ret = std::move(processedPackets); - processedPackets = std::vector>(); // Reset the vector + processedPackets = std::vector>(); // Reset the vector return ret; } \ No newline at end of file