From 5681ad537c8a09d1193680ba758afbb3b243ac85 Mon Sep 17 00:00:00 2001 From: technyon Date: Thu, 2 Mar 2023 20:26:22 +0100 Subject: [PATCH] inject device name for LAN8720 devices --- Network.cpp | 4 ++-- networkDevices/EthLan8720Device.cpp | 17 +++++++++-------- networkDevices/EthLan8720Device.h | 4 +++- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Network.cpp b/Network.cpp index 3ce6995..c06ae1a 100644 --- a/Network.cpp +++ b/Network.cpp @@ -96,10 +96,10 @@ void Network::setupDevice() _device = new W5500Device(_hostname, _preferences, hardwareDetect); break; case NetworkDeviceType::Olimex_LAN8720: - _device = new EthLan8720Device(_hostname, _preferences, ETH_PHY_ADDR, 12, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLOCK_GPIO17_OUT); + _device = new EthLan8720Device(_hostname, _preferences, "Olimex (LAN8720)", ETH_PHY_ADDR, 12, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLOCK_GPIO17_OUT); break; case NetworkDeviceType::WT32_LAN8720: - _device = new EthLan8720Device(_hostname, _preferences, 1, 16); + _device = new EthLan8720Device(_hostname, _preferences, "WT32-ETH01", 1, 16); break; case NetworkDeviceType::WiFi: _device = new WifiDevice(_hostname, _preferences); diff --git a/networkDevices/EthLan8720Device.cpp b/networkDevices/EthLan8720Device.cpp index f9eb6a4..d02acf3 100644 --- a/networkDevices/EthLan8720Device.cpp +++ b/networkDevices/EthLan8720Device.cpp @@ -10,8 +10,9 @@ #include "espMqttClient.h" #include "../RestartReason.h" -EthLan8720Device::EthLan8720Device(const String& hostname, Preferences* _preferences, uint8_t phy_addr, int power, int mdc, int mdio, eth_phy_type_t ethtype, eth_clock_mode_t clock_mode, bool use_mac_from_efuse) +EthLan8720Device::EthLan8720Device(const String& hostname, Preferences* preferences, const std::string& deviceName, uint8_t phy_addr, int power, int mdc, int mdio, eth_phy_type_t ethtype, eth_clock_mode_t clock_mode, bool use_mac_from_efuse) : NetworkDevice(hostname), + _deviceName(deviceName), _phy_addr(phy_addr), _power(power), _mdc(mdc), @@ -20,11 +21,11 @@ EthLan8720Device::EthLan8720Device(const String& hostname, Preferences* _prefere _clock_mode(clock_mode), _use_mac_from_efuse(use_mac_from_efuse) { - _restartOnDisconnect = _preferences->getBool(preference_restart_on_disconnect); + _restartOnDisconnect = preferences->getBool(preference_restart_on_disconnect); - size_t caLength = _preferences->getString(preference_mqtt_ca,_ca,TLS_CA_MAX_SIZE); - size_t crtLength = _preferences->getString(preference_mqtt_crt,_cert,TLS_CERT_MAX_SIZE); - size_t keyLength = _preferences->getString(preference_mqtt_key,_key,TLS_KEY_MAX_SIZE); + size_t caLength = preferences->getString(preference_mqtt_ca, _ca, TLS_CA_MAX_SIZE); + size_t crtLength = preferences->getString(preference_mqtt_crt, _cert, TLS_CERT_MAX_SIZE); + size_t keyLength = preferences->getString(preference_mqtt_key, _key, TLS_KEY_MAX_SIZE); _useEncryption = caLength > 1; // length is 1 when empty @@ -48,12 +49,12 @@ EthLan8720Device::EthLan8720Device(const String& hostname, Preferences* _prefere _mqttClient = new espMqttClient(false); } - if(_preferences->getBool(preference_mqtt_log_enabled)) + if(preferences->getBool(preference_mqtt_log_enabled)) { _path = new char[200]; memset(_path, 0, sizeof(_path)); - String pathStr = _preferences->getString(preference_mqtt_lock_path); + String pathStr = preferences->getString(preference_mqtt_lock_path); pathStr.concat(mqtt_topic_log); strcpy(_path, pathStr.c_str()); Log = new MqttLogger(this, _path, MqttLoggerMode::MqttAndSerial); @@ -62,7 +63,7 @@ EthLan8720Device::EthLan8720Device(const String& hostname, Preferences* _prefere const String EthLan8720Device::deviceName() const { - return "Olimex LAN8720"; + return _deviceName.c_str(); } void EthLan8720Device::initialize() diff --git a/networkDevices/EthLan8720Device.h b/networkDevices/EthLan8720Device.h index 005fe6b..c601a1d 100644 --- a/networkDevices/EthLan8720Device.h +++ b/networkDevices/EthLan8720Device.h @@ -12,7 +12,8 @@ class EthLan8720Device : public NetworkDevice public: EthLan8720Device(const String& hostname, - Preferences* _preferences, + Preferences* preferences, + const std::string& deviceName, uint8_t phy_addr = ETH_PHY_ADDR, int power = ETH_PHY_POWER, int mdc = ETH_PHY_MDC, @@ -74,6 +75,7 @@ private: bool _hardwareInitialized = false; bool _lastConnected = false; + const std::string _deviceName; uint8_t _phy_addr; int _power; int _mdc;