Compare commits

..

2 Commits

Author SHA1 Message Date
Thomas Stoddard 5ee450353b Bindings: Python: Add T1S members 2026-01-07 23:32:20 -05:00
Thomas Stoddard 516bca682c EthernetMessage: Add T1S symbol support 2026-01-07 16:34:34 -05:00
3 changed files with 49 additions and 7 deletions

View File

@ -18,6 +18,17 @@ void init_ethernetmessage(pybind11::module_& m) {
.def_readwrite("fcs", &EthernetMessage::fcs)
.def_readwrite("frameTooShort", &EthernetMessage::frameTooShort)
.def_readwrite("noPadding", &EthernetMessage::noPadding)
.def_readwrite("fcsVerified", &EthernetMessage::fcsVerified)
.def_readwrite("txAborted", &EthernetMessage::txAborted)
.def_readwrite("crcError", &EthernetMessage::crcError)
.def_readwrite("isT1S", &EthernetMessage::isT1S)
.def_readwrite("isT1SSymbol", &EthernetMessage::isT1SSymbol)
.def_readwrite("isT1SBurst", &EthernetMessage::isT1SBurst)
.def_readwrite("txCollision", &EthernetMessage::txCollision)
.def_readwrite("isT1SWake", &EthernetMessage::isT1SWake)
.def_readwrite("t1sNodeId", &EthernetMessage::t1sNodeId)
.def_readwrite("t1sBurstCount", &EthernetMessage::t1sBurstCount)
.def_readwrite("t1sSymbolType", &EthernetMessage::t1sSymbolType)
.def("get_destination_mac", &EthernetMessage::getDestinationMAC, pybind11::return_value_policy::reference)
.def("get_source_mac", &EthernetMessage::getSourceMAC, pybind11::return_value_policy::reference)
.def("get_ether_type", &EthernetMessage::getEtherType);

View File

@ -1,5 +1,5 @@
#include "icsneo/communication/packet/ethernetpacket.h"
#include <algorithm> // for std::copy
#include <algorithm>
#include <iostream>
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
if(bytestream.size() < sizeof(HardwareEthernetPacket))
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;
// 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 bytestreamActualSize = bytestream.size();
if(bytestreamActualSize < bytestreamExpectedSize)
return nullptr;
auto messagePtr = std::make_shared<EthernetMessage>();
EthernetMessage& message = *messagePtr;
// Standard Ethernet fields
message.transmitted = packet->eid.TXMSG;
if(message.transmitted)
message.description = packet->stats;
@ -27,12 +28,28 @@ std::shared_ptr<EthernetMessage> HardwareEthernetPacket::DecodeToMessage(const s
if(message.preemptionEnabled)
message.preemptionFlags = (uint8_t)((rawWords[0] & 0x03F8) >> 4);
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)
message.error = true;
// This timestamp is raw off the device (in timestampResolution increments)
// Decoder will fix as it has information about the timestampResolution increments
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 dataend = databegin + packet->Length - fcsSize;
message.data.insert(message.data.begin(), databegin, dataend);

View File

@ -4,17 +4,17 @@
#ifdef __cplusplus
#include "icsneo/communication/message/message.h"
// Used for MACAddress.toString() only
#include <string>
#include <vector>
#include <sstream>
#include <iomanip>
#include <cstring>
namespace icsneo {
struct MACAddress {
uint8_t data[6];
// Helpers
std::string toString() const {
std::stringstream ss;
for(size_t i = 0; i < 6; i++) {
@ -33,11 +33,25 @@ struct MACAddress {
class EthernetMessage : public Frame {
public:
// Standard Ethernet fields
bool preemptionEnabled = false;
uint8_t preemptionFlags = 0;
std::optional<uint32_t> fcs;
bool frameTooShort = 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
const MACAddress& getDestinationMAC() const { return *(const MACAddress*)(data.data() + 0); }