Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ethernet, initCallback, ctor and eth_if #901

Merged
merged 6 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions libraries/Ethernet/src/Ethernet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

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 +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);
Expand All @@ -68,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);
}

Expand All @@ -77,7 +82,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 +106,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()));
10 changes: 1 addition & 9 deletions libraries/Ethernet/src/Ethernet.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ enum { // compatibility with Arduino ::maintain()
DHCP_CHECK_REBIND_OK = 4
};

typedef void *(*voidPrtFuncPtr)(void);

class EthernetClass : public MbedSocketClass {

public:
Expand All @@ -60,10 +58,6 @@ class EthernetClass : public MbedSocketClass {
// Returns 0 if the DHCP configuration failed, and 1 if it succeeded
EthernetClass(EthernetInterface *_if)
: 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();
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
Loading