From 0ded5508c198c72f3396858cde4ddb7451fda7eb Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Mon, 14 Feb 2022 19:20:50 -0500 Subject: [PATCH] Windows: Fix build issues with EthPhyRegPacket --- communication/encoder.cpp | 1 + communication/packet/ethphyregpacket.cpp | 20 +------- .../communication/message/ethphymessage.h | 29 ++++------- .../communication/packet/ethphyregpacket.h | 50 ++++++++++--------- 4 files changed, 40 insertions(+), 60 deletions(-) diff --git a/communication/encoder.cpp b/communication/encoder.cpp index 30cc489..9bf60e3 100644 --- a/communication/encoder.cpp +++ b/communication/encoder.cpp @@ -5,6 +5,7 @@ #include "icsneo/communication/packet/iso9141packet.h" #include "icsneo/communication/packet/canpacket.h" #include "icsneo/communication/packet/ethphyregpacket.h" +#include "icsneo/communication/message/ethphymessage.h" using namespace icsneo; diff --git a/communication/packet/ethphyregpacket.cpp b/communication/packet/ethphyregpacket.cpp index f439191..06db93a 100644 --- a/communication/packet/ethphyregpacket.cpp +++ b/communication/packet/ethphyregpacket.cpp @@ -36,25 +36,9 @@ std::shared_ptr HardwareEthernetPhyRegisterPacket::DecodeToMessag phyMessage->Clause45Enable = (pEntry->Clause45Enable != 0u); phyMessage->version = static_cast(pEntry->version); if(phyMessage->Clause45Enable) - { - phyMessage->clause45 = - { - .port = pEntry->clause45.port, - .device = pEntry->clause45.device, - .regAddr = pEntry->clause45.regAddr, - .regVal = pEntry->clause45.regVal - }; - } + phyMessage->clause45 = pEntry->clause45; else - { - phyMessage->clause22 = - { - .phyAddr = pEntry->clause22.phyAddr, - .page = pEntry->clause22.page, - .regAddr = pEntry->clause22.regAddr, - .regVal = pEntry->clause22.regVal - }; - } + phyMessage->clause22 = pEntry->clause22; msg->messages.push_back(phyMessage); } } diff --git a/include/icsneo/communication/message/ethphymessage.h b/include/icsneo/communication/message/ethphymessage.h index 75d6769..470208e 100644 --- a/include/icsneo/communication/message/ethphymessage.h +++ b/include/icsneo/communication/message/ethphymessage.h @@ -12,35 +12,26 @@ namespace icsneo { -struct Clause22Message -{ - uint8_t phyAddr; - uint8_t page; - uint16_t regAddr; - uint16_t regVal; -}; +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4201) // nameless struct/union +#endif -struct Clause45Message -{ - uint8_t port; - uint8_t device; - uint16_t regAddr; - uint16_t regVal; -}; - -struct PhyMessage -{ +struct PhyMessage { bool Enabled; bool WriteEnable; bool Clause45Enable; uint8_t version; - union - { + union { Clause22Message clause22; Clause45Message clause45; }; }; +#ifdef _MSC_VER +#pragma warning(pop) +#endif + //Internal message which provides an interface with device ethernet PHY registers, //with Clause22 and Clause45 message support class EthPhyMessage : public Message { diff --git a/include/icsneo/communication/packet/ethphyregpacket.h b/include/icsneo/communication/packet/ethphyregpacket.h index 58d999d..2f0a805 100644 --- a/include/icsneo/communication/packet/ethphyregpacket.h +++ b/include/icsneo/communication/packet/ethphyregpacket.h @@ -3,7 +3,6 @@ #ifdef __cplusplus -#include "icsneo/communication/message/ethphymessage.h" #include "icsneo/api/eventmanager.h" #include #include @@ -14,35 +13,35 @@ namespace icsneo class Packetizer; class EthPhyMessage; -typedef struct -{ +#pragma pack(push, 1) +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4201) // nameless struct/union +#endif + +struct PhyRegisterHeader_t { uint16_t numEntries; uint8_t version; uint8_t entryBytes; -} PhyRegisterHeader_t; +}; -typedef struct -{ +struct Clause22Message { uint8_t phyAddr; //5 bits uint8_t page; //8 bits uint16_t regAddr; //5 bits uint16_t regVal; -} Clause22Message_t; //6 bytes +}; //6 bytes -typedef struct -{ +struct Clause45Message { uint8_t port; //5 bits uint8_t device; //5 bits uint16_t regAddr; uint16_t regVal; -} Clause45Message_t; //6 bytes +}; //6 bytes -typedef struct -{ - union - { - struct - { +struct PhyRegisterPacket_t { + union { + struct { uint16_t Enabled : 1; uint16_t WriteEnable : 1; uint16_t Clause45Enable : 1; @@ -52,20 +51,25 @@ typedef struct uint16_t flags; }; - union - { - Clause22Message_t clause22; - Clause45Message_t clause45; + union { + Clause22Message clause22; + Clause45Message clause45; }; -} PhyRegisterPacket_t; +}; + +#ifdef _MSC_VER +#pragma warning(pop) +#endif +#pragma pack(pop) static constexpr size_t MaxPhyEntries = 128u; static constexpr size_t MaxBytesPhyEntries = MaxPhyEntries * sizeof(PhyRegisterHeader_t); static constexpr uint8_t PhyPacketVersion = 1u; static constexpr uint8_t FiveBits = 0x1Fu; -struct HardwareEthernetPhyRegisterPacket -{ +class EthPhyMessage; + +struct HardwareEthernetPhyRegisterPacket { static std::shared_ptr DecodeToMessage(const std::vector& bytestream, const device_eventhandler_t& report); static bool EncodeFromMessage(const EthPhyMessage& message, std::vector& bytestream, const device_eventhandler_t& report); };