EthernetMessage: Add T1S symbol support
parent
3f5150bef3
commit
516bca682c
|
|
@ -1,5 +1,5 @@
|
||||||
#include "icsneo/communication/packet/ethernetpacket.h"
|
#include "icsneo/communication/packet/ethernetpacket.h"
|
||||||
#include <algorithm> // for std::copy
|
#include <algorithm>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
using namespace icsneo;
|
using namespace icsneo;
|
||||||
|
|
@ -10,16 +10,17 @@ std::shared_ptr<EthernetMessage> HardwareEthernetPacket::DecodeToMessage(const s
|
||||||
// Make sure we have enough to read the packet length first
|
// Make sure we have enough to read the packet length first
|
||||||
if(bytestream.size() < sizeof(HardwareEthernetPacket))
|
if(bytestream.size() < sizeof(HardwareEthernetPacket))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
// packet->Length will also encompass the two uint16_t's at the end of the struct, make sure that at least they are here
|
|
||||||
if(packet->Length < 4)
|
|
||||||
return nullptr;
|
|
||||||
const size_t fcsSize = packet->header.FCS_AVAIL ? 4 : 0;
|
const size_t fcsSize = packet->header.FCS_AVAIL ? 4 : 0;
|
||||||
|
// Ensure Length is sufficient for FCS extraction to avoid invalid iterator arithmetic
|
||||||
|
if(packet->Length < fcsSize)
|
||||||
|
return nullptr;
|
||||||
const size_t bytestreamExpectedSize = sizeof(HardwareEthernetPacket) + packet->Length;
|
const size_t bytestreamExpectedSize = sizeof(HardwareEthernetPacket) + packet->Length;
|
||||||
const size_t bytestreamActualSize = bytestream.size();
|
const size_t bytestreamActualSize = bytestream.size();
|
||||||
if(bytestreamActualSize < bytestreamExpectedSize)
|
if(bytestreamActualSize < bytestreamExpectedSize)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
auto messagePtr = std::make_shared<EthernetMessage>();
|
auto messagePtr = std::make_shared<EthernetMessage>();
|
||||||
EthernetMessage& message = *messagePtr;
|
EthernetMessage& message = *messagePtr;
|
||||||
|
// Standard Ethernet fields
|
||||||
message.transmitted = packet->eid.TXMSG;
|
message.transmitted = packet->eid.TXMSG;
|
||||||
if(message.transmitted)
|
if(message.transmitted)
|
||||||
message.description = packet->stats;
|
message.description = packet->stats;
|
||||||
|
|
@ -27,12 +28,28 @@ std::shared_ptr<EthernetMessage> HardwareEthernetPacket::DecodeToMessage(const s
|
||||||
if(message.preemptionEnabled)
|
if(message.preemptionEnabled)
|
||||||
message.preemptionFlags = (uint8_t)((rawWords[0] & 0x03F8) >> 4);
|
message.preemptionFlags = (uint8_t)((rawWords[0] & 0x03F8) >> 4);
|
||||||
message.frameTooShort = packet->header.RUNT_FRAME;
|
message.frameTooShort = packet->header.RUNT_FRAME;
|
||||||
|
message.noPadding = !packet->header.ENABLE_PADDING;
|
||||||
|
message.fcsVerified = packet->header.FCS_VERIFIED;
|
||||||
|
message.txAborted = packet->eid.TXAborted;
|
||||||
|
message.crcError = packet->header.CRC_ERROR;
|
||||||
|
|
||||||
if(message.frameTooShort)
|
if(message.frameTooShort)
|
||||||
message.error = true;
|
message.error = true;
|
||||||
// This timestamp is raw off the device (in timestampResolution increments)
|
// This timestamp is raw off the device (in timestampResolution increments)
|
||||||
// Decoder will fix as it has information about the timestampResolution increments
|
// Decoder will fix as it has information about the timestampResolution increments
|
||||||
message.timestamp = packet->timestamp.TS;
|
message.timestamp = packet->timestamp.TS;
|
||||||
|
|
||||||
|
// Check if this is a T1S packet and populate T1S-specific fields
|
||||||
|
message.isT1S = packet->header.T1S_ETHERNET;
|
||||||
|
if(message.isT1S) {
|
||||||
|
message.isT1SSymbol = packet->eid.T1S_SYMBOL;
|
||||||
|
message.isT1SBurst = packet->eid.T1S_BURST;
|
||||||
|
message.txCollision = packet->t1s_status.TXCollision;
|
||||||
|
message.isT1SWake = packet->t1s_status.T1SWake;
|
||||||
|
message.t1sNodeId = packet->t1s_node.T1S_NODE_ID;
|
||||||
|
message.t1sBurstCount = packet->t1s_node.T1S_BURST_COUNT;
|
||||||
|
}
|
||||||
|
|
||||||
const std::vector<uint8_t>::const_iterator databegin = bytestream.begin() + sizeof(HardwareEthernetPacket);
|
const std::vector<uint8_t>::const_iterator databegin = bytestream.begin() + sizeof(HardwareEthernetPacket);
|
||||||
const std::vector<uint8_t>::const_iterator dataend = databegin + packet->Length - fcsSize;
|
const std::vector<uint8_t>::const_iterator dataend = databegin + packet->Length - fcsSize;
|
||||||
message.data.insert(message.data.begin(), databegin, dataend);
|
message.data.insert(message.data.begin(), databegin, dataend);
|
||||||
|
|
|
||||||
|
|
@ -4,17 +4,17 @@
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
||||||
#include "icsneo/communication/message/message.h"
|
#include "icsneo/communication/message/message.h"
|
||||||
|
#include <string>
|
||||||
// Used for MACAddress.toString() only
|
#include <vector>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
namespace icsneo {
|
namespace icsneo {
|
||||||
|
|
||||||
struct MACAddress {
|
struct MACAddress {
|
||||||
uint8_t data[6];
|
uint8_t data[6];
|
||||||
|
|
||||||
// Helpers
|
|
||||||
std::string toString() const {
|
std::string toString() const {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
for(size_t i = 0; i < 6; i++) {
|
for(size_t i = 0; i < 6; i++) {
|
||||||
|
|
@ -33,11 +33,25 @@ struct MACAddress {
|
||||||
|
|
||||||
class EthernetMessage : public Frame {
|
class EthernetMessage : public Frame {
|
||||||
public:
|
public:
|
||||||
|
// Standard Ethernet fields
|
||||||
bool preemptionEnabled = false;
|
bool preemptionEnabled = false;
|
||||||
uint8_t preemptionFlags = 0;
|
uint8_t preemptionFlags = 0;
|
||||||
std::optional<uint32_t> fcs;
|
std::optional<uint32_t> fcs;
|
||||||
bool frameTooShort = false;
|
bool frameTooShort = false;
|
||||||
bool noPadding = false;
|
bool noPadding = false;
|
||||||
|
bool fcsVerified = false;
|
||||||
|
bool txAborted = false;
|
||||||
|
bool crcError = false;
|
||||||
|
bool isT1S = false;
|
||||||
|
|
||||||
|
|
||||||
|
bool isT1SSymbol = false;
|
||||||
|
bool isT1SBurst = false;
|
||||||
|
bool txCollision = false;
|
||||||
|
bool isT1SWake = false;
|
||||||
|
uint8_t t1sNodeId = 0;
|
||||||
|
uint8_t t1sBurstCount = 0;
|
||||||
|
uint8_t t1sSymbolType = 0;
|
||||||
|
|
||||||
// Accessors
|
// Accessors
|
||||||
const MACAddress& getDestinationMAC() const { return *(const MACAddress*)(data.data() + 0); }
|
const MACAddress& getDestinationMAC() const { return *(const MACAddress*)(data.data() + 0); }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue