diff options
author | David Crocker <dcrocker@eschertech.com> | 2020-01-26 23:56:03 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2020-01-26 23:56:03 +0300 |
commit | 79df4b88ed68875cd58ef4e1ec5ea22f9ab9d55e (patch) | |
tree | 701938eab5583381e5896116dec79e21cc278a82 /src/Networking/LwipEthernet | |
parent | 6e8f8223fd862eae27545ead596b52c5a6a46ca2 (diff) |
Refactored MAC address code
M540 on Duet WiFi now returns correct MAC address
MAC address added to object model
WiFi firmware version now returned correctly in object model
Diffstat (limited to 'src/Networking/LwipEthernet')
-rw-r--r-- | src/Networking/LwipEthernet/LwipEthernetInterface.cpp | 11 | ||||
-rw-r--r-- | src/Networking/LwipEthernet/LwipEthernetInterface.h | 6 |
2 files changed, 9 insertions, 8 deletions
diff --git a/src/Networking/LwipEthernet/LwipEthernetInterface.cpp b/src/Networking/LwipEthernet/LwipEthernetInterface.cpp index 4fa2dd36..ba6f0f85 100644 --- a/src/Networking/LwipEthernet/LwipEthernetInterface.cpp +++ b/src/Networking/LwipEthernet/LwipEthernetInterface.cpp @@ -112,8 +112,8 @@ constexpr ObjectModelTableEntry LwipEthernetInterface::objectModelTable[] = { // These entries must be in alphabetical order { "actualIP", OBJECT_MODEL_FUNC(self->ipAddress), ObjectModelEntryFlags::none }, - { "firmwareVersion", OBJECT_MODEL_FUNC_NOSELF(nullptr), ObjectModelEntryFlags::none }, { "gateway", OBJECT_MODEL_FUNC(self->gateway), ObjectModelEntryFlags::none }, + { "mac", OBJECT_MODEL_FUNC(self->macAddress), ObjectModelEntryFlags::none }, { "subnet", OBJECT_MODEL_FUNC(self->netmask), ObjectModelEntryFlags::none }, { "type", OBJECT_MODEL_FUNC_NOSELF("ethernet"), ObjectModelEntryFlags::none }, }; @@ -137,7 +137,7 @@ void LwipEthernetInterface::Init() noexcept listeningPcbs[i] = nullptr; } - memcpy(macAddress, platform.GetDefaultMacAddress(), sizeof(macAddress)); + macAddress = platform.GetDefaultMacAddress(); } GCodeResult LwipEthernetInterface::EnableProtocol(NetworkProtocol protocol, int port, int secure, const StringRef& reply) noexcept @@ -338,7 +338,7 @@ void LwipEthernetInterface::Start() noexcept const char *hostname = reprap.GetNetwork().GetHostname(); // Allow the MAC address to be set only before LwIP is started... - ethernet_configure_interface(platform.GetDefaultMacAddress(), hostname); + ethernet_configure_interface(platform.GetDefaultMacAddress().bytes, hostname); init_ethernet(DefaultIpAddress, DefaultNetMask, DefaultGateway); // Initialise mDNS subsystem @@ -589,9 +589,10 @@ void LwipEthernetInterface::UpdateHostname(const char *hostname) noexcept } } -void LwipEthernetInterface::SetMacAddress(const uint8_t mac[]) noexcept +GCodeResult LwipEthernetInterface::SetMacAddress(const MacAddress& mac, const StringRef& reply) noexcept { - memcpy(macAddress, mac, sizeof(macAddress)); + macAddress = mac; + return GCodeResult::ok; } void LwipEthernetInterface::OpenDataPort(Port port) noexcept diff --git a/src/Networking/LwipEthernet/LwipEthernetInterface.h b/src/Networking/LwipEthernet/LwipEthernetInterface.h index d4269cd3..04c57947 100644 --- a/src/Networking/LwipEthernet/LwipEthernetInterface.h +++ b/src/Networking/LwipEthernet/LwipEthernetInterface.h @@ -48,8 +48,8 @@ public: void UpdateHostname(const char *hostname) noexcept override; IPAddress GetIPAddress() const noexcept override; void SetIPAddress(IPAddress p_ipAddress, IPAddress p_netmask, IPAddress p_gateway) noexcept override; - void SetMacAddress(const uint8_t mac[]) noexcept override; - const uint8_t *GetMacAddress() const noexcept override { return macAddress; } + GCodeResult SetMacAddress(const MacAddress& mac, const StringRef& reply) noexcept override; + const MacAddress& GetMacAddress() const noexcept override { return macAddress; } // LwIP interfaces bool ConnectionEstablished(tcp_pcb *pcb) noexcept; @@ -105,7 +105,7 @@ private: IPAddress ipAddress; IPAddress netmask; IPAddress gateway; - uint8_t macAddress[6]; + MacAddress macAddress; }; #endif |