C2: Add Ethernet message support

This commit is contained in:
David Rebbe
2026-04-30 15:28:40 -04:00
committed by Kyle Schwarz
parent 87f45e060e
commit 9ae3e115fc
27 changed files with 2295 additions and 152 deletions
@@ -223,8 +223,30 @@ void printMessage(const std::shared_ptr<icsneo::Message>& message) {
std::cout << "\t\t Timestamped:\t"<< ethMessage->timestamp << " ns since 1/1/2007\n";
// The MACAddress may be printed directly or accessed with the `data` member
std::cout << "\t\t Source:\t" << ethMessage->getSourceMAC() << "\n";
std::cout << "\t\t Destination:\t" << ethMessage->getDestinationMAC();
auto printMAC = [](const icsneo::MACAddress& mac) {
std::ostringstream oss;
for(size_t i = 0; i < mac.size(); i++) {
oss << std::hex << std::setw(2) << std::setfill('0') << (uint32_t)mac[i];
if(i != mac.size() - 1)
oss << ':';
}
return oss.str();
};
if (auto destMAC = ethMessage->getDestinationMAC(); destMAC.has_value()) {
std::cout << "\t\t Destination:\t" << printMAC(*destMAC) << "\n";
} else {
std::cout << "\t\t Destination:\t N/A\n";
}
if (auto srcMAC = ethMessage->getSourceMAC(); srcMAC.has_value()) {
std::cout << "\t\t Source:\t" << printMAC(*srcMAC) << "\n";
} else {
std::cout << "\t\t Source:\t N/A\n";
}
if (auto etherType = ethMessage->getEtherType(); etherType.has_value()) {
std::cout << "\t\t EtherType:\t" << std::hex << std::setw(4) << std::setfill('0') << *etherType << "\n";
} else {
std::cout << "\t\t EtherType:\t N/A\n";
}
// Print the data
for(size_t i = 0; i < ethMessage->data.size(); i++) {
+20 -2
View File
@@ -208,8 +208,26 @@ int main() {
std::cout << "\t\t Timestamped:\t"<< ethMessage->timestamp << " ns since 1/1/2007\n";
// The MACAddress may be printed directly or accessed with the `data` member
std::cout << "\t\t Source:\t" << ethMessage->getSourceMAC() << "\n";
std::cout << "\t\t Destination:\t" << ethMessage->getDestinationMAC();
// The MACAddress may be printed directly or accessed with the `data` member
auto printMAC = [](const icsneo::MACAddress& mac) {
std::ostringstream oss;
for(size_t i = 0; i < mac.size(); i++) {
oss << std::hex << std::setw(2) << std::setfill('0') << (uint32_t)mac[i];
if(i != mac.size() - 1)
oss << ':';
}
return oss.str();
};
if (auto destMAC = ethMessage->getDestinationMAC(); destMAC.has_value()) {
std::cout << "\t\t Destination:\t" << printMAC(*destMAC) << "\n";
} else {
std::cout << "\t\t Destination:\t N/A\n";
}
if (auto srcMAC = ethMessage->getSourceMAC(); srcMAC.has_value()) {
std::cout << "\t\t Source:\t" << printMAC(*srcMAC) << "\n";
} else {
std::cout << "\t\t Source:\t N/A\n";
}
// Print the data
for(size_t i = 0; i < ethMessage->data.size(); i++) {
@@ -154,12 +154,12 @@ void setupSymbolMonitoring(std::shared_ptr<icsneo::Device>& device,
auto ethMsg = std::static_pointer_cast<icsneo::EthernetMessage>(frame);
if (!ethMsg->isT1S)
if (!ethMsg->t1s)
return;
double timestamp_ms = ethMsg->timestamp / 1000000.0;
if (ethMsg->isT1SSymbol) {
if (ethMsg->t1s->isSymbol) {
size_t numSymbols = ethMsg->data.size();
std::cout << std::fixed << std::setprecision(3)
@@ -169,7 +169,7 @@ void setupSymbolMonitoring(std::shared_ptr<icsneo::Device>& device,
if (numSymbols > 0) {
std::cout << " (" << numSymbols << " symbol" << (numSymbols > 1 ? "s" : "") << ")";
}
std::cout << " | Node ID: " << (int)ethMsg->t1sNodeId << std::endl;
std::cout << " | Node ID: " << (int)ethMsg->t1s->nodeId << std::endl;
for (size_t i = 0; i < numSymbols; i++) {
uint8_t symbolValue = ethMsg->data[i];
@@ -188,8 +188,8 @@ void setupSymbolMonitoring(std::shared_ptr<icsneo::Device>& device,
<< std::dec << std::endl;
}
if (numSymbols == 0 && ethMsg->t1sSymbolType != 0) {
uint8_t symbolValue = ethMsg->t1sSymbolType;
if (numSymbols == 0 && ethMsg->t1s->symbolType != 0) {
uint8_t symbolValue = ethMsg->t1s->symbolType;
std::string symbolName = getSymbolName(symbolValue);
stats.symbolCount++;
@@ -205,20 +205,20 @@ void setupSymbolMonitoring(std::shared_ptr<icsneo::Device>& device,
<< std::dec << " (from t1sSymbolType field)" << std::endl;
}
}
else if (ethMsg->isT1SBurst) {
else if (ethMsg->t1s->isBurst) {
stats.burstCount++;
std::cout << std::fixed << std::setprecision(3)
<< "[" << std::setw(12) << timestamp_ms << " ms] "
<< "BURST | "
<< "Node ID: " << (int)ethMsg->t1sNodeId << " | "
<< "Burst Count: " << (int)ethMsg->t1sBurstCount << std::endl;
<< "Node ID: " << (int)ethMsg->t1s->nodeId << " | "
<< "Burst Count: " << (int)ethMsg->t1s->burstCount << std::endl;
}
else if (ethMsg->isT1SWake) {
else if (ethMsg->t1s->isWake) {
stats.wakeCount++;
std::cout << std::fixed << std::setprecision(3)
<< "[" << std::setw(12) << timestamp_ms << " ms] "
<< "WAKE signal detected | "
<< "Node ID: " << (int)ethMsg->t1sNodeId << std::endl;
<< "Node ID: " << (int)ethMsg->t1s->nodeId << std::endl;
}
else {
stats.dataFrameCount++;
@@ -226,7 +226,7 @@ void setupSymbolMonitoring(std::shared_ptr<icsneo::Device>& device,
<< "[" << std::setw(12) << timestamp_ms << " ms] "
<< "T1S Data Frame | "
<< "Length: " << ethMsg->data.size() << " bytes | "
<< "Node ID: " << (int)ethMsg->t1sNodeId << std::endl;
<< "Node ID: " << (int)ethMsg->t1s->nodeId << std::endl;
if (!ethMsg->data.empty()) {
std::cout << " Data: ";