#pragma once #include #include "Config.h" // nRF24L01 transmitter. Uses hardware auto-ack to measure the link: the // robot's radio acks every packet it receives, so an ack = the robot heard us. // The robot's Telemetry comes back as the ack's payload. class RadioLink { public: bool begin(); // false if the radio chip didn't respond bool send(const CmdPacket& p); // blocking, returns true if acked void update(uint32_t now_ms); // refreshes linkOk() bool present() const { return present_; } bool linkOk() const { return link_ok_; } uint8_t qualityPct() const; // acked share of the last 32 packets // Latest telemetry from the robot, and whether it's recent enough to show. const Telemetry& telemetry() const { return telemetry_; } bool telemetryFresh(uint32_t now_ms) const { return has_telemetry_ && (now_ms - telemetry_ms_) < TELEMETRY_STALE_MS; } private: bool present_ = false; bool link_ok_ = false; uint32_t last_ack_ms_ = 0; bool ever_acked_ = false; uint32_t history_ = 0; // 1 bit per packet, newest in bit 0 Telemetry telemetry_; bool has_telemetry_ = false; uint32_t telemetry_ms_ = 0; };