-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdsbWrapper.h
365 lines (287 loc) · 9.27 KB
/
AdsbWrapper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
//
// AdsbWrapper.h: ADSB decoding
//
// Copyright (c) 2019 Bruce Clay
// Portions of thei code was adapted from dump1090 and dump978
// Copyright (c) 2017 Oliver Jowett <[email protected]>
// This file is free software: you may copy, redistribute and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation, either version 2 of the License, or (at your
// option) any later version.
//
// This file is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
#ifndef _ADSB_WRAPPER_H_
#define _ADSB_WRAPPER_H_
#include <qlist.h>
#include <map>
#define GDL90_FLAGBYTE 0x7E
#define GDL90_ESCAPEBYTE 0x7D
#define GDL90_ID_HEARTBEAT 0x00
#define GDL90_ID_HEARTBEAT_SIZE 0x09
#define GDL90_ID_INIT 0x02
#define GDL90_ID_INIT_SIZE 0x03
#define GDL90_ID_UPLINK_DATA 0x07
#define GDL90_ID_UPLINK_DATA_SIZE 0x01B6 /* 438 bytes */
#define GDL90_ID_HEIGHT_AGL 0x09
#define GDL90_ID_OWNSHIP 0x0A // decimal 10
#define GDL90_ID_OWNSHIP_SIZE 0x1E /* 30 bytes */ // spec states 28 bytes
#define GDL90_ID_OWNSHIP_ALTITUDE 0x0B // decimal 11
#define GDL90_ID_BASIC_REPORT 0x1E // Basic UAT report
#define GDL90_ID_LONG_REPORT 0x1F // Long report
#define GDL90_ID_TRAFFIC 0x14 // decimal 20
#define GDL90_ID_TRAFFIC_SIZE 0x1E /* 30 bytes */ // spec states 28 bytes
#define GDL90_ID_BASIC_REPORT 0x1E
#define GDL90_ID_LONG_REPORT 0x1F
#define GDL90_ID_STRATUX_HEARTBEAT0 0xCC
#define GDL90_ID_STRATUX_HEARTBEAT1 0x5358
#define GDL90_ID_STRATUX_AHRS 0x4C
#define GDL90_ID_STRATUX_AHRS_SIZE 0x1A /* 26 bytes */
#define GDL90_ID_GPS_TIME 0x65 // 101 decimal
#define FOREFRONT_AHRS 0x65 // 101 decimal
class AdsbWrapper
{
#define GDL90_LAT_LONG_RES (180.0f / 8388608.0f)
/*
message types
heartbeat
initialization
uplink data
ownship report
traffic report
pass through report
height above terrain
ownship geometric altitude
*/
enum emergencyOrPriorityCodeKinds
{
noEmergency,
generalEmergency,
medicalEmergency,
minimumFuel,
noCommunication,
unlawfulInterference,
downedAircraft
};
enum addressKinds
{
adsbWithIcaoAddress,
adsbWithSelfAssignedAddress,
tisbWithIcaoAddress,
tisbWithTrackFileId,
surfaceVehicle,
groundStationBeacon
};
struct statusBitsRec1
{
unsigned uatInitialized : 1;
unsigned reserved : 1;
unsigned statRatcs : 1;
unsigned statGpsBattLow : 1;
unsigned stataddrType : 1;
unsigned statIdent : 1;
unsigned statMaintReqd : 1;
unsigned statGpsPosValid : 1;
};
enum emitterCategoryKinds
{
noAircraftTypeInformation = 0,
// ICAO < 15,500 lbs
light = 1,
// [15000 lbs, 75000 lbs]
small = 2,
// [75000 lbs, 300000 lbs]
large = 3,
// Aircraft such as a B757
highVortexLarge = 4,
// > 300,000 lbs
heavy = 5,
// > 5g acceleration and high speed
highlyManeuverable = 6,
rotorcraft = 7,
gliderOrSailplane = 9,
lighterThanAir = 10,
parachutistOrSkyDiver = 11,
ultraLightOrHangGliderOrParaGlider = 12,
uav = 14,
space = 15,
surfaceEmergencyVehicle = 17,
surfaceServiceVehicle = 18,
pointObstacle = 19,
clusterObstacle = 20,
lineObstacle = 21
};
enum trafficAlertStatusKind
{
noAlert,
trafficAlert
};
union statusByteRec1
{
struct statusBitsRec1 bits;
unsigned char statusByte;
};
struct statusBitsRec2
{
unsigned utcOk : 1;
unsigned reserved4 : 1;
unsigned reserved3 : 1;
unsigned reserved2 : 1;
unsigned reserved1 : 1;
unsigned csaNotAvail : 1;
unsigned csaRequested : 1;
unsigned timestamp : 1;
};
union statusByteRec2
{
struct statusBitsRec2 bits;
unsigned char statusByte;
};
struct heartbeatMsgRec
{
unsigned char msgId;
statusByteRec1 statusByte1;
statusByteRec2 statusByte2;
unsigned int timestamp;
unsigned short msgCounts;
unsigned short crc;
};
struct trafficReportNumRec
{
unsigned char alertStatus;
unsigned char addressType;
unsigned int participantAddr;
double latitude;
double longitude;
int altitude;
unsigned char miscIndicators;
unsigned char integrityCode;
unsigned char accuracyCode;
int horzVelocity;
int vertVelocity;
float trackHeading;
unsigned char emitterCategory; // what size
std::string callsign;
unsigned char emergencyPriorityCode; // what size
unsigned char crc[2];
int address;
std::string nNumber;
std::string name;
int typeAircraft;
int typeEngine;
float range;
float bearing;
time_t lastUpdate;
};
struct ahrsMsgRec
{
unsigned char msgId;
unsigned char subMsgId;
unsigned char roll[2];
unsigned char pitch[2];
unsigned char heading[2];
unsigned char indicatedAirspeed[2];
unsigned char trueAirspeed[2];
};
struct ahrsDataRec
{
unsigned char msgId;
unsigned char subMsgId;
float roll;
float pitch;
float heading;
bool headingIsTrue;
unsigned short indicatedAirspeed;
unsigned short trueAirspeed;
};
struct stratuxStatusMsgRec
{
unsigned char msgVersion;
unsigned char versionBuf[4];
unsigned int hardwareRevCode;
unsigned short validAndEnableFlags;
unsigned short connectHardwareFlags;
unsigned char numSatsLocked;
unsigned char numSatsConnected;
unsigned short num978Targets;
unsigned short num1090Targets;
unsigned short num978MsgRate;
unsigned short num1090MsgRate;
float cpuTemp;
unsigned char numAdsbTowers;
};
public:
AdsbWrapper();
void CrcInit(void);
unsigned int CrcCompute(unsigned char *block, unsigned int length);
unsigned int CalculateCrc(unsigned char *msgBuf, int msgSize);
void ClearAhrsData(struct ahrsDataRec &data);
void ClearAircraftData(struct trafficReportNumRec &srcData);
void ClearHeartbeatInfo(struct heartbeatMsgRec &msg);
void ClearTrafficDataList();
void CopyAircraftData(struct trafficReportNumRec &srcData, struct trafficReportNumRec&tgtData);
unsigned int GetUint32(unsigned char *dataBuf);
unsigned int GetUint24(unsigned char *dataBuf);
unsigned short GetUint16(unsigned char *dataBuf);
int DecodeMessage(unsigned int msgSize, char *msgBuf, bool filterData = true);
int GetGeodeticLocation(unsigned char *dataBuf, double &location);
int DecodeTrafficMessage(unsigned int msgSize, unsigned char *msgBuf, struct trafficReportNumRec &trafficData);
int DecodeAirPositionReport(unsigned char *msgBuf);
int DecodeCallsign(unsigned char *msgBuf,
unsigned char &emitterCategory, std::string &callsign);
int DecodePayloadHeader(unsigned char *msgBuf);
int DecodeStateVector(unsigned char *msgBuf);
int DecodeModeStatus(unsigned char *msgBuf);
int DecodeCapabilityCodes(unsigned char *msgBuf);
int DecodeAuxiliaryStateVector(unsigned char *msgBuf);
int DecodeTargetState(unsigned char *msgBuf);
int DecodeTrajectoryChange(unsigned char *msgBuf);
int GetLastMsgType();
void GetLastCallsign(std::string &callsign);
int GetNumTrafficReports();
int GetLocation(std:: string callsign,
double &latitude, double &longitude, double &altitude);
int GetHeading(std::string callsign, float &heading);
int GetHorzVelocity(std::string callsign, float &velocity);
int GetVertVelocity(std::string callsign, float &velocity);
int GetAircraftOwnerInfo(std::string callsign, unsigned int &address,
std::string &nNumber, std::string &name, int &typeAircraft, int &typeEngine);
int SetAircraftOwnerInfo(std::string callsign, unsigned int address,
std::string nNumber, std::string name, int typeAircraft, int typeEngine);
int GetLastUpdate(std::string callsign, unsigned int &updateTime);
int GetParticipantAddress(std::string callsign, unsigned char &addrType,
unsigned int &address);
int GetLastDataIndex();
unsigned int GetLatestTimestamp();
void GetSatelliteCnt(int &numConnected, int &numLocked);
void GetTargetCnt(int &num978Targets, int &num1090Targets);
void GetTowerCnt(int &numTowers);
void GetOwnshipCallsign(std::string &callsign);
int ParseApplicationData(int appDataLen, unsigned char *appData);
int SerializeTrafficData(unsigned int dataIndex, char delimiter,
std::string &serializedData);
int SerializeTrafficData(struct trafficReportNumRec *dataPtr,
char delimiter, std::string &serializedData);
int SetRangeValues(std::string callsign, float range, float bearing);
int GetRangeValues(std::string callsign, float &range, float &bearing);
protected:
struct trafficReportNumRec *GetAircraftInfo(std::string callsign, unsigned int &dataIndex);
struct trafficReportNumRec *GetTrafficInfo(std::string callsign, unsigned int &dataIndex);
private:
struct heartbeatMsgRec mLatetestHeartbeat;
struct heartbeatMsgRec mTestHeartbeat;
struct ahrsDataRec mAhrsData;
struct ahrsDataRec mStatuxAhrsData;
struct trafficReportNumRec mOwnshipData;
QList<struct trafficReportNumRec *> mAircraftInfoList;
struct stratuxStatusMsgRec mStratuxStatusMessage;
int mLastMsgType;
std::string mLastCallsign;
unsigned short mCrc16Table[256];
int mLastDataIndex;
std::string mOwnshipCallsign;
};
#endif // _ADSB_WRAPPER_H_