2026-09-28 15:36:37 +02:00
|
|
|
#pragma once
|
|
|
|
|
#include <Arduino.h>
|
2026-09-28 18:14:00 +02:00
|
|
|
#include <HexapodProtocol.h> // CmdPacket + FLAG_* + radio settings, shared with the remote (shared/)
|
2026-09-28 15:36:37 +02:00
|
|
|
|
|
|
|
|
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(); }
|
|
|
|
|
|
2026-11-17 14:42:37 +01:00
|
|
|
// 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_; }
|
|
|
|
|
|
2026-09-28 15:36:37 +02:00
|
|
|
private:
|
|
|
|
|
CmdPacket packet_;
|
|
|
|
|
uint32_t last_rx_ms_ = 0;
|
|
|
|
|
bool link_ok_ = false;
|
|
|
|
|
bool radio_present_ = false;
|
2026-11-17 14:42:37 +01:00
|
|
|
Telemetry telemetry_;
|
|
|
|
|
uint16_t rx_count_ = 0;
|
|
|
|
|
uint8_t rx_per_sec_ = 0;
|
|
|
|
|
uint32_t rate_window_ms_ = 0;
|
|
|
|
|
|
|
|
|
|
void loadAckPayload();
|
2026-09-28 15:36:37 +02:00
|
|
|
};
|