sat_chain.h
Generated from the header
This page is rodeo-sdk/common/sat_chain.h — its comments and declarations.
To change it, change the header.
This is the engine, and it is pure logic: no UART, no clock, no libDaisy. It decides what frame to send next and makes sense of what comes back; a transport moves the bytes (sat_chain_port.h on the Seed, a simulated ring in common/tests/sat_chain_gtest.cpp). The frame format is sat_frame.h, and the rules are RODEO_SATELLITE_CHAIN_CONTRACT.md (§ numbers below):
- wait 50 ms after power for the satellites to boot (§6.1), then DISCOVER;
- SCAN every 4 ms (§6.2), output slots out, input slots back;
- three bad SCANs in a row: DISCOVER again, up to three times (§5.1);
- still nothing: find the break by closing the ring one satellite further each time, and keep scanning the satellites before it (§5.2); retry the whole ring every couple of seconds in case it has been fixed.
Controls are addressed by satellite (chain order, from 0) and slot within it. Which control is which parameter is the instrument’s business.
One exchange at a time:
SatChain::Exchange ex;if(chain.Poll(now_us, ex)) // something to send now port.Start(ex); // ...and later, when it has come back or timed out:chain.Reply(rx, len, now_us);SatChain
class SatChainMembers
static constexpr int kMaxSatellites = SAT_MAX_SLOTS— one slot each, at most
SatChain::Config
struct ConfigMembers
uint32_t scan_period_us = SAT_SCAN_PERIOD_MS * 1000uuint32_t power_wait_us = SAT_FIRST_DISCOVER_MS * 1000uuint32_t retry_period_us = 2000000u— how often a broken ring is retried wholeuint8_t fw_major = 1— the satellite firmware major this build speaks
SatChain::State
enum class State : uint8_tkPowerWait— waiting for the satellites to bootkDiscover— learning the chainkScan— the whole ring answerskFindBreak— the ring is broken: looking for wherekPartial— broken: scanning the satellites before the breakkVersion— a satellite runs a firmware major this build doesn’t speak
SatChain::Exchange
struct ExchangeOne frame to send, and what to expect back.
Members
uint8_t tx[SAT_MAX_FRAME_LEN]uint16_t tx_lenuint16_t rx_len— the reply’s exact length; 0: read it from the reply’s headeruint32_t timeout_us— give up on the reply after this long
SatChain::Init
void Init(const Config& cfg, uint32_t now_us);SatChain::Poll
bool Poll(uint32_t now_us, Exchange& ex);True when a frame should go out now; fills ex. Call often from the
main loop. Nothing is sent while a reply is awaited.
SatChain::Reply
void Reply(const uint8_t* rx, size_t len, uint32_t now_us);The reply to the last exchange: len bytes, or fewer (0 included) when
it timed out.
SatChain::GetState
State GetState() const;SatChain::Satellites
int Satellites() const;Satellites being scanned: the whole ring, or those before a break.
SatChain::Satellite
const sat_descriptor& Satellite(int i) const;SatChain::BrokenAfter
int BrokenAfter() const;A break was found after this many satellites, or -1 if there is none.
SatChain::Changed
bool Changed();True once after the chain’s layout changes (discovered, grown, broken).
SatChain::GoodScans
uint32_t GoodScans() const;SCAN replies that came back whole, and those that didn’t.
SatChain::BadScans
uint32_t BadScans() const;SatChain::Input
sat_slot Input(int i, int s) const;The slot as last received with a good CRC.
SatChain::Pot
float Pot(int i, int s) const;A POT slot’s position, 0..1.
SatChain::EncoderSteps
int EncoderSteps(int i, int s);Encoder detents since the last call, + or -.
SatChain::Pressed
bool Pressed(int i, int s) const;Whether a button, or an encoder’s push switch, is held now.
SatChain::Presses
int Presses(int i, int s);Presses since the last call.
SatChain::SwitchPosition
int SwitchPosition(int i, int s) const;A SWITCH slot’s position index.
SatChain::Fault
bool Fault(int i, int s, uint8_t* code = nullptr, uint8_t* detail = nullptr) const;True if the slot reports a FAULT; *code and *detail say which (§7).
SatChain::SetLed
void SetLed(int i, uint8_t brightness, uint8_t mode = SAT_LED_STEADY);A satellite’s LED: brightness 0..255 and a SAT_LED_ mode. Sent with every scan.
SatChain::SetRgb
void SetRgb(int i, int s, uint8_t r, uint8_t g, uint8_t b);The colour of the RGB LED on satellite i’s slot s, for boards with one per slot (the button bank). Sent with every scan as an RGB slot (§3.2), in place of SetLed’s on slot 0. Colours travel as RGB565.