Skip to content

Commit 27e8c19

Browse files
committed
Merge branch 'main' into portentas_compatibility
2 parents 1238ad3 + c0ff964 commit 27e8c19

File tree

12 files changed

+367
-97
lines changed

12 files changed

+367
-97
lines changed

.github/workflows/arduino-lint.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
uses: actions/checkout@v4
2121

2222
- name: Arduino Lint
23-
uses: arduino/arduino-lint-action@v1
23+
uses: arduino/arduino-lint-action@v2
2424
with:
2525
official: true
2626
project-type: library

.github/workflows/compile-examples.yml

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ jobs:
4242
- fqbn: arduino:renesas_uno:unor4wifi
4343
platforms: |
4444
- name: arduino:renesas_uno
45+
- fqbn: arduino:mbed_giga:giga
46+
platforms: |
47+
- name: arduino:mbed_giga
4548
4649
steps:
4750
- name: Checkout

examples/UDP_Client/UDP_Client.ino

+31-18
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,20 @@ static T1SMacSettings const t1s_default_mac_settings;
2929
static IPAddress const UDP_SERVER_IP_ADDR = {192, 168, 42, 100 + 0};
3030
static uint16_t const UDP_CLIENT_PORT = 8889;
3131
static uint16_t const UDP_SERVER_PORT = 8888;
32-
static uint8_t udp_tx_msg_buf[256] = {0};
33-
static uint8_t udp_rx_msg_buf[256] = {0};
3432

3533
/**************************************************************************************
3634
* GLOBAL VARIABLES
3735
**************************************************************************************/
3836

39-
auto const tc6_io = new TC6::TC6_Io
40-
( SPI
41-
, CS_PIN
42-
, RESET_PIN
43-
, IRQ_PIN);
37+
auto const tc6_io = new TC6::TC6_Io(
38+
#ifdef ARDUINO_GIGA
39+
SPI1
40+
#else
41+
SPI
42+
#endif
43+
, CS_PIN
44+
, RESET_PIN
45+
, IRQ_PIN);
4446
auto const tc6_inst = new TC6::TC6_Arduino_10BASE_T1S(tc6_io);
4547
Arduino_10BASE_T1S_UDP udp_client;
4648

@@ -123,6 +125,7 @@ void loop()
123125
prev_udp_packet_sent = now;
124126

125127
/* Prepare UDP packet. */
128+
uint8_t udp_tx_msg_buf[256] = {0};
126129
int const tx_packet_size = snprintf((char *)udp_tx_msg_buf, sizeof(udp_tx_msg_buf), "Single-Pair Ethernet / 10BASE-T1S: packet cnt = %d", tx_packet_cnt);
127130

128131
/* Send a UDP packet to the UDP server. */
@@ -143,24 +146,34 @@ void loop()
143146
int const rx_packet_size = udp_client.parsePacket();
144147
if (rx_packet_size)
145148
{
146-
/* Receive incoming UDP packets. */
147-
Serial.print("Received ");
149+
/* Print some metadata from received UDP packet. */
150+
Serial.print("[");
151+
Serial.print(millis());
152+
Serial.print("] Received ");
148153
Serial.print(rx_packet_size);
149154
Serial.print(" bytes from ");
150155
Serial.print(udp_client.remoteIP());
151156
Serial.print(" port ");
152157
Serial.print(udp_client.remotePort());
153-
Serial.println();
154-
155-
int const bytes_read = udp_client.read(udp_rx_msg_buf, sizeof(udp_rx_msg_buf));
156-
if (bytes_read > 0) {
157-
udp_rx_msg_buf[bytes_read] = 0;
158+
Serial.print(", data = \"");
159+
160+
/* Read from received UDP packet. */
161+
size_t const UDP_RX_MSG_BUF_SIZE = 16 + 1; /* Reserve the last byte for the '\0' termination. */
162+
uint8_t udp_rx_msg_buf[UDP_RX_MSG_BUF_SIZE] = {0};
163+
int bytes_read = udp_client.read(udp_rx_msg_buf, UDP_RX_MSG_BUF_SIZE - 1);
164+
while(bytes_read != 0)
165+
{
166+
/* Print received data to Serial. */
167+
udp_rx_msg_buf[bytes_read] = '\0'; /* Terminate buffer so that we can print it as a C-string. */
168+
Serial.print(reinterpret_cast<char *>(udp_rx_msg_buf));
169+
170+
/* Continue reading. */
171+
bytes_read = udp_client.read(udp_rx_msg_buf, UDP_RX_MSG_BUF_SIZE - 1);
158172
}
159-
Serial.print("[");
160-
Serial.print(millis());
161-
Serial.print("] UDP_Client received packet content: \"");
162-
Serial.print(reinterpret_cast<char *>(udp_rx_msg_buf));
163173
Serial.println("\"");
174+
175+
/* Finish reading the current packet. */
176+
udp_client.flush();
164177
}
165178
}
166179

examples/UDP_Server/UDP_Server.ino

+42-21
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,20 @@ static T1SPlcaSettings const t1s_plca_settings{T1S_PLCA_NODE_ID};
3333
static T1SMacSettings const t1s_default_mac_settings;
3434

3535
static uint16_t const UDP_SERVER_LOCAL_PORT = 8888;
36-
static uint8_t udp_rx_msg_buf[256] = {0};
3736

3837
/**************************************************************************************
3938
* GLOBAL VARIABLES
4039
**************************************************************************************/
4140

42-
auto const tc6_io = new TC6::TC6_Io
43-
( SPI
44-
, CS_PIN
45-
, RESET_PIN
46-
, IRQ_PIN);
41+
auto const tc6_io = new TC6::TC6_Io(
42+
#ifdef ARDUINO_GIGA
43+
SPI1
44+
#else
45+
SPI
46+
#endif
47+
, CS_PIN
48+
, RESET_PIN
49+
, IRQ_PIN);
4750
auto const tc6_inst = new TC6::TC6_Arduino_10BASE_T1S(tc6_io);
4851
Arduino_10BASE_T1S_UDP udp_server;
4952

@@ -119,34 +122,52 @@ void loop()
119122
}
120123

121124
/* Check for incoming UDP packets. */
122-
int const packet_size = udp_server.parsePacket();
123-
if (packet_size)
125+
int const rx_packet_size = udp_server.parsePacket();
126+
if (rx_packet_size)
124127
{
125-
/* Receive incoming UDP packets. */
126-
Serial.print("Received ");
127-
Serial.print(packet_size);
128+
std::vector<uint8_t> udp_tx_buf;
129+
IPAddress const destination_ip = udp_server.remoteIP();
130+
uint16_t const destination_port = udp_server.remotePort();
131+
132+
/* Print some metadata from received UDP packet. */
133+
Serial.print("[");
134+
Serial.print(millis());
135+
Serial.print("] Received ");
136+
Serial.print(rx_packet_size);
128137
Serial.print(" bytes from ");
129138
Serial.print(udp_server.remoteIP());
130139
Serial.print(" port ");
131140
Serial.print(udp_server.remotePort());
132-
Serial.println();
133-
134-
int const bytes_read = udp_server.read(udp_rx_msg_buf, sizeof(udp_rx_msg_buf));
135-
if (bytes_read > 0) {
136-
udp_rx_msg_buf[bytes_read] = 0;
141+
Serial.print(", data = \"");
142+
143+
/* Read from received UDP packet. */
144+
size_t const UDP_RX_MSG_BUF_SIZE = 16 + 1; /* Reserve the last byte for the '\0' termination. */
145+
uint8_t udp_rx_msg_buf[UDP_RX_MSG_BUF_SIZE] = {0};
146+
int bytes_read = udp_server.read(udp_rx_msg_buf, UDP_RX_MSG_BUF_SIZE - 1);
147+
while(bytes_read != 0)
148+
{
149+
/* Copy received data into transmit buffer for echo functionality. */
150+
std::copy(udp_rx_msg_buf, udp_rx_msg_buf + bytes_read, std::back_inserter(udp_tx_buf));
151+
152+
/* Print received data to Serial. */
153+
udp_rx_msg_buf[bytes_read] = '\0'; /* Terminate buffer so that we can print it as a C-string. */
154+
Serial.print(reinterpret_cast<char *>(udp_rx_msg_buf));
155+
156+
/* Continue reading. */
157+
bytes_read = udp_server.read(udp_rx_msg_buf, UDP_RX_MSG_BUF_SIZE - 1);
137158
}
138-
Serial.print("UDP_Server received packet content: \"");
139-
Serial.print(reinterpret_cast<char *>(udp_rx_msg_buf));
140159
Serial.println("\"");
141160

161+
/* Finish reading the current packet. */
162+
udp_server.flush();
163+
142164
/* Send back a reply, to the IP address and port we got the packet from. */
143-
udp_server.beginPacket(udp_server.remoteIP(), udp_server.remotePort());
144-
udp_server.write((const uint8_t *)udp_rx_msg_buf, packet_size);
165+
udp_server.beginPacket(destination_ip, destination_port);
166+
udp_server.write(udp_tx_buf.data(), udp_tx_buf.size());
145167
udp_server.endPacket();
146168
}
147169
}
148170

149-
150171
static void OnPlcaStatus(bool success, bool plcaStatus)
151172
{
152173
if (!success)

examples/iperf-client/iperf-client.ino

+4-8
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,15 @@ static T1SMacSettings const t1s_mac_settings{MAC_PROMISCUOUS_MODE, MAC_TX_CUT_TH
4141
* GLOBAL VARIABLES
4242
**************************************************************************************/
4343

44+
auto const tc6_io = new TC6::TC6_Io(
4445
#ifdef ARDUINO_GIGA
45-
auto const tc6_io = new TC6::TC6_Io
46-
( SPI1
47-
, CS_PIN
48-
, RESET_PIN
49-
, IRQ_PIN);
46+
SPI1
5047
#else
51-
auto const tc6_io = new TC6::TC6_Io
52-
( SPI
48+
SPI
49+
#endif
5350
, CS_PIN
5451
, RESET_PIN
5552
, IRQ_PIN);
56-
#endif
5753
auto const tc6_inst = new TC6::TC6_Arduino_10BASE_T1S(tc6_io);
5854

5955
/**************************************************************************************

examples/tools/Control-DIOx/Control-DIOx.ino

+9-5
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,15 @@ static auto const DIO_PIN = TC6::DIO::A0;
3535
* GLOBAL VARIABLES
3636
**************************************************************************************/
3737

38-
auto const tc6_io = new TC6::TC6_Io
39-
( SPI
40-
, CS_PIN
41-
, RESET_PIN
42-
, IRQ_PIN);
38+
auto const tc6_io = new TC6::TC6_Io(
39+
#ifdef ARDUINO_GIGA
40+
SPI1
41+
#else
42+
SPI
43+
#endif
44+
, CS_PIN
45+
, RESET_PIN
46+
, IRQ_PIN);
4347
auto const tc6_inst = new TC6::TC6_Arduino_10BASE_T1S(tc6_io);
4448

4549
/**************************************************************************************

examples/tools/PoDL-Sink-Auto-TurnOff/PoDL-Sink-Auto-TurnOff.ino

+9-5
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,15 @@ static T1SMacSettings const t1s_default_mac_settings;
3232
* GLOBAL VARIABLES
3333
**************************************************************************************/
3434

35-
auto const tc6_io = new TC6::TC6_Io
36-
( SPI
37-
, CS_PIN
38-
, RESET_PIN
39-
, IRQ_PIN);
35+
auto const tc6_io = new TC6::TC6_Io(
36+
#ifdef ARDUINO_GIGA
37+
SPI1
38+
#else
39+
SPI
40+
#endif
41+
, CS_PIN
42+
, RESET_PIN
43+
, IRQ_PIN);
4044
auto const tc6_inst = new TC6::TC6_Arduino_10BASE_T1S(tc6_io);
4145

4246
/**************************************************************************************

examples/tools/PoDL-Source/PoDL-Source.ino

+9-5
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,15 @@ static T1SMacSettings const t1s_default_mac_settings;
3232
* GLOBAL VARIABLES
3333
**************************************************************************************/
3434

35-
auto const tc6_io = new TC6::TC6_Io
36-
( SPI
37-
, CS_PIN
38-
, RESET_PIN
39-
, IRQ_PIN);
35+
auto const tc6_io = new TC6::TC6_Io(
36+
#ifdef ARDUINO_GIGA
37+
SPI1
38+
#else
39+
SPI
40+
#endif
41+
, CS_PIN
42+
, RESET_PIN
43+
, IRQ_PIN);
4044
auto const tc6_inst = new TC6::TC6_Arduino_10BASE_T1S(tc6_io);
4145

4246
/**************************************************************************************

0 commit comments

Comments
 (0)