Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Adsb support for inav #1846

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3590,6 +3590,12 @@
"osdAlarmGFORCE_AXIS_MAX_HELP": {
"message": "The axes g force elements will start blinking when greater than this value"
},
"osdAlarmADSB_MAX_DISTANCE_WARNING": {
"message": "Distance in meters of ADSB aircraft that is displayed"
},
"osdAlarmADSB_MAX_DISTANCE_ALERT": {
"message": "Distance inside which ADSB data flashes for proximity warning"
},
"osd_current_alarm": {
"message": "Current (A)"
},
Expand Down Expand Up @@ -3629,6 +3635,12 @@
"osd_rssi_dbm_alarm": {
"message": "CRSF RSSI dBm Alarm"
},
"osd_adsb_distance_warning": {
"message": "ADSB distance warning"
},
"osd_adsb_distance_alert": {
"message": "ADSB distance alert"
},
"osd_rssi_dbm_alarm_HELP": {
"message": "RSSI indicator blinks below this value. Range: [-130,0]. Zero disables this alarm."
},
Expand Down
7 changes: 7 additions & 0 deletions js/fc.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var CONFIG,
MOTOR_DATA,
SERVO_DATA,
GPS_DATA,
ADSB_VEHICLES,
MISSION_PLANNER,
ANALOG,
ARMING_CONFIG,
Expand Down Expand Up @@ -251,6 +252,12 @@ var FC = {
packetCount: 0
};

ADSB_VEHICLES = {
vehiclesCount: 0,
callsignLength: 0,
vehicles: []
};

MISSION_PLANNER = new WaypointCollection();

ANALOG = {
Expand Down
4 changes: 3 additions & 1 deletion js/msp/MSPCodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,5 +245,7 @@ var MSPCodes = {
MSP2_INAV_EZ_TUNE: 0x2070,
MSP2_INAV_EZ_TUNE_SET: 0x2071,

MSP2_INAV_SELECT_MIXER_PROFILE: 0x2080
MSP2_INAV_SELECT_MIXER_PROFILE: 0x2080,

MSP2_ADSB_VEHICLE_LIST: 0x2090,
};
29 changes: 29 additions & 0 deletions js/msp/MSPHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,35 @@ var mspHelper = (function (gui) {
GPS_DATA.eph = data.getUint16(16, true);
GPS_DATA.epv = data.getUint16(18, true);
break;
case MSPCodes.MSP2_ADSB_VEHICLE_LIST:
var byteOffsetCounter = 0;
ADSB_VEHICLES.vehicles = [];
ADSB_VEHICLES.vehiclesCount = data.getUint8(byteOffsetCounter++);
ADSB_VEHICLES.callsignLength = data.getUint8(byteOffsetCounter++);

for(i = 0; i < ADSB_VEHICLES.vehiclesCount; i++){

var vehicle = {callSignByteArray: [], callsign: "", icao: 0, lat: 0, lon: 0, alt: 0, heading: 0, ttl: 0, tslc: 0, emitterType: 0};

for(ii = 0; ii < ADSB_VEHICLES.callsignLength; ii++){
vehicle.callSignByteArray.push(data.getUint8(byteOffsetCounter++));
}

vehicle.callsign = (String.fromCharCode(...vehicle.callSignByteArray)).replace(/[^\x20-\x7E]/g, '');
vehicle.icao = data.getUint32(byteOffsetCounter, true); byteOffsetCounter += 4;
vehicle.lat = data.getInt32(byteOffsetCounter, true); byteOffsetCounter += 4;
vehicle.lon = data.getInt32(byteOffsetCounter, true); byteOffsetCounter += 4;
vehicle.altCM = data.getInt32(byteOffsetCounter, true); byteOffsetCounter += 4;
vehicle.headingDegrees = data.getUint16(byteOffsetCounter, true); byteOffsetCounter += 2;
vehicle.tslc = data.getUint8(byteOffsetCounter++);
vehicle.emitterType = data.getUint8(byteOffsetCounter++);
vehicle.ttl = data.getUint8(byteOffsetCounter++);

ADSB_VEHICLES.vehicles.push(vehicle);
}

break;

case MSPCodes.MSP_ATTITUDE:
SENSOR_DATA.kinematics[0] = data.getInt16(0, true) / 10.0; // x
SENSOR_DATA.kinematics[1] = data.getInt16(2, true) / 10.0; // y
Expand Down
Binary file added resources/adsb/adsb_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/adsb/adsb_10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/adsb/adsb_11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/adsb/adsb_12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/adsb/adsb_13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/adsb/adsb_14.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/adsb/adsb_15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/adsb/adsb_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/adsb/adsb_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/adsb/adsb_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/adsb/adsb_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/adsb/adsb_6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/adsb/adsb_7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/adsb/adsb_8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/adsb/adsb_9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
123 changes: 123 additions & 0 deletions tabs/gps.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,32 @@ TABS.gps.initialize = function (callback) {
googleAnalytics.sendAppView('GPS');
}

// mavlink ADSB_EMITTER_TYPE
const ADSB_VEHICLE_TYPE = {
0: 'adsb_14.png', // ADSB_EMITTER_TYPE_NO_INFO
1: 'adsb_1.png', // ADSB_EMITTER_TYPE_LIGHT
2: 'adsb_1.png', // ADSB_EMITTER_TYPE_SMALL
3: 'adsb_2.png', // ADSB_EMITTER_TYPE_LARGE
4: 'adsb_14.png', // ADSB_EMITTER_TYPE_HIGH_VORTEX_LARGE
5: 'adsb_5.png', // ADSB_EMITTER_TYPE_HEAVY
6: 'adsb_14.png', // ADSB_EMITTER_TYPE_HIGHLY_MANUV
7: 'adsb_13.png', // ADSB_EMITTER_TYPE_ROTOCRAFT
8: 'adsb_14.png', // ADSB_EMITTER_TYPE_UNASSIGNED
9: 'adsb_6.png', // ADSB_EMITTER_TYPE_GLIDER
10: 'adsb_7.png', // ADSB_EMITTER_TYPE_LIGHTER_AIR
11: 'adsb_15.png', // ADSB_EMITTER_TYPE_PARACHUTE
12: 'adsb_1.png', // ADSB_EMITTER_TYPE_ULTRA_LIGHT
13: 'adsb_14.png', // ADSB_EMITTER_TYPE_UNASSIGNED2
14: 'adsb_8.png', // ADSB_EMITTER_TYPE_UAV
15: 'adsb_14.png', // ADSB_EMITTER_TYPE_SPACE
16: 'adsb_14.png', // ADSB_EMITTER_TYPE_UNASSGINED3
17: 'adsb_9.png', // ADSB_EMITTER_TYPE_EMERGENCY_SURFACE
18: 'adsb_10.png', // ADSB_EMITTER_TYPE_SERVICE_SURFACE
19: 'adsb_12.png', // ADSB_EMITTER_TYPE_POINT_OBSTACLE
};



var loadChainer = new MSPChainerClass();

var loadChain = [
Expand Down Expand Up @@ -58,6 +84,10 @@ TABS.gps.initialize = function (callback) {
let iconGeometry;
let iconFeature;

let vehicleVectorSource;
let vehiclesCursorInitialized = false;


function process_html() {
localize();

Expand Down Expand Up @@ -131,6 +161,36 @@ TABS.gps.initialize = function (callback) {
view: mapView
});

TABS.gps.toolboxAdsbVehicle = new jBox('Mouse', {
position: {
x: "right",
y: "bottom"
},
offset: {
x: -5,
y: 20,
},
});

mapHandler.on('pointermove', function(evt) {
var feature = mapHandler.forEachFeatureAtPixel(mapHandler.getEventPixel(evt.originalEvent), function(feature, layer) {
return feature;
});

if (feature) {
TABS.gps.toolboxAdsbVehicle.setContent(
`icao: <strong>` + feature.get('name') + `</strong><br />`
+ `lat: <strong>`+ (feature.get('data').lat / 10000000) + `</strong><br />`
+ `lon: <strong>`+ (feature.get('data').lon / 10000000) + `</strong><br />`
+ `ASL: <strong>`+ (feature.get('data').altCM ) / 100 + `m</strong><br />`
+ `heading: <strong>`+ feature.get('data').headingDegrees + `°</strong><br />`
+ `type: <strong>`+ feature.get('data').emitterType + `</strong>`
).open();
}else{
TABS.gps.toolboxAdsbVehicle.close();
}
});

let center = ol.proj.fromLonLat([0, 0]);
mapView.setCenter(center);
mapView.setZoom(2);
Expand Down Expand Up @@ -221,6 +281,66 @@ TABS.gps.initialize = function (callback) {
iconGeometry.setCoordinates(center);

}

if (semver.gte(CONFIG.flightControllerVersion, "7.1.0")) {
MSP.send_message(MSPCodes.MSP2_ADSB_VEHICLE_LIST, false, false, function () {
//ADSB vehicles

if (vehiclesCursorInitialized) {
vehicleVectorSource.clear();
}

for (let key in ADSB_VEHICLES.vehicles) {
let vehicle = ADSB_VEHICLES.vehicles[key];

if (!vehiclesCursorInitialized) {
vehiclesCursorInitialized = true;

vehicleVectorSource = new ol.source.Vector({});

let vehicleLayer = new ol.layer.Vector({
source: vehicleVectorSource
});

mapHandler.addLayer(vehicleLayer);
}

if (vehicle.lat > 0 && vehicle.lon > 0 && vehicle.ttl > 0) {
let vehicleIconStyle = new ol.style.Style({
image: new ol.style.Icon(({
opacity: 1,
rotation: vehicle.headingDegrees * (Math.PI / 180),
scale: 0.8,
anchor: [0.5, 0.5],
src: '../resources/adsb/' + ADSB_VEHICLE_TYPE[vehicle.emitterType],
})),
text: new ol.style.Text(({
text: vehicle.callsign,
textAlign: 'center',
textBaseline: "bottom",
offsetY: +40,
padding: [2, 2, 2, 2],
backgroundFill: '#444444',
fill: new ol.style.Fill({color: '#ffffff'}),
})),
});


let iconGeometry = new ol.geom.Point(ol.proj.fromLonLat([vehicle.lon / 10000000, vehicle.lat / 10000000]));
let iconFeature = new ol.Feature({
geometry: iconGeometry,
name: vehicle.callsign,
type: 'adsb',
data: vehicle,
});

iconFeature.setStyle(vehicleIconStyle);
vehicleVectorSource.addFeature(iconFeature);
}
}
});
}

}

/*
Expand Down Expand Up @@ -271,4 +391,7 @@ TABS.gps.initialize = function (callback) {

TABS.gps.cleanup = function (callback) {
if (callback) callback();
if(TABS.gps.toolboxAdsbVehicle){
TABS.gps.toolboxAdsbVehicle.close();
}
};
10 changes: 10 additions & 0 deletions tabs/osd.html
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,16 @@ <h1 class="tab_title" data-i18n="tabOSD"></h1>
<input id="osd_gforce_axis_alarm_max" data-setting="osd_gforce_axis_alarm_max" data-setting-multiplier="1" type="number" data-step="0.1" />
<span data-i18n="osd_gforce_axis_alarm_max"></span>
</label>
<div for="adsb_distance_warning" class="helpicon cf_tip" data-i18n_title="osdAlarmADSB_MAX_DISTANCE_WARNING"></div>
<label for="adsb_distance_warning">
<input id="adsb_distance_warning" data-setting="osd_adsb_distance_warning" data-unit="m" data-setting-multiplier="1" type="number" data-step="1" />
<span data-i18n="osd_adsb_distance_warning"></span>
</label>
<div for="adsb_distance_alert" class="helpicon cf_tip" data-i18n_title="osdAlarmADSB_MAX_DISTANCE_ALERT"></div>
<label for="adsb_distance_alert">
<input id="adsb_distance_alert" data-setting="osd_adsb_distance_alert" data-unit="m" data-setting-multiplier="1" type="number" data-step="1" />
<span data-i18n="osd_adsb_distance_alert"></span>
</label>
</div>
</div>
<div class="gui_box grey dji-hd-container" id="dji_settings">
Expand Down
37 changes: 37 additions & 0 deletions tabs/osd.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ SYM.FLIGHT_DIST_REMAINING = 0x167;
SYM.GROUND_COURSE = 0xDC;
SYM.ALERT = 0xDD;
SYM.CROSS_TRACK_ERROR = 0xFC;
SYM.ADSB = 0xFD;
SYM.PAN_SERVO_IS_OFFSET_L = 0x1C7;
SYM.ODOMETER = 0X168;
SYM.PILOT_LOGO_SML_L = 0x1D5;
Expand Down Expand Up @@ -480,6 +481,8 @@ OSD.initData = function () {
imu_temp_alarm_max: null,
baro_temp_alarm_min: null,
baro_temp_alarm_max: null,
adsb_distance_warning: null,
adsb_distance_alert: null,
},
layouts: [],
layout_count: 1, // This needs to be 1 for compatibility with < 2.0
Expand Down Expand Up @@ -781,6 +784,24 @@ OSD.constants = {
min: -55,
max: 125
},
{
name: 'ADSB_MAX_DISTANCE_WARNING',
field: 'adsb_distance_warning',
step: 1,
unit: "meters",
min: 1,
max: 64000,
min_version: '7.1.0',
},
{
name: 'ADSB_MAX_DISTANCE_ALERT',
field: 'adsb_distance_alert',
step: 1,
unit: "meters",
min: 1,
max: 64000,
min_version: '7.1.0',
},
],

// All display fields, from every version, do not remove elements, only add!
Expand Down Expand Up @@ -1654,6 +1675,18 @@ OSD.constants = {
min_version: '6.0.0',
preview: FONT.symbol(SYM.GROUND_COURSE) + '245' + FONT.symbol(SYM.DEGREES)
},
{
name: 'ADSB_WARNING_MESSAGE',
id: 147,
min_version: '7.1.0',
preview: FONT.symbol(SYM.ADSB) + '19.25' + FONT.symbol(SYM.DIR_TO_HOME+1) + '2.75',
},
{
name: 'ADSB_INFO',
id: 148,
min_version: '7.1.0',
preview: FONT.symbol(SYM.ADSB) + '2',
},
{
name: 'CROSS TRACK ERROR',
id: 141,
Expand Down Expand Up @@ -2264,6 +2297,8 @@ OSD.msp = {
result.push16(OSD.data.alarms.imu_temp_alarm_max);
result.push16(OSD.data.alarms.baro_temp_alarm_min);
result.push16(OSD.data.alarms.baro_temp_alarm_max);
result.push16(OSD.data.alarms.adsb_distance_warning);
result.push16(OSD.data.alarms.adsb_distance_alert);
return result;
},

Expand All @@ -2283,6 +2318,8 @@ OSD.msp = {
OSD.data.alarms.imu_temp_alarm_max = alarms.read16();
OSD.data.alarms.baro_temp_alarm_min = alarms.read16();
OSD.data.alarms.baro_temp_alarm_max = alarms.read16();
OSD.data.alarms.adsb_distance_warning = alarms.read16();
OSD.data.alarms.adsb_distance_alert = alarms.read16();
},

encodePreferences: function() {
Expand Down