From 39853dda1a5a2f5624bb119375c00d1ac9de3d4e Mon Sep 17 00:00:00 2001 From: Giampaolo Mancini Date: Mon, 17 Jun 2024 11:53:15 +0200 Subject: [PATCH 1/6] Ethernet: Remove initCallback --- libraries/Ethernet/src/Ethernet.cpp | 5 ----- libraries/Ethernet/src/Ethernet.h | 4 ---- 2 files changed, 9 deletions(-) diff --git a/libraries/Ethernet/src/Ethernet.cpp b/libraries/Ethernet/src/Ethernet.cpp index 2e0f1a94f..d6c92d635 100644 --- a/libraries/Ethernet/src/Ethernet.cpp +++ b/libraries/Ethernet/src/Ethernet.cpp @@ -3,11 +3,6 @@ #define SSID_MAX_LENGTH 32 int arduino::EthernetClass::begin(uint8_t *mac, unsigned long timeout, unsigned long responseTimeout) { - if (eth_if == nullptr) { - //Q: What is the callback for? - _initializerCallback(); - if (eth_if == nullptr) return 0; - } eth_if->set_dhcp(true); return _begin(mac, timeout, responseTimeout); } diff --git a/libraries/Ethernet/src/Ethernet.h b/libraries/Ethernet/src/Ethernet.h index 2fc2ef240..b1919e481 100644 --- a/libraries/Ethernet/src/Ethernet.h +++ b/libraries/Ethernet/src/Ethernet.h @@ -62,9 +62,6 @@ class EthernetClass : public MbedSocketClass { : eth_if(_if){}; EthernetClass(){}; - EthernetClass(voidPrtFuncPtr _cb) - : _initializerCallback(_cb){}; - int begin(uint8_t *mac = nullptr, unsigned long timeout = 60000, unsigned long responseTimeout = 4000); EthernetLinkStatus linkStatus(); EthernetHardwareStatus hardwareStatus(); @@ -121,7 +118,6 @@ class EthernetClass : public MbedSocketClass { volatile EthernetLinkStatus _currentNetworkStatus = Unknown; EthernetInterface net; EthernetInterface *eth_if = &net; - voidPrtFuncPtr _initializerCallback; arduino::IPAddress ipAddressFromSocketAddress(SocketAddress socketAddress); }; From 3e6aa5e378226fd079ec08dd17aa503ff89ea85e Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 18 Jun 2024 16:25:47 +0200 Subject: [PATCH 2/6] Ethernet: align ctor to WiFi --- libraries/Ethernet/src/Ethernet.cpp | 5 ++++- libraries/Ethernet/src/Ethernet.h | 4 +--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/libraries/Ethernet/src/Ethernet.cpp b/libraries/Ethernet/src/Ethernet.cpp index d6c92d635..b20eb7923 100644 --- a/libraries/Ethernet/src/Ethernet.cpp +++ b/libraries/Ethernet/src/Ethernet.cpp @@ -3,6 +3,9 @@ #define SSID_MAX_LENGTH 32 int arduino::EthernetClass::begin(uint8_t *mac, unsigned long timeout, unsigned long responseTimeout) { + if (eth_if == nullptr) { + return 0; + } eth_if->set_dhcp(true); return _begin(mac, timeout, responseTimeout); } @@ -94,4 +97,4 @@ void arduino::EthernetClass::MACAddress(uint8_t *mac_address) macAddress(mac_address); } -arduino::EthernetClass Ethernet; +arduino::EthernetClass Ethernet(static_cast(EthInterface::get_default_instance())); diff --git a/libraries/Ethernet/src/Ethernet.h b/libraries/Ethernet/src/Ethernet.h index b1919e481..7c89f2ad6 100644 --- a/libraries/Ethernet/src/Ethernet.h +++ b/libraries/Ethernet/src/Ethernet.h @@ -60,7 +60,6 @@ class EthernetClass : public MbedSocketClass { // Returns 0 if the DHCP configuration failed, and 1 if it succeeded EthernetClass(EthernetInterface *_if) : eth_if(_if){}; - EthernetClass(){}; int begin(uint8_t *mac = nullptr, unsigned long timeout = 60000, unsigned long responseTimeout = 4000); EthernetLinkStatus linkStatus(); @@ -116,8 +115,7 @@ class EthernetClass : public MbedSocketClass { int _begin(uint8_t *mac, unsigned long timeout, unsigned long responseTimeout); volatile EthernetLinkStatus _currentNetworkStatus = Unknown; - EthernetInterface net; - EthernetInterface *eth_if = &net; + EthernetInterface *eth_if = nullptr; arduino::IPAddress ipAddressFromSocketAddress(SocketAddress socketAddress); }; From 3749dc17c498fdff15af0af5dec2a91eb5ae3d9f Mon Sep 17 00:00:00 2001 From: maidnl Date: Mon, 17 Jun 2024 12:00:48 +0200 Subject: [PATCH 3/6] Ethernet: add eth_if nullptr checks --- libraries/Ethernet/src/Ethernet.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libraries/Ethernet/src/Ethernet.cpp b/libraries/Ethernet/src/Ethernet.cpp index b20eb7923..2a2f01ad4 100644 --- a/libraries/Ethernet/src/Ethernet.cpp +++ b/libraries/Ethernet/src/Ethernet.cpp @@ -49,6 +49,10 @@ int arduino::EthernetClass::begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPA } int arduino::EthernetClass::begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet, unsigned long timeout, unsigned long responseTimeout) { + if(eth_if == nullptr) { + return 0; + } + config(ip, dns, gateway, subnet); eth_if->set_dhcp(false); @@ -66,6 +70,9 @@ void arduino::EthernetClass::end() { } EthernetLinkStatus arduino::EthernetClass::linkStatus() { + if(eth_if == nullptr) { + return LinkOFF; + } return (eth_if->get_connection_status() == NSAPI_STATUS_GLOBAL_UP ? LinkON : LinkOFF); } @@ -75,7 +82,9 @@ EthernetHardwareStatus arduino::EthernetClass::hardwareStatus() { int arduino::EthernetClass::disconnect() { - eth_if->disconnect(); + if(eth_if != nullptr) { + eth_if->disconnect(); + } return 1; } From 25a3e8a42661a877073e8c5376b5eef19a97c1bc Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 18 Jun 2024 16:33:29 +0200 Subject: [PATCH 4/6] Remove unused function pointer definitions --- libraries/Ethernet/src/Ethernet.h | 2 -- libraries/GPS/src/GPS.h | 2 -- libraries/GSM/src/GSM.h | 2 -- libraries/WiFi/src/WiFi.h | 2 -- 4 files changed, 8 deletions(-) diff --git a/libraries/Ethernet/src/Ethernet.h b/libraries/Ethernet/src/Ethernet.h index 7c89f2ad6..5c55d4729 100644 --- a/libraries/Ethernet/src/Ethernet.h +++ b/libraries/Ethernet/src/Ethernet.h @@ -50,8 +50,6 @@ enum { // compatibility with Arduino ::maintain() DHCP_CHECK_REBIND_OK = 4 }; -typedef void *(*voidPrtFuncPtr)(void); - class EthernetClass : public MbedSocketClass { public: diff --git a/libraries/GPS/src/GPS.h b/libraries/GPS/src/GPS.h index 998430ecc..e02d5e9db 100644 --- a/libraries/GPS/src/GPS.h +++ b/libraries/GPS/src/GPS.h @@ -25,8 +25,6 @@ namespace arduino { -typedef void* (*voidPrtFuncPtr)(void); - class GPSClass : public HardwareSerial { public: diff --git a/libraries/GSM/src/GSM.h b/libraries/GSM/src/GSM.h index a41e7692d..cf3652c26 100644 --- a/libraries/GSM/src/GSM.h +++ b/libraries/GSM/src/GSM.h @@ -65,8 +65,6 @@ namespace arduino { -typedef void* (*voidPrtFuncPtr)(void); - class GSMClass : public MbedSocketClass { public: diff --git a/libraries/WiFi/src/WiFi.h b/libraries/WiFi/src/WiFi.h index 1dd01df61..ad650fb14 100644 --- a/libraries/WiFi/src/WiFi.h +++ b/libraries/WiFi/src/WiFi.h @@ -46,8 +46,6 @@ extern "C" { namespace arduino { -typedef void* (*voidPrtFuncPtr)(void); - class WiFiClass : public MbedSocketClass { public: static int16_t _state[MAX_SOCK_NUM]; From 70bf03b54400eb3d7f20621334a3cdbb2e5eae63 Mon Sep 17 00:00:00 2001 From: pennam Date: Wed, 19 Jun 2024 11:27:56 +0200 Subject: [PATCH 5/6] Ethernet: fix comment placing belonging to begin function --- libraries/Ethernet/src/Ethernet.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/Ethernet/src/Ethernet.h b/libraries/Ethernet/src/Ethernet.h index 5c55d4729..8783d651c 100644 --- a/libraries/Ethernet/src/Ethernet.h +++ b/libraries/Ethernet/src/Ethernet.h @@ -53,12 +53,12 @@ enum { // compatibility with Arduino ::maintain() class EthernetClass : public MbedSocketClass { public: - // Initialise the Ethernet shield to use the provided MAC address and - // gain the rest of the configuration through DHCP. - // Returns 0 if the DHCP configuration failed, and 1 if it succeeded EthernetClass(EthernetInterface *_if) : eth_if(_if){}; + // Initialise the Ethernet shield to use the provided MAC address and + // gain the rest of the configuration through DHCP. + // Returns 0 if the DHCP configuration failed, and 1 if it succeeded int begin(uint8_t *mac = nullptr, unsigned long timeout = 60000, unsigned long responseTimeout = 4000); EthernetLinkStatus linkStatus(); EthernetHardwareStatus hardwareStatus(); From 50def68e316d730203cc55039c8abac32b04905a Mon Sep 17 00:00:00 2001 From: pennam Date: Wed, 19 Jun 2024 11:30:00 +0200 Subject: [PATCH 6/6] Ethernet: remove SSID_MAX_LENGTH define --- libraries/Ethernet/src/Ethernet.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/libraries/Ethernet/src/Ethernet.cpp b/libraries/Ethernet/src/Ethernet.cpp index 2a2f01ad4..0f6450a7a 100644 --- a/libraries/Ethernet/src/Ethernet.cpp +++ b/libraries/Ethernet/src/Ethernet.cpp @@ -1,7 +1,5 @@ #include "Ethernet.h" -#define SSID_MAX_LENGTH 32 - int arduino::EthernetClass::begin(uint8_t *mac, unsigned long timeout, unsigned long responseTimeout) { if (eth_if == nullptr) { return 0;