Epsilon: Add PHY settings

This commit is contained in:
Jonathan Schwartz
2025-04-09 14:08:55 +00:00
committed by Kyle Schwarz
parent f743f32e63
commit 70733b3d96
11 changed files with 385 additions and 7 deletions
+4 -3
View File
@@ -110,6 +110,7 @@ public:
ModeNotFound = 0x2054,
AppErrorParsingFailed = 0x2055,
GPTPNotSupported = 0x2056,
SettingNotAvaiableDevice = 0x2057,
// Transport Events
FailedToRead = 0x3000,
@@ -186,19 +187,19 @@ public:
APIEvent() : eventStruct({}), serial(), timepoint(), device(nullptr) {}
APIEvent(APIEvent::Type event, APIEvent::Severity severity, const Device* device = nullptr);
const neoevent_t* getNeoEvent() const noexcept { return &eventStruct; }
Type getType() const noexcept { return Type(eventStruct.eventNumber); }
Severity getSeverity() const noexcept { return Severity(eventStruct.severity); }
std::string getDescription() const noexcept { return std::string(eventStruct.description); }
const Device* getDevice() const noexcept { return device; } // Will return nullptr if this is an API-wide event
EventTimePoint getTimestamp() const noexcept { return timepoint; }
void downgradeFromError() noexcept;
bool isForDevice(const Device* forDevice) const noexcept { return forDevice == device; }
bool isForDevice(std::string serial) const noexcept;
// As opposed to getDescription, this will also add text such as "neoVI FIRE 2 CY2468 Error: " to fully describe the problem
std::string describe() const noexcept;
friend std::ostream& operator<<(std::ostream& os, const APIEvent& event) {
+3 -3
View File
@@ -621,7 +621,7 @@ public:
std::optional<bool> SetRootDirectoryEntryFlags(uint8_t mask, uint8_t values, uint32_t collectionEntryByteAddress);
std::shared_ptr<Communication> com;
std::unique_ptr<IDeviceSettings> settings;
std::shared_ptr<IDeviceSettings> settings;
std::optional<size_t> getGenericBinarySize(uint16_t binaryIndex);
bool readBinaryFile(std::ostream& stream, uint16_t binaryIndex);
@@ -814,8 +814,8 @@ protected:
}
template<typename Settings>
std::unique_ptr<IDeviceSettings> makeSettings(std::shared_ptr<Communication> comm) {
return std::unique_ptr<IDeviceSettings>(new Settings(comm));
std::shared_ptr<IDeviceSettings> makeSettings(std::shared_ptr<Communication> comm) {
return std::make_shared<Settings>(comm);
}
virtual void setupSettings(IDeviceSettings&) {}
+35
View File
@@ -59,6 +59,9 @@ enum EthLinkSpeed
ETH_SPEED_10 = 0,
ETH_SPEED_100,
ETH_SPEED_1000,
ETH_SPEED_2500,
ETH_SPEED_5000,
ETH_SPEED_10000,
};
typedef struct
@@ -851,6 +854,38 @@ public:
*/
bool setLINCommanderResponseTimeFor(Network net, uint8_t bits);
virtual bool setPhyMode(uint8_t index, OPEthLinkMode mode) {
(void)index, (void)mode;
return false;
}
virtual bool setPhyEnable(uint8_t index, bool enable) {
(void)index, (void)enable;
return false;
}
virtual bool setPhySpeed(uint8_t index, EthLinkSpeed speed) {
(void)index, (void)speed;
return false;
}
virtual std::optional<OPEthLinkMode> getPhyMode(uint8_t index) {
(void)index;
report(APIEvent::Type::SettingNotAvaiableDevice, APIEvent::Severity::EventWarning);
return std::nullopt;
}
virtual std::optional<bool> getPhyEnable(uint8_t index) {
(void)index;
report(APIEvent::Type::SettingNotAvaiableDevice, APIEvent::Severity::EventWarning);
return std::nullopt;
}
virtual std::optional<EthLinkSpeed> getPhySpeed(uint8_t index) {
(void)index;
report(APIEvent::Type::SettingNotAvaiableDevice, APIEvent::Severity::EventWarning);
return std::nullopt;
}
const void* getRawStructurePointer() const { return settingsInDeviceRAM.data(); }
void* getMutableRawStructurePointer() { return settings.data(); }
template<typename T> const T* getStructurePointer() const { return reinterpret_cast<const T*>(getRawStructurePointer()); }
@@ -4,6 +4,7 @@
#include <stdint.h>
#include "icsneo/device/idevicesettings.h"
#include "icsneo/communication/network.h"
#include <optional>
#ifdef __cplusplus
@@ -122,6 +123,155 @@ public:
return nullptr;
}
}
bool setPhyMode(uint8_t index, OPEthLinkMode mode) override {
if (index > RADEPSILON_MAX_PHY) {
report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error);
return false;
}
auto cfg = getMutableStructurePointer<radepsilon_settings_t>();
if (cfg == nullptr) {
return false;
}
EpsilonPhyMode epsilonMode;
switch (mode) {
default:
report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error);
return false;
case OPETH_LINK_AUTO:
epsilonMode = EpsilonPhyMode::Auto;
break;
case OPETH_LINK_SLAVE:
epsilonMode = EpsilonPhyMode::Slave;
break;
case OPETH_LINK_MASTER:
epsilonMode = EpsilonPhyMode::Master;
break;
}
cfg->switchSettings.phyMode[index] = static_cast<uint8_t>(epsilonMode);
return true;
}
bool setPhyEnable(uint8_t index, bool enable) override {
if (index > RADEPSILON_MAX_PHY) {
report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error);
return false;
}
auto cfg = getMutableStructurePointer<radepsilon_settings_t>();
if (cfg == nullptr) {
return false;
}
cfg->switchSettings.enablePhy[index] = enable;
return true;
}
bool setPhySpeed(uint8_t index, EthLinkSpeed speed) override {
if (index > RADEPSILON_MAX_PHY) {
report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error);
return false;
}
auto cfg = getMutableStructurePointer<radepsilon_settings_t>();
if (cfg == nullptr) {
return false;
}
EpsilonPhySpeed epsilonSpeed;
switch (speed) {
default:
report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error);
return false;
case ETH_SPEED_100:
epsilonSpeed = EpsilonPhySpeed::Speed100;
break;
case ETH_SPEED_1000:
epsilonSpeed = EpsilonPhySpeed::Speed1000;
break;
case ETH_SPEED_10000:
epsilonSpeed = EpsilonPhySpeed::Speed10000;
break;
}
cfg->switchSettings.speed[index] = static_cast<uint8_t>(epsilonSpeed);
return true;
}
std::optional<OPEthLinkMode> getPhyMode(uint8_t index) override {
if (index > RADEPSILON_MAX_PHY) {
report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error);
return std::nullopt;
}
auto cfg = getStructurePointer<radepsilon_settings_t>();
if (cfg == nullptr) {
return std::nullopt;
}
OPEthLinkMode mode;
switch (static_cast<EpsilonPhyMode>(cfg->switchSettings.phyMode[index])) {
default:
report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error);
return std::nullopt;
case EpsilonPhyMode::Auto:
mode = OPETH_LINK_AUTO;
break;
case EpsilonPhyMode::Slave:
mode = OPETH_LINK_SLAVE;
break;
case EpsilonPhyMode::Master:
mode = OPETH_LINK_MASTER;
break;
}
return std::make_optional(mode);
}
std::optional<bool> getPhyEnable(uint8_t index) override {
if (index > RADEPSILON_MAX_PHY) {
report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error);
return std::nullopt;
}
auto cfg = getStructurePointer<radepsilon_settings_t>();
if (cfg == nullptr) {
return false;
}
return std::make_optional(static_cast<bool>(cfg->switchSettings.enablePhy[index]));
}
std::optional<EthLinkSpeed> getPhySpeed(uint8_t index) override {
if (index > RADEPSILON_MAX_PHY) {
report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error);
return std::nullopt;
}
auto cfg = getStructurePointer<radepsilon_settings_t>();
if (cfg == nullptr) {
return std::nullopt;
}
EthLinkSpeed speed;
switch (static_cast<EpsilonPhySpeed>(cfg->switchSettings.speed[index])) {
default:
report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error);
return std::nullopt;
case EpsilonPhySpeed::Speed100:
speed = ETH_SPEED_100;
break;
case EpsilonPhySpeed::Speed1000:
speed = ETH_SPEED_1000;
break;
case EpsilonPhySpeed::Speed10000:
speed = ETH_SPEED_10000;
break;
}
return std::make_optional(speed);
}
private:
enum class EpsilonPhyMode : uint8_t {
Auto = 0,
Master = 1,
Slave = 2,
};
enum class EpsilonPhySpeed : uint8_t {
Speed100 = 0,
Speed1000 = 1,
Speed10000 = 2,
};
};
}; // namespace icsneo