Communication::Packet refactored out to Packet
parent
d27b516894
commit
585abe7cbb
|
|
@ -4,7 +4,7 @@
|
||||||
#include "communication/include/icommunication.h"
|
#include "communication/include/icommunication.h"
|
||||||
#include "communication/include/command.h"
|
#include "communication/include/command.h"
|
||||||
#include "communication/include/network.h"
|
#include "communication/include/network.h"
|
||||||
#include "communication/include/messagecallback.h"
|
#include "communication/include/packet.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
|
@ -40,11 +40,6 @@ public:
|
||||||
|
|
||||||
void setAlign16Bit(bool enable) { align16bit = enable; }
|
void setAlign16Bit(bool enable) { align16bit = enable; }
|
||||||
|
|
||||||
class Packet {
|
|
||||||
public:
|
|
||||||
Network network;
|
|
||||||
std::vector<uint8_t> data;
|
|
||||||
};
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::shared_ptr<ICommunication> impl;
|
std::shared_ptr<ICommunication> impl;
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
#ifndef __MESSAGEDECODER_H_
|
#ifndef __MESSAGEDECODER_H_
|
||||||
#define __MESSAGEDECODER_H_
|
#define __MESSAGEDECODER_H_
|
||||||
|
|
||||||
#include "communication/include/communication.h"
|
|
||||||
#include "communication/message/include/message.h"
|
#include "communication/message/include/message.h"
|
||||||
#include "communication/message/include/canmessage.h"
|
#include "communication/message/include/canmessage.h"
|
||||||
|
#include "communication/include/packet.h"
|
||||||
#include "communication/include/network.h"
|
#include "communication/include/network.h"
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
@ -16,7 +16,8 @@ namespace icsneo {
|
||||||
|
|
||||||
class MessageDecoder {
|
class MessageDecoder {
|
||||||
public:
|
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:
|
private:
|
||||||
typedef uint16_t icscm_bitfield;
|
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 {
|
class Packetizer {
|
||||||
public:
|
public:
|
||||||
bool input(const std::vector<uint8_t>& bytes);
|
bool input(const std::vector<uint8_t>& bytes);
|
||||||
std::vector<std::shared_ptr<Communication::Packet>> output();
|
std::vector<std::shared_ptr<Packet>> output();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum class ReadState {
|
enum class ReadState {
|
||||||
|
|
@ -27,10 +27,10 @@ private:
|
||||||
int headerSize = 0;
|
int headerSize = 0;
|
||||||
bool checksum = false;
|
bool checksum = false;
|
||||||
bool gotGoodPackets = false; // Tracks whether we've ever gotten a good packet
|
bool gotGoodPackets = false; // Tracks whether we've ever gotten a good packet
|
||||||
Communication::Packet packet;
|
Packet packet;
|
||||||
std::deque<uint8_t> bytes;
|
std::deque<uint8_t> bytes;
|
||||||
|
|
||||||
std::vector<std::shared_ptr<Communication::Packet>> processedPackets;
|
std::vector<std::shared_ptr<Packet>> processedPackets;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,19 @@
|
||||||
#include "communication/include/messagedecoder.h"
|
#include "communication/include/messagedecoder.h"
|
||||||
#include "communication/include/communication.h"
|
#include "communication/include/communication.h"
|
||||||
|
#include "communication/include/command.h"
|
||||||
|
#include "device/include/device.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
using namespace icsneo;
|
using namespace icsneo;
|
||||||
|
|
||||||
std::shared_ptr<Message> MessageDecoder::decodePacket(const std::shared_ptr<Communication::Packet>& packet) {
|
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()) {
|
switch(packet->network.getType()) {
|
||||||
case Network::Type::CAN: {
|
case Network::Type::CAN: {
|
||||||
if(packet->data.size() < 24)
|
if(packet->data.size() < 24)
|
||||||
|
|
|
||||||
|
|
@ -103,8 +103,8 @@ bool Packetizer::input(const std::vector<uint8_t>& inputBytes) {
|
||||||
return processedPackets.size() > 0;
|
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);
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue