2015-02-08 15:27:03 +01:00
|
|
|
// Part of dump1090, a Mode S message decoder for RTLSDR devices.
|
|
|
|
//
|
|
|
|
// track.h: aircraft state tracking prototypes
|
|
|
|
//
|
2016-08-27 15:34:14 +02:00
|
|
|
// Copyright (c) 2014-2016 Oliver Jowett <oliver@mutability.co.uk>
|
2015-02-08 15:27:03 +01:00
|
|
|
//
|
2017-06-15 19:16:51 +02:00
|
|
|
// This file is free software: you may copy, redistribute and/or modify it
|
2015-02-08 15:27:03 +01:00
|
|
|
// under the terms of the GNU General Public License as published by the
|
2017-06-15 19:16:51 +02:00
|
|
|
// Free Software Foundation, either version 2 of the License, or (at your
|
|
|
|
// option) any later version.
|
2015-02-08 15:27:03 +01:00
|
|
|
//
|
2017-06-15 19:16:51 +02:00
|
|
|
// 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
|
2015-02-08 15:27:03 +01:00
|
|
|
// General Public License for more details.
|
|
|
|
//
|
2017-06-15 19:16:51 +02:00
|
|
|
// You should have received a copy of the GNU General Public License
|
2015-02-08 15:27:03 +01:00
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2017-06-15 19:16:51 +02:00
|
|
|
// This file incorporates work covered by the following copyright and
|
2015-02-08 15:27:03 +01:00
|
|
|
// permission notice:
|
|
|
|
//
|
|
|
|
// Copyright (C) 2012 by Salvatore Sanfilippo <antirez@gmail.com>
|
|
|
|
//
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
//
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer in the
|
|
|
|
// documentation and/or other materials provided with the distribution.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
#ifndef DUMP1090_TRACK_H
|
|
|
|
#define DUMP1090_TRACK_H
|
|
|
|
|
2015-02-10 22:49:37 +01:00
|
|
|
/* Maximum age of tracked aircraft in milliseconds */
|
|
|
|
#define TRACK_AIRCRAFT_TTL 300000
|
2015-02-08 15:27:03 +01:00
|
|
|
|
2015-02-10 22:49:37 +01:00
|
|
|
/* Maximum age of a tracked aircraft with only 1 message received, in milliseconds */
|
|
|
|
#define TRACK_AIRCRAFT_ONEHIT_TTL 60000
|
2015-02-08 15:37:35 +01:00
|
|
|
|
2015-02-18 01:12:35 +01:00
|
|
|
/* Maximum validity of an aircraft position */
|
|
|
|
#define TRACK_AIRCRAFT_POSITION_TTL 60000
|
|
|
|
|
2016-10-11 19:00:11 +02:00
|
|
|
/* Minimum number of repeated Mode A/C replies with a particular Mode A code needed in a
|
|
|
|
* 1 second period before accepting that code.
|
|
|
|
*/
|
2016-10-11 22:29:39 +02:00
|
|
|
#define TRACK_MODEAC_MIN_MESSAGES 4
|
2016-10-11 19:00:11 +02:00
|
|
|
|
2017-12-07 17:34:08 +01:00
|
|
|
/* Special value for Rc unknown (100NM) */
|
|
|
|
#define RC_UNKNOWN 185200
|
|
|
|
|
2017-12-02 18:38:33 +01:00
|
|
|
// data moves through three states:
|
|
|
|
// fresh: data is valid. Updates from a less reliable source are not accepted.
|
|
|
|
// stale: data is valid. Updates from a less reliable source are accepted.
|
|
|
|
// expired: data is not valid.
|
2016-08-27 15:34:14 +02:00
|
|
|
typedef struct {
|
2017-12-02 18:38:33 +01:00
|
|
|
uint64_t stale_interval; /* how long after an update until the data is stale */
|
2018-01-09 18:13:34 +01:00
|
|
|
uint64_t expire_interval; /* how long after an update until the data expires */
|
2017-12-02 18:38:33 +01:00
|
|
|
|
2016-08-27 15:34:14 +02:00
|
|
|
datasource_t source; /* where the data came from */
|
2017-12-02 18:38:33 +01:00
|
|
|
uint64_t updated; /* when it arrived */
|
|
|
|
uint64_t stale; /* when it goes stale */
|
|
|
|
uint64_t expires; /* when it expires */
|
2016-08-27 15:34:14 +02:00
|
|
|
} data_validity;
|
|
|
|
|
2015-02-08 15:27:03 +01:00
|
|
|
/* Structure used to describe the state of one tracked aircraft */
|
|
|
|
struct aircraft {
|
|
|
|
uint32_t addr; // ICAO address
|
2016-09-14 17:54:00 +02:00
|
|
|
addrtype_t addrtype; // highest priority address type seen for this aircraft
|
2016-08-27 15:34:14 +02:00
|
|
|
|
|
|
|
uint64_t seen; // Time (millis) at which the last packet was received
|
|
|
|
long messages; // Number of Mode S messages received
|
|
|
|
|
2015-02-08 15:27:03 +01:00
|
|
|
double signalLevel[8]; // Last 8 Signal Amplitudes
|
2016-02-24 12:51:45 +01:00
|
|
|
int signalNext; // next index of signalLevel to use
|
2015-06-16 00:13:04 +02:00
|
|
|
|
2016-08-27 15:34:14 +02:00
|
|
|
data_validity callsign_valid;
|
|
|
|
char callsign[9]; // Flight number
|
2015-06-16 00:13:04 +02:00
|
|
|
|
2017-12-07 17:34:08 +01:00
|
|
|
data_validity altitude_baro_valid;
|
|
|
|
int altitude_baro; // Altitude (Baro)
|
2015-06-28 21:04:09 +02:00
|
|
|
|
2017-06-15 19:07:40 +02:00
|
|
|
data_validity altitude_geom_valid;
|
|
|
|
int altitude_geom; // Altitude (Geometric)
|
2016-08-27 15:34:14 +02:00
|
|
|
|
2017-06-15 19:07:40 +02:00
|
|
|
data_validity geom_delta_valid;
|
|
|
|
int geom_delta; // Difference between Geometric and Baro altitudes
|
2016-08-27 15:34:14 +02:00
|
|
|
|
2017-06-15 19:07:40 +02:00
|
|
|
data_validity gs_valid;
|
2017-12-07 17:34:08 +01:00
|
|
|
float gs;
|
2016-08-27 15:34:14 +02:00
|
|
|
|
2017-06-15 19:07:40 +02:00
|
|
|
data_validity ias_valid;
|
|
|
|
unsigned ias;
|
2016-08-27 15:34:14 +02:00
|
|
|
|
2017-06-15 19:07:40 +02:00
|
|
|
data_validity tas_valid;
|
|
|
|
unsigned tas;
|
2015-02-08 15:27:03 +01:00
|
|
|
|
2017-06-15 19:07:40 +02:00
|
|
|
data_validity mach_valid;
|
|
|
|
float mach;
|
2015-02-08 15:27:03 +01:00
|
|
|
|
2017-06-15 19:07:40 +02:00
|
|
|
data_validity track_valid;
|
|
|
|
float track; // Ground track
|
2015-02-18 01:12:35 +01:00
|
|
|
|
2017-06-15 19:07:40 +02:00
|
|
|
data_validity track_rate_valid;
|
|
|
|
float track_rate; // Rate of change of ground track, degrees/second
|
|
|
|
|
|
|
|
data_validity roll_valid;
|
|
|
|
float roll; // Roll angle, degrees right
|
|
|
|
|
|
|
|
data_validity mag_heading_valid;
|
|
|
|
float mag_heading; // Magnetic heading
|
|
|
|
|
2017-06-15 22:07:53 +02:00
|
|
|
data_validity true_heading_valid;
|
|
|
|
float true_heading; // True heading
|
|
|
|
|
2017-06-15 19:07:40 +02:00
|
|
|
data_validity baro_rate_valid;
|
|
|
|
int baro_rate; // Vertical rate (barometric)
|
|
|
|
|
|
|
|
data_validity geom_rate_valid;
|
|
|
|
int geom_rate; // Vertical rate (geometric)
|
2015-02-18 01:12:35 +01:00
|
|
|
|
2016-08-27 15:34:14 +02:00
|
|
|
data_validity squawk_valid;
|
|
|
|
unsigned squawk; // Squawk
|
|
|
|
|
2018-01-09 15:43:58 +01:00
|
|
|
data_validity emergency_valid;
|
|
|
|
emergency_t emergency; // Emergency/priority status
|
|
|
|
|
2018-01-09 15:49:16 +01:00
|
|
|
unsigned category; // Aircraft category A0 - D7 encoded as a single hex byte. 00 = unset
|
2016-08-27 15:34:14 +02:00
|
|
|
|
|
|
|
data_validity airground_valid;
|
|
|
|
airground_t airground; // air/ground status
|
|
|
|
|
2017-12-07 17:34:08 +01:00
|
|
|
data_validity nav_qnh_valid;
|
|
|
|
float nav_qnh; // Altimeter setting (QNH/QFE), millibars
|
2017-06-15 19:07:40 +02:00
|
|
|
|
2017-12-07 17:34:08 +01:00
|
|
|
data_validity nav_altitude_valid;
|
|
|
|
unsigned nav_altitude; // FMS or FCU selected altitude
|
2017-06-15 19:07:40 +02:00
|
|
|
|
2017-12-07 17:34:08 +01:00
|
|
|
data_validity nav_heading_valid;
|
|
|
|
float nav_heading; // target heading, degrees (0-359)
|
2017-06-15 19:07:40 +02:00
|
|
|
|
2017-12-07 17:34:08 +01:00
|
|
|
data_validity nav_modes_valid;
|
|
|
|
nav_modes_t nav_modes; // enabled modes (autopilot, vnav, etc)
|
2017-06-16 11:39:01 +02:00
|
|
|
|
2016-08-27 15:34:14 +02:00
|
|
|
data_validity cpr_odd_valid; // Last seen even CPR message
|
2016-10-02 01:16:29 +02:00
|
|
|
cpr_type_t cpr_odd_type;
|
2016-08-27 15:34:14 +02:00
|
|
|
unsigned cpr_odd_lat;
|
|
|
|
unsigned cpr_odd_lon;
|
2017-12-07 17:34:08 +01:00
|
|
|
unsigned cpr_odd_nic;
|
|
|
|
unsigned cpr_odd_rc;
|
2016-08-27 15:34:14 +02:00
|
|
|
|
|
|
|
data_validity cpr_even_valid; // Last seen odd CPR message
|
2016-10-02 01:16:29 +02:00
|
|
|
cpr_type_t cpr_even_type;
|
2016-08-27 15:34:14 +02:00
|
|
|
unsigned cpr_even_lat;
|
|
|
|
unsigned cpr_even_lon;
|
2017-12-07 17:34:08 +01:00
|
|
|
unsigned cpr_even_nic;
|
|
|
|
unsigned cpr_even_rc;
|
2016-08-27 15:34:14 +02:00
|
|
|
|
|
|
|
data_validity position_valid;
|
2015-02-08 15:27:03 +01:00
|
|
|
double lat, lon; // Coordinated obtained from CPR encoded data
|
2017-12-07 17:34:08 +01:00
|
|
|
unsigned pos_nic; // NIC of last computed position
|
|
|
|
unsigned pos_rc; // Rc of last computed position
|
2015-02-18 01:12:35 +01:00
|
|
|
|
2017-12-07 17:34:08 +01:00
|
|
|
// data extracted from opstatus etc
|
2017-06-15 22:07:53 +02:00
|
|
|
int adsb_version; // ADS-B version (from ADS-B operational status); -1 means no ADS-B messages seen
|
|
|
|
heading_type_t adsb_hrd; // Heading Reference Direction setting (from ADS-B operational status)
|
|
|
|
heading_type_t adsb_tah; // Track Angle / Heading setting (from ADS-B operational status)
|
|
|
|
|
2017-12-07 17:34:08 +01:00
|
|
|
data_validity nic_a_valid;
|
|
|
|
data_validity nic_c_valid;
|
|
|
|
data_validity nic_baro_valid;
|
|
|
|
data_validity nac_p_valid;
|
|
|
|
data_validity nac_v_valid;
|
|
|
|
data_validity sil_valid;
|
|
|
|
data_validity gva_valid;
|
|
|
|
data_validity sda_valid;
|
|
|
|
|
|
|
|
unsigned nic_a : 1; // NIC supplement A from opstatus
|
|
|
|
unsigned nic_c : 1; // NIC supplement C from opstatus
|
|
|
|
unsigned nic_baro : 1; // NIC baro supplement from TSS or opstatus
|
|
|
|
unsigned nac_p : 4; // NACp from TSS or opstatus
|
2018-01-09 15:46:33 +01:00
|
|
|
unsigned nac_v : 3; // NACv from airborne velocity or opstatus
|
|
|
|
unsigned sil : 2; // SIL from TSS or opstatus
|
|
|
|
sil_type_t sil_type; // SIL supplement from TSS or opstatus
|
2017-12-07 17:34:08 +01:00
|
|
|
|
2016-10-11 19:00:11 +02:00
|
|
|
int modeA_hit; // did our squawk match a possible mode A reply in the last check period?
|
|
|
|
int modeC_hit; // did our altitude match a possible mode C reply in the last check period?
|
2016-08-27 15:34:14 +02:00
|
|
|
|
2017-12-07 17:34:08 +01:00
|
|
|
int fatsv_emitted_altitude_baro; // last FA emitted altitude
|
|
|
|
int fatsv_emitted_altitude_geom; // -"- GNSS altitude
|
2017-06-15 19:07:40 +02:00
|
|
|
int fatsv_emitted_baro_rate; // -"- barometric rate
|
|
|
|
int fatsv_emitted_geom_rate; // -"- geometric rate
|
2017-06-15 22:07:53 +02:00
|
|
|
float fatsv_emitted_track; // -"- true track
|
2017-06-15 19:07:40 +02:00
|
|
|
float fatsv_emitted_track_rate; // -"- track rate of change
|
2017-06-15 22:07:53 +02:00
|
|
|
float fatsv_emitted_mag_heading; // -"- magnetic heading
|
|
|
|
float fatsv_emitted_true_heading; // -"- true heading
|
2017-06-15 19:07:40 +02:00
|
|
|
float fatsv_emitted_roll; // -"- roll angle
|
2017-12-07 17:34:08 +01:00
|
|
|
float fatsv_emitted_gs; // -"- groundspeed
|
|
|
|
unsigned fatsv_emitted_ias; // -"- IAS
|
|
|
|
unsigned fatsv_emitted_tas; // -"- TAS
|
2017-06-15 19:07:40 +02:00
|
|
|
float fatsv_emitted_mach; // -"- Mach number
|
2016-08-27 15:34:14 +02:00
|
|
|
airground_t fatsv_emitted_airground; // -"- air/ground state
|
2017-12-07 17:34:08 +01:00
|
|
|
unsigned fatsv_emitted_nav_altitude; // -"- target altitude
|
|
|
|
float fatsv_emitted_nav_heading; // -"- target heading
|
|
|
|
nav_modes_t fatsv_emitted_nav_modes; // -"- enabled navigation modes
|
|
|
|
float fatsv_emitted_nav_qnh; // -"- altimeter setting
|
2016-08-28 02:29:37 +02:00
|
|
|
unsigned char fatsv_emitted_bds_10[7]; // -"- BDS 1,0 message
|
|
|
|
unsigned char fatsv_emitted_bds_30[7]; // -"- BDS 3,0 message
|
|
|
|
unsigned char fatsv_emitted_es_status[7]; // -"- ES operational status message
|
2016-09-24 17:09:38 +02:00
|
|
|
unsigned char fatsv_emitted_es_acas_ra[7]; // -"- ES ACAS RA report message
|
2017-06-15 19:30:12 +02:00
|
|
|
char fatsv_emitted_callsign[9]; // -"- callsign
|
2017-12-07 17:34:08 +01:00
|
|
|
addrtype_t fatsv_emitted_addrtype; // -"- address type (assumed ADSB_ICAO initially)
|
|
|
|
int fatsv_emitted_adsb_version; // -"- ADS-B version (assumed non-ADS-B initially)
|
|
|
|
unsigned fatsv_emitted_category; // -"- ADS-B emitter category (assumed A0 initially)
|
|
|
|
unsigned fatsv_emitted_squawk; // -"- squawk
|
2018-01-09 15:46:33 +01:00
|
|
|
unsigned fatsv_emitted_nac_p; // -"- NACp
|
|
|
|
unsigned fatsv_emitted_nac_v; // -"- NACv
|
|
|
|
unsigned fatsv_emitted_sil; // -"- SIL
|
|
|
|
sil_type_t fatsv_emitted_sil_type; // -"- SIL supplement
|
|
|
|
unsigned fatsv_emitted_nic_baro; // -"- NICbaro
|
2018-02-19 12:25:49 +01:00
|
|
|
emergency_t fatsv_emitted_emergency; // -"- emergency/priority status
|
2016-08-27 15:34:14 +02:00
|
|
|
|
|
|
|
uint64_t fatsv_last_emitted; // time (millis) aircraft was last FA emitted
|
2017-12-07 17:34:08 +01:00
|
|
|
uint64_t fatsv_last_force_emit; // time (millis) we last emitted only-on-change data
|
2015-02-22 13:15:26 +01:00
|
|
|
|
2015-02-08 15:27:03 +01:00
|
|
|
struct aircraft *next; // Next aircraft in our linked list
|
If we squelch the first message from an aircraft, emit it when we see a second message.
This is possible now that the SBS output doesn't rely on the global block timestamp;
the output will look like this:
MSG,8,111,11111,4AC954,111111,2015/02/08,17:57:53.917,2015/02/08,17:57:53.936,,,,,,,,,,,,0
MSG,7,111,11111,392AEB,111111,2015/02/08,17:57:53.744,2015/02/08,17:57:53.936,,15375,,,,,,,,,,0
MSG,8,111,11111,392AEB,111111,2015/02/08,17:57:53.917,2015/02/08,17:57:53.936,,,,,,,,,,,,0
MSG,6,111,11111,800387,111111,2015/02/08,17:57:53.919,2015/02/08,17:57:53.936,,,,,,,,4745,0,0,0,0
where the "receive timestamp" (first time column) goes backwards to reflect the original reception
time of the delayed message, but the "forwarded timestamp" (second time column) reflects the actual
forwarding time.
2015-02-08 19:00:18 +01:00
|
|
|
|
|
|
|
struct modesMessage first_message; // A copy of the first message we received for this aircraft.
|
2015-02-08 15:27:03 +01:00
|
|
|
};
|
|
|
|
|
2016-10-11 19:00:11 +02:00
|
|
|
/* Mode A/C tracking is done separately, not via the aircraft list,
|
|
|
|
* and via a flat array rather than a list since there are only 4k possible values
|
|
|
|
* (nb: we ignore the ident/SPI bit when tracking)
|
|
|
|
*/
|
|
|
|
extern uint32_t modeAC_count[4096];
|
|
|
|
extern uint32_t modeAC_match[4096];
|
2016-10-11 22:29:39 +02:00
|
|
|
extern uint32_t modeAC_age[4096];
|
2016-10-11 19:00:11 +02:00
|
|
|
|
2016-08-27 15:34:14 +02:00
|
|
|
/* is this bit of data valid? */
|
|
|
|
static inline int trackDataValid(const data_validity *v)
|
|
|
|
{
|
2017-12-02 18:38:33 +01:00
|
|
|
return (v->source != SOURCE_INVALID && messageNow() < v->expires);
|
2016-08-27 15:34:14 +02:00
|
|
|
}
|
|
|
|
|
2018-01-09 15:47:08 +01:00
|
|
|
/* is this bit of data fresh? */
|
|
|
|
static inline int trackDataFresh(const data_validity *v)
|
|
|
|
{
|
|
|
|
return (v->source != SOURCE_INVALID && messageNow() < v->stale);
|
|
|
|
}
|
|
|
|
|
2017-12-02 18:38:33 +01:00
|
|
|
/* what's the age of this data, in milliseconds? */
|
|
|
|
static inline uint64_t trackDataAge(const data_validity *v)
|
2016-08-27 15:34:14 +02:00
|
|
|
{
|
|
|
|
if (v->source == SOURCE_INVALID)
|
|
|
|
return ~(uint64_t)0;
|
2017-12-02 18:38:33 +01:00
|
|
|
if (v->updated >= messageNow())
|
2016-08-27 15:34:14 +02:00
|
|
|
return 0;
|
2017-12-02 18:38:33 +01:00
|
|
|
return (messageNow() - v->updated);
|
2016-08-27 15:34:14 +02:00
|
|
|
}
|
2015-02-08 15:27:03 +01:00
|
|
|
|
|
|
|
/* Update aircraft state from data in the provided mesage.
|
|
|
|
* Return the tracked aircraft.
|
|
|
|
*/
|
|
|
|
struct modesMessage;
|
|
|
|
struct aircraft *trackUpdateFromMessage(struct modesMessage *mm);
|
|
|
|
|
|
|
|
/* Call periodically */
|
|
|
|
void trackPeriodicUpdate();
|
|
|
|
|
2016-10-11 18:57:25 +02:00
|
|
|
/* Convert from a (hex) mode A value to a 0-4095 index */
|
|
|
|
static inline unsigned modeAToIndex(unsigned modeA)
|
|
|
|
{
|
|
|
|
return (modeA & 0x0007) | ((modeA & 0x0070) >> 1) | ((modeA & 0x0700) >> 2) | ((modeA & 0x7000) >> 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert from a 0-4095 index to a (hex) mode A value */
|
|
|
|
static inline unsigned indexToModeA(unsigned index)
|
|
|
|
{
|
|
|
|
return (index & 0007) | ((index & 0070) << 1) | ((index & 0700) << 2) | ((index & 07000) << 3);
|
|
|
|
}
|
|
|
|
|
2015-02-08 15:27:03 +01:00
|
|
|
#endif
|