Skip to content

Commit

Permalink
Merge pull request #901 from pennam/rm_initCallback
Browse files Browse the repository at this point in the history
Ethernet, initCallback, ctor and eth_if
  • Loading branch information
pennam committed Jun 20, 2024
2 parents 14950ea + 50def68 commit 546529a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 25 deletions.
19 changes: 12 additions & 7 deletions libraries/Ethernet/src/Ethernet.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
#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) {
//Q: What is the callback for?
_initializerCallback();
if (eth_if == nullptr) return 0;
return 0;
}
eth_if->set_dhcp(true);
return _begin(mac, timeout, responseTimeout);
Expand Down Expand Up @@ -51,6 +47,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);
Expand All @@ -68,6 +68,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);
}

Expand All @@ -77,7 +80,9 @@ EthernetHardwareStatus arduino::EthernetClass::hardwareStatus() {


int arduino::EthernetClass::disconnect() {
eth_if->disconnect();
if(eth_if != nullptr) {
eth_if->disconnect();
}
return 1;
}

Expand All @@ -99,4 +104,4 @@ void arduino::EthernetClass::MACAddress(uint8_t *mac_address)
macAddress(mac_address);
}

arduino::EthernetClass Ethernet;
arduino::EthernetClass Ethernet(static_cast<EthernetInterface*>(EthInterface::get_default_instance()));
16 changes: 4 additions & 12 deletions libraries/Ethernet/src/Ethernet.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,15 @@ enum { // compatibility with Arduino ::maintain()
DHCP_CHECK_REBIND_OK = 4
};

typedef void *(*voidPrtFuncPtr)(void);

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){};
EthernetClass(){};

EthernetClass(voidPrtFuncPtr _cb)
: _initializerCallback(_cb){};

// 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();
Expand Down Expand Up @@ -119,9 +113,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;
voidPrtFuncPtr _initializerCallback;
EthernetInterface *eth_if = nullptr;
arduino::IPAddress ipAddressFromSocketAddress(SocketAddress socketAddress);
};

Expand Down
2 changes: 0 additions & 2 deletions libraries/GPS/src/GPS.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

namespace arduino {

typedef void* (*voidPrtFuncPtr)(void);

class GPSClass : public HardwareSerial {
public:

Expand Down
2 changes: 0 additions & 2 deletions libraries/GSM/src/GSM.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@

namespace arduino {

typedef void* (*voidPrtFuncPtr)(void);

class GSMClass : public MbedSocketClass {
public:

Expand Down
2 changes: 0 additions & 2 deletions libraries/WiFi/src/WiFi.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ extern "C" {

namespace arduino {

typedef void* (*voidPrtFuncPtr)(void);

class WiFiClass : public MbedSocketClass {
public:
static int16_t _state[MAX_SOCK_NUM];
Expand Down

0 comments on commit 546529a

Please sign in to comment.