Communication::Packet refactored out to Packet
parent
d27b516894
commit
585abe7cbb
|
|
@ -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 <memory>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
|
|
@ -40,11 +40,6 @@ public:
|
|||
|
||||
void setAlign16Bit(bool enable) { align16bit = enable; }
|
||||
|
||||
class Packet {
|
||||
public:
|
||||
Network network;
|
||||
std::vector<uint8_t> data;
|
||||
};
|
||||
|
||||
protected:
|
||||
std::shared_ptr<ICommunication> impl;
|
||||
|
|
|
|||
|
|
@ -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 <queue>
|
||||
#include <vector>
|
||||
|
|
@ -16,7 +16,8 @@ namespace icsneo {
|
|||
|
||||
class MessageDecoder {
|
||||
public:
|
||||
std::shared_ptr<Message> decodePacket(const std::shared_ptr<Communication::Packet>& message);
|
||||
static uint64_t GetUInt64FromLEBytes(uint8_t* bytes);
|
||||
std::shared_ptr<Message> decodePacket(const std::shared_ptr<Packet>& message);
|
||||
|
||||
private:
|
||||
typedef uint16_t icscm_bitfield;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef __PACKET_H_
|
||||
#define __PACKET_H_
|
||||
|
||||
#include "communication/include/network.h"
|
||||
#include <vector>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
class Packet {
|
||||
public:
|
||||
Network network;
|
||||
std::vector<uint8_t> data;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -11,7 +11,7 @@ namespace icsneo {
|
|||
class Packetizer {
|
||||
public:
|
||||
bool input(const std::vector<uint8_t>& bytes);
|
||||
std::vector<std::shared_ptr<Communication::Packet>> output();
|
||||
std::vector<std::shared_ptr<Packet>> 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<uint8_t> bytes;
|
||||
|
||||
std::vector<std::shared_ptr<Communication::Packet>> processedPackets;
|
||||
std::vector<std::shared_ptr<Packet>> processedPackets;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,35 +1,44 @@
|
|||
#include "communication/include/messagedecoder.h"
|
||||
#include "communication/include/communication.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace icsneo;
|
||||
|
||||
std::shared_ptr<Message> MessageDecoder::decodePacket(const std::shared_ptr<Communication::Packet>& 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<CANMessage>();
|
||||
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<Message>();
|
||||
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 <iostream>
|
||||
|
||||
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<Message> MessageDecoder::decodePacket(const std::shared_ptr<Packet>& 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<CANMessage>();
|
||||
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<Message>();
|
||||
msg->network = packet->network;
|
||||
msg->data = packet->data;
|
||||
return msg;
|
||||
}
|
||||
|
|
@ -103,8 +103,8 @@ bool Packetizer::input(const std::vector<uint8_t>& inputBytes) {
|
|||
return processedPackets.size() > 0;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<Communication::Packet>> Packetizer::output() {
|
||||
std::vector<std::shared_ptr<Packet>> Packetizer::output() {
|
||||
auto ret = std::move(processedPackets);
|
||||
processedPackets = std::vector<std::shared_ptr<Communication::Packet>>(); // Reset the vector
|
||||
processedPackets = std::vector<std::shared_ptr<Packet>>(); // Reset the vector
|
||||
return ret;
|
||||
}
|
||||
Loading…
Reference in New Issue