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_ADSB/AP_ADSB_Sagetech.h
Views: 1798
1
#pragma once
2
3
/*
4
This program is free software: you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation, either version 3 of the License, or
7
(at your option) any later version.
8
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
13
14
You should have received a copy of the GNU General Public License
15
along with this program. If not, see <http://www.gnu.org/licenses/>.
16
*/
17
18
#include "AP_ADSB_Backend.h"
19
20
#if HAL_ADSB_SAGETECH_ENABLED
21
class AP_ADSB_Sagetech : public AP_ADSB_Backend {
22
public:
23
using AP_ADSB_Backend::AP_ADSB_Backend;
24
25
// init - performs any required initialisation for this instance
26
bool init() override;
27
28
// update - should be called periodically
29
void update() override;
30
31
// static detection function
32
static bool detect();
33
34
private:
35
36
static const uint32_t PAYLOAD_XP_MAX_SIZE = 52;
37
38
enum class SystemStateBits {
39
Error_Transponder = (1U<<0),
40
Altitidue_Source = (1U<<1),
41
Error_GPS = (1U<<2),
42
Error_ICAO = (1U<<3),
43
Error_Over_Temperature = (1U<<4),
44
Error_Extended_Squitter = (1U<<5),
45
Mode_Transponder = (3U<<6), // 2 bit status:
46
};
47
48
enum class Transponder_Type {
49
Mode_C = 0x00,
50
Mode_S_ADSB_OUT = 0x01,
51
Mode_S_ADSB_OUT_and_IN = 0x02,
52
Unknown = 0xFF,
53
};
54
55
enum class MsgType_XP {
56
INVALID = 0,
57
Installation_Set = 0x01,
58
Preflight_Set = 0x02,
59
Operating_Set = 0x03,
60
GPS_Set = 0x04,
61
Request = 0x05,
62
63
ACK = 0x80,
64
Installation_Response = 0x81,
65
Preflight_Response = 0x82,
66
Status_Response = 0x83,
67
ADSB_StateVector_Report = 0x91,
68
ADSB_ModeStatus_Report = 0x92,
69
TISB_StateVector_Report = 0x93,
70
TISB_ModeStatus_Report = 0x94,
71
TISB_CorasePos_Report = 0x95,
72
TISB_ADSB_Mgr_Report = 0x96,
73
};
74
75
enum class ParseState {
76
WaitingFor_Start,
77
WaitingFor_AssmAddr,
78
WaitingFor_MsgType,
79
WaitingFor_MsgId,
80
WaitingFor_PayloadLen,
81
WaitingFor_PayloadContents,
82
WaitingFor_ChecksumFletcher,
83
WaitingFor_Checksum,
84
WaitingFor_End,
85
};
86
87
struct Packet_XP {
88
const uint8_t start = 0xA5;
89
const uint8_t assemAddr = 0x01;
90
MsgType_XP type;
91
uint8_t id;
92
uint8_t payload_length;
93
uint8_t payload[PAYLOAD_XP_MAX_SIZE];
94
uint8_t checksumFletcher;
95
uint8_t checksum;
96
const uint8_t end = 0x5A;
97
};
98
99
struct {
100
ParseState state;
101
uint8_t index;
102
Packet_XP packet;
103
} message_in;
104
105
// compute Sum and FletcherSum values
106
uint16_t checksum_generate_XP(Packet_XP &msg) const;
107
bool checksum_verify_XP(Packet_XP &msg) const;
108
void checksum_assign_XP(Packet_XP &msg);
109
110
111
// handling inbound byte and process it in the state machine
112
bool parse_byte_XP(const uint8_t data);
113
114
// handle inbound packet
115
void handle_packet_XP(const Packet_XP &msg);
116
117
// send message to serial port
118
void send_msg(Packet_XP &msg);
119
120
// handle inbound msgs
121
void handle_adsb_in_msg(const Packet_XP &msg);
122
void handle_ack(const Packet_XP &msg);
123
124
// send messages to transceiver
125
void send_msg_Installation();
126
void send_msg_PreFlight();
127
void send_msg_Operating();
128
void send_msg_GPS();
129
130
// send packet by type
131
void send_packet(const MsgType_XP type);
132
133
// send msg to request a packet by type
134
void request_packet(const MsgType_XP type);
135
136
// timers for each out-bound packet
137
uint32_t last_packet_initialize_ms;
138
uint32_t last_packet_PreFlight_ms;
139
uint32_t last_packet_GPS_ms;
140
uint32_t last_packet_Operating_ms;
141
142
// cached variables to compare against params so we can send msg on param change.
143
uint16_t last_operating_squawk;
144
int32_t last_operating_alt;
145
uint8_t last_operating_rf_select;
146
147
// track status changes in acks
148
uint8_t last_ack_transponder_mode;
149
Transponder_Type transponder_type = Transponder_Type::Unknown;
150
};
151
#endif // HAL_ADSB_SAGETECH_ENABLED
152
153
154