2026-09-28 18:14:00 +02:00
|
|
|
#pragma once
|
|
|
|
|
#include <HexapodProtocol.h>
|
2026-11-17 14:42:37 +01:00
|
|
|
#include "Config.h"
|
2026-09-28 18:14:00 +02:00
|
|
|
|
|
|
|
|
// 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.
|
2026-11-17 14:42:37 +01:00
|
|
|
// The robot's Telemetry comes back as the ack's payload.
|
2026-09-28 18:14:00 +02:00
|
|
|
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
|
|
|
|
|
|
2026-11-17 14:42:37 +01:00
|
|
|
// 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;
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-28 18:14:00 +02:00
|
|
|
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
|
2026-11-17 14:42:37 +01:00
|
|
|
Telemetry telemetry_;
|
|
|
|
|
bool has_telemetry_ = false;
|
|
|
|
|
uint32_t telemetry_ms_ = 0;
|
2026-09-28 18:14:00 +02:00
|
|
|
};
|