Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
27d36d8
Fix MacOS (case) filename clashes
manchoz Jul 6, 2021
357dba7
Add examples
manchoz Jul 6, 2021
c39cfee
Add helpers begin methods
manchoz Feb 1, 2021
05a1b80
Fix WebClient example
manchoz Feb 1, 2021
540e0ab
Add Static IP support
manchoz Jul 5, 2021
a5e512a
Manage Client status
manchoz Jul 5, 2021
d1501d0
Add support for Static Network configuration
manchoz Jul 5, 2021
b04124a
Update examples
manchoz Jul 5, 2021
817b47a
Add forgotten mac parameter
manchoz Jul 5, 2021
cf184fd
Add checks on socket validity before operations
manchoz Jul 6, 2021
9172c17
Manage sockets already connected
manchoz Jul 6, 2021
4aad72b
Add client socket management
manchoz Jul 6, 2021
5f802c1
WiFi: Cleanup libraries and error handling
facchinm Jul 7, 2021
4ded56c
WiFi: make library compliant with Arduino APIs
facchinm Jul 7, 2021
ec4109d
Initial: start moving WiFi generic classes into a standalone library
facchinm Jul 8, 2021
e0e8647
WiFi: port Client and Server to the new wrapper class
facchinm Jul 8, 2021
02b1239
TEMP: MbedClient: add horrible Client "constructor"
facchinm Jul 8, 2021
73cbc6b
WiFi: port UDP to new MbedUdp class
facchinm Jul 8, 2021
175d09f
Ethernet: port library to SocketWrapper
facchinm Jul 8, 2021
37edb74
MbedClient: fix copy constructor
facchinm Jul 8, 2021
974f4c2
Network: cleanup libraries and licenses
facchinm Jul 9, 2021
d4bb9d8
Network: apply clang-format on libraries
facchinm Jul 9, 2021
4340946
MbedUdp: make socket non blocking
facchinm Jul 9, 2021
123694b
SocketWrapper: fix download() API visibility
facchinm Jul 9, 2021
bc92047
MbedUDP: take into account write() errors
facchinm Jul 9, 2021
7fd7c9a
Remove protected leftovers
manchoz Jul 13, 2021
d9fa625
Add EthernetServer::available()
manchoz Jul 13, 2021
8c7962f
Add ::dnsServerIP
manchoz Jul 13, 2021
a175f35
Unlock mutexes before return
manchoz Jul 13, 2021
15ca271
Fix Typo
manchoz Jul 13, 2021
d3e8ee3
Manage copy and assignement
manchoz Jul 13, 2021
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
Prev Previous commit
Next Next commit
Network: apply clang-format on libraries
  • Loading branch information
facchinm authored and manchoz committed Jul 14, 2021
commit d4bb9d8556e94fc8fef12d6d8ccaed7b164a383d
78 changes: 39 additions & 39 deletions libraries/Ethernet/src/Ethernet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,85 +3,85 @@
#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;
}
if (eth_if == nullptr) {
//Q: What is the callback for?
_initializerCallback();
if (eth_if == nullptr) return 0;
}

unsigned long start = millis();
eth_if->set_blocking(false);
eth_if->connect();
unsigned long start = millis();
eth_if->set_blocking(false);
eth_if->connect();

while ((millis() - start < timeout) && (linkStatus() != LinkON)) {
delay(10);
}
while ((millis() - start < timeout) && (linkStatus() != LinkON)) {
delay(10);
}

return (linkStatus() == LinkON ? 1 : 0);
return (linkStatus() == LinkON ? 1 : 0);
}

int arduino::EthernetClass::begin(uint8_t *mac, IPAddress ip) {
IPAddress dns = ip;
dns[3] = 1;
IPAddress dns = ip;
dns[3] = 1;

auto ret = begin(mac, ip, dns);
return ret;
auto ret = begin(mac, ip, dns);
return ret;
}

int arduino::EthernetClass::begin(uint8_t *mac, IPAddress ip, IPAddress dns) {
IPAddress gateway = ip;
gateway[3] = 1;
auto ret = begin(mac, ip, dns, gateway);
return ret;
IPAddress gateway = ip;
gateway[3] = 1;

auto ret = begin(mac, ip, dns, gateway);
return ret;
}

int arduino::EthernetClass::begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPAddress gateway) {
IPAddress subnet(255, 255, 255, 0);
auto ret = begin(mac, ip, dns, gateway, subnet);
return ret;
IPAddress subnet(255, 255, 255, 0);
auto ret = begin(mac, ip, dns, gateway, subnet);
return ret;
}

int arduino::EthernetClass::begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet) {
config(ip, dns, gateway, subnet);
config(ip, dns, gateway, subnet);

eth_if->set_dhcp(false);
eth_if->set_network(_ip, _netmask, _gateway);
eth_if->add_dns_server(_dnsServer1, nullptr);
eth_if->set_dhcp(false);
eth_if->set_network(_ip, _netmask, _gateway);
eth_if->add_dns_server(_dnsServer1, nullptr);

auto ret = begin(mac);
return ret;
auto ret = begin(mac);
return ret;
}

void arduino::EthernetClass::end() {
disconnect();
disconnect();
}

EthernetLinkStatus arduino::EthernetClass::linkStatus() {
return (eth_if->get_connection_status() == NSAPI_STATUS_GLOBAL_UP ? LinkON : LinkOFF);
return (eth_if->get_connection_status() == NSAPI_STATUS_GLOBAL_UP ? LinkON : LinkOFF);
}

EthernetHardwareStatus arduino::EthernetClass::hardwareStatus() {
return EthernetMbed;
return EthernetMbed;
}


int arduino::EthernetClass::disconnect() {
eth_if->disconnect();
return 1;
eth_if->disconnect();
return 1;
}


uint8_t arduino::EthernetClass::status() {
return _currentNetworkStatus;
uint8_t arduino::EthernetClass::status() {
return _currentNetworkStatus;
}

NetworkInterface *arduino::EthernetClass::getNetwork() {
return eth_if;
return eth_if;
}

unsigned long arduino::EthernetClass::getTime() {
return 0;
return 0;
}

arduino::EthernetClass Ethernet;
141 changes: 76 additions & 65 deletions libraries/Ethernet/src/Ethernet.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,86 +30,97 @@
#include "EthernetInterface.h"

enum EthernetLinkStatus {
Unknown,
LinkON,
LinkOFF
Unknown,
LinkON,
LinkOFF
};

enum EthernetHardwareStatus {
EthernetNoHardware,
EthernetMbed = 6
EthernetNoHardware,
EthernetMbed = 6
};

namespace arduino {

typedef void* (*voidPrtFuncPtr)(void);
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) {};

int begin(uint8_t *mac = nullptr, unsigned long timeout = 60000, unsigned long responseTimeout = 4000);
EthernetLinkStatus linkStatus();
EthernetHardwareStatus hardwareStatus();

// Manual configuration
int begin(uint8_t *mac, IPAddress ip);
int begin(uint8_t *mac, IPAddress ip, IPAddress dns);
int begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPAddress gateway);
int begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet);

int begin(IPAddress ip) { return begin(nullptr, ip); }
int begin(IPAddress ip, IPAddress dns) { return begin(nullptr, ip, dns); }
int begin(IPAddress ip, IPAddress dns, IPAddress gateway) { return begin(nullptr, ip, dns, gateway); }
int begin(IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet) {return begin(nullptr, ip, dns, gateway, subnet); }
void init(uint8_t sspin = 10);

void MACAddress(uint8_t *mac_address);

void setHostname(const char* name);

int disconnect(void);
void end(void);

uint8_t status();
unsigned long getTime();

void setMACAddress(const uint8_t *mac_address);
void setLocalIP(const IPAddress local_ip);
void setSubnetMask(const IPAddress subnet);
void setGatewayIP(const IPAddress gateway);
void setDnsServerIP(const IPAddress dns_server) { _dnsServer1 = socketAddressFromIpAddress(dns_server, 0); }
void setRetransmissionTimeout(uint16_t milliseconds);
void setRetransmissionCount(uint8_t num);

friend class EthernetClient;
friend class EthernetServer;
friend class EthernetUDP;

NetworkInterface *getNetwork();
// 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){};

int begin(uint8_t *mac = nullptr, unsigned long timeout = 60000, unsigned long responseTimeout = 4000);
EthernetLinkStatus linkStatus();
EthernetHardwareStatus hardwareStatus();

// Manual configuration
int begin(uint8_t *mac, IPAddress ip);
int begin(uint8_t *mac, IPAddress ip, IPAddress dns);
int begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPAddress gateway);
int begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet);

int begin(IPAddress ip) {
return begin(nullptr, ip);
}
int begin(IPAddress ip, IPAddress dns) {
return begin(nullptr, ip, dns);
}
int begin(IPAddress ip, IPAddress dns, IPAddress gateway) {
return begin(nullptr, ip, dns, gateway);
}
int begin(IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet) {
return begin(nullptr, ip, dns, gateway, subnet);
}
void init(uint8_t sspin = 10);

void MACAddress(uint8_t *mac_address);

void setHostname(const char *name);

int disconnect(void);
void end(void);

uint8_t status();
unsigned long getTime();

void setMACAddress(const uint8_t *mac_address);
void setLocalIP(const IPAddress local_ip);
void setSubnetMask(const IPAddress subnet);
void setGatewayIP(const IPAddress gateway);
void setDnsServerIP(const IPAddress dns_server) {
_dnsServer1 = socketAddressFromIpAddress(dns_server, 0);
}
void setRetransmissionTimeout(uint16_t milliseconds);
void setRetransmissionCount(uint8_t num);

friend class EthernetClient;
friend class EthernetServer;
friend class EthernetUDP;

NetworkInterface *getNetwork();

protected:
SocketAddress _ip = nullptr;
SocketAddress _gateway = nullptr;
SocketAddress _netmask = nullptr;
SocketAddress _dnsServer1 = nullptr;
SocketAddress _dnsServer2 = nullptr;
SocketAddress _ip = nullptr;
SocketAddress _gateway = nullptr;
SocketAddress _netmask = nullptr;
SocketAddress _dnsServer1 = nullptr;
SocketAddress _dnsServer2 = nullptr;

private:

volatile EthernetLinkStatus _currentNetworkStatus = Unknown;
EthernetInterface net;
EthernetInterface* eth_if = &net;
voidPrtFuncPtr _initializerCallback;
arduino::IPAddress ipAddressFromSocketAddress(SocketAddress socketAddress);
SocketAddress socketAddressFromIpAddress(arduino::IPAddress ip, uint16_t port);
volatile EthernetLinkStatus _currentNetworkStatus = Unknown;
EthernetInterface net;
EthernetInterface *eth_if = &net;
voidPrtFuncPtr _initializerCallback;
arduino::IPAddress ipAddressFromSocketAddress(SocketAddress socketAddress);
SocketAddress socketAddressFromIpAddress(arduino::IPAddress ip, uint16_t port);
};

}
Expand Down
6 changes: 3 additions & 3 deletions libraries/Ethernet/src/EthernetClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
namespace arduino {

class EthernetClient : public MbedClient {
NetworkInterface *getNetwork() {
return Ethernet.getNetwork();
}
NetworkInterface *getNetwork() {
return Ethernet.getNetwork();
}
};

}
Expand Down
12 changes: 7 additions & 5 deletions libraries/Ethernet/src/EthernetServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ namespace arduino {
class EthernetClient;

class EthernetServer : public MbedServer {
NetworkInterface *getNetwork() {
return Ethernet.getNetwork();
}
NetworkInterface* getNetwork() {
return Ethernet.getNetwork();
}

public:
EthernetServer(uint16_t port) : MbedServer(port) {}
EthernetClient available(uint8_t* status = nullptr);
EthernetServer(uint16_t port)
: MbedServer(port) {}
EthernetClient available(uint8_t* status = nullptr);
};

}
Expand Down
6 changes: 3 additions & 3 deletions libraries/Ethernet/src/EthernetUdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
namespace arduino {

class EthernetUDP : public MbedUDP {
NetworkInterface *getNetwork() {
return Ethernet.getNetwork();
}
NetworkInterface *getNetwork() {
return Ethernet.getNetwork();
}
};

}
Expand Down
Loading