Repository navigation
Ethernet interface - #9
Merged
Merged
Conversation
…ommon.h Split the medium-independent parts out of racelink_transport_core.h so the LoRa backend and the upcoming Ethernet (W5500/UDP) backend share one copy: - MAC / 3-byte address helpers (readEfuseMac6, last3FromMac6, mac6ToStr, same3, isBroadcast3, receiverMatches) - StreamStatus + the RX-side stream-reassembly state machine (handleStreamPacket / streamBuffer / clearStreamReady), now templated on the Core type so both transports reuse a single definition. LoRa-specific code (LBT/RNG, TX-side stream scheduling, PhyCfg/RadioLib) stays in racelink_transport_core.h, which now includes the common header. Pure move + templatization, no behaviour change; v4 LLCC68 target builds and links clean.
Ethernet sibling of racelink_transport_core.h exposing the same RaceLinkTransport:: surface the usermod consumes, selected later by -D RACELINK_ETH. Drives the W5500 via the standalone Arduino Ethernet lib + EthernetUDP over a dedicated SPIClass (Tasmota Arduino-ESP32 2.0.18 ETH.h has no W5500 support). Translates between the firmware-internal Header7 frame and the host UDP framing (verified against RaceLink_Host ethernet_transport.py + mock_ethernet_node.py): - scheduleSend(out,n): datagram = [out[6]] ++ out[0..n) to the learned host endpoint (else broadcast:5079); fire-and-forget, no LBT/CAD. - service(): inbound M2N [type_full][recv3][body] -> learn host endpoint, reconstruct Header7 frame [synthSender3][recv3][type_full][body] -> onRxPacket. attachDio1/setDefaultRxContinuous are no-ops; RF telemetry reads 0. RX stream reassembly reuses the shared template from racelink_transport_common.h. Inert until Stage 3 wires the selector; LoRa build unaffected. No proto change.
…build profile Stage 3 (usermod wiring): - racelink_wled.h selects racelink_transport_eth.h vs racelink_transport_core.h on RACELINK_ETH; omit the RadioLib 'radio' member on ETH builds. - radioInit() branches: ETH path brings up the transport via beginCommon(rl); the service-loop radio gate uses radioReady on ETH. RF-only opcode handlers (rf_config_nvs is RadioLib-free) stay compiled but inert. Stage 5 (driver + profile): - racelink_w5500_udp.h: self-contained Wiznet W5500 UDP driver over SPI (socket0 UDP, broadcast RX, static IP). No external Ethernet lib -- none compile on the pinned Tasmota 2.0.18 core (ETH.h lacks W5500; IDF esp_eth W5500 not in the precompiled SDK; arduino W5500 libs hit an ambiguous IPAddress ctor). - racelink_transport_eth.h now drives the W5500 via that header (was a stand-in external-lib include). - build_profiles/RaceLink_Node_v5_s3_eth.platformio_override.ini: ESP32-S3 + W5500 target, DEV_TYPE 13 (NODE_WLED_REV5), W5500 SPI pins 11-14/9/10, LED2 moved off GPIO11 to GPIO4, static IP flags. NOTE: register DEV_TYPE 13 in the host. Compile-verified: v5 ETH target builds + links (real firmware.bin); v4 LoRa LLCC68 target still builds green (no regression). No proto change.
racelink_w5500_udp.h: minimal DHCP client over socket 0 (DISCOVER -> OFFER -> REQUEST -> ACK, BOOTP + options 53/50/54/55/61, broadcast flag). Refactored begin() to do chip bring-up + MAC only; IP assignment is now setStaticIp() or dhcpConfigure(), then udpOpen() opens the app port. racelink_transport_eth.h: beginCommon() runs DHCP by default (-D RACELINK_ETH_DHCP=1) with static-IP fallback; -D RACELINK_ETH_DHCP=0 forces static. Core now exposes dhcpOk + ip/subnet/gateway for later status/UI. build profile: document DHCP-default; static flags are the fallback. v5 ETH target builds + links green with DHCP enabled.
In racelink_wled.cpp, gate the LoRa-specific UI behind RACELINK_ETH and add the Ethernet equivalents: - addToJsonInfo: replace the 'RaceLink Init' radio line with an Ethernet status line (link up/down, IP, DHCP vs static) plus UDP port and W5500 SPI pin map; hide 'Last RSSI/SNR' (meaningless on Ethernet). 'RaceLink MyID (3B)' kept. - addToConfig: emit the LoRa RL_RF + radio-pins block only on non-ETH builds (ETH SPI pins/ports/DHCP are compile-time, surfaced read-only in Info). - readFromConfig: gate the radio-pin read + pins-changed reboot logic out on ETH (firstReadFromConfig handling kept for both). v5 ETH + v4 LoRa LLCC68 both build green.
Replace the blocking dhcpConfigure() (which could stall setup() ~12s) with a non-blocking DHCP state machine in racelink_w5500_udp.h: dhcpBegin() kicks off DISCOVER, dhcpPoll() advances DISCOVER->OFFER->REQUEST->ACK one step per call (retransmit every 3s, overall timeout -> Failed), dhcpResult() returns the lease. racelink_transport_eth.h: beginCommon() now starts DHCP without waiting and returns; service() drives dhcpPoll() each loop and, once bound (or on timeout -> static fallback), opens the app UDP socket and sets rl.netReady. scheduleSend() and the RX pump are gated on netReady so nothing transmits before the network is up. Static-IP builds come up immediately as before. v5 ETH + v4 LoRa both build green.
- racelink_transport_eth.h: refresh rl.linkUp from PHYCFGR in service() (throttled to 500 ms). beginCommon() read it once right after reset, before auto-negotiation finished, so the WLED 'RaceLink ETH' info line showed 'no link' even after DHCP had already obtained a lease (the reported contradiction: 'no link' + a valid 192.168.x IP + (DHCP)). - racelink_wled.cpp: on RACELINK_ETH builds, OPC_RF_CONFIG / OPC_GET_RF_CONFIG now reject with ACK_BAD_TYPE (unicast) instead of persisting a meaningless LoRa PHY config and rebooting. The host's EthernetTransport does not send these anyway. v5 ETH + v4 LoRa both build green.
- racelink_wled.cpp (ETH radioInit): allocate the W5500 pins (SCLK/MOSI/MISO/CS/ RST/INT) through WLED's PinManager so a misconfigured LED bus on any of them fails loudly at init instead of silently breaking the link. - racelink_w5500_udp.h: track the DHCP lease (option 51) and rebind at ~85% of the lease lifetime (dhcpRenewDue/dhcpBegin(renew)); throttled retries. The rebind reuses the existing non-blocking state machine. - racelink_transport_eth.h: trigger the rebind from service() when due; on a failed renewal keep the current lease IP (dhcpKeepLease) instead of dropping to the static fallback (which is only for initial-acquisition failure). v5 ETH + v4 LoRa both build green.
…Ra pins)
The Ethernet build's W5500 pins were compile-time only. Expose them in the usermod
settings exactly like the LoRa radio pins:
- racelink_wled.h: add eth{Sclk,Mosi,Miso,Cs,Rst,Int} members (RACELINK_ETH_*
build flags as defaults).
- addToConfig: emit an 'eth_pins' object (SCLK/MOSI/MISO/CS/RST/INT).
- readFromConfig: load eth_pins into the members; a change sets doReboot (SPI/
Ethernet re-init at boot), suppressed on first boot — same pattern as the LoRa
pins.
- radioInit (ETH): reserve and bring up the W5500 on the runtime pins via an
EthCfg passed to beginCommon(), instead of the macro defaults.
- addToJsonInfo: show the live pin map from the members (incl. INT).
UDP ports / DHCP-vs-static stay compile-time. v5 ETH + v4 LoRa build green.
…ngs) The W5500 SPI pins are now editable in the usermod settings (for ETH builds, just like the LoRa pins for RF builds), so the read-only 'ETH W5500 Pins' info row is redundant. Keep the ETH link/IP status and UDP port rows.
rl.linkUp was only consumed by the info panel, so the periodic service() refresh was unnecessary. Drop the cached linkUp/lastLinkPollMs fields and the throttled poll; read the W5500 PHY link state live in addToJsonInfo (i.e. only when the info panel is rendered).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces a new shared header for transport-agnostic RaceLink helpers and refactors the codebase to improve maintainability and code reuse between the LoRa and Ethernet backends. The main changes include moving address/MAC utilities and RX-side stream reassembly logic into a new header, updating the LoRa backend to use these shared helpers, and adding a new PlatformIO build profile for the Ethernet node.
Refactoring for code reuse and maintainability:
racelink_transport_common.hcontaining all transport-agnostic helpers, including address/MAC utilities (e.g.,readEfuseMac6,last3FromMac6,mac6ToStr,same3,isBroadcast3,receiverMatches), theStreamStatustype, and the RX-side stream reassembly state machine (handleStreamPacket,streamBuffer,clearStreamReady). This header is now included by both LoRa and Ethernet backends.racelink_transport_core.h(LoRa backend) to remove its own copies of the shared helpers and instead include and use the newracelink_transport_common.hheader. Only LoRa-specific helpers remain in the core header. [1] [2] [3] [4]Build system and configuration:
build_profiles/RaceLink_Node_v5_s3_eth.platformio_override.inifor the RaceLink Ethernet node, defining all relevant build flags, pin assignments, and device type for the new Ethernet variant.These changes improve code clarity, reduce duplication, and make it easier to maintain and extend both transport backends in the future.