Device: Implement Ethernet PHY MDIO Communication

The following fixups were added during the squash/merge:

Fix formatting in EthPhyMessage and EthPhyRegPacket
Device: Use std::make_shared when creating the EthPHYControl filter
Network: Create NetID String for EthPHYControl
EthPhyRegPacket: Constants in PascalCase
This commit is contained in:
Kyle Johannes
2021-12-08 19:07:07 -05:00
committed by Paul Hollinsky
parent 890eb1e1bc
commit 2d1bb381f6
21 changed files with 421 additions and 1 deletions
+32
View File
@@ -3,6 +3,7 @@
#include "icsneo/api/eventmanager.h"
#include "icsneo/communication/command.h"
#include "icsneo/device/extensions/deviceextension.h"
#include "icsneo/platform/optional.h"
#include <string.h>
#include <iostream>
#include <sstream>
@@ -786,4 +787,35 @@ APIEvent::Type Device::getCommunicationNotEstablishedError() {
void Device::updateLEDState() {
std::vector<uint8_t> args {(uint8_t) ledState};
com->sendCommand(Command::UpdateLEDState, args);
}
optional<EthPhyMessage> Device::sendEthPhyMsg(const EthPhyMessage& message, std::chrono::milliseconds timeout) {
if(!isOpen()) {
report(APIEvent::Type::DeviceCurrentlyClosed, APIEvent::Severity::Error);
return nullopt;
}
if(!getEthPhyRegControlSupported()) {
report(APIEvent::Type::EthPhyRegisterControlNotAvailable, APIEvent::Severity::Error);
return nullopt;
}
if(!isOnline()) {
report(APIEvent::Type::DeviceCurrentlyOffline, APIEvent::Severity::Error);
return nullopt;
}
std::vector<uint8_t> bytes;
HardwareEthernetPhyRegisterPacket::EncodeFromMessage(message, bytes, report);
std::shared_ptr<Message> response = com->waitForMessageSync(
[this, bytes](){ return com->sendCommand(Command::PHYControlRegisters, bytes); },
std::make_shared<MessageFilter>(Network::NetID::EthPHYControl), timeout);
if(!response) {
report(APIEvent::Type::NoDeviceResponse, APIEvent::Severity::Error);
return nullopt;
}
auto retMsg = std::static_pointer_cast<EthPhyMessage>(response);
if(!retMsg) {
return nullopt;
}
return make_optional<EthPhyMessage>(*retMsg);
}