|
STAR
Cal STAR — firmware, DAQ server, and engine design
|
Board networking — the ground station decides addresses, not the board. More...
Classes | |
| struct | State |
Enumerations | |
| enum class | AddressSource : uint8_t { None , Dhcp , Recovery } |
| How the board ended up with the address it is using. More... | |
Functions | |
| const char * | sourceName (AddressSource s) |
| IPAddress | recoverySubnet () |
| Subnet of the recovery address: link-local, 169.254.0.0/16. | |
| IPAddress | recoveryAddress (const byte mac[6]) |
| The board's recovery address, from its MAC: 169.254. | |
| void | configure (State &s, const byte mac[6]) |
| void | printMac (const State &s) |
| Print the MAC as aa:bb:cc:dd:ee:ff. | |
| bool | usingDhcp (const State &s) |
| bool | hasAddress (const State &s) |
| uint8_t | boardId (const State &s) |
| The board's ID: the last octet of the address the server assigned (192.168.2.31 -> 31). | |
| void | maintainLease (State &s) |
| Renew the lease as it expires. | |
| void | beginOtaHold (State &s) |
| Called when an OTA transfer starts, so the address cannot move under it. | |
| bool | onServerPacket (State &s, IPAddress remote_ip, IPAddress &serverIP) |
| A server packet arrived from remote_ip; adopt it as the server address. | |
| bool | serverWentSilent (const State &s) |
| Server has stopped talking — forget it and resume discovery broadcasts. | |
| void | useRecoveryAddress (State &s, IPAddress dns, IPAddress gateway) |
| AddressSource | begin (State &s, IPAddress dns, IPAddress gateway) |
| Bring the interface up: ask the ground station for an address, and take the recovery address only if nothing answers. | |
| bool | retryDhcp (State &s, IPAddress dns, IPAddress gateway) |
| On the recovery address, ask for a lease again every SENSOR_ETH_DHCP_RETRY_INTERVAL_MS. | |
Board networking — the ground station decides addresses, not the board.
Enabled per board with -DSENSOR_ETH_USE_DHCP (every hotfire board today).
When no DHCP server answers, the board takes its RECOVERY address, 169.254.<1 + mac[4] % 254>.<mac[5]>/16, and keeps asking for a lease every SENSOR_ETH_DHCP_RETRY_INTERVAL_MS. The recovery address exists so a board whose DHCP failed (server down, booted before the switch) can still be reflashed over Ethernet: ota_upload.py --mac <mac> computes the same address. It is never a working address — the DAQ does not talk to a board there, and the board's ID is 0 until a lease arrives.
Why not the old static 192.168.2.<BOARD_ID> fallback: it needed a per-board build, and a board that missed DHCP looked exactly like one that got it, so DHCP could be broken for weeks unnoticed. Why derive from the MAC: it is burned into the ESP32, unique, and survives any flash erase; two bytes of it give 64k addresses, so collisions are checkable in advance (the config editor refuses two boards whose recovery addresses match).
No ESP32 dependencies beyond Arduino/Ethernet, so it is unit-testable off-target — see Hotfire_Tests/test/test_board_net.
|
strong |
How the board ended up with the address it is using.
| Enumerator | |
|---|---|
| None | not yet brought up |
| Dhcp | assigned by the ground station — the normal case |
| Recovery | no DHCP answer: 169.254.x.y from the MAC, reflash-only |
Definition at line 46 of file board_net.h.
|
inline |
Bring the interface up: ask the ground station for an address, and take the recovery address only if nothing answers.
Returns how we ended up addressed.
Definition at line 181 of file board_net.h.
References Dhcp, dns, Ethernet, gateway, BoardNet::State::lastDhcpAttemptMillis, BoardNet::State::mac, millis(), recoveryAddress(), SENSOR_ETH_DHCP_RESPONSE_TIMEOUT_MS, SENSOR_ETH_DHCP_TIMEOUT_MS, Serial, BoardNet::State::source, and useRecoveryAddress().
Referenced by recoveringState(), SensorHotfire::setup(), setup(), test_board_id_is_the_assigned_address(), test_dhcp_lease_is_adopted(), test_learning_a_server_never_moves_our_address(), test_lease_is_renewed_only_on_a_lease(), test_ota_suspends_renewal(), and test_source_is_reported_honestly().
|
inline |
Called when an OTA transfer starts, so the address cannot move under it.
Definition at line 144 of file board_net.h.
References BoardNet::State::otaHold.
Referenced by otaFreezeAddress(), SensorHotfire::otaFreezeAddress(), otaStart(), test_no_retry_during_an_ota(), and test_ota_suspends_renewal().
|
inline |
The board's ID: the last octet of the address the server assigned (192.168.2.31 -> 31).
0 while on the recovery address, where the board has no identity the server gave it.
Definition at line 129 of file board_net.h.
References Ethernet, and usingDhcp().
Referenced by loop(), SensorHotfire::loop(), pollNetwork(), SensorHotfire::setup(), setup(), test_board_id_is_the_assigned_address(), test_no_answer_puts_the_board_on_its_recovery_address(), and test_retry_that_gets_a_lease_moves_the_board().
Definition at line 93 of file board_net.h.
References BoardNet::State::mac, and mac.
Referenced by makeState(), SensorHotfire::setup(), and setup().
|
inline |
Definition at line 120 of file board_net.h.
References None, and BoardNet::State::source.
Referenced by test_source_is_reported_honestly().
|
inline |
Renew the lease as it expires.
No-op when we are not on a lease, and deliberately a no-op during an OTA: a renewal that moved our address mid-flash would drop the transfer.
Definition at line 138 of file board_net.h.
References Ethernet, BoardNet::State::otaHold, and usingDhcp().
Referenced by loop(), SensorHotfire::loop(), pollNetwork(), test_lease_is_renewed_only_on_a_lease(), and test_ota_suspends_renewal().
A server packet arrived from remote_ip; adopt it as the server address.
Returns true if serverIP changed.
Definition at line 152 of file board_net.h.
References BoardNet::State::lastServerPacketMillis, millis(), Serial, serverIP, and BoardNet::State::serverLearned.
Referenced by processIncomingPacket(), SensorHotfire::processIncomingPacket(), test_learning_a_server_never_moves_our_address(), test_repeat_server_packet_is_not_a_change(), test_server_is_learned_from_its_packets(), and test_server_silence_trips_after_timeout().
|
inline |
Print the MAC as aa:bb:cc:dd:ee:ff.
The ground station keys its reservation table on this, so it has to be readable off the serial log — otherwise registering a new board means guessing, or sniffing its DHCP request.
Definition at line 103 of file board_net.h.
References HEX, BoardNet::State::mac, and Serial.
Referenced by SensorHotfire::setup(), setup(), and test_mac_is_stored_for_reporting().
The board's recovery address, from its MAC: 169.254.
<1 + mac[4] % 254>.<mac[5]>.
The third octet stays in 1..254, the range RFC 3927 lets a host use. firmware/tools/ota_upload.py and daq-server's config validation compute the same thing; test_board_net pins the formula with the vectors they test.
Definition at line 77 of file board_net.h.
References IPAddress, and mac.
Referenced by begin(), test_recovery_address_formula(), and useRecoveryAddress().
|
inline |
Subnet of the recovery address: link-local, 169.254.0.0/16.
Definition at line 65 of file board_net.h.
References IPAddress.
Referenced by useRecoveryAddress().
On the recovery address, ask for a lease again every SENSOR_ETH_DHCP_RETRY_INTERVAL_MS.
Call every loop(); a no-op on a lease and during an OTA. Returns true when a lease arrived: the address and boardId() changed, so the caller should re-announce itself.
Each attempt blocks for up to SENSOR_ETH_DHCP_RETRY_TIMEOUT_MS. That is only ever spent on the recovery address, where the DAQ cannot reach the board, so it can never stall a session. Open sockets survive: a new address does not close them, and the W5500 is not reset.
Definition at line 213 of file board_net.h.
References Dhcp, dns, Ethernet, gateway, BoardNet::State::lastDhcpAttemptMillis, BoardNet::State::mac, millis(), BoardNet::State::otaHold, Recovery, SENSOR_ETH_DHCP_RESPONSE_TIMEOUT_MS, SENSOR_ETH_DHCP_RETRY_INTERVAL_MS, SENSOR_ETH_DHCP_RETRY_TIMEOUT_MS, Serial, BoardNet::State::source, and useRecoveryAddress().
Referenced by loop(), SensorHotfire::loop(), pollNetwork(), test_failed_retry_stays_reflashable(), test_no_retry_during_an_ota(), test_retry_that_gets_a_lease_moves_the_board(), and test_retry_waits_for_the_interval().
|
inline |
Server has stopped talking — forget it and resume discovery broadcasts.
Definition at line 166 of file board_net.h.
References BoardNet::State::lastServerPacketMillis, millis(), SENSOR_ZEROCONF_SERVER_SILENCE_MS, and BoardNet::State::serverLearned.
Referenced by loop(), SensorHotfire::loop(), pollNetwork(), test_server_silence_only_after_it_was_learned(), and test_server_silence_trips_after_timeout().
|
inline |
Definition at line 52 of file board_net.h.
References Dhcp, None, and Recovery.
Referenced by SensorHotfire::setup(), setup(), and test_source_is_reported_honestly().
Definition at line 171 of file board_net.h.
References dns, Ethernet, gateway, BoardNet::State::mac, Recovery, recoveryAddress(), recoverySubnet(), and BoardNet::State::source.
Referenced by begin(), and retryDhcp().
|
inline |
Definition at line 116 of file board_net.h.
References Dhcp, and BoardNet::State::source.
Referenced by boardId(), maintainLease(), test_dhcp_lease_is_adopted(), test_no_answer_puts_the_board_on_its_recovery_address(), and test_retry_that_gets_a_lease_moves_the_board().