mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
Support Ethernet and Broad-R Reach TX and RX
This commit is contained in:
@@ -10,8 +10,6 @@
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
class Decoder {
|
||||
@@ -20,44 +18,13 @@ public:
|
||||
|
||||
Decoder(device_errorhandler_t err) : err(err) {}
|
||||
bool decode(std::shared_ptr<Message>& result, const std::shared_ptr<Packet>& packet);
|
||||
|
||||
|
||||
int timestampMultiplier = 25;
|
||||
|
||||
private:
|
||||
device_errorhandler_t err;
|
||||
typedef uint16_t icscm_bitfield;
|
||||
struct HardwareCANPacket {
|
||||
struct {
|
||||
icscm_bitfield IDE : 1;
|
||||
icscm_bitfield SRR : 1;
|
||||
icscm_bitfield SID : 11;
|
||||
icscm_bitfield EDL : 1;
|
||||
icscm_bitfield BRS : 1;
|
||||
icscm_bitfield ESI : 1;
|
||||
} header;
|
||||
struct {
|
||||
icscm_bitfield EID : 12;
|
||||
icscm_bitfield TXMSG : 1;
|
||||
icscm_bitfield TXAborted : 1;
|
||||
icscm_bitfield TXLostArb : 1;
|
||||
icscm_bitfield TXError : 1;
|
||||
} eid;
|
||||
struct {
|
||||
icscm_bitfield DLC : 4;
|
||||
icscm_bitfield RB0 : 1;
|
||||
icscm_bitfield IVRIF : 1;
|
||||
icscm_bitfield HVEnable : 1;// must be cleared before passing into CAN driver
|
||||
icscm_bitfield ExtendedNetworkIndexBit : 1;//DO NOT CLOBBER THIS
|
||||
icscm_bitfield RB1 : 1;
|
||||
icscm_bitfield RTR : 1;
|
||||
icscm_bitfield EID2 : 6;
|
||||
} dlc;
|
||||
unsigned char data[8];
|
||||
uint16_t stats;
|
||||
struct {
|
||||
uint64_t TS : 60;
|
||||
uint64_t : 3; // Reserved for future status bits
|
||||
uint64_t IsExtended : 1;
|
||||
} timestamp;
|
||||
};
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push)
|
||||
@@ -99,10 +66,9 @@ private:
|
||||
uint16_t busVoltage;
|
||||
uint16_t deviceTemperature;
|
||||
};
|
||||
#pragma pack(pop)
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
#endif
|
||||
@@ -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 {
|
||||
|
||||
|
||||
@@ -245,11 +245,11 @@ public:
|
||||
case NetID::LIN:
|
||||
return "LIN";
|
||||
case NetID::OP_Ethernet1:
|
||||
return "Ethernet 1";
|
||||
return "OP (BR) Ethernet 1";
|
||||
case NetID::OP_Ethernet2:
|
||||
return "Ethernet 2";
|
||||
return "OP (BR) Ethernet 2";
|
||||
case NetID::OP_Ethernet3:
|
||||
return "Ethernet 3";
|
||||
return "OP (BR) Ethernet 3";
|
||||
case NetID::RED_EXT_MEMORYREAD:
|
||||
return "RED_EXT_MEMORYREAD";
|
||||
case NetID::RED_INT_MEMORYREAD:
|
||||
@@ -299,9 +299,9 @@ public:
|
||||
case NetID::HSCAN3:
|
||||
return "HSCAN 3";
|
||||
case NetID::OP_Ethernet4:
|
||||
return "Ethernet 4";
|
||||
return "OP (BR) Ethernet 4";
|
||||
case NetID::OP_Ethernet5:
|
||||
return "Ethernet 5";
|
||||
return "OP (BR) Ethernet 5";
|
||||
case NetID::ISO4:
|
||||
return "ISO 4";
|
||||
case NetID::LIN2:
|
||||
@@ -351,19 +351,19 @@ public:
|
||||
case NetID::TextAPI_To_Host:
|
||||
return "TextAPI To Host";
|
||||
case NetID::OP_Ethernet6:
|
||||
return "Ethernet 6";
|
||||
return "OP (BR) Ethernet 6";
|
||||
case NetID::Red_VBat:
|
||||
return "Red VBat";
|
||||
case NetID::OP_Ethernet7:
|
||||
return "Ethernet 7";
|
||||
return "OP (BR) Ethernet 7";
|
||||
case NetID::OP_Ethernet8:
|
||||
return "Ethernet 8";
|
||||
return "OP (BR) Ethernet 8";
|
||||
case NetID::OP_Ethernet9:
|
||||
return "Ethernet 9";
|
||||
return "OP (BR) Ethernet 9";
|
||||
case NetID::OP_Ethernet10:
|
||||
return "Ethernet 10";
|
||||
return "OP (BR) Ethernet 10";
|
||||
case NetID::OP_Ethernet11:
|
||||
return "Ethernet 11";
|
||||
return "OP (BR) Ethernet 11";
|
||||
case NetID::FlexRay1a:
|
||||
return "FlexRay 1a";
|
||||
case NetID::FlexRay1b:
|
||||
@@ -379,7 +379,7 @@ public:
|
||||
case NetID::FlexRay2:
|
||||
return "FlexRay 2";
|
||||
case NetID::OP_Ethernet12:
|
||||
return "Ethernet 12";
|
||||
return "OP (BR) Ethernet 12";
|
||||
case NetID::MOST25:
|
||||
return "MOST25";
|
||||
case NetID::MOST50:
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
#ifndef __CANPACKET_H__
|
||||
#define __CANPACKET_H__
|
||||
|
||||
#include "icsneo/communication/message/canmessage.h"
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
typedef uint16_t icscm_bitfield;
|
||||
|
||||
struct HardwareCANPacket {
|
||||
static std::shared_ptr<CANMessage> DecodeToMessage(const std::vector<uint8_t>& bytestream);
|
||||
static bool EncodeFromMessage(const CANMessage& message, std::vector<uint8_t>& bytestream);
|
||||
|
||||
struct {
|
||||
icscm_bitfield IDE : 1;
|
||||
icscm_bitfield SRR : 1;
|
||||
icscm_bitfield SID : 11;
|
||||
icscm_bitfield EDL : 1;
|
||||
icscm_bitfield BRS : 1;
|
||||
icscm_bitfield ESI : 1;
|
||||
} header;
|
||||
struct {
|
||||
icscm_bitfield EID : 12;
|
||||
icscm_bitfield TXMSG : 1;
|
||||
icscm_bitfield TXAborted : 1;
|
||||
icscm_bitfield TXLostArb : 1;
|
||||
icscm_bitfield TXError : 1;
|
||||
} eid;
|
||||
struct {
|
||||
icscm_bitfield DLC : 4;
|
||||
icscm_bitfield RB0 : 1;
|
||||
icscm_bitfield IVRIF : 1;
|
||||
icscm_bitfield HVEnable : 1;// must be cleared before passing into CAN driver
|
||||
icscm_bitfield ExtendedNetworkIndexBit : 1;//DO NOT CLOBBER THIS
|
||||
icscm_bitfield RB1 : 1;
|
||||
icscm_bitfield RTR : 1;
|
||||
icscm_bitfield EID2 : 6;
|
||||
} dlc;
|
||||
unsigned char data[8];
|
||||
uint16_t stats;
|
||||
struct {
|
||||
uint64_t TS : 60;
|
||||
uint64_t : 3; // Reserved for future status bits
|
||||
uint64_t IsExtended : 1;
|
||||
} timestamp;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,44 @@
|
||||
#ifndef __ETHERNETPACKET_H__
|
||||
#define __ETHERNETPACKET_H__
|
||||
|
||||
#include "icsneo/communication/message/ethernetmessage.h"
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
typedef uint16_t icscm_bitfield;
|
||||
|
||||
struct HardwareEthernetPacket {
|
||||
static std::shared_ptr<EthernetMessage> DecodeToMessage(const std::vector<uint8_t>& bytestream);
|
||||
static bool EncodeFromMessage(const EthernetMessage& message, std::vector<uint8_t>& bytestream);
|
||||
|
||||
struct {
|
||||
icscm_bitfield FCS_AVAIL : 1;
|
||||
icscm_bitfield RUNT_FRAME : 1;
|
||||
icscm_bitfield DISABLE_PADDING : 1;
|
||||
icscm_bitfield PREEMPTION_ENABLED : 1;
|
||||
icscm_bitfield MPACKET_TYPE : 4;
|
||||
icscm_bitfield MPACKET_FRAG_CNT : 2;
|
||||
icscm_bitfield : 6;
|
||||
} header;
|
||||
struct {
|
||||
icscm_bitfield txlen : 12;
|
||||
icscm_bitfield TXMSG : 1;
|
||||
icscm_bitfield : 3;
|
||||
} eid;
|
||||
icscm_bitfield reserved;
|
||||
unsigned char data[8];
|
||||
uint16_t stats;
|
||||
struct {
|
||||
uint64_t TS : 60;
|
||||
uint64_t : 3; // Reserved for future status bits
|
||||
uint64_t IsExtended : 1;
|
||||
} timestamp;
|
||||
uint16_t NetworkID;
|
||||
uint16_t Length;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -8,6 +8,9 @@
|
||||
#include "icsneo/api/version.h"
|
||||
#include "icsneo/api/errormanager.h"
|
||||
|
||||
#include "icsneo/communication/message/canmessage.h"
|
||||
#include "icsneo/communication/message/ethernetmessage.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
std::vector<std::shared_ptr<Device>> FindAllDevices();
|
||||
|
||||
Reference in New Issue
Block a user