-
Notifications
You must be signed in to change notification settings - Fork 1
/
uat2json-wrapper.cpp
122 lines (114 loc) · 4.08 KB
/
uat2json-wrapper.cpp
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
extern "C"
{
// NOLINTBEGIN(readability-magic-numbers)
#include "dump978/uat.h"
#include "dump978/uat_decode.h"
void dump_raw_message(char updown, uint8_t* data, int len, int rsErrors); // NOLINT
}
#include "UAT978.h"
#include <algorithm>
#include <iostream>
void dump_raw_message(char /*updown*/, uint8_t* data, int /*len*/, int /*rs_errors*/) // NOLINT
{
struct uat_adsb_mdb mdb{};
uat_decode_adsb_mdb(data, &mdb);
auto* handler = *GetThreadLocalUAT978Handler();
auto& aircraft = handler->_trafficManager->FindOrCreate(mdb.address);
auto sourceId = handler->_sourceId;
if (mdb.has_ms)
{
/*
*
fprintf(to,
"MS:\n"
" Emitter category: %s\n"
" Callsign: %s%s\n"
" Emergency status: %s\n"
" UAT version: %u\n"
" SIL: %u\n"
" Transmit MSO: %u\n"
" NACp: %u\n"
" NACv: %u\n"
" NICbaro: %u\n"
" Capabilities: %s%s\n"
" Active modes: %s%s%s\n"
" Target track type: %s\n",
emitter_category_names[mdb->emitter_category],
mdb->callsign_type == CS_SQUAWK ? "squawk " : "",
mdb->callsign_type == CS_INVALID ? "unavailable" : mdb->callsign,
emergency_status_names[mdb->emergency_status],
mdb->uat_version,
mdb->sil,
mdb->transmit_mso,
mdb->nac_p,
mdb->nac_v,
mdb->nic_baro,
mdb->has_cdti ? "CDTI " : "", mdb->has_acas ? "ACAS " : "",
mdb->acas_ra_active ? "ACASRA " : "", mdb->ident_active ? "IDENT " : "", mdb->atc_services ? "ATC " : "",
mdb->heading_type == HT_MAGNETIC ? "magnetic heading" : "true heading");
*/
if (mdb.callsign_type == CS_CALLSIGN) { std::ranges::copy(mdb.callsign, std::begin(aircraft.callsign)); }
if (mdb.callsign_type == CS_SQUAWK)
{
// std::cerr << "Squawk:" << aircraft.callsign << std::endl;
// std::copy(std::begin(mdb.callsign), std::end(mdb.callsign), std::begin(aircraft.callsign));
}
}
if (mdb.has_sv)
{
if (mdb.position_valid)
{
aircraft.lat1E7 = static_cast<int32_t>(mdb.lat * 10000000);
aircraft.lon1E7 = static_cast<int32_t>(mdb.lon * 10000000);
}
if (mdb.speed_valid) { aircraft.speed = mdb.speed; }
// if (mdb->ns_vel_valid) fprintf(to, " N/S velocity: %d kt\n", mdb->ns_vel);
// if (mdb->ew_vel_valid) fprintf(to, " E/W velocity: %d kt\n", mdb->ew_vel);
switch (mdb.altitude_type)
{
case ALT_BARO: [[fallthrough]];
case ALT_GEO: aircraft.altitude = mdb.altitude; break;
case ALT_INVALID:
default: break;
}
switch (mdb.track_type)
{
case TT_TRACK: [[fallthrough]];
case TT_MAG_HEADING: [[fallthrough]];
case TT_TRUE_HEADING: aircraft.track = mdb.track; break;
case TT_INVALID:
default: break;
}
switch (mdb.vert_rate_source)
{
case ALT_BARO: [[fallthrough]];
case ALT_GEO: aircraft.vert_rate = mdb.vert_rate; break;
case ALT_INVALID:
default: break;
}
/*
if (mdb->dimensions_valid)
fprintf(to,
" Dimensions: %.1fm L x %.1fm W%s\n",
mdb->length,
mdb->width,
mdb->position_offset ? " (position offset applied)" : "");
fprintf(to, " UTC coupling: %s\nTIS-B site ID: %u\n", mdb->utc_coupled ? "yes" : "no", mdb->tisb_site_id);
*/
}
if (mdb.has_auxsv)
{
#if defined TODO_ALTITUDE_TYPE
switch (mdb.sec_altitude_type)
{
case ALT_BARO: /*mdb.sec_altitude;*/ break;
case ALT_GEO: /*mdb.sec_altitude;*/ break;
case ALT_INVALID:
default: break;
}
#endif
}
aircraft.sourceId = 2u;
handler->_trafficManager->NotifyChanged(aircraft);
}
// NOLINTEND(readability-magic-numbers)