STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
link.h
Go to the documentation of this file.
1/**
2 * @file link.h
3 * @brief Glue: radio_receive() -> decode_frame() -> ArmGate. Call poll() from
4 * the main loop (or after the radio interrupt wakes the MCU).
5 */
6#ifndef LINK_H
7#define LINK_H
8
9#include <stdint.h>
10
11#include "arm_gate.h"
12#include "frame.h"
13
14namespace radio_link {
15
16class Link {
17public:
18 explicit Link(uint8_t target_id) : gate_(target_id) {
19 }
20
21 /**
22 * Drain at most one waiting packet (the SX1262 holds one at a time, so
23 * do not loop here; call again on the next DIO1 interrupt). Returns the
24 * gate's action for it: ArmAction::None if nothing was waiting, the packet
25 * was invalid, or it was not an ARM/UN_ARM frame (check the counters to
26 * tell them apart).
27 */
28 ArmAction poll(uint32_t now_ms);
29
30 uint32_t frames_ok() const {
31 return frames_ok_;
32 } // valid frames
33 uint32_t frames_dropped() const {
34 return frames_dropped_;
35 } // a packet arrived but was unusable: bad CRC, too long, etc.
36 uint32_t radio_errors() const {
37 return radio_errors_;
38 } // the radio did not answer (ErrNotFound, ErrTimeout, ...)
39 // The last frame that decoded (any type), for telemetry and link tests.
40 // Valid once frames_ok() > 0; the next good frame overwrites it.
41 const Frame& last_frame() const {
42 return frame_;
43 }
44
45private:
47 uint32_t frames_ok_ = 0;
48 uint32_t frames_dropped_ = 0;
49 uint32_t radio_errors_ = 0;
50 // Packet and frame buffers live here, not on the caller's stack
51 // (~0.5 KB): one Link per radio task.
54};
55
56} // namespace radio_link
57
58#endif // LINK_H
Decides whether a valid frame is allowed to ARM or UN-ARM the rocket.
Over-the-air frame format for the LoRa command link.