Address PR review feedback from liamcottle (second round)

- Rename eth command to eth.status for consistency with other commands
- Rename generateDeviceMac to generateEthernetMac for clarity
- Refactor ethernet_handle_command to return false by default
- Allow new TCP clients to replace existing connections (repeater, room server, SerialEthernetInterface)
- Boot companion radio without Ethernet on init failure (LoRa-only recovery mode)
- Remove > prompt from ethernet CLI for consistency with serial interface
- Fix variable redeclaration compile error in SerialEthernetInterface when ETHERNET_STATIC_IP is defined
- Fix TCP socket leak when duplicate client detection fires
- Remove dead recv_queue and adv_restart_time members from SerialEthernetInterface
- Fix port numbers in docs (port 23 for repeater/room server CLI, port 5000 for companion radio)
- Clarify eth.status command is only available in repeater and room server firmware

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Ryan Gregg
2026-03-11 12:43:08 -07:00
co-authored by Claude Sonnet 4.6
parent 3e9ceba24a
commit 61ba79966b
8 changed files with 82 additions and 94 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
#include <Arduino.h>
static inline void generateDeviceMac(uint8_t mac[6]) {
static inline void generateEthernetMac(uint8_t mac[6]) {
uint32_t device_id = NRF_FICR->DEVICEID[0];
mac[0] = 0x02;
mac[1] = 0x92;
+40 -48
View File
@@ -39,7 +39,7 @@ bool SerialEthernetInterface::begin() {
#endif
uint8_t mac[6];
generateDeviceMac(mac);
generateEthernetMac(mac);
ETHERNET_DEBUG_PRINTLN(
"Ethernet MAC: %02X:%02X:%02X:%02X:%02X:%02X",
mac[0],
@@ -80,14 +80,9 @@ bool SerialEthernetInterface::begin() {
}
#endif
ETHERNET_DEBUG_PRINTLN("Ethernet begin complete");
IPAddress ip = Ethernet.localIP();
ETHERNET_DEBUG_PRINT_IP("IP", ip);
IPAddress subnet = Ethernet.subnetMask();
ETHERNET_DEBUG_PRINT_IP("Subnet", subnet);
IPAddress gateway = Ethernet.gatewayIP();
ETHERNET_DEBUG_PRINT_IP("Gateway", gateway);
ETHERNET_DEBUG_PRINT_IP("IP", Ethernet.localIP());
ETHERNET_DEBUG_PRINT_IP("Subnet", Ethernet.subnetMask());
ETHERNET_DEBUG_PRINT_IP("Gateway", Ethernet.gatewayIP());
server.begin(); // start listening for clients
ETHERNET_DEBUG_PRINTLN("Ethernet: listening on TCP port: %d", ETHERNET_TCP_PORT);
@@ -132,48 +127,45 @@ bool SerialEthernetInterface::isWriteBusy() const {
}
size_t SerialEthernetInterface::checkRecvFrame(uint8_t dest[]) {
// check if new client connected
if (client && client.connected()) {
// Avoid polling for new clients while an active connection exists.
} else {
auto newClient = server.available();
if (newClient) {
IPAddress new_ip = newClient.remoteIP();
uint16_t new_port = newClient.remotePort();
// check if new client connected; new connections replace existing ones
auto newClient = server.available();
if (newClient) {
IPAddress new_ip = newClient.remoteIP();
uint16_t new_port = newClient.remotePort();
ETHERNET_DEBUG_PRINTLN(
"New client available %u.%u.%u.%u:%u",
new_ip[0],
new_ip[1],
new_ip[2],
new_ip[3],
new_port);
if (client && client.connected()) {
IPAddress cur_ip = client.remoteIP();
uint16_t cur_port = client.remotePort();
ETHERNET_DEBUG_PRINTLN(
"New client available %u.%u.%u.%u:%u",
new_ip[0],
new_ip[1],
new_ip[2],
new_ip[3],
new_port);
if (client && client.connected()) {
IPAddress cur_ip = client.remoteIP();
uint16_t cur_port = client.remotePort();
ETHERNET_DEBUG_PRINTLN(
"Current client %u.%u.%u.%u:%u",
cur_ip[0],
cur_ip[1],
cur_ip[2],
cur_ip[3],
cur_port);
if (cur_ip == new_ip && cur_port == new_port) {
ETHERNET_DEBUG_PRINTLN("Ignoring duplicate client");
return 0;
}
"Current client %u.%u.%u.%u:%u",
cur_ip[0],
cur_ip[1],
cur_ip[2],
cur_ip[3],
cur_port);
if (cur_ip == new_ip && cur_port == new_port) {
ETHERNET_DEBUG_PRINTLN("Ignoring duplicate client");
newClient.stop();
return 0;
}
deviceConnected = false;
if (client) {
ETHERNET_DEBUG_PRINTLN("Closing previous client");
client.stop();
}
_state = RECV_STATE_IDLE;
_frame_len = 0;
_rx_len = 0;
client = newClient;
ETHERNET_DEBUG_PRINTLN("Switched to new client");
}
deviceConnected = false;
if (client) {
ETHERNET_DEBUG_PRINTLN("Closing previous client");
client.stop();
}
_state = RECV_STATE_IDLE;
_frame_len = 0;
_rx_len = 0;
client = newClient;
ETHERNET_DEBUG_PRINTLN("Switched to new client");
}
if (client.connected()) {
+1 -5
View File
@@ -13,7 +13,6 @@ class SerialEthernetInterface : public BaseSerialInterface {
bool deviceConnected;
bool _isEnabled;
unsigned long _last_write;
unsigned long adv_restart_time;
uint8_t _state;
uint16_t _frame_len;
uint16_t _rx_len;
@@ -28,13 +27,10 @@ class SerialEthernetInterface : public BaseSerialInterface {
};
#define FRAME_QUEUE_SIZE 4
int recv_queue_len;
Frame recv_queue[FRAME_QUEUE_SIZE];
int send_queue_len;
Frame send_queue[FRAME_QUEUE_SIZE];
void clearBuffers() {
recv_queue_len = 0;
send_queue_len = 0;
_state = 0;
_frame_len = 0;
@@ -48,7 +44,7 @@ class SerialEthernetInterface : public BaseSerialInterface {
deviceConnected = false;
_isEnabled = false;
_last_write = 0;
send_queue_len = recv_queue_len = 0;
send_queue_len = 0;
_state = 0;
_frame_len = 0;
_rx_len = 0;