mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
Add error system
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "icsneo/communication/packet.h"
|
||||
#include "icsneo/communication/message/callback/messagecallback.h"
|
||||
#include "icsneo/communication/message/serialnumbermessage.h"
|
||||
#include "icsneo/api/errormanager.h"
|
||||
#include "icsneo/communication/packetizer.h"
|
||||
#include "icsneo/communication/encoder.h"
|
||||
#include "icsneo/communication/decoder.h"
|
||||
@@ -22,10 +23,11 @@ namespace icsneo {
|
||||
class Communication {
|
||||
public:
|
||||
Communication(
|
||||
device_errorhandler_t err,
|
||||
std::unique_ptr<ICommunication> com,
|
||||
std::shared_ptr<Packetizer> p,
|
||||
std::unique_ptr<Encoder> e,
|
||||
std::unique_ptr<Decoder> md) : packetizer(p), encoder(std::move(e)), decoder(std::move(md)), impl(std::move(com)) {}
|
||||
std::unique_ptr<Decoder> md) : packetizer(p), encoder(std::move(e)), decoder(std::move(md)), err(err), impl(std::move(com)) {}
|
||||
virtual ~Communication() { close(); }
|
||||
|
||||
bool open();
|
||||
@@ -50,6 +52,7 @@ public:
|
||||
std::shared_ptr<Packetizer> packetizer; // Ownership is shared with the encoder
|
||||
std::unique_ptr<Encoder> encoder;
|
||||
std::unique_ptr<Decoder> decoder;
|
||||
device_errorhandler_t err;
|
||||
|
||||
protected:
|
||||
std::unique_ptr<ICommunication> impl;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "icsneo/communication/message/canmessage.h"
|
||||
#include "icsneo/communication/packet.h"
|
||||
#include "icsneo/communication/network.h"
|
||||
#include "icsneo/api/errormanager.h"
|
||||
#include <queue>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
@@ -16,9 +17,12 @@ namespace icsneo {
|
||||
class Decoder {
|
||||
public:
|
||||
static uint64_t GetUInt64FromLEBytes(uint8_t* bytes);
|
||||
|
||||
Decoder(device_errorhandler_t err) : err(err) {}
|
||||
bool decode(std::shared_ptr<Message>& result, const std::shared_ptr<Packet>& packet);
|
||||
|
||||
private:
|
||||
device_errorhandler_t err;
|
||||
typedef uint16_t icscm_bitfield;
|
||||
struct HardwareCANPacket {
|
||||
struct {
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace icsneo {
|
||||
|
||||
class Encoder {
|
||||
public:
|
||||
Encoder(std::shared_ptr<Packetizer> packetizerInstance) : packetizer(packetizerInstance) {}
|
||||
Encoder(device_errorhandler_t err, std::shared_ptr<Packetizer> p) : packetizer(p), err(err) {}
|
||||
bool encode(std::vector<uint8_t>& result, const std::shared_ptr<Message>& message);
|
||||
bool encode(std::vector<uint8_t>& result, Command cmd, bool boolean) { return encode(result, cmd, std::vector<uint8_t>({ (uint8_t)boolean })); }
|
||||
bool encode(std::vector<uint8_t>& result, Command cmd, std::vector<uint8_t> arguments = {});
|
||||
@@ -23,6 +23,7 @@ public:
|
||||
bool supportCANFD = false;
|
||||
private:
|
||||
std::shared_ptr<Packetizer> packetizer;
|
||||
device_errorhandler_t err;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -11,10 +11,11 @@ namespace icsneo {
|
||||
class MultiChannelCommunication : public Communication {
|
||||
public:
|
||||
MultiChannelCommunication(
|
||||
device_errorhandler_t err,
|
||||
std::unique_ptr<ICommunication> com,
|
||||
std::shared_ptr<Packetizer> p,
|
||||
std::unique_ptr<Encoder> e,
|
||||
std::unique_ptr<Decoder> md) : Communication(std::move(com), p, std::move(e), std::move(md)) {}
|
||||
std::unique_ptr<Decoder> md) : Communication(err, std::move(com), p, std::move(e), std::move(md)) {}
|
||||
void spawnThreads() override;
|
||||
void joinThreads() override;
|
||||
bool sendPacket(std::vector<uint8_t>& bytes) override;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define __PACKETIZER_H_
|
||||
|
||||
#include "icsneo/communication/packet.h"
|
||||
#include "icsneo/api/errormanager.h"
|
||||
#include <queue>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
@@ -11,6 +12,9 @@ namespace icsneo {
|
||||
class Packetizer {
|
||||
public:
|
||||
static uint8_t ICSChecksum(const std::vector<uint8_t>& data);
|
||||
|
||||
Packetizer(device_errorhandler_t err) : err(err) {}
|
||||
|
||||
std::vector<uint8_t>& packetWrap(std::vector<uint8_t>& data, bool shortFormat);
|
||||
|
||||
bool input(const std::vector<uint8_t>& bytes);
|
||||
@@ -37,6 +41,8 @@ private:
|
||||
std::deque<uint8_t> bytes;
|
||||
|
||||
std::vector<std::shared_ptr<Packet>> processedPackets;
|
||||
|
||||
device_errorhandler_t err;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user