Skip to content

Commit

Permalink
adsb enhanced
Browse files Browse the repository at this point in the history
  • Loading branch information
error414 committed Aug 10, 2024
1 parent 3226f68 commit 03e37a3
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 77 deletions.
2 changes: 2 additions & 0 deletions js/fc.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ var FC = {
this.ADSB_VEHICLES = {
vehiclesCount: 0,
callsignLength: 0,
vehiclePacketCount: 0,
heartbeatPacketCount: 0,
vehicles: []
};

Expand Down
2 changes: 2 additions & 0 deletions js/msp/MSPHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ var mspHelper = (function () {
FC.ADSB_VEHICLES.vehicles = [];
FC.ADSB_VEHICLES.vehiclesCount = data.getUint8(byteOffsetCounter++);
FC.ADSB_VEHICLES.callsignLength = data.getUint8(byteOffsetCounter++);
FC.ADSB_VEHICLES.vehiclePacketCount = data.getUint32(byteOffsetCounter, true); byteOffsetCounter += 4;
FC.ADSB_VEHICLES.heartbeatPacketCount = data.getUint32(byteOffsetCounter, true); byteOffsetCounter += 4;

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

Expand Down
6 changes: 6 additions & 0 deletions locale/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -5935,5 +5935,11 @@
},
"gpsAssistnowLoadDataError": {
"message": "Error loading AssistNow data."
},
"adsbVehicleTotalMessages": {
"message": "Vehicle msgs"
},
"adsbHeartbeatTotalMessages": {
"message": "Heartbeat msgs"
}
}
7 changes: 4 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions tabs/gps.html
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,23 @@
</table>
</div>
</div>
<div class="gui_box grey adsb_info_block">
<div class="gui_box_titlebar">
<div class="spacer_box_title">ADSB</div>
</div>
<div class="spacer_box GPS_stat">
<table class="cf_table">
<tr>
<td style="width: 85px" data-i18n="adsbVehicleTotalMessages"></td>
<td class="adsbVehicleTotalMessages">0</td>
</tr>
<tr>
<td style="width: 85px" data-i18n="adsbHeartbeatTotalMessages"></td>
<td class="adsbHeartbeatTotalMessages">0</td>
</tr>
</table>
</div>
</div>
</div>
</div>

Expand Down
166 changes: 92 additions & 74 deletions tabs/gps.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,26 @@ TABS.gps.initialize = function (callback) {

// 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
0: {icon: 'adsb_14.png', name: 'No info'}, // ADSB_EMITTER_TYPE_NO_INFO
1: {icon: 'adsb_1.png', name: 'Light'}, // ADSB_EMITTER_TYPE_LIGHT
2: {icon: 'adsb_1.png', name: 'Small'}, // ADSB_EMITTER_TYPE_SMALL
3: {icon: 'adsb_2.png', name: 'Large'}, // ADSB_EMITTER_TYPE_LARGE
4: {icon: 'adsb_14.png', name: 'High vortex large'}, // ADSB_EMITTER_TYPE_HIGH_VORTEX_LARGE
5: {icon: 'adsb_5.png', name: 'Heavy'}, // ADSB_EMITTER_TYPE_HEAVY
6: {icon: 'adsb_14.png', name: 'Manuv'}, // ADSB_EMITTER_TYPE_HIGHLY_MANUV
7: {icon: 'adsb_13.png', name: 'Rotorcraft'}, // ADSB_EMITTER_TYPE_ROTOCRAFT
8: {icon: 'adsb_14.png', name: 'Unassigned'}, // ADSB_EMITTER_TYPE_UNASSIGNED
9: {icon: 'adsb_6.png', name: 'Glider'}, // ADSB_EMITTER_TYPE_GLIDER
10:{icon: 'adsb_7.png', name: 'Lighter air'}, // ADSB_EMITTER_TYPE_LIGHTER_AIR
11:{icon: 'adsb_15.png', name: 'Parachute'}, // ADSB_EMITTER_TYPE_PARACHUTE
12:{icon: 'adsb_1.png', name: 'Ultra light'}, // ADSB_EMITTER_TYPE_ULTRA_LIGHT
13:{icon: 'adsb_14.png', name: 'Unassigned 2'}, // ADSB_EMITTER_TYPE_UNASSIGNED2
14:{icon: 'adsb_8.png', name: 'UAV'}, // ADSB_EMITTER_TYPE_UAV
15:{icon: 'adsb_14.png', name: 'Space'}, // ADSB_EMITTER_TYPE_SPACE
16:{icon: 'adsb_14.png', name: 'Unassigned 3'}, // ADSB_EMITTER_TYPE_UNASSGINED3
17:{icon: 'adsb_9.png', name: 'Surface'}, // ADSB_EMITTER_TYPE_EMERGENCY_SURFACE
18:{icon: 'adsb_10.png', name: 'Service surface'}, // ADSB_EMITTER_TYPE_SERVICE_SURFACE
19:{icon: 'adsb_12.png', name: 'Pint obstacle'}, // ADSB_EMITTER_TYPE_POINT_OBSTACLE
};

var loadChainer = new MSPChainerClass();
Expand Down Expand Up @@ -238,7 +238,7 @@ TABS.gps.initialize = function (callback) {
+ `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>`
+ `type: <strong>`+ ADSB_VEHICLE_TYPE[feature.get('data').emitterType].name + `</strong>`
).open();
}else{
TABS.gps.toolboxAdsbVehicle.close();
Expand All @@ -258,10 +258,14 @@ TABS.gps.initialize = function (callback) {
}

function get_gpsstatistics_data() {
MSP.send_message(MSPCodes.MSP_GPSSTATISTICS, false, false, update_ui);
MSP.send_message(MSPCodes.MSP_GPSSTATISTICS, false, false, update_gps_ui);
}

function update_ui() {
function get_raw_adsb_data() {
MSP.send_message(MSPCodes.MSP2_ADSB_VEHICLE_LIST, false, false, update_adsb_ui);
}

function update_gps_ui() {
let lat = FC.GPS_DATA.lat / 10000000;
let lon = FC.GPS_DATA.lon / 10000000;

Expand Down Expand Up @@ -334,64 +338,64 @@ TABS.gps.initialize = function (callback) {
iconGeometry.setCoordinates(center);

}
}

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

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

for (let key in FC.ADSB_VEHICLES.vehicles) {
let vehicle = FC.ADSB_VEHICLES.vehicles[key];
$('.adsbVehicleTotalMessages').html(FC.ADSB_VEHICLES.vehiclePacketCount);
$('.adsbHeartbeatTotalMessages').html(FC.ADSB_VEHICLES.heartbeatPacketCount);

if (!vehiclesCursorInitialized) {
vehiclesCursorInitialized = true;
for (let key in FC.ADSB_VEHICLES.vehicles) {
let vehicle = FC.ADSB_VEHICLES.vehicles[key];

vehicleVectorSource = new ol.source.Vector({});
if (!vehiclesCursorInitialized) {
vehiclesCursorInitialized = true;

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

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

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: path.join(__dirname, './../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);
}
}
});
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: path.join(__dirname, './../resources/adsb/' + ADSB_VEHICLE_TYPE[vehicle.emitterType].icon),
})),
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 All @@ -402,14 +406,28 @@ TABS.gps.initialize = function (callback) {
interval.add('gps_pull', function gps_update() {
// avoid usage of the GPS commands until a GPS sensor is detected for targets that are compiled without GPS support.
if (!SerialBackend.have_sensor(FC.CONFIG.activeSensors, 'gps')) {
update_ui();
update_gps_ui();
return;
}

get_raw_gps_data();

}, 200);


if (semver.gte(FC.CONFIG.flightControllerVersion, "8.0.0")) {
$('.adsb_info_block').hide();
mspHelper.loadSerialPorts(function () {
for(var i in FC.SERIAL_CONFIG.ports){
if(FC.SERIAL_CONFIG.ports[i].functions && FC.SERIAL_CONFIG.ports[i].functions.includes("TELEMETRY_MAVLINK")){
$('.adsb_info_block').show();
interval.add('adsb_pull', get_raw_adsb_data, 200);
break;
}
}
});
}

$('a.save').on('click', function () {
serialPortHelper.set($port.val(), 'GPS', $baud.val());
features.reset();
Expand Down

0 comments on commit 03e37a3

Please sign in to comment.