Skip to content

Commit 329600a

Browse files
committed
Reduce program size (fits on Nano)
1 parent 5ee77b5 commit 329600a

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,6 @@ Not everything could fit into the limited flash memory of Arduino Nano / Uno. If
104104

105105
<img src="/pics/modbus6.png" alt="06" style="zoom:100%;" />
106106

107-
* #define ENABLE_EXTRA_DIAG shows extra info on "Current status" page: per socket diagnostics, run time counter.
107+
* #define ENABLE_EXTRA_DIAG shows extra info on "Current status" page: per socket diagnostics, run time counter, ethernet data counter.
108108

109109
<img src="/pics/modbus1x.png" alt="01x" style="zoom:100%;" />

arduino-modbus-rtu-tcp-gateway/02-modbus-tcp.ino

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,10 @@ void recvUdp()
8787
Udp.write(highByte(crc));
8888
}
8989
Udp.endPacket();
90+
#ifdef ENABLE_EXTRA_DIAG
9091
ethTxCount += 5;
9192
if (!localConfig.enableRtuOverTcp) ethTxCount += 4;
93+
#endif /* ENABLE_EXTRA_DIAG */
9294
}
9395
}
9496
}
@@ -133,8 +135,10 @@ void recvTcp()
133135
client.write(lowByte(crc)); // send CRC, low byte first
134136
client.write(highByte(crc));
135137
}
138+
#ifdef ENABLE_EXTRA_DIAG
136139
ethTxCount += 5;
137140
if (!localConfig.enableRtuOverTcp) ethTxCount += 4;
141+
#endif /* ENABLE_EXTRA_DIAG */
138142
}
139143
}
140144
}

arduino-modbus-rtu-tcp-gateway/03-modbus-rtu.ino

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,10 @@ void recvSerial()
105105
Udp.write(serialIn, rxNdx - 2); //send without CRC
106106
}
107107
Udp.endPacket();
108+
#ifdef ENABLE_EXTRA_DIAG
108109
ethTxCount += rxNdx;
109110
if (!localConfig.enableRtuOverTcp) ethTxCount += 4;
111+
#endif /* ENABLE_EXTRA_DIAG */
110112
} else if (queueHeaders.first().clientNum != SCAN_REQUEST) {
111113
EthernetClient client = EthernetClient(queueHeaders.first().clientNum);
112114
// make sure that this is really our socket
@@ -116,8 +118,10 @@ void recvSerial()
116118
client.write(MBAP, 6);
117119
client.write(serialIn, rxNdx - 2); //send without CRC
118120
}
121+
#ifdef ENABLE_EXTRA_DIAG
119122
ethTxCount += rxNdx;
120123
if (!localConfig.enableRtuOverTcp) ethTxCount += 4;
124+
#endif /* ENABLE_EXTRA_DIAG */
121125
}
122126
}
123127
deleteRequest();
@@ -150,8 +154,10 @@ void recvSerial()
150154
Udp.write(highByte(crc));
151155
}
152156
Udp.endPacket();
157+
#ifdef ENABLE_EXTRA_DIAG
153158
ethTxCount += 5;
154159
if (!localConfig.enableRtuOverTcp) ethTxCount += 4;
160+
#endif /* ENABLE_EXTRA_DIAG */
155161
} else {
156162
EthernetClient client = EthernetClient(queueHeaders.first().clientNum);
157163
// make sure that this is really our socket
@@ -164,8 +170,10 @@ void recvSerial()
164170
client.write(lowByte(crc)); // send CRC, low byte first
165171
client.write(highByte(crc));
166172
}
173+
#ifdef ENABLE_EXTRA_DIAG
167174
ethTxCount += 5;
168175
if (!localConfig.enableRtuOverTcp) ethTxCount += 4;
176+
#endif /* ENABLE_EXTRA_DIAG */
169177
}
170178
}
171179
deleteRequest();

arduino-modbus-rtu-tcp-gateway/05-pages.ino

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,15 +221,15 @@ void contentStatus(ChunkedPrint &chunked)
221221
chunked.print(serialTxCount);
222222
chunked.print(F(" Tx bytes / "));
223223
chunked.print(serialRxCount);
224-
chunked.print(F(" Rx bytes"
225-
"<tr><td>Ethernet Data:<td>"));
224+
chunked.print(F(" Rx bytes"));
225+
226+
#ifdef ENABLE_EXTRA_DIAG
227+
chunked.print(F("<tr><td>Ethernet Data:<td>"));
226228
chunked.print(ethTxCount);
227229
chunked.print(F(" Tx bytes / "));
228230
chunked.print(ethRxCount);
229-
chunked.print(F(" Rx bytes (excl. WebUI)"));
230-
231-
#ifdef ENABLE_EXTRA_DIAG
232-
chunked.print(F("<tr><td colspan=2>"
231+
chunked.print(F(" Rx bytes (excl. WebUI)"
232+
"<tr><td colspan=2>"
233233
"<table style=border-collapse:collapse;text-align:center>"
234234
"<tr><td><td>Socket Mode<td>Socket Status<td>Local Port<td>Remote IP<td>Remote Port"));
235235
for (byte i = 0; i < maxSockNum ; i++) {

arduino-modbus-rtu-tcp-gateway/arduino-modbus-rtu-tcp-gateway.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@
3636
v2.4 2021-10-15 Add SW version. Forced factory reset (load defaut settings from sketch) on MAJOR version change.
3737
v3.0 2021-11-07 Improve POST parameters processing, bugfix 404 and 204 error headers.
3838
v3.1 2022-01-28 Code optimization, bugfix DHCP settings.
39+
v3.2 2022-06-04 Reduce program size (so that it fits on Nano), ethernet data counter only available when ENABLE_EXTRA_DIAG.
3940
4041
*/
4142

42-
const byte version[] = {3, 1};
43+
const byte version[] = {3, 2};
4344

4445
#include <SPI.h>
4546
#include <Ethernet.h>

0 commit comments

Comments
 (0)