mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
Refactor ICSChecksum and packetWrap into the Packetizer
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
#include "communication/include/command.h"
|
||||
#include "communication/include/network.h"
|
||||
#include "communication/include/packet.h"
|
||||
#include "communication/include/packetizer.h"
|
||||
#include "communication/include/messagedecoder.h"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
@@ -16,8 +18,6 @@ namespace icsneo {
|
||||
|
||||
class Communication {
|
||||
public:
|
||||
static uint8_t ICSChecksum(const std::vector<uint8_t>& data);
|
||||
|
||||
Communication(std::shared_ptr<ICommunication> com, std::shared_ptr<Packetizer> p, std::shared_ptr<MessageDecoder> md) : impl(com), packetizer(p), decoder(md) {}
|
||||
virtual ~Communication() { close(); }
|
||||
|
||||
@@ -26,7 +26,6 @@ public:
|
||||
virtual void spawnThreads();
|
||||
virtual void joinThreads();
|
||||
bool rawWrite(const std::vector<uint8_t>& bytes) { return impl->write(bytes); }
|
||||
std::vector<uint8_t>& packetWrap(std::vector<uint8_t>& data, bool addChecksum = true);
|
||||
bool sendPacket(std::vector<uint8_t>& bytes);
|
||||
|
||||
virtual bool sendCommand(Command cmd, bool boolean) { return sendCommand(cmd, std::vector<uint8_t>({ (uint8_t)boolean })); }
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef __PACKETIZER_H_
|
||||
#define __PACKETIZER_H_
|
||||
|
||||
#include "communication/include/communication.h"
|
||||
#include "communication/include/packet.h"
|
||||
#include <queue>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
@@ -10,8 +10,14 @@ namespace icsneo {
|
||||
|
||||
class Packetizer {
|
||||
public:
|
||||
static uint8_t ICSChecksum(const std::vector<uint8_t>& data);
|
||||
std::vector<uint8_t>& packetWrap(std::vector<uint8_t>& data);
|
||||
|
||||
bool input(const std::vector<uint8_t>& bytes);
|
||||
std::vector<std::shared_ptr<Packet>> output();
|
||||
|
||||
bool disableChecksum = false; // Even for short packets
|
||||
bool align16bit = true; // Not needed for Gigalog, Galaxy, etc and newer
|
||||
|
||||
private:
|
||||
enum class ReadState {
|
||||
|
||||
Reference in New Issue
Block a user