Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f90c10a

Browse files
committedJan 9, 2024
Merge branch 'main' into ethernet_debugging
2 parents cc5ad5f + 79e014e commit f90c10a

File tree

10 files changed

+875
-28
lines changed

10 files changed

+875
-28
lines changed
 

‎libraries/Arduino_LED_Matrix/examples/TextWithArduinoGraphics/TextWithArduinoGraphics.ino

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,20 @@
55
ArduinoLEDMatrix matrix;
66

77
void setup() {
8-
Serial.begin(115200);
98
matrix.begin();
109

1110
matrix.beginDraw();
11+
1212
matrix.stroke(0xFFFFFFFF);
13-
// add some static text
14-
// will only show "UNO" (not enough space on the display)
15-
const char text[] = "UNO r4";
13+
matrix.textScrollSpeed(100);
14+
15+
const char text[] = " UNO r4 ";
1616
matrix.textFont(Font_4x6);
1717
matrix.beginText(0, 1, 0xFFFFFF);
1818
matrix.println(text);
19-
matrix.endText();
19+
matrix.endText(SCROLL_LEFT);
2020

2121
matrix.endDraw();
22-
23-
delay(2000);
2422
}
2523

2624
void loop() {

‎libraries/Arduino_LED_Matrix/src/Arduino_LED_Matrix.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#pragma once
2+
13
#include "Arduino.h"
24
#include "FspTimer.h"
35
#include "gallery.h"
@@ -248,7 +250,7 @@ class ArduinoLEDMatrix
248250

249251
#ifdef MATRIX_WITH_ARDUINOGRAPHICS
250252
virtual void set(int x, int y, uint8_t r, uint8_t g, uint8_t b) {
251-
if (y >= canvasHeight || x >= canvasWidth) {
253+
if (y >= canvasHeight || x >= canvasWidth || y < 0 || x < 0) {
252254
return;
253255
}
254256
// the r parameter is (mis)used to set the character to draw with
@@ -300,4 +302,4 @@ class ArduinoLEDMatrix
300302
}
301303
}
302304
}
303-
};
305+
};

‎libraries/ESPhost/examples/ESP32_TEST/ESP32_TEST.ino

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "CEspControl.h"
2-
#include "CNetIf.h"
32
#include <string>
43
#include <vector>
54

@@ -23,8 +22,6 @@ using namespace std;
2322

2423
#define SerialESP Serial5
2524

26-
extern int esp_host_spi_init();
27-
2825
void getESPDebugLog();
2926
int displayMenu();
3027
void makeRequest(int req);
@@ -33,12 +30,15 @@ string prompt(string p);
3330

3431
const char mac_address[] = "aa:bb:cc:dd:ee:ff";
3532

33+
bool wifiHwInitialized = false;
3634

3735

3836
int initEvent(CCtrlMsgWrapper *resp) {
3937
if(resp->isInitEventReceived() == ESP_CONTROL_OK) {
4038
Serial.println("[EVENT !!!!]: Init event received");
39+
wifiHwInitialized = true;
4140
}
41+
return ESP_CONTROL_OK;
4242
}
4343

4444
int stationDisconnectionEvent(CCtrlMsgWrapper *resp) {
@@ -47,6 +47,7 @@ int stationDisconnectionEvent(CCtrlMsgWrapper *resp) {
4747
Serial.print("[EVENT !!!!]: C33 was disconnected from AP for reason ");
4848
Serial.println(reason);
4949
}
50+
return ESP_CONTROL_OK;
5051
}
5152

5253
int disconnectionFromSofApEvent(CCtrlMsgWrapper *resp) {
@@ -56,6 +57,7 @@ int disconnectionFromSofApEvent(CCtrlMsgWrapper *resp) {
5657
Serial.print(MAC);
5758
Serial.println(" disconnected from ESP32 Soft AP");
5859
}
60+
return ESP_CONTROL_OK;
5961
}
6062

6163

@@ -65,6 +67,7 @@ int heartBeatEvent(CCtrlMsgWrapper *resp) {
6567
Serial.print("[EVENT !!!!]: heart beat n ");
6668
Serial.println(hb);
6769
}
70+
return ESP_CONTROL_OK;
6871
}
6972

7073

@@ -83,10 +86,19 @@ void setup() {
8386
CEspControl::getInstance().listenForDisconnectionFromSoftApEvent(disconnectionFromSofApEvent);
8487

8588

86-
89+
int err = CEspControl::getInstance().initSpiDriver();
90+
if (err != 0) {
91+
Serial.print("Error initSpiDriver err ");
92+
Serial.println(err);
93+
} else {
94+
Serial.println("initSpiDriver OK");
95+
}
96+
while (!wifiHwInitialized) {
97+
CEspControl::getInstance().communicateWithEsp();
98+
delay(100);
99+
}
87100

88101
Serial.println("STARTING PROGRAM");
89-
delay(1000);
90102
}
91103

92104

@@ -685,7 +697,7 @@ int displayMenu() {
685697
cmd_acquired = true;
686698
rv = stoi(c);
687699
}
688-
else {
700+
else if(ch >= '0' && ch <='9') {
689701
c += ch;
690702
}
691703
}

‎libraries/ESPhost/src/CEspControl.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
#include "CCtrlWrapper.h"
3636
#include "CEspCommunication.h"
3737
#include "EspSpiDriver.h"
38-
#include "CNetIf.h"
3938
#include "CEspCbks.h"
4039
#include <string>
4140

‎libraries/Ethernet/src/Ethernet.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,32 @@ int CEthernet::begin(unsigned long timeout, unsigned long responseTimeout) {
2828
/* -------------------------------------------------------------------------- */
2929
int CEthernet::begin(IPAddress local_ip) {
3030
/* -------------------------------------------------------------------------- */
31-
IPAddress subnet(255, 255, 255, 0);
32-
return begin(local_ip, subnet);
31+
// Assume the DNS server will be the machine on the same network as the local IP
32+
// but with last octet being '1'
33+
IPAddress dns_server = local_ip;
34+
dns_server[3] = 1;
35+
return begin(local_ip, dns_server);
3336
}
3437

3538
/* -------------------------------------------------------------------------- */
36-
int CEthernet::begin(IPAddress local_ip, IPAddress subnet) {
39+
int CEthernet::begin(IPAddress local_ip, IPAddress dns_server) {
3740
/* -------------------------------------------------------------------------- */
3841
// Assume the gateway will be the machine on the same network as the local IP
3942
// but with last octet being '1'
4043
IPAddress gateway = local_ip;
4144
gateway[3] = 1;
42-
return begin(local_ip, subnet, gateway);
45+
return begin(local_ip, dns_server, gateway);
4346
}
4447

4548
/* -------------------------------------------------------------------------- */
46-
int CEthernet::begin(IPAddress local_ip, IPAddress subnet, IPAddress gateway) {
49+
int CEthernet::begin(IPAddress local_ip, IPAddress dns_server, IPAddress gateway) {
4750
/* -------------------------------------------------------------------------- */
48-
// Assume the DNS server will be the same machine than gateway
49-
return begin(local_ip, subnet, gateway, gateway);
51+
IPAddress subnet(255, 255, 255, 0);
52+
return begin(local_ip, dns_server, gateway, subnet);
5053
}
5154

5255
/* -------------------------------------------------------------------------- */
53-
int CEthernet::begin(IPAddress local_ip, IPAddress subnet, IPAddress gateway, IPAddress dns_server) {
56+
int CEthernet::begin(IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet) {
5457
/* -------------------------------------------------------------------------- */
5558

5659
ni = CLwipIf::getInstance().get(NI_ETHERNET, local_ip, gateway, subnet);
@@ -108,7 +111,7 @@ int CEthernet::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_ser
108111
int CEthernet::begin(uint8_t *mac, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet, unsigned long timeout, unsigned long responseTimeout) {
109112
/* -------------------------------------------------------------------------- */
110113
CLwipIf::getInstance().setMacAddress(NI_ETHERNET, mac);
111-
return begin(local_ip, subnet, gateway, dns_server);
114+
return begin(local_ip, dns_server, gateway, subnet);
112115
}
113116

114117
/* -------------------------------------------------------------------------- */

‎libraries/Ethernet/src/EthernetC33.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ class CEthernet {
4141
int begin(unsigned long timeout = 60000, unsigned long responseTimeout = 4000);
4242
EthernetLinkStatus linkStatus();
4343
int begin(IPAddress local_ip);
44-
int begin(IPAddress local_ip, IPAddress subnet);
45-
int begin(IPAddress local_ip, IPAddress subnet, IPAddress gateway);
46-
int begin(IPAddress local_ip, IPAddress subnet, IPAddress gateway, IPAddress dns_server);
44+
int begin(IPAddress local_ip, IPAddress dns_server);
45+
int begin(IPAddress local_ip, IPAddress dns_server, IPAddress gateway);
46+
int begin(IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet);
4747
// Initialise the Ethernet shield to use the provided MAC address and gain the rest of the
4848
// configuration through DHCP.
4949
// Returns 0 if the DHCP configuration failed, and 1 if it succeeded
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
#include <EthernetC33.h>
2+
3+
/*
4+
* The old implementation of the begin set a default mac address:
5+
* this does not make any sense.
6+
* Default mac address is in the hardware, when lwip start that mac
7+
* address is passed to lwip
8+
* If mac address needs to be changed then call the appropriate function
9+
* of lwIpIf before to get the interface
10+
*/
11+
12+
/* -------------------------------------------------------------------------- */
13+
int CEthernet::begin(unsigned long timeout, unsigned long responseTimeout) {
14+
/* -------------------------------------------------------------------------- */
15+
(void)responseTimeout;
16+
17+
int rv = 0;
18+
19+
ni = CLwipIf::getInstance().get(NI_ETHERNET);
20+
if(ni != nullptr) {
21+
ni->DhcpSetTimeout(timeout);
22+
rv = (int)ni->DhcpStart();
23+
}
24+
25+
return rv;
26+
}
27+
28+
/* -------------------------------------------------------------------------- */
29+
int CEthernet::begin(IPAddress local_ip) {
30+
/* -------------------------------------------------------------------------- */
31+
// Assume the DNS server will be the machine on the same network as the local IP
32+
// but with last octet being '1'
33+
IPAddress dns_server = local_ip;
34+
dns_server[3] = 1;
35+
return begin(local_ip, dns_server);
36+
}
37+
38+
/* -------------------------------------------------------------------------- */
39+
int CEthernet::begin(IPAddress local_ip, IPAddress dns_server) {
40+
/* -------------------------------------------------------------------------- */
41+
// Assume the gateway will be the machine on the same network as the local IP
42+
// but with last octet being '1'
43+
IPAddress gateway = local_ip;
44+
gateway[3] = 1;
45+
return begin(local_ip, dns_server, gateway);
46+
}
47+
48+
/* -------------------------------------------------------------------------- */
49+
int CEthernet::begin(IPAddress local_ip, IPAddress dns_server, IPAddress gateway) {
50+
/* -------------------------------------------------------------------------- */
51+
IPAddress subnet(255, 255, 255, 0);
52+
return begin(local_ip, dns_server, gateway, subnet);
53+
}
54+
55+
/* -------------------------------------------------------------------------- */
56+
int CEthernet::begin(IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet) {
57+
/* -------------------------------------------------------------------------- */
58+
59+
ni = CLwipIf::getInstance().get(NI_ETHERNET, local_ip, gateway, subnet);
60+
if(ni == nullptr) {
61+
return 0;
62+
}
63+
64+
/* If there is a local DHCP informs it of our manual IP configuration to prevent IP conflict */
65+
ni->DhcpNotUsed();
66+
CLwipIf::getInstance().addDns(dns_server);
67+
return 1;
68+
}
69+
70+
/* -------------------------------------------------------------------------- */
71+
void CEthernet::setDNS(IPAddress dns_server) {
72+
/* -------------------------------------------------------------------------- */
73+
CLwipIf::getInstance().addDns(dns_server);
74+
}
75+
76+
/* -------------------------------------------------------------------------- */
77+
int CEthernet::begin(uint8_t *mac, unsigned long timeout, unsigned long responseTimeout) {
78+
/* -------------------------------------------------------------------------- */
79+
CLwipIf::getInstance().setMacAddress(NI_ETHERNET, mac);
80+
return begin(timeout, responseTimeout);
81+
}
82+
83+
/* -------------------------------------------------------------------------- */
84+
int CEthernet::begin(uint8_t *mac_address, IPAddress local_ip) {
85+
/* -------------------------------------------------------------------------- */
86+
// Assume the DNS server will be the machine on the same network as the local IP
87+
// but with last octet being '1'
88+
IPAddress dns_server = local_ip;
89+
dns_server[3] = 1;
90+
return begin(mac_address, local_ip, dns_server);
91+
}
92+
93+
/* -------------------------------------------------------------------------- */
94+
int CEthernet::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server) {
95+
/* -------------------------------------------------------------------------- */
96+
// Assume the gateway will be the machine on the same network as the local IP
97+
// but with last octet being '1'
98+
IPAddress gateway = local_ip;
99+
gateway[3] = 1;
100+
return begin(mac_address, local_ip, dns_server, gateway);
101+
}
102+
103+
/* -------------------------------------------------------------------------- */
104+
int CEthernet::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway) {
105+
/* -------------------------------------------------------------------------- */
106+
IPAddress subnet(255, 255, 255, 0);
107+
return begin(mac_address, local_ip, dns_server, gateway, subnet);
108+
}
109+
110+
/* -------------------------------------------------------------------------- */
111+
int CEthernet::begin(uint8_t *mac, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet, unsigned long timeout, unsigned long responseTimeout) {
112+
/* -------------------------------------------------------------------------- */
113+
<<<<<<< HEAD
114+
CLwipIf::getInstance().setMacAddress(NI_ETHERNET, mac);
115+
return begin(local_ip, subnet, gateway, dns_server);
116+
=======
117+
CLwipIf::getInstance().setMacAddress(NI_ETHERNET, mac_address);
118+
return begin(local_ip, dns_server, gateway, subnet);
119+
>>>>>>> main
120+
}
121+
122+
/* -------------------------------------------------------------------------- */
123+
EthernetLinkStatus CEthernet::linkStatus() {
124+
/* -------------------------------------------------------------------------- */
125+
if(ni != nullptr) {
126+
return (!CLwipIf::getInstance().isEthInitialized()) ? Unknown : (ni->isLinkUp() ? LinkON : LinkOFF);
127+
}
128+
return Unknown;
129+
}
130+
131+
/* -------------------------------------------------------------------------- */
132+
EthernetHardwareStatus CEthernet::hardwareStatus() {
133+
/* -------------------------------------------------------------------------- */
134+
return EthernetLwip;
135+
}
136+
137+
/* -------------------------------------------------------------------------- */
138+
int CEthernet::disconnect() {
139+
/* -------------------------------------------------------------------------- */
140+
return 1;
141+
}
142+
143+
/* -------------------------------------------------------------------------- */
144+
int CEthernet::maintain() {
145+
/* -------------------------------------------------------------------------- */
146+
int rc = DHCP_CHECK_NONE;
147+
148+
if (ni != NULL) {
149+
//we have a pointer to dhcp, use it
150+
rc = ni->checkLease();
151+
switch (rc) {
152+
case DHCP_CHECK_NONE:
153+
//nothing done
154+
break;
155+
case DHCP_CHECK_RENEW_OK:
156+
case DHCP_CHECK_REBIND_OK:
157+
//_dnsServerAddress = _dhcp->getDnsServerIp();
158+
break;
159+
default:
160+
//this is actually a error, it will retry though
161+
break;
162+
}
163+
}
164+
return rc;
165+
}
166+
167+
/*
168+
* This function updates the LwIP stack and can be called to be sure to update
169+
* the stack (e.g. in case of a long loop).
170+
*/
171+
void CEthernet::schedule(void) {
172+
if (ni != NULL) {
173+
ni->task();
174+
}
175+
}
176+
177+
178+
179+
uint8_t *CEthernet::MACAddress(void) {
180+
CLwipIf::getInstance().getMacAddress(NI_ETHERNET, mac_address);
181+
return mac_address;
182+
}
183+
184+
void CEthernet::MACAddress(uint8_t *mac) {
185+
CLwipIf::getInstance().getMacAddress(NI_ETHERNET, mac);
186+
}
187+
188+
IPAddress CEthernet::localIP() {
189+
if(ni != nullptr) {
190+
return IPAddress(ni->getIpAdd());
191+
}
192+
return IPAddress((uint32_t)0);
193+
}
194+
195+
IPAddress CEthernet::subnetMask() {
196+
if(ni != nullptr) {
197+
return IPAddress(ni->getNmAdd());
198+
}
199+
return IPAddress((uint32_t)0);
200+
}
201+
202+
IPAddress CEthernet::gatewayIP() {
203+
if(ni != nullptr) {
204+
return IPAddress(ni->getGwAdd());
205+
}
206+
return IPAddress((uint32_t)0);
207+
}
208+
209+
IPAddress CEthernet::dnsServerIP() {
210+
return CLwipIf::getInstance().getDns();
211+
}
212+
213+
CEthernet Ethernet;
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
#include <EthernetC33.h>
2+
3+
/*
4+
* The old implementation of the begin set a default mac address:
5+
* this does not make any sense.
6+
* Default mac address is in the hardware, when lwip start that mac
7+
* address is passed to lwip
8+
* If mac address needs to be changed then call the appropriate function
9+
* of lwIpIf before to get the interface
10+
*/
11+
12+
/* -------------------------------------------------------------------------- */
13+
int CEthernet::begin(unsigned long timeout, unsigned long responseTimeout) {
14+
/* -------------------------------------------------------------------------- */
15+
(void)responseTimeout;
16+
17+
int rv = 0;
18+
19+
ni = CLwipIf::getInstance().get(NI_ETHERNET);
20+
if(ni != nullptr) {
21+
ni->DhcpSetTimeout(timeout);
22+
rv = (int)ni->DhcpStart();
23+
}
24+
25+
return rv;
26+
}
27+
28+
/* -------------------------------------------------------------------------- */
29+
int CEthernet::begin(IPAddress local_ip) {
30+
/* -------------------------------------------------------------------------- */
31+
IPAddress subnet(255, 255, 255, 0);
32+
return begin(local_ip, subnet);
33+
}
34+
35+
/* -------------------------------------------------------------------------- */
36+
int CEthernet::begin(IPAddress local_ip, IPAddress subnet) {
37+
/* -------------------------------------------------------------------------- */
38+
// Assume the gateway will be the machine on the same network as the local IP
39+
// but with last octet being '1'
40+
IPAddress gateway = local_ip;
41+
gateway[3] = 1;
42+
return begin(local_ip, subnet, gateway);
43+
}
44+
45+
/* -------------------------------------------------------------------------- */
46+
int CEthernet::begin(IPAddress local_ip, IPAddress subnet, IPAddress gateway) {
47+
/* -------------------------------------------------------------------------- */
48+
// Assume the DNS server will be the same machine than gateway
49+
return begin(local_ip, subnet, gateway, gateway);
50+
}
51+
52+
/* -------------------------------------------------------------------------- */
53+
int CEthernet::begin(IPAddress local_ip, IPAddress subnet, IPAddress gateway, IPAddress dns_server) {
54+
/* -------------------------------------------------------------------------- */
55+
56+
ni = CLwipIf::getInstance().get(NI_ETHERNET, local_ip, gateway, subnet);
57+
if(ni == nullptr) {
58+
return 0;
59+
}
60+
61+
/* If there is a local DHCP informs it of our manual IP configuration to prevent IP conflict */
62+
ni->DhcpNotUsed();
63+
CLwipIf::getInstance().addDns(dns_server);
64+
return 1;
65+
}
66+
67+
/* -------------------------------------------------------------------------- */
68+
void CEthernet::setDNS(IPAddress dns_server) {
69+
/* -------------------------------------------------------------------------- */
70+
CLwipIf::getInstance().addDns(dns_server);
71+
}
72+
73+
/* -------------------------------------------------------------------------- */
74+
int CEthernet::begin(uint8_t *mac, unsigned long timeout, unsigned long responseTimeout) {
75+
/* -------------------------------------------------------------------------- */
76+
int ret = (int)CLwipIf::getInstance().setMacAddress(NI_ETHERNET, mac);
77+
begin(timeout, responseTimeout);
78+
return ret;
79+
}
80+
81+
/* -------------------------------------------------------------------------- */
82+
int CEthernet::begin(uint8_t *mac_address, IPAddress local_ip) {
83+
/* -------------------------------------------------------------------------- */
84+
// Assume the DNS server will be the machine on the same network as the local IP
85+
// but with last octet being '1'
86+
IPAddress dns_server = local_ip;
87+
dns_server[3] = 1;
88+
return begin(mac_address, local_ip, dns_server);
89+
}
90+
91+
/* -------------------------------------------------------------------------- */
92+
int CEthernet::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server) {
93+
/* -------------------------------------------------------------------------- */
94+
// Assume the gateway will be the machine on the same network as the local IP
95+
// but with last octet being '1'
96+
IPAddress gateway = local_ip;
97+
gateway[3] = 1;
98+
return begin(mac_address, local_ip, dns_server, gateway);
99+
}
100+
101+
/* -------------------------------------------------------------------------- */
102+
int CEthernet::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway) {
103+
/* -------------------------------------------------------------------------- */
104+
IPAddress subnet(255, 255, 255, 0);
105+
return begin(mac_address, local_ip, dns_server, gateway, subnet);
106+
}
107+
108+
/* -------------------------------------------------------------------------- */
109+
int CEthernet::begin(uint8_t *mac, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet, unsigned long timeout, unsigned long responseTimeout) {
110+
/* -------------------------------------------------------------------------- */
111+
CLwipIf::getInstance().setMacAddress(NI_ETHERNET, mac_address);
112+
return begin(local_ip, subnet, gateway, dns_server);
113+
}
114+
115+
/* -------------------------------------------------------------------------- */
116+
EthernetLinkStatus CEthernet::linkStatus() {
117+
/* -------------------------------------------------------------------------- */
118+
if(ni != nullptr) {
119+
return (!CLwipIf::getInstance().isEthInitialized()) ? Unknown : (ni->isLinkUp() ? LinkON : LinkOFF);
120+
}
121+
return Unknown;
122+
}
123+
124+
/* -------------------------------------------------------------------------- */
125+
EthernetHardwareStatus CEthernet::hardwareStatus() {
126+
/* -------------------------------------------------------------------------- */
127+
return EthernetLwip;
128+
}
129+
130+
/* -------------------------------------------------------------------------- */
131+
int CEthernet::disconnect() {
132+
/* -------------------------------------------------------------------------- */
133+
return 1;
134+
}
135+
136+
/* -------------------------------------------------------------------------- */
137+
int CEthernet::maintain() {
138+
/* -------------------------------------------------------------------------- */
139+
int rc = DHCP_CHECK_NONE;
140+
141+
if (ni != NULL) {
142+
//we have a pointer to dhcp, use it
143+
rc = ni->checkLease();
144+
switch (rc) {
145+
case DHCP_CHECK_NONE:
146+
//nothing done
147+
break;
148+
case DHCP_CHECK_RENEW_OK:
149+
case DHCP_CHECK_REBIND_OK:
150+
//_dnsServerAddress = _dhcp->getDnsServerIp();
151+
break;
152+
default:
153+
//this is actually a error, it will retry though
154+
break;
155+
}
156+
}
157+
return rc;
158+
}
159+
160+
/*
161+
* This function updates the LwIP stack and can be called to be sure to update
162+
* the stack (e.g. in case of a long loop).
163+
*/
164+
void CEthernet::schedule(void) {
165+
if (ni != NULL) {
166+
ni->task();
167+
}
168+
}
169+
170+
171+
172+
uint8_t *CEthernet::MACAddress(void) {
173+
CLwipIf::getInstance().getMacAddress(NI_ETHERNET, mac_address);
174+
return mac_address;
175+
}
176+
177+
void CEthernet::MACAddress(uint8_t *mac) {
178+
CLwipIf::getInstance().getMacAddress(NI_ETHERNET, mac);
179+
}
180+
181+
IPAddress CEthernet::localIP() {
182+
if(ni != nullptr) {
183+
return IPAddress(ni->getIpAdd());
184+
}
185+
return IPAddress((uint32_t)0);
186+
}
187+
188+
IPAddress CEthernet::subnetMask() {
189+
if(ni != nullptr) {
190+
return IPAddress(ni->getNmAdd());
191+
}
192+
return IPAddress((uint32_t)0);
193+
}
194+
195+
IPAddress CEthernet::gatewayIP() {
196+
if(ni != nullptr) {
197+
return IPAddress(ni->getGwAdd());
198+
}
199+
return IPAddress((uint32_t)0);
200+
}
201+
202+
IPAddress CEthernet::dnsServerIP() {
203+
return CLwipIf::getInstance().getDns();
204+
}
205+
206+
CEthernet Ethernet;
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
#include <EthernetC33.h>
2+
3+
/*
4+
* The old implementation of the begin set a default mac address:
5+
* this does not make any sense.
6+
* Default mac address is in the hardware, when lwip start that mac
7+
* address is passed to lwip
8+
* If mac address needs to be changed then call the appropriate function
9+
* of lwIpIf before to get the interface
10+
*/
11+
12+
/* -------------------------------------------------------------------------- */
13+
int CEthernet::begin(unsigned long timeout, unsigned long responseTimeout) {
14+
/* -------------------------------------------------------------------------- */
15+
(void)responseTimeout;
16+
17+
int rv = 0;
18+
19+
ni = CLwipIf::getInstance().get(NI_ETHERNET);
20+
if(ni != nullptr) {
21+
ni->DhcpSetTimeout(timeout);
22+
rv = (int)ni->DhcpStart();
23+
}
24+
25+
return rv;
26+
}
27+
28+
/* -------------------------------------------------------------------------- */
29+
int CEthernet::begin(IPAddress local_ip) {
30+
/* -------------------------------------------------------------------------- */
31+
IPAddress subnet(255, 255, 255, 0);
32+
return begin(local_ip, subnet);
33+
}
34+
35+
/* -------------------------------------------------------------------------- */
36+
int CEthernet::begin(IPAddress local_ip, IPAddress subnet) {
37+
/* -------------------------------------------------------------------------- */
38+
// Assume the gateway will be the machine on the same network as the local IP
39+
// but with last octet being '1'
40+
IPAddress gateway = local_ip;
41+
gateway[3] = 1;
42+
return begin(local_ip, subnet, gateway);
43+
}
44+
45+
/* -------------------------------------------------------------------------- */
46+
int CEthernet::begin(IPAddress local_ip, IPAddress subnet, IPAddress gateway) {
47+
/* -------------------------------------------------------------------------- */
48+
// Assume the DNS server will be the same machine than gateway
49+
return begin(local_ip, subnet, gateway, gateway);
50+
}
51+
52+
/* -------------------------------------------------------------------------- */
53+
int CEthernet::begin(IPAddress local_ip, IPAddress subnet, IPAddress gateway, IPAddress dns_server) {
54+
/* -------------------------------------------------------------------------- */
55+
56+
ni = CLwipIf::getInstance().get(NI_ETHERNET, local_ip, gateway, subnet);
57+
if(ni == nullptr) {
58+
return 0;
59+
}
60+
61+
/* If there is a local DHCP informs it of our manual IP configuration to prevent IP conflict */
62+
ni->DhcpNotUsed();
63+
CLwipIf::getInstance().addDns(dns_server);
64+
return 1;
65+
}
66+
67+
/* -------------------------------------------------------------------------- */
68+
void CEthernet::setDNS(IPAddress dns_server) {
69+
/* -------------------------------------------------------------------------- */
70+
CLwipIf::getInstance().addDns(dns_server);
71+
}
72+
73+
/* -------------------------------------------------------------------------- */
74+
int CEthernet::begin(uint8_t *mac, unsigned long timeout, unsigned long responseTimeout) {
75+
/* -------------------------------------------------------------------------- */
76+
CLwipIf::getInstance().setMacAddress(NI_ETHERNET, mac);
77+
return begin(timeout, responseTimeout);
78+
}
79+
80+
/* -------------------------------------------------------------------------- */
81+
int CEthernet::begin(uint8_t *mac_address, IPAddress local_ip) {
82+
/* -------------------------------------------------------------------------- */
83+
// Assume the DNS server will be the machine on the same network as the local IP
84+
// but with last octet being '1'
85+
IPAddress dns_server = local_ip;
86+
dns_server[3] = 1;
87+
return begin(mac_address, local_ip, dns_server);
88+
}
89+
90+
/* -------------------------------------------------------------------------- */
91+
int CEthernet::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server) {
92+
/* -------------------------------------------------------------------------- */
93+
// Assume the gateway will be the machine on the same network as the local IP
94+
// but with last octet being '1'
95+
IPAddress gateway = local_ip;
96+
gateway[3] = 1;
97+
return begin(mac_address, local_ip, dns_server, gateway);
98+
}
99+
100+
/* -------------------------------------------------------------------------- */
101+
int CEthernet::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway) {
102+
/* -------------------------------------------------------------------------- */
103+
IPAddress subnet(255, 255, 255, 0);
104+
return begin(mac_address, local_ip, dns_server, gateway, subnet);
105+
}
106+
107+
/* -------------------------------------------------------------------------- */
108+
int CEthernet::begin(uint8_t *mac, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet, unsigned long timeout, unsigned long responseTimeout) {
109+
/* -------------------------------------------------------------------------- */
110+
CLwipIf::getInstance().setMacAddress(NI_ETHERNET, mac);
111+
return begin(local_ip, subnet, gateway, dns_server);
112+
}
113+
114+
/* -------------------------------------------------------------------------- */
115+
EthernetLinkStatus CEthernet::linkStatus() {
116+
/* -------------------------------------------------------------------------- */
117+
if(ni != nullptr) {
118+
return (!CLwipIf::getInstance().isEthInitialized()) ? Unknown : (ni->isLinkUp() ? LinkON : LinkOFF);
119+
}
120+
return Unknown;
121+
}
122+
123+
/* -------------------------------------------------------------------------- */
124+
EthernetHardwareStatus CEthernet::hardwareStatus() {
125+
/* -------------------------------------------------------------------------- */
126+
return EthernetLwip;
127+
}
128+
129+
/* -------------------------------------------------------------------------- */
130+
int CEthernet::disconnect() {
131+
/* -------------------------------------------------------------------------- */
132+
return 1;
133+
}
134+
135+
/* -------------------------------------------------------------------------- */
136+
int CEthernet::maintain() {
137+
/* -------------------------------------------------------------------------- */
138+
int rc = DHCP_CHECK_NONE;
139+
140+
if (ni != NULL) {
141+
//we have a pointer to dhcp, use it
142+
rc = ni->checkLease();
143+
switch (rc) {
144+
case DHCP_CHECK_NONE:
145+
//nothing done
146+
break;
147+
case DHCP_CHECK_RENEW_OK:
148+
case DHCP_CHECK_REBIND_OK:
149+
//_dnsServerAddress = _dhcp->getDnsServerIp();
150+
break;
151+
default:
152+
//this is actually a error, it will retry though
153+
break;
154+
}
155+
}
156+
return rc;
157+
}
158+
159+
/*
160+
* This function updates the LwIP stack and can be called to be sure to update
161+
* the stack (e.g. in case of a long loop).
162+
*/
163+
void CEthernet::schedule(void) {
164+
if (ni != NULL) {
165+
ni->task();
166+
}
167+
}
168+
169+
170+
171+
uint8_t *CEthernet::MACAddress(void) {
172+
CLwipIf::getInstance().getMacAddress(NI_ETHERNET, mac_address);
173+
return mac_address;
174+
}
175+
176+
void CEthernet::MACAddress(uint8_t *mac) {
177+
CLwipIf::getInstance().getMacAddress(NI_ETHERNET, mac);
178+
}
179+
180+
IPAddress CEthernet::localIP() {
181+
if(ni != nullptr) {
182+
return IPAddress(ni->getIpAdd());
183+
}
184+
return IPAddress((uint32_t)0);
185+
}
186+
187+
IPAddress CEthernet::subnetMask() {
188+
if(ni != nullptr) {
189+
return IPAddress(ni->getNmAdd());
190+
}
191+
return IPAddress((uint32_t)0);
192+
}
193+
194+
IPAddress CEthernet::gatewayIP() {
195+
if(ni != nullptr) {
196+
return IPAddress(ni->getGwAdd());
197+
}
198+
return IPAddress((uint32_t)0);
199+
}
200+
201+
IPAddress CEthernet::dnsServerIP() {
202+
return CLwipIf::getInstance().getDns();
203+
}
204+
205+
CEthernet Ethernet;
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
#include <EthernetC33.h>
2+
3+
/*
4+
* The old implementation of the begin set a default mac address:
5+
* this does not make any sense.
6+
* Default mac address is in the hardware, when lwip start that mac
7+
* address is passed to lwip
8+
* If mac address needs to be changed then call the appropriate function
9+
* of lwIpIf before to get the interface
10+
*/
11+
12+
/* -------------------------------------------------------------------------- */
13+
int CEthernet::begin(unsigned long timeout, unsigned long responseTimeout) {
14+
/* -------------------------------------------------------------------------- */
15+
(void)responseTimeout;
16+
17+
int rv = 0;
18+
19+
ni = CLwipIf::getInstance().get(NI_ETHERNET);
20+
if(ni != nullptr) {
21+
ni->DhcpSetTimeout(timeout);
22+
rv = (int)ni->DhcpStart();
23+
}
24+
25+
return rv;
26+
}
27+
28+
/* -------------------------------------------------------------------------- */
29+
int CEthernet::begin(IPAddress local_ip) {
30+
/* -------------------------------------------------------------------------- */
31+
// Assume the DNS server will be the machine on the same network as the local IP
32+
// but with last octet being '1'
33+
IPAddress dns_server = local_ip;
34+
dns_server[3] = 1;
35+
return begin(local_ip, dns_server);
36+
}
37+
38+
/* -------------------------------------------------------------------------- */
39+
int CEthernet::begin(IPAddress local_ip, IPAddress dns_server) {
40+
/* -------------------------------------------------------------------------- */
41+
// Assume the gateway will be the machine on the same network as the local IP
42+
// but with last octet being '1'
43+
IPAddress gateway = local_ip;
44+
gateway[3] = 1;
45+
return begin(local_ip, dns_server, gateway);
46+
}
47+
48+
/* -------------------------------------------------------------------------- */
49+
int CEthernet::begin(IPAddress local_ip, IPAddress dns_server, IPAddress gateway) {
50+
/* -------------------------------------------------------------------------- */
51+
IPAddress subnet(255, 255, 255, 0);
52+
return begin(local_ip, dns_server, gateway, subnet);
53+
}
54+
55+
/* -------------------------------------------------------------------------- */
56+
int CEthernet::begin(IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet) {
57+
/* -------------------------------------------------------------------------- */
58+
59+
ni = CLwipIf::getInstance().get(NI_ETHERNET, local_ip, gateway, subnet);
60+
if(ni == nullptr) {
61+
return 0;
62+
}
63+
64+
/* If there is a local DHCP informs it of our manual IP configuration to prevent IP conflict */
65+
ni->DhcpNotUsed();
66+
CLwipIf::getInstance().addDns(dns_server);
67+
return 1;
68+
}
69+
70+
/* -------------------------------------------------------------------------- */
71+
void CEthernet::setDNS(IPAddress dns_server) {
72+
/* -------------------------------------------------------------------------- */
73+
CLwipIf::getInstance().addDns(dns_server);
74+
}
75+
76+
/* -------------------------------------------------------------------------- */
77+
int CEthernet::begin(uint8_t *mac, unsigned long timeout, unsigned long responseTimeout) {
78+
/* -------------------------------------------------------------------------- */
79+
int ret = (int)CLwipIf::getInstance().setMacAddress(NI_ETHERNET, mac);
80+
begin(timeout, responseTimeout);
81+
return ret;
82+
}
83+
84+
/* -------------------------------------------------------------------------- */
85+
int CEthernet::begin(uint8_t *mac_address, IPAddress local_ip) {
86+
/* -------------------------------------------------------------------------- */
87+
// Assume the DNS server will be the machine on the same network as the local IP
88+
// but with last octet being '1'
89+
IPAddress dns_server = local_ip;
90+
dns_server[3] = 1;
91+
return begin(mac_address, local_ip, dns_server);
92+
}
93+
94+
/* -------------------------------------------------------------------------- */
95+
int CEthernet::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server) {
96+
/* -------------------------------------------------------------------------- */
97+
// Assume the gateway will be the machine on the same network as the local IP
98+
// but with last octet being '1'
99+
IPAddress gateway = local_ip;
100+
gateway[3] = 1;
101+
return begin(mac_address, local_ip, dns_server, gateway);
102+
}
103+
104+
/* -------------------------------------------------------------------------- */
105+
int CEthernet::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway) {
106+
/* -------------------------------------------------------------------------- */
107+
IPAddress subnet(255, 255, 255, 0);
108+
return begin(mac_address, local_ip, dns_server, gateway, subnet);
109+
}
110+
111+
/* -------------------------------------------------------------------------- */
112+
int CEthernet::begin(uint8_t *mac, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet, unsigned long timeout, unsigned long responseTimeout) {
113+
/* -------------------------------------------------------------------------- */
114+
CLwipIf::getInstance().setMacAddress(NI_ETHERNET, mac_address);
115+
return begin(local_ip, dns_server, gateway, subnet);
116+
}
117+
118+
/* -------------------------------------------------------------------------- */
119+
EthernetLinkStatus CEthernet::linkStatus() {
120+
/* -------------------------------------------------------------------------- */
121+
if(ni != nullptr) {
122+
return (!CLwipIf::getInstance().isEthInitialized()) ? Unknown : (ni->isLinkUp() ? LinkON : LinkOFF);
123+
}
124+
return Unknown;
125+
}
126+
127+
/* -------------------------------------------------------------------------- */
128+
EthernetHardwareStatus CEthernet::hardwareStatus() {
129+
/* -------------------------------------------------------------------------- */
130+
return EthernetLwip;
131+
}
132+
133+
/* -------------------------------------------------------------------------- */
134+
int CEthernet::disconnect() {
135+
/* -------------------------------------------------------------------------- */
136+
return 1;
137+
}
138+
139+
/* -------------------------------------------------------------------------- */
140+
int CEthernet::maintain() {
141+
/* -------------------------------------------------------------------------- */
142+
int rc = DHCP_CHECK_NONE;
143+
144+
if (ni != NULL) {
145+
//we have a pointer to dhcp, use it
146+
rc = ni->checkLease();
147+
switch (rc) {
148+
case DHCP_CHECK_NONE:
149+
//nothing done
150+
break;
151+
case DHCP_CHECK_RENEW_OK:
152+
case DHCP_CHECK_REBIND_OK:
153+
//_dnsServerAddress = _dhcp->getDnsServerIp();
154+
break;
155+
default:
156+
//this is actually a error, it will retry though
157+
break;
158+
}
159+
}
160+
return rc;
161+
}
162+
163+
/*
164+
* This function updates the LwIP stack and can be called to be sure to update
165+
* the stack (e.g. in case of a long loop).
166+
*/
167+
void CEthernet::schedule(void) {
168+
if (ni != NULL) {
169+
ni->task();
170+
}
171+
}
172+
173+
174+
175+
uint8_t *CEthernet::MACAddress(void) {
176+
CLwipIf::getInstance().getMacAddress(NI_ETHERNET, mac_address);
177+
return mac_address;
178+
}
179+
180+
void CEthernet::MACAddress(uint8_t *mac) {
181+
CLwipIf::getInstance().getMacAddress(NI_ETHERNET, mac);
182+
}
183+
184+
IPAddress CEthernet::localIP() {
185+
if(ni != nullptr) {
186+
return IPAddress(ni->getIpAdd());
187+
}
188+
return IPAddress((uint32_t)0);
189+
}
190+
191+
IPAddress CEthernet::subnetMask() {
192+
if(ni != nullptr) {
193+
return IPAddress(ni->getNmAdd());
194+
}
195+
return IPAddress((uint32_t)0);
196+
}
197+
198+
IPAddress CEthernet::gatewayIP() {
199+
if(ni != nullptr) {
200+
return IPAddress(ni->getGwAdd());
201+
}
202+
return IPAddress((uint32_t)0);
203+
}
204+
205+
IPAddress CEthernet::dnsServerIP() {
206+
return CLwipIf::getInstance().getDns();
207+
}
208+
209+
CEthernet Ethernet;

0 commit comments

Comments
 (0)
Please sign in to comment.