Skip to content

Commit c085669

Browse files
committed
ADSB support for inav over mavlink
1 parent b6fb884 commit c085669

16 files changed

+565
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ make/local.mk
3535
launch.json
3636
.vscode/tasks.json
3737
.vscode/c_cpp_properties.json
38+
/cmake-build-debug/

docs/Settings.md

+30
Original file line numberDiff line numberDiff line change
@@ -3982,6 +3982,36 @@ _// TODO_
39823982

39833983
---
39843984

3985+
### osd_adsb_distance_alert
3986+
3987+
Distance inside which ADSB data flashes for proximity warning
3988+
3989+
| Default | Min | Max |
3990+
| --- | --- | --- |
3991+
| 3000 | 1 | 64000 |
3992+
3993+
---
3994+
3995+
### osd_adsb_distance_warning
3996+
3997+
Distance in meters of ADSB aircraft that is displayed
3998+
3999+
| Default | Min | Max |
4000+
| --- | --- | --- |
4001+
| 20000 | 1 | 64000 |
4002+
4003+
---
4004+
4005+
### osd_adsb_ignore_plane_above_me_limit
4006+
4007+
Ignore adsb planes above, limit, 0 disabled (meters)
4008+
4009+
| Default | Min | Max |
4010+
| --- | --- | --- |
4011+
| 0 | 0 | 64000 |
4012+
4013+
---
4014+
39854015
### osd_ahi_bordered
39864016

39874017
Shows a border/corners around the AHI region (pixel OSD only)

src/main/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ main_sources(COMMON_SRC
344344
flight/ez_tune.c
345345
flight/ez_tune.h
346346

347+
io/adsb.c
347348
io/beeper.c
348349
io/beeper.h
349350
io/servo_sbus.c

src/main/drivers/osd_symbols.h

+2
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@
180180
#define SYM_CROSS_TRACK_ERROR 0xFC // 252 Cross track error
181181

182182

183+
#define SYM_ADSB 0xFD // 253 ADSB
184+
183185
#define SYM_LOGO_START 0x101 // 257 to 297, INAV logo
184186
#define SYM_LOGO_WIDTH 10
185187
#define SYM_LOGO_HEIGHT 4

src/main/fc/cli.c

+42
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ bool cliMode = false;
8585
#include "flight/pid.h"
8686
#include "flight/servos.h"
8787

88+
#include "io/adsb.h"
8889
#include "io/asyncfatfs/asyncfatfs.h"
8990
#include "io/beeper.h"
9091
#include "io/flashfs.h"
@@ -2690,6 +2691,44 @@ static void cliFeature(char *cmdline)
26902691
}
26912692
}
26922693

2694+
#ifdef USE_ADSB
2695+
static void cliAdsbVehicles(char *cmdLine)
2696+
{
2697+
UNUSED(cmdLine);
2698+
2699+
adsbVehicle_t* adsbVehicle;
2700+
adsbVehicle_t* adsbTheClosestVehicle = findVehicleClosest();
2701+
cliPrintf("%-10s%-10s%-10s%-10s%-10s%-16s%-16s%-10s%-14s%-10s%-20s\n", "#", "callsign", "icao", "lat", "lon", " alt (m)", " dist (km)", "dir", "vert dist (m)", "tslc", "ttl", "note");
2702+
2703+
for(uint8_t i = 0; i < MAX_ADSB_VEHICLES; i++){
2704+
adsbVehicle = findVehicle(i);
2705+
if(adsbVehicle != NULL && adsbVehicle->ttl > 0){
2706+
2707+
cliPrintf("%-10d%-10s%-10d%-10u%-10d%-16f%-16f%-10d%-14f%-10d%-10d%-20s \n",
2708+
i,
2709+
adsbVehicle->vehicleValues.callsign,
2710+
adsbVehicle->vehicleValues.icao,
2711+
adsbVehicle->vehicleValues.lat,
2712+
adsbVehicle->vehicleValues.lon,
2713+
(double)CENTIMETERS_TO_METERS(adsbVehicle->vehicleValues.alt),
2714+
(double)CENTIMETERS_TO_METERS(adsbVehicle->calculatedVehicleValues.dist) / 1000,
2715+
adsbVehicle->calculatedVehicleValues.dir,
2716+
(double)CENTIMETERS_TO_METERS(adsbVehicle->calculatedVehicleValues.verticalDistance),
2717+
adsbVehicle->vehicleValues.tslc,
2718+
adsbVehicle->ttl,
2719+
adsbTheClosestVehicle != NULL && adsbTheClosestVehicle->vehicleValues.icao == adsbVehicle->vehicleValues.icao ? "the closest": ""
2720+
);
2721+
}
2722+
}
2723+
2724+
cliPrintf("Messages count from device: %d\n", getAdsbStatus()->vehiclesMessagesTotal);
2725+
2726+
if(!enviromentOkForCalculatingDistaceBearing()){
2727+
cliPrintErrorLine("No GPS FIX, can't calculate distance and direction");
2728+
}
2729+
}
2730+
#endif
2731+
26932732
#ifdef USE_BLACKBOX
26942733
static void printBlackbox(uint8_t dumpMask, const blackboxConfig_t *config, const blackboxConfig_t *configDefault)
26952734
{
@@ -3997,6 +4036,9 @@ const clicmd_t cmdTable[] = {
39974036
#if defined(USE_BOOTLOG)
39984037
CLI_COMMAND_DEF("bootlog", "show boot events", NULL, cliBootlog),
39994038
#endif
4039+
#if defined(USE_ADSB)
4040+
CLI_COMMAND_DEF("adsb_vehicles", "the closest vehicle", NULL, cliAdsbVehicles),
4041+
#endif
40004042
#ifdef USE_LED_STRIP
40014043
CLI_COMMAND_DEF("color", "configure colors", NULL, cliColor),
40024044
CLI_COMMAND_DEF("mode_color", "configure mode and special colors", NULL, cliModeColor),

src/main/fc/fc_msp.c

+35
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
#include "config/config_eeprom.h"
8484
#include "config/feature.h"
8585

86+
#include "io/adsb.h"
8687
#include "io/asyncfatfs/asyncfatfs.h"
8788
#include "io/flashfs.h"
8889
#include "io/gps.h"
@@ -928,6 +929,33 @@ static bool mspFcProcessOutCommand(uint16_t cmdMSP, sbuf_t *dst, mspPostProcessF
928929
sbufWriteU16(dst, gpsSol.epv);
929930
break;
930931
#endif
932+
case MSP2_ADSB_VEHICLE_LIST:
933+
#ifdef USE_ADSB
934+
sbufWriteU8(dst, MAX_ADSB_VEHICLES);
935+
sbufWriteU8(dst, ADSB_CALL_SIGN_MAX_LENGTH);
936+
937+
for(uint8_t i = 0; i < MAX_ADSB_VEHICLES; i++){
938+
939+
adsbVehicle_t *adsbVehicle = findVehicle(i);
940+
941+
for(uint8_t ii = 0; ii < ADSB_CALL_SIGN_MAX_LENGTH; ii++){
942+
sbufWriteU8(dst, adsbVehicle->vehicleValues.callsign[ii]);
943+
}
944+
945+
sbufWriteU32(dst, adsbVehicle->vehicleValues.icao);
946+
sbufWriteU32(dst, adsbVehicle->vehicleValues.lat);
947+
sbufWriteU32(dst, adsbVehicle->vehicleValues.lon);
948+
sbufWriteU32(dst, adsbVehicle->vehicleValues.alt);
949+
sbufWriteU16(dst, (uint16_t)CENTIDEGREES_TO_DEGREES(adsbVehicle->vehicleValues.heading));
950+
sbufWriteU8(dst, adsbVehicle->vehicleValues.tslc);
951+
sbufWriteU8(dst, adsbVehicle->vehicleValues.emitterType);
952+
sbufWriteU8(dst, adsbVehicle->ttl);
953+
}
954+
#else
955+
sbufWriteU8(dst, 0);
956+
sbufWriteU8(dst, 0);
957+
#endif
958+
break;
931959
case MSP_DEBUG:
932960
// output some useful QA statistics
933961
// debug[x] = ((hse_value / 1000000) * 1000) + (SystemCoreClock / 1000000); // XX0YY [crystal clock : core clock]
@@ -1498,6 +1526,13 @@ static bool mspFcProcessOutCommand(uint16_t cmdMSP, sbuf_t *dst, mspPostProcessF
14981526
#else
14991527
sbufWriteU16(dst, 0);
15001528
sbufWriteU16(dst, 0);
1529+
#endif
1530+
#ifdef USE_ADSB
1531+
sbufWriteU16(dst, osdConfig()->adsb_distance_warning);
1532+
sbufWriteU16(dst, osdConfig()->adsb_distance_alert);
1533+
#else
1534+
sbufWriteU16(dst, 0);
1535+
sbufWriteU16(dst, 0);
15011536
#endif
15021537
break;
15031538

src/main/fc/fc_tasks.c

+21
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
#include "io/osd_dji_hd.h"
6969
#include "io/displayport_msp_osd.h"
7070
#include "io/servo_sbus.h"
71+
#include "io/adsb.h"
7172

7273
#include "msp/msp_serial.h"
7374

@@ -180,6 +181,14 @@ void taskUpdateCompass(timeUs_t currentTimeUs)
180181
}
181182
#endif
182183

184+
#ifdef USE_ADSB
185+
void taskAdsb(timeUs_t currentTimeUs)
186+
{
187+
UNUSED(currentTimeUs);
188+
adsbTtlClean(currentTimeUs);
189+
}
190+
#endif
191+
183192
#ifdef USE_BARO
184193
void taskUpdateBaro(timeUs_t currentTimeUs)
185194
{
@@ -359,6 +368,9 @@ void fcTasksInit(void)
359368
#ifdef USE_PITOT
360369
setTaskEnabled(TASK_PITOT, sensors(SENSOR_PITOT));
361370
#endif
371+
#ifdef USE_ADSB
372+
setTaskEnabled(TASK_ADSB, true);
373+
#endif
362374
#ifdef USE_RANGEFINDER
363375
setTaskEnabled(TASK_RANGEFINDER, sensors(SENSOR_RANGEFINDER));
364376
#endif
@@ -490,6 +502,15 @@ cfTask_t cfTasks[TASK_COUNT] = {
490502
},
491503
#endif
492504

505+
#ifdef USE_ADSB
506+
[TASK_ADSB] = {
507+
.taskName = "ADSB",
508+
.taskFunc = taskAdsb,
509+
.desiredPeriod = TASK_PERIOD_HZ(1), // ADSB is updated at 1 Hz
510+
.staticPriority = TASK_PRIORITY_IDLE,
511+
},
512+
#endif
513+
493514
#ifdef USE_BARO
494515
[TASK_BARO] = {
495516
.taskName = "BARO",

src/main/fc/settings.yaml

+25
Original file line numberDiff line numberDiff line change
@@ -3418,6 +3418,31 @@ groups:
34183418
max: 11
34193419
default_value: 9
34203420

3421+
- name: osd_adsb_distance_warning
3422+
description: "Distance in meters of ADSB aircraft that is displayed"
3423+
default_value: 20000
3424+
condition: USE_ADSB
3425+
field: adsb_distance_warning
3426+
min: 1
3427+
max: 64000
3428+
type: uint16_t
3429+
- name: osd_adsb_distance_alert
3430+
description: "Distance inside which ADSB data flashes for proximity warning"
3431+
default_value: 3000
3432+
condition: USE_ADSB
3433+
field: adsb_distance_alert
3434+
min: 1
3435+
max: 64000
3436+
type: uint16_t
3437+
- name: osd_adsb_ignore_plane_above_me_limit
3438+
description: "Ignore adsb planes above, limit, 0 disabled (meters)"
3439+
default_value: 0
3440+
condition: USE_ADSB
3441+
field: adsb_ignore_plane_above_me_limit
3442+
min: 0
3443+
max: 64000
3444+
type: uint16_t
3445+
34213446
- name: osd_estimations_wind_compensation
34223447
description: "Use wind estimation for remaining flight time/distance estimation"
34233448
default_value: ON

0 commit comments

Comments
 (0)