Message: Create a type system so non-frame data can be represented

This change breaks existing code, hence the version bump, but it's
going to be much less error prone going forward.
This commit is contained in:
Paul Hollinsky
2021-05-22 01:58:36 -04:00
parent 21e93d1f73
commit 21bc4eeff2
48 changed files with 853 additions and 527 deletions
+50 -1
View File
@@ -1,6 +1,9 @@
#ifndef __MESSAGE_H_
#define __MESSAGE_H_
#include <stdint.h>
typedef uint16_t neomessagetype_t;
#ifdef __cplusplus
#include "icsneo/communication/network.h"
@@ -10,10 +13,42 @@ namespace icsneo {
class Message {
public:
enum class Type : neomessagetype_t {
Frame = 0,
CANErrorCount = 0x100,
// Past 0x8000 are all for internal use only
Invalid = 0x8000,
RawMessage = 0x8001,
ReadSettings = 0x8002,
ResetStatus = 0x8003,
DeviceVersion = 0x8004,
Main51 = 0x8005,
FlexRayControl = 0x8006,
};
Message(Type t) : type(t) {}
virtual ~Message() = default;
const Type type;
uint64_t timestamp = 0;
};
class RawMessage : public Message {
public:
RawMessage(Message::Type type = Message::Type::RawMessage) : Message(type) {}
RawMessage(Message::Type type, Network net) : Message(type), network(net) {}
RawMessage(Network net) : Message(Message::Type::RawMessage), network(net) {}
RawMessage(Network net, std::vector<uint8_t> d) : Message(Message::Type::RawMessage), network(net), data(d) {}
Network network;
std::vector<uint8_t> data;
uint64_t timestamp = 0;
};
class Frame : public RawMessage {
public:
Frame() : RawMessage(Message::Type::Frame) {}
uint16_t description = 0;
bool transmitted = false;
bool error = false;
@@ -23,4 +58,18 @@ public:
#endif // __cplusplus
#ifdef __ICSNEOC_H_
#define ICSNEO_MESSAGE_TYPE_FRAME (0x0)
#define ICSNEO_MESSAGE_TYPE_CAN_ERROR_COUNT (0x100)
#define ICSNEO_MESSAGE_TYPE_INVALID (0x8000)
#define ICSNEO_MESSAGE_TYPE_RAW_MESSAGE (0x8001)
#define ICSNEO_MESSAGE_TYPE_READ_SETTINGS (0x8002)
#define ICSNEO_MESSAGE_TYPE_RESET_STATUS (0x8003)
#define ICSNEO_MESSAGE_TYPE_DEVICE_VERSION (0x8004)
#define ICSNEO_MESSAGE_TYPE_MAIN51 (0x8005)
#define ICSNEO_MESSAGE_TYPE_FLEXRAY_CONTROL (0x8006)
#endif // __ICSNEOC_H_
#endif