CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_Beacon/AP_Beacon_Nooploop.h
Views: 1798
1
#pragma once
2
3
#include "AP_Beacon_Backend.h"
4
5
#if AP_BEACON_NOOPLOOP_ENABLED
6
7
#define NOOPLOOP_MSG_BUF_MAX 256
8
9
class AP_Beacon_Nooploop : public AP_Beacon_Backend
10
{
11
12
public:
13
// constructor
14
using AP_Beacon_Backend::AP_Beacon_Backend;
15
16
// return true if sensor is basically healthy (we are receiving data)
17
bool healthy() override;
18
19
// update the state of the sensor
20
void update() override;
21
22
private:
23
enum class MsgType : uint8_t {
24
INVALID = 0,
25
NODE_FRAME2,
26
SETTING_FRAME0
27
};
28
29
// process one byte received on serial port
30
// message is stored in _msgbuf
31
MsgType parse_byte(uint8_t b);
32
33
// send setting_frame0 to tag. tag will ack setting_frame0 with anchor position filled
34
void request_setting();
35
36
// parse node_frame2 to get tag position and distance
37
void parse_node_frame2();
38
39
// parse setting_frame0 to get anchor position
40
void parse_setting_frame0();
41
42
enum class ParseState : uint8_t {
43
HEADER = 0, // waiting for header
44
H55_FUNCTION_MARK, // waiting for function mark
45
H54_FUNCTION_MARK, // waiting for function mark
46
LEN_L, // waiting for low byte of length
47
LEN_H, // waiting for high byte of length
48
NF2_PAYLOAD, // receiving payload bytes
49
SF0_PAYLOAD, // receiving payload bytes
50
} _state = ParseState::HEADER;
51
52
// members
53
uint8_t _msgbuf[NOOPLOOP_MSG_BUF_MAX]; // buffer to hold most recent message from tag
54
uint16_t _msg_len; // number of bytes received from the current message (may be larger than size of _msgbuf)
55
uint16_t _frame_len; // message supplied frame length
56
uint8_t _crc_expected; // calculated crc which is compared against actual received crc
57
uint32_t _last_update_ms; // last time we receive data from tag
58
bool _anchor_pos_avail; // flag indicates if we got anchor position or not
59
uint32_t _last_request_setting_ms; // last time we sent request_setting0 packet to tag
60
};
61
62
#endif // AP_BEACON_NOOPLOOP_ENABLED
63
64