libicsneo/include/icsneo/communication/packet/ethphyregpacket.h

77 lines
1.5 KiB
C++

#ifndef __ETHPHYREGPACKET_H__
#define __ETHPHYREGPACKET_H__
#ifdef __cplusplus
#include "icsneo/communication/message/ethphymessage.h"
#include "icsneo/api/eventmanager.h"
#include <cstdint>
#include <memory>
namespace icsneo
{
class Packetizer;
class EthPhyMessage;
typedef struct
{
uint16_t numEntries;
uint8_t version;
uint8_t entryBytes;
} PhyRegisterHeader_t;
typedef struct
{
uint8_t phyAddr; //5 bits
uint8_t page; //8 bits
uint16_t regAddr; //5 bits
uint16_t regVal;
} Clause22Message_t; //6 bytes
typedef struct
{
uint8_t port; //5 bits
uint8_t device; //5 bits
uint16_t regAddr;
uint16_t regVal;
} Clause45Message_t; //6 bytes
typedef struct
{
union
{
struct
{
uint16_t Enabled : 1;
uint16_t WriteEnable : 1;
uint16_t Clause45Enable : 1;
uint16_t reserved : 9;
uint16_t version : 4;
};
uint16_t flags;
};
union
{
Clause22Message_t clause22;
Clause45Message_t clause45;
};
} PhyRegisterPacket_t;
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
{
static std::shared_ptr<EthPhyMessage> DecodeToMessage(const std::vector<uint8_t>& bytestream, const device_eventhandler_t& report);
static bool EncodeFromMessage(const EthPhyMessage& message, std::vector<uint8_t>& bytestream, const device_eventhandler_t& report);
};
}
#endif //__cplusplus
#endif