#pragma once #include #include // CmdPacket + FLAG_* + radio settings, shared with the remote (shared/) class Comms { public: bool begin(); void update(); // call every loop; polls the radio if present bool linkOk() const { return link_ok_; } const CmdPacket& latest() const { return packet_; } // Lets the serial test harness (or, later, real radio) inject a packet directly. void injectPacket(const CmdPacket& p) { packet_ = p; last_rx_ms_ = millis(); } // Telemetry for the remote. Goes out as the ack payload of the next packet // received, so set it every loop. void setTelemetry(const Telemetry& t) { telemetry_ = t; } uint8_t packetsPerSec() const { return rx_per_sec_; } private: CmdPacket packet_; uint32_t last_rx_ms_ = 0; bool link_ok_ = false; bool radio_present_ = false; Telemetry telemetry_; uint16_t rx_count_ = 0; uint8_t rx_per_sec_ = 0; uint32_t rate_window_ms_ = 0; void loadAckPayload(); };