-
-
Notifications
You must be signed in to change notification settings - Fork 203
/
Ethernet.cpp
92 lines (68 loc) · 2.05 KB
/
Ethernet.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#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;
}
unsigned long start = millis();
eth_if->set_blocking(false);
eth_if->connect();
while ((millis() - start < timeout) && (linkStatus() != LinkON)) {
delay(10);
}
return (linkStatus() == LinkON ? 1 : 0);
}
int arduino::EthernetClass::begin(uint8_t *mac, IPAddress ip) {
IPAddress dns = ip;
dns[3] = 1;
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;
}
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;
}
int arduino::EthernetClass::begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress 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);
auto ret = begin(mac);
return ret;
}
void arduino::EthernetClass::end() {
disconnect();
}
EthernetLinkStatus arduino::EthernetClass::linkStatus() {
return (eth_if->get_connection_status() == NSAPI_STATUS_GLOBAL_UP ? LinkON : LinkOFF);
}
EthernetHardwareStatus arduino::EthernetClass::hardwareStatus() {
return EthernetMbed;
}
int arduino::EthernetClass::disconnect() {
eth_if->disconnect();
return 1;
}
uint8_t arduino::EthernetClass::status() {
return _currentNetworkStatus;
}
NetworkInterface *arduino::EthernetClass::getNetwork() {
return eth_if;
}
unsigned long arduino::EthernetClass::getTime() {
return 0;
}
void arduino::EthernetClass::MACAddress(uint8_t *mac_address)
{
macAddress(mac_address);
}
arduino::EthernetClass Ethernet;