VSA: Remove packet truncation mechanism

pull/76/merge
Max Brombach 2025-09-30 15:41:40 +00:00 committed by Kyle Schwarz
parent 11643e2281
commit b9d3dde8d5
7 changed files with 8 additions and 25 deletions

View File

@ -59,7 +59,7 @@ uint64_t Decoder::GetUInt64FromLEBytes(const uint8_t* bytes) {
bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Packet>& packet) {
switch(packet->network.getType()) {
case Network::Type::Ethernet: {
result = HardwareEthernetPacket::DecodeToMessage(packet->data, report);
result = HardwareEthernetPacket::DecodeToMessage(packet->data);
if(!result) {
report(APIEvent::Type::PacketDecodingError, APIEvent::Severity::Error);
return false; // A nullptr was returned, the packet was not long enough to decode

View File

@ -4,7 +4,7 @@
using namespace icsneo;
std::shared_ptr<EthernetMessage> HardwareEthernetPacket::DecodeToMessage(const std::vector<uint8_t>& bytestream, const device_eventhandler_t& report) {
std::shared_ptr<EthernetMessage> HardwareEthernetPacket::DecodeToMessage(const std::vector<uint8_t>& bytestream) {
const HardwareEthernetPacket* packet = (const HardwareEthernetPacket*)((const void*)bytestream.data());
const uint16_t* rawWords = (const uint16_t*)bytestream.data();
// Make sure we have enough to read the packet length first
@ -18,9 +18,6 @@ std::shared_ptr<EthernetMessage> HardwareEthernetPacket::DecodeToMessage(const s
const size_t bytestreamActualSize = bytestream.size();
if(bytestreamActualSize < bytestreamExpectedSize)
return nullptr;
// Check for oversized packets, noting that some devices will send an extra byte to have an even number of bytes
if(bytestreamActualSize > bytestreamExpectedSize + 1)
report(APIEvent::Type::PacketDecodingError, APIEvent::Severity::EventWarning);
auto messagePtr = std::make_shared<EthernetMessage>();
EthernetMessage& message = *messagePtr;
message.transmitted = packet->eid.TXMSG;

View File

@ -25,19 +25,4 @@ void VSAExtendedMessage::appendPacket(std::shared_ptr<Packet> packet) const
if(packet->network.getNetID() == Network::NetID::Invalid) {
packet->network = network;
}
}
void VSAExtendedMessage::truncatePacket(std::shared_ptr<Packet> packet)
{
static constexpr auto EthernetLengthOffset = 26u;
switch(packet->network.getType()) {
case Network::Type::Ethernet:
{
const auto& packetLength = *reinterpret_cast<uint16_t*>(packet->data.data() + EthernetLengthOffset);
const size_t ethernetFrameSize = packetLength - (sizeof(uint16_t) * 2);
const size_t bytestreamExpectedSize = sizeof(HardwareEthernetPacket) + ethernetFrameSize;
packet->data.resize(bytestreamExpectedSize);
}
break;
}
}

View File

@ -430,7 +430,6 @@ bool VSAParser::extractMessagePackets(std::vector<std::shared_ptr<Packet>>& pack
extendedMessageRecord->appendPacket(packet);
if(extendedMessageRecord->getRecordCount() == static_cast<uint32_t>(extendedMessageRecord->getIndex() + 1)) { // Last record in sequence
if(!settings.messageFilter || extendedMessageRecord->filter(settings.messageFilter)) {
VSAExtendedMessage::truncatePacket(packet);
packets.push_back(packet);
}
activeExtendedMessage = false;

View File

@ -239,6 +239,9 @@ int main(int argc, char* argv[]) {
return -1;
}
std::cout << "Waiting for 5 seconds..." << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(5));
std::cout << "info: " << currentMessage << " transmitted frames found" << std::endl;
resetScriptStatus(rxDevice, txDevice, rxInitialCoreminiStatus, txInitialCoreminiStatus);

View File

@ -18,7 +18,7 @@ namespace icsneo {
typedef uint16_t icscm_bitfield;
struct HardwareEthernetPacket {
static std::shared_ptr<EthernetMessage> DecodeToMessage(const std::vector<uint8_t>& bytestream, const device_eventhandler_t& report);
static std::shared_ptr<EthernetMessage> DecodeToMessage(const std::vector<uint8_t>& bytestream);
static bool EncodeFromMessage(const EthernetMessage& message, std::vector<uint8_t>& bytestream, const device_eventhandler_t& report);
// Word 0 - Header flags (offset 0)
@ -57,8 +57,9 @@ struct HardwareEthernetPacket {
struct {
icscm_bitfield T1S_BURST_COUNT : 8;
icscm_bitfield T1S_NODE_ID : 8;
uint8_t RESERVED[6];
} t1s_node;
uint8_t RESERVED[6];
// Words 4-7 - Reserved/Padding
uint16_t stats;

View File

@ -238,8 +238,6 @@ protected:
*/
class VSAExtendedMessage : public VSAMessage {
public:
static void truncatePacket(std::shared_ptr<Packet> packet);
/**
* Appends the payload for this message to the given packet.
* Also sets the network of the packet if unset (used primarily for AA0F records which do not contain the network in the first extended message record).