Support Ethernet and Broad-R Reach TX and RX

This commit is contained in:
Paul Hollinsky
2018-12-21 20:32:27 -05:00
parent 603d532d2d
commit d37d5bb23e
14 changed files with 490 additions and 209 deletions
@@ -0,0 +1,48 @@
#ifndef __ETHERNETMESSAGE_H_
#define __ETHERNETMESSAGE_H_
#include "icsneo/communication/message/message.h"
// Used for MACAddress.toString() only
#include <sstream>
#include <iomanip>
namespace icsneo {
struct MACAddress {
uint8_t data[6];
// Helpers
std::string toString() const {
std::stringstream ss;
for(size_t i = 0; i < 6; i++) {
ss << std::hex << std::setw(2) << std::setfill('0') << (int)data[i];
if(i != 5)
ss << ':';
}
return ss.str();
}
friend std::ostream& operator<<(std::ostream& os, const MACAddress& mac) {
os << mac.toString();
return os;
}
};
class EthernetMessage : public Message {
public:
bool preemptionEnabled = false;
uint8_t preemptionFlags = 0;
bool fcsAvailable = false;
bool frameTooShort = false;
bool noPadding = false;
// Accessors
const MACAddress& getDestinationMAC() const { return *(const MACAddress*)(data.data() + 0); }
const MACAddress& getSourceMAC() const { return *(const MACAddress*)(data.data() + 6); }
uint16_t getEtherType() const { return (data[12] << 8) | data[13]; }
};
}
#endif
@@ -11,7 +11,10 @@ public:
virtual ~Message() = default;
Network network;
std::vector<uint8_t> data;
uint64_t timestamp;
uint64_t timestamp = 0;
uint16_t description = 0;
bool transmitted = false;
bool error = false;
};
}
@@ -102,18 +102,20 @@ typedef union {
typedef struct {
neomessage_statusbitfield_t status;
uint64_t timestamp;
uint64_t timestampReserved;
const uint8_t* data;
size_t length;
uint8_t header[4];
uint16_t netid;
uint8_t type;
uint8_t reserved[17];
} neomessage_t; // 64 bytes total
} neomessage_t; // 72 bytes total
// Any time you add another neomessage_*_t type, make sure to add it to the static_asserts below!
typedef struct {
neomessage_statusbitfield_t status;
uint64_t timestamp;
uint64_t timestampReserved;
const uint8_t* data;
size_t length;
uint32_t arbid;
@@ -123,13 +125,28 @@ typedef struct {
uint8_t reserved[16];
} neomessage_can_t;
typedef struct {
neomessage_statusbitfield_t status;
uint64_t timestamp;
uint64_t timestampReserved;
const uint8_t* data;
size_t length;
uint8_t preemptionFlags;
uint8_t reservedHeader[3];
uint16_t netid;
uint8_t type;
uint8_t reserved[17];
} neomessage_eth_t;
#pragma pack(pop)
#ifdef __cplusplus
#include "icsneo/communication/message/message.h"
#include <memory>
static_assert(sizeof(neomessage_can_t) == sizeof(neomessage_t), "All types of neomessage_t must be the same size!");
static_assert(sizeof(neomessage_t) == 72, "neomessage_t may not change size from 72 bytes!");
static_assert(sizeof(neomessage_can_t) == sizeof(neomessage_t), "All types of neomessage_t must be the same size! (CAN is not)");
static_assert(sizeof(neomessage_eth_t) == sizeof(neomessage_t), "All types of neomessage_t must be the same size! (Ethernet is not)");
namespace icsneo {