2015-11-19 14:21:00 -04:00
/*
This program is free software : you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
This program 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 General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
/*
AP_ADSB . cpp
ADS - B RF based collision avoidance module
https : //en.wikipedia.org/wiki/Automatic_dependent_surveillance_%E2%80%93_broadcast
*/
# include "AP_ADSB.h"
2020-10-28 10:44:49 -03:00
2020-10-06 08:32:51 -03:00
# if HAL_ADSB_ENABLED
2020-10-21 15:37:08 -03:00
# include "AP_ADSB_uAvionix_MAVLink.h"
2021-07-27 19:48:53 -03:00
# include "AP_ADSB_uAvionix_UCP.h"
2020-12-07 21:43:44 -04:00
# include "AP_ADSB_Sagetech.h"
2016-07-21 03:19:11 -03:00
# include <AP_Vehicle/AP_Vehicle.h>
2016-07-21 20:49:41 -03:00
# include <GCS_MAVLink/GCS.h>
2019-02-23 15:30:49 -04:00
# include <AP_Logger/AP_Logger.h>
2016-07-21 03:19:11 -03:00
2020-10-06 08:22:16 -03:00
# define VEHICLE_TIMEOUT_MS 5000 // if no updates in this time, drop it from the list
# define ADSB_SQUAWK_OCTAL_DEFAULT 1200
2020-10-28 10:44:49 -03:00
# ifndef ADSB_VEHICLE_LIST_SIZE_DEFAULT
# define ADSB_VEHICLE_LIST_SIZE_DEFAULT 25
# endif
# ifndef ADSB_LIST_RADIUS_DEFAULT
# if APM_BUILD_TYPE(APM_BUILD_ArduPlane)
# define ADSB_LIST_RADIUS_DEFAULT 10000 // in meters
# else
# define ADSB_LIST_RADIUS_DEFAULT 2000 // in meters
# endif
2020-10-06 08:22:16 -03:00
# endif
2015-11-19 14:21:00 -04:00
extern const AP_HAL : : HAL & hal ;
2019-10-02 07:54:10 -03:00
AP_ADSB * AP_ADSB : : _singleton ;
2015-11-19 14:21:00 -04:00
// table of user settable parameters
const AP_Param : : GroupInfo AP_ADSB : : var_info [ ] = {
2020-11-05 20:24:47 -04:00
// @Param: TYPE
// @DisplayName: ADSB Type
// @Description: Type of ADS-B hardware for ADSB-in and ADSB-out configuration and operation. If any type is selected then MAVLink based ADSB-in messages will always be enabled
2021-07-27 19:48:53 -03:00
// @Values: 0:Disabled,1:uAvionix-MAVLink,2:Sagetech,3:uAvionix-UCP
2016-06-25 11:05:17 -03:00
// @User: Standard
2020-11-25 21:54:01 -04:00
// @RebootRequired: True
2020-11-05 20:24:47 -04:00
AP_GROUPINFO_FLAGS ( " TYPE " , 0 , AP_ADSB , _type [ 0 ] , 0 , AP_PARAM_FLAG_ENABLE ) ,
2015-11-19 14:21:00 -04:00
2016-08-01 21:56:04 -03:00
// index 1 is reserved - was BEHAVIOR
2015-11-19 14:21:00 -04:00
2016-06-25 11:05:17 -03:00
// @Param: LIST_MAX
// @DisplayName: ADSB vehicle list size
// @Description: ADSB list size of nearest vehicles. Longer lists take longer to refresh with lower SRx_ADSB values.
// @Range: 1 100
// @User: Advanced
2020-10-28 10:44:49 -03:00
// @RebootRequired: True
2016-07-10 20:20:25 -03:00
AP_GROUPINFO ( " LIST_MAX " , 2 , AP_ADSB , in_state . list_size_param , ADSB_VEHICLE_LIST_SIZE_DEFAULT ) ,
2016-06-25 11:05:17 -03:00
2016-07-10 20:51:37 -03:00
// @Param: LIST_RADIUS
// @DisplayName: ADSB vehicle list radius filter
2018-07-10 11:21:16 -03:00
// @Description: ADSB vehicle list radius filter. Vehicles detected outside this radius will be completely ignored. They will not show up in the SRx_ADSB stream to the GCS and will not be considered in any avoidance calculations. A value of 0 will disable this filter.
// @Range: 0 100000
2016-07-10 20:51:37 -03:00
// @User: Advanced
2018-07-10 11:21:16 -03:00
// @Units: m
2020-10-06 08:22:16 -03:00
AP_GROUPINFO ( " LIST_RADIUS " , 3 , AP_ADSB , in_state . list_radius , ADSB_LIST_RADIUS_DEFAULT ) ,
2016-07-10 20:51:37 -03:00
2016-07-10 20:53:19 -03:00
// @Param: ICAO_ID
2018-02-16 10:23:57 -04:00
// @DisplayName: ICAO_ID vehicle identification number
2021-07-27 19:48:53 -03:00
// @Description: ICAO_ID unique vehicle identification number of this aircraft. This is an integer limited to 24bits. If set to 0 then one will be randomly generated. If set to -1 then static information is not sent, transceiver is assumed pre-programmed.
2016-07-10 20:53:19 -03:00
// @Range: -1 16777215
// @User: Advanced
AP_GROUPINFO ( " ICAO_ID " , 4 , AP_ADSB , out_state . cfg . ICAO_id_param , 0 ) ,
// @Param: EMIT_TYPE
// @DisplayName: Emitter type
// @Description: ADSB classification for the type of vehicle emitting the transponder signal. Default value is 14 (UAV).
// @Values: 0:NoInfo,1:Light,2:Small,3:Large,4:HighVortexlarge,5:Heavy,6:HighlyManuv,7:Rotocraft,8:RESERVED,9:Glider,10:LightAir,11:Parachute,12:UltraLight,13:RESERVED,14:UAV,15:Space,16:RESERVED,17:EmergencySurface,18:ServiceSurface,19:PointObstacle
// @User: Advanced
2016-07-22 17:55:20 -03:00
AP_GROUPINFO ( " EMIT_TYPE " , 5 , AP_ADSB , out_state . cfg . emitterType , ADSB_EMITTER_TYPE_UAV ) ,
2016-07-10 20:53:19 -03:00
// @Param: LEN_WIDTH
// @DisplayName: Aircraft length and width
2016-07-22 21:09:10 -03:00
// @Description: Aircraft length and width dimension options in Length and Width in meters. In most cases, use a value of 1 for smallest size.
// @Values: 0:NO_DATA,1:L15W23,2:L25W28P5,3:L25W34,4:L35W33,5:L35W38,6:L45W39P5,7:L45W45,8:L55W45,9:L55W52,10:L65W59P5,11:L65W67,12:L75W72P5,13:L75W80,14:L85W80,15:L85W90
2016-07-10 20:53:19 -03:00
// @User: Advanced
2016-07-22 21:09:10 -03:00
AP_GROUPINFO ( " LEN_WIDTH " , 6 , AP_ADSB , out_state . cfg . lengthWidth , UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE_L15M_W23M ) ,
2016-07-10 20:53:19 -03:00
// @Param: OFFSET_LAT
// @DisplayName: GPS antenna lateral offset
2016-07-22 21:09:10 -03:00
// @Description: GPS antenna lateral offset. This describes the physical location offest from center of the GPS antenna on the aircraft.
// @Values: 0:NoData,1:Left2m,2:Left4m,3:Left6m,4:Center,5:Right2m,6:Right4m,7:Right6m
2016-07-10 20:53:19 -03:00
// @User: Advanced
2020-10-28 10:44:49 -03:00
AP_GROUPINFO ( " OFFSET_LAT " , 7 , AP_ADSB , out_state . cfg . gpsOffsetLat , UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LAT_RIGHT_0M ) ,
2016-07-10 20:53:19 -03:00
// @Param: OFFSET_LON
// @DisplayName: GPS antenna longitudinal offset
2016-07-22 21:09:10 -03:00
// @Description: GPS antenna longitudinal offset. This is usually set to 1, Applied By Sensor
// @Values: 0:NO_DATA,1:AppliedBySensor
2016-07-10 20:53:19 -03:00
// @User: Advanced
2020-10-28 10:44:49 -03:00
AP_GROUPINFO ( " OFFSET_LON " , 8 , AP_ADSB , out_state . cfg . gpsOffsetLon , UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LON_APPLIED_BY_SENSOR ) ,
2016-07-22 17:55:20 -03:00
// @Param: RF_SELECT
// @DisplayName: Transceiver RF selection
2020-10-28 10:44:49 -03:00
// @Description: Transceiver RF selection for Rx enable and/or Tx enable. This only effects devices that can Tx and/or Rx. Rx-only devices should override this to always be Rx-only.
// @Bitmask: 0:Rx,1:Tx
2016-07-22 17:55:20 -03:00
// @User: Advanced
2016-10-31 23:45:03 -03:00
AP_GROUPINFO ( " RF_SELECT " , 9 , AP_ADSB , out_state . cfg . rfSelect , UAVIONIX_ADSB_OUT_RF_SELECT_RX_ENABLED ) ,
2016-07-10 20:53:19 -03:00
2018-05-22 14:33:53 -03:00
// @Param: SQUAWK
// @DisplayName: Squawk code
// @Description: VFR squawk (Mode 3/A) code is a pre-programmed default code when the pilot is flying VFR and not in contact with ATC. In the USA, the VFR squawk code is octal 1200 (hex 0x280, decimal 640) and in most parts of Europe the VFR squawk code is octal 7000. If an invalid octal number is set then it will be reset to 1200.
2018-07-09 09:06:18 -03:00
// @Range: 0 7777
2018-05-22 14:33:53 -03:00
// @Units: octal
// @User: Advanced
AP_GROUPINFO ( " SQUAWK " , 10 , AP_ADSB , out_state . cfg . squawk_octal_param , ADSB_SQUAWK_OCTAL_DEFAULT ) ,
// @Param: RF_CAPABLE
// @DisplayName: RF capabilities
// @Description: Describes your hardware RF In/Out capabilities.
// @Bitmask: 0:UAT_in,1:1090ES_in,2:UAT_out,3:1090ES_out
// @User: Advanced
AP_GROUPINFO ( " RF_CAPABLE " , 11 , AP_ADSB , out_state . cfg . rf_capable , 0 ) ,
2016-07-10 20:53:19 -03:00
2018-07-10 11:21:16 -03:00
// @Param: LIST_ALT
// @DisplayName: ADSB vehicle list altitude filter
// @Description: ADSB vehicle list altitude filter. Vehicles detected above this altitude will be completely ignored. They will not show up in the SRx_ADSB stream to the GCS and will not be considered in any avoidance calculations. A value of 0 will disable this filter.
// @Range: 0 32767
// @User: Advanced
// @Units: m
AP_GROUPINFO ( " LIST_ALT " , 12 , AP_ADSB , in_state . list_altitude , 0 ) ,
2019-02-17 11:44:28 -04:00
// @Param: ICAO_SPECL
// @DisplayName: ICAO_ID of special vehicle
// @Description: ICAO_ID of special vehicle that ignores ADSB_LIST_RADIUS and ADSB_LIST_ALT. The vehicle is always tracked. Use 0 to disable.
// @User: Advanced
AP_GROUPINFO ( " ICAO_SPECL " , 13 , AP_ADSB , _special_ICAO_target , 0 ) ,
2016-07-10 20:53:19 -03:00
2019-02-23 15:30:49 -04:00
// @Param: LOG
// @DisplayName: ADS-B logging
// @Description: 0: no logging, 1: log only special ID, 2:log all
2019-03-28 15:17:27 -03:00
// @Values: 0:no logging,1:log only special ID,2:log all
2019-02-23 15:30:49 -04:00
// @User: Advanced
AP_GROUPINFO ( " LOG " , 14 , AP_ADSB , _log , 1 ) ,
2021-07-27 19:48:53 -03:00
// @Param: OPTIONS
// @DisplayName: ADS-B Options
// @Bitmask: 0:Ping200X Send GPS,1:Squawk 7400 on RC failsafe,2:Squawk 7400 on GCS failsafe
// @User: Advanced
AP_GROUPINFO ( " OPTIONS " , 15 , AP_ADSB , _options , 0 ) ,
2015-11-19 14:21:00 -04:00
AP_GROUPEND
} ;
2019-10-02 07:54:10 -03:00
// constructor
AP_ADSB : : AP_ADSB ( )
{
AP_Param : : setup_object_defaults ( this , var_info ) ;
2020-10-28 10:44:49 -03:00
# if CONFIG_HAL_BOARD == HAL_BOARD_SITL
2019-10-02 07:54:10 -03:00
if ( _singleton ! = nullptr ) {
AP_HAL : : panic ( " AP_ADSB must be singleton " ) ;
}
2020-10-28 10:44:49 -03:00
# endif
2019-10-02 07:54:10 -03:00
_singleton = this ;
2020-10-28 10:44:49 -03:00
# ifdef ADSB_STATIC_CALLSIGN
strncpy ( & out_state . cfg . callsign , ADSB_STATIC_CALLSIGN , sizeof ( out_state . cfg . callsign ) ) ;
# endif
2019-10-02 07:54:10 -03:00
}
2015-11-19 14:21:00 -04:00
/*
2020-10-06 08:22:16 -03:00
* Initialize variables and allocate memory for array
2015-11-19 14:21:00 -04:00
*/
2020-10-06 08:22:16 -03:00
void AP_ADSB : : init ( void )
2015-11-19 14:21:00 -04:00
{
2016-07-10 20:20:25 -03:00
if ( in_state . vehicle_list = = nullptr ) {
2020-10-28 10:44:49 -03:00
// sanity check param
in_state . list_size_param = constrain_int16 ( in_state . list_size_param , 1 , INT16_MAX ) ;
in_state . vehicle_list = new adsb_vehicle_t [ in_state . list_size_param ] ;
2020-10-06 08:22:16 -03:00
if ( in_state . vehicle_list = = nullptr ) {
2020-10-28 10:44:49 -03:00
// dynamic RAM allocation of in_state.vehicle_list[] failed
_init_failed = true ; // this keeps us from constantly trying to init forever in main update
gcs ( ) . send_text ( MAV_SEVERITY_INFO , " ADSB: Unable to initialize ADSB vehicle list " ) ;
return ;
2020-10-06 08:22:16 -03:00
}
2020-10-28 10:44:49 -03:00
in_state . list_size_allocated = in_state . list_size_param ;
2015-11-19 14:21:00 -04:00
}
2020-10-21 15:37:08 -03:00
2020-11-05 20:24:47 -04:00
if ( detected_num_instances = = 0 ) {
for ( uint8_t i = 0 ; i < ADSB_MAX_INSTANCES ; i + + ) {
detect_instance ( i ) ;
2020-12-07 21:43:44 -04:00
if ( _backend [ i ] = = nullptr ) {
continue ;
2020-11-05 20:24:47 -04:00
}
2020-12-07 21:43:44 -04:00
if ( ! _backend [ i ] - > init ( ) ) {
delete _backend [ i ] ;
_backend [ i ] = nullptr ;
continue ;
}
// success
detected_num_instances = i + 1 ;
2020-10-21 15:37:08 -03:00
}
}
2020-11-05 20:24:47 -04:00
if ( detected_num_instances = = 0 ) {
_init_failed = true ;
gcs ( ) . send_text ( MAV_SEVERITY_CRITICAL , " ADSB: Unable to initialize ADSB driver " ) ;
}
2015-11-19 14:21:00 -04:00
}
2020-11-25 21:54:01 -04:00
bool AP_ADSB : : check_startup ( )
2015-11-19 14:21:00 -04:00
{
2020-11-25 21:54:01 -04:00
if ( _init_failed ) {
return false ;
2020-11-05 20:24:47 -04:00
}
2015-11-19 14:21:00 -04:00
2020-11-05 20:24:47 -04:00
bool all_backends_disabled = true ;
for ( uint8_t instance = 0 ; instance < ADSB_MAX_INSTANCES ; instance + + ) {
if ( _type [ instance ] > 0 ) {
all_backends_disabled = false ;
break ;
}
}
2020-11-25 21:54:01 -04:00
if ( all_backends_disabled ) {
2020-10-28 10:44:49 -03:00
// nothing to do
return false ;
}
if ( in_state . vehicle_list = = nullptr ) {
init ( ) ;
}
return in_state . vehicle_list ! = nullptr ;
}
2020-11-05 20:24:47 -04:00
// detect if an instance of an ADSB sensor is connected.
void AP_ADSB : : detect_instance ( uint8_t instance )
{
switch ( get_type ( instance ) ) {
case Type : : None :
return ;
2020-12-07 21:43:44 -04:00
2020-11-05 20:24:47 -04:00
case Type : : uAvionix_MAVLink :
2021-07-27 19:48:53 -03:00
# if HAL_ADSB_UAVIONIX_MAVLINK_ENABLED
2020-11-05 20:24:47 -04:00
if ( AP_ADSB_uAvionix_MAVLink : : detect ( ) ) {
_backend [ instance ] = new AP_ADSB_uAvionix_MAVLink ( * this , instance ) ;
return ;
}
2021-07-27 19:48:53 -03:00
# endif
break ;
case Type : : uAvionix_UCP :
# if HAL_ADSB_UCP_ENABLED
if ( AP_ADSB_uAvionix_UCP : : detect ( ) ) {
_backend [ instance ] = new AP_ADSB_uAvionix_UCP ( * this , instance ) ;
return ;
}
# endif
2020-11-05 20:24:47 -04:00
break ;
2020-12-07 21:43:44 -04:00
case Type : : Sagetech :
2021-07-27 19:48:53 -03:00
# if HAL_ADSB_SAGETECH_ENABLED
2020-12-07 21:43:44 -04:00
if ( AP_ADSB_Sagetech : : detect ( ) ) {
_backend [ instance ] = new AP_ADSB_Sagetech ( * this , instance ) ;
return ;
}
2021-07-27 19:48:53 -03:00
# endif
2020-12-07 21:43:44 -04:00
break ;
2020-11-05 20:24:47 -04:00
}
}
// get instance type from instance
AP_ADSB : : Type AP_ADSB : : get_type ( uint8_t instance ) const
{
if ( instance < ADSB_MAX_INSTANCES ) {
return ( Type ) ( _type [ instance ] . get ( ) ) ;
}
return Type : : None ;
}
2020-10-06 08:22:16 -03:00
bool AP_ADSB : : is_valid_callsign ( uint16_t octal )
{
// treat "octal" as decimal and test if any decimal digit is > 7
if ( octal > 7777 ) {
return false ;
}
while ( octal ! = 0 ) {
if ( octal % 10 > 7 ) {
return false ;
}
octal / = 10 ;
}
return true ;
}
2015-11-19 14:21:00 -04:00
/*
* periodic update to handle vehicle timeouts and trigger collision detection
*/
void AP_ADSB : : update ( void )
{
2020-10-28 10:44:49 -03:00
if ( ! check_startup ( ) ) {
2016-06-25 11:05:17 -03:00
return ;
2015-11-19 14:21:00 -04:00
}
2019-02-17 11:43:49 -04:00
const uint32_t now = AP_HAL : : millis ( ) ;
2016-07-10 20:20:25 -03:00
2020-10-28 10:44:49 -03:00
if ( ! AP : : ahrs ( ) . get_position ( _my_loc ) ) {
_my_loc . zero ( ) ;
}
2016-07-10 20:20:25 -03:00
// check current list for vehicles that time out
2015-11-19 14:21:00 -04:00
uint16_t index = 0 ;
2016-07-10 20:20:25 -03:00
while ( index < in_state . vehicle_count ) {
2015-11-19 14:21:00 -04:00
// check list and drop stale vehicles. When disabled, the list will get flushed
2016-07-10 20:20:25 -03:00
if ( now - in_state . vehicle_list [ index ] . last_update_ms > VEHICLE_TIMEOUT_MS ) {
2015-11-27 00:54:41 -04:00
// don't increment index, we want to check this same index again because the contents changed
2015-11-19 14:21:00 -04:00
// also, if we're disabled then clear the list
delete_vehicle ( index ) ;
} else {
index + + ;
}
}
2018-05-22 14:33:53 -03:00
if ( out_state . cfg . squawk_octal_param ! = out_state . cfg . squawk_octal ) {
// param changed, check that it's a valid octal
2019-09-26 00:22:55 -03:00
if ( ! is_valid_callsign ( out_state . cfg . squawk_octal_param ) ) {
2018-05-22 14:33:53 -03:00
// invalid, reset it to default
2020-10-06 08:22:16 -03:00
out_state . cfg . squawk_octal_param = ADSB_SQUAWK_OCTAL_DEFAULT ;
2018-05-22 14:33:53 -03:00
}
out_state . cfg . squawk_octal = ( uint16_t ) out_state . cfg . squawk_octal_param ;
}
2016-07-10 20:53:19 -03:00
// ensure it's positive 24bit but allow -1
2016-07-11 23:08:02 -03:00
if ( out_state . cfg . ICAO_id_param < = - 1 | | out_state . cfg . ICAO_id_param > 0x00FFFFFF ) {
2016-07-10 20:53:19 -03:00
// icao param of -1 means static information is not sent, transceiver is assumed pre-programmed.
// reset timer constantly so it never reaches 10s so it never sends
out_state . last_config_ms = now ;
2020-10-28 10:44:49 -03:00
} else if ( ( out_state . cfg . rfSelect & UAVIONIX_ADSB_OUT_RF_SELECT_TX_ENABLED ) & &
( out_state . cfg . ICAO_id = = 0 | | out_state . cfg . ICAO_id_param_prev ! = out_state . cfg . ICAO_id_param ) ) {
2016-07-10 20:53:19 -03:00
2016-07-11 23:08:02 -03:00
// if param changed then regenerate. This allows the param to be changed back to zero to trigger a re-generate
if ( out_state . cfg . ICAO_id_param = = 0 ) {
out_state . cfg . ICAO_id = genICAO ( _my_loc ) ;
} else {
out_state . cfg . ICAO_id = out_state . cfg . ICAO_id_param ;
}
2016-07-10 20:53:19 -03:00
out_state . cfg . ICAO_id_param_prev = out_state . cfg . ICAO_id_param ;
2020-10-28 10:44:49 -03:00
# ifndef ADSB_STATIC_CALLSIGN
if ( ! out_state . cfg . was_set_externally ) {
set_callsign ( " PING " , true ) ;
}
# endif
2020-10-06 08:22:16 -03:00
gcs ( ) . send_text ( MAV_SEVERITY_INFO , " ADSB: Using ICAO_id %d and Callsign %s " , ( int ) out_state . cfg . ICAO_id , out_state . cfg . callsign ) ;
2016-07-10 20:53:19 -03:00
out_state . last_config_ms = 0 ; // send now
}
2020-11-05 20:24:47 -04:00
for ( uint8_t i = 0 ; i < detected_num_instances ; i + + ) {
2020-11-25 21:54:01 -04:00
if ( _backend [ i ] ! = nullptr & & _type [ i ] . get ( ) ! = ( int8_t ) Type : : None ) {
2020-11-05 20:24:47 -04:00
_backend [ i ] - > update ( ) ;
}
2020-11-04 02:51:22 -04:00
}
2020-11-05 20:24:47 -04:00
2015-11-19 14:21:00 -04:00
}
/*
2016-08-01 19:19:48 -03:00
* determine index and distance of furthest vehicle . This is
* used to bump it off when a new closer aircraft is detected
2015-11-19 14:21:00 -04:00
*/
2016-08-01 19:19:48 -03:00
void AP_ADSB : : determine_furthest_aircraft ( void )
2015-11-19 14:21:00 -04:00
{
2015-11-23 17:54:16 -04:00
float max_distance = 0 ;
uint16_t max_distance_index = 0 ;
2016-07-10 20:20:25 -03:00
for ( uint16_t index = 0 ; index < in_state . vehicle_count ; index + + ) {
2019-02-17 11:44:28 -04:00
if ( is_special_vehicle ( in_state . vehicle_list [ index ] . info . ICAO_address ) ) {
continue ;
}
2019-02-17 11:43:49 -04:00
const float distance = _my_loc . get_distance ( get_location ( in_state . vehicle_list [ index ] ) ) ;
2015-11-23 17:54:16 -04:00
if ( max_distance < distance | | index = = 0 ) {
max_distance = distance ;
max_distance_index = index ;
}
} // for index
2020-10-28 10:44:49 -03:00
in_state . furthest_vehicle_index = max_distance_index ;
in_state . furthest_vehicle_distance = max_distance ;
2015-11-19 14:21:00 -04:00
}
/*
* Convert / Extract a Location from a vehicle
*/
2019-01-01 23:11:27 -04:00
Location AP_ADSB : : get_location ( const adsb_vehicle_t & vehicle ) const
2015-11-19 14:21:00 -04:00
{
2019-02-17 11:43:49 -04:00
const Location loc = Location (
2016-07-12 17:22:28 -03:00
vehicle . info . lat ,
vehicle . info . lon ,
vehicle . info . altitude * 0.1f ,
2019-03-14 22:45:26 -03:00
Location : : AltFrame : : ABSOLUTE ) ;
2016-07-12 17:22:28 -03:00
2015-11-19 14:21:00 -04:00
return loc ;
}
/*
* delete a vehicle by copying last vehicle to
* current index then decrementing count
*/
2016-07-12 17:22:28 -03:00
void AP_ADSB : : delete_vehicle ( const uint16_t index )
2015-11-19 14:21:00 -04:00
{
2019-02-17 11:43:49 -04:00
if ( index > = in_state . vehicle_count ) {
// index out of range
return ;
2015-11-19 14:21:00 -04:00
}
2019-02-17 11:43:49 -04:00
// if the vehicle is the furthest, invalidate it. It has been bumped
2020-10-28 10:44:49 -03:00
if ( index = = in_state . furthest_vehicle_index & & in_state . furthest_vehicle_distance > 0 ) {
in_state . furthest_vehicle_distance = 0 ;
in_state . furthest_vehicle_index = 0 ;
2019-02-17 11:43:49 -04:00
}
if ( index ! = ( in_state . vehicle_count - 1 ) ) {
in_state . vehicle_list [ index ] = in_state . vehicle_list [ in_state . vehicle_count - 1 ] ;
}
// TODO: is memset needed? When we decrement the index we essentially forget about it
memset ( & in_state . vehicle_list [ in_state . vehicle_count - 1 ] , 0 , sizeof ( adsb_vehicle_t ) ) ;
in_state . vehicle_count - - ;
2015-11-19 14:21:00 -04:00
}
/*
* Search _vehicle_list for the given vehicle . A match
* depends on ICAO_address . Returns true if match found
* and index is populated . otherwise , return false .
*/
bool AP_ADSB : : find_index ( const adsb_vehicle_t & vehicle , uint16_t * index ) const
{
2016-07-10 20:20:25 -03:00
for ( uint16_t i = 0 ; i < in_state . vehicle_count ; i + + ) {
if ( in_state . vehicle_list [ i ] . info . ICAO_address = = vehicle . info . ICAO_address ) {
2015-11-19 14:21:00 -04:00
* index = i ;
return true ;
}
}
return false ;
}
/*
* Update the vehicle list . If the vehicle is already in the
* list then it will update it , otherwise it will be added .
*/
2019-10-02 07:54:35 -03:00
void AP_ADSB : : handle_adsb_vehicle ( const adsb_vehicle_t & vehicle )
2015-11-19 14:21:00 -04:00
{
2020-10-28 10:44:49 -03:00
if ( ! check_startup ( ) ) {
2015-11-19 14:21:00 -04:00
return ;
}
2020-10-28 10:44:49 -03:00
uint16_t index = in_state . list_size_allocated + 1 ; // initialize with invalid index
2019-01-01 23:11:27 -04:00
const Location vehicle_loc = AP_ADSB : : get_location ( vehicle ) ;
2019-02-17 11:43:49 -04:00
const bool my_loc_is_zero = _my_loc . is_zero ( ) ;
const float my_loc_distance_to_vehicle = _my_loc . get_distance ( vehicle_loc ) ;
2019-02-17 11:44:28 -04:00
const bool is_special = is_special_vehicle ( vehicle . info . ICAO_address ) ;
const bool out_of_range = in_state . list_radius > 0 & & ! my_loc_is_zero & & my_loc_distance_to_vehicle > in_state . list_radius & & ! is_special ;
const bool out_of_range_alt = in_state . list_altitude > 0 & & ! my_loc_is_zero & & abs ( vehicle_loc . alt - _my_loc . alt ) > in_state . list_altitude * 100 & & ! is_special ;
2019-02-17 11:43:49 -04:00
const bool is_tracked_in_list = find_index ( vehicle , & index ) ;
const uint32_t now = AP_HAL : : millis ( ) ;
2016-08-01 16:43:47 -03:00
2016-08-01 16:44:20 -03:00
const uint16_t required_flags_position = ADSB_FLAGS_VALID_COORDS | ADSB_FLAGS_VALID_ALTITUDE ;
2016-08-16 22:49:48 -03:00
const bool detected_ourself = ( out_state . cfg . ICAO_id ! = 0 ) & & ( ( uint32_t ) out_state . cfg . ICAO_id = = vehicle . info . ICAO_address ) ;
2016-08-01 16:44:20 -03:00
if ( vehicle_loc . is_zero ( ) | |
out_of_range | |
2018-07-10 11:21:16 -03:00
out_of_range_alt | |
2016-08-16 21:29:34 -03:00
detected_ourself | |
2016-08-16 22:49:48 -03:00
( vehicle . info . ICAO_address > 0x00FFFFFF ) | | // ICAO address is 24bits, so ignore higher values.
2016-08-01 16:44:20 -03:00
! ( vehicle . info . flags & required_flags_position ) | |
now - vehicle . last_update_ms > VEHICLE_TIMEOUT_MS ) {
2016-07-12 17:27:59 -03:00
2016-07-25 14:03:48 -03:00
// vehicle is out of range or invalid lat/lng. If we're tracking it, delete from list. Otherwise ignore it.
if ( is_tracked_in_list ) {
delete_vehicle ( index ) ;
}
2016-07-10 20:51:37 -03:00
return ;
2016-07-25 14:03:48 -03:00
} else if ( is_tracked_in_list ) {
2015-11-23 17:54:16 -04:00
2015-11-19 14:21:00 -04:00
// found, update it
set_vehicle ( index , vehicle ) ;
2015-11-23 17:54:16 -04:00
2020-10-28 10:44:49 -03:00
} else if ( in_state . vehicle_count < in_state . list_size_allocated ) {
2015-11-23 17:54:16 -04:00
// not found and there's room, add it to the end of the list
2016-07-10 20:20:25 -03:00
set_vehicle ( in_state . vehicle_count , vehicle ) ;
in_state . vehicle_count + + ;
2015-11-23 17:54:16 -04:00
2016-08-01 19:19:48 -03:00
} else {
// buffer is full. if new vehicle is closer than furthest, replace furthest with new
2015-11-23 17:54:16 -04:00
2016-08-01 19:19:48 -03:00
if ( my_loc_is_zero ) {
// nothing else to do
2020-10-28 10:44:49 -03:00
in_state . furthest_vehicle_distance = 0 ;
in_state . furthest_vehicle_index = 0 ;
2015-11-23 17:54:16 -04:00
2016-08-01 19:19:48 -03:00
} else {
2020-10-28 10:44:49 -03:00
if ( in_state . furthest_vehicle_distance < = 0 ) {
2016-08-01 19:19:48 -03:00
// ensure this is populated
determine_furthest_aircraft ( ) ;
}
2020-10-28 10:44:49 -03:00
if ( my_loc_distance_to_vehicle < in_state . furthest_vehicle_distance ) { // is closer than the furthest
2016-08-01 19:19:48 -03:00
// replace with the furthest vehicle
2020-10-28 10:44:49 -03:00
set_vehicle ( in_state . furthest_vehicle_index , vehicle ) ;
2016-08-01 19:19:48 -03:00
2020-10-28 10:44:49 -03:00
// in_state.furthest_vehicle_index is now invalid because the vehicle was overwritten, need
2016-08-01 19:19:48 -03:00
// to run determine_furthest_aircraft() to determine a new one next time
2020-10-28 10:44:49 -03:00
in_state . furthest_vehicle_distance = 0 ;
in_state . furthest_vehicle_index = 0 ;
2016-08-01 19:19:48 -03:00
}
2016-07-25 14:03:48 -03:00
}
2015-11-23 17:54:16 -04:00
} // if buffer full
2016-07-22 01:52:29 -03:00
2016-08-01 16:47:18 -03:00
const uint16_t required_flags_avoidance =
ADSB_FLAGS_VALID_COORDS |
ADSB_FLAGS_VALID_ALTITUDE |
ADSB_FLAGS_VALID_HEADING |
ADSB_FLAGS_VALID_VELOCITY ;
if ( vehicle . info . flags & required_flags_avoidance ) {
push_sample ( vehicle ) ; // note that set_vehicle modifies vehicle
}
2015-11-19 14:21:00 -04:00
}
/*
* Copy a vehicle ' s data into the list
*/
2016-07-12 17:22:28 -03:00
void AP_ADSB : : set_vehicle ( const uint16_t index , const adsb_vehicle_t & vehicle )
2015-11-19 14:21:00 -04:00
{
2020-10-28 10:44:49 -03:00
if ( index > = in_state . list_size_allocated ) {
2019-02-17 11:43:49 -04:00
// out of range
return ;
2015-11-19 14:21:00 -04:00
}
2020-10-06 08:22:16 -03:00
in_state . vehicle_list [ index ] = vehicle ;
2019-02-23 15:30:49 -04:00
write_log ( vehicle ) ;
2015-11-19 14:21:00 -04:00
}
2016-07-12 17:22:28 -03:00
void AP_ADSB : : send_adsb_vehicle ( const mavlink_channel_t chan )
2016-06-15 17:56:25 -03:00
{
2020-10-28 10:44:49 -03:00
if ( ! check_startup ( ) | | in_state . vehicle_count = = 0 ) {
2016-06-15 17:56:25 -03:00
return ;
}
uint32_t now = AP_HAL : : millis ( ) ;
2016-07-10 20:20:25 -03:00
if ( in_state . send_index [ chan ] > = in_state . vehicle_count ) {
2016-06-15 17:56:25 -03:00
// we've finished a list
2016-07-10 20:20:25 -03:00
if ( now - in_state . send_start_ms [ chan ] < 1000 ) {
2016-06-15 17:56:25 -03:00
// too soon to start a new one
return ;
} else {
// start new list
2016-07-10 20:20:25 -03:00
in_state . send_start_ms [ chan ] = now ;
in_state . send_index [ chan ] = 0 ;
2016-06-15 17:56:25 -03:00
}
}
2016-07-10 20:20:25 -03:00
if ( in_state . send_index [ chan ] < in_state . vehicle_count ) {
mavlink_adsb_vehicle_t vehicle = in_state . vehicle_list [ in_state . send_index [ chan ] ] . info ;
in_state . send_index [ chan ] + + ;
2016-06-15 17:56:25 -03:00
mavlink_msg_adsb_vehicle_send ( chan ,
vehicle . ICAO_address ,
vehicle . lat ,
vehicle . lon ,
vehicle . altitude_type ,
vehicle . altitude ,
vehicle . heading ,
vehicle . hor_velocity ,
vehicle . ver_velocity ,
vehicle . callsign ,
vehicle . emitter_type ,
vehicle . tslc ,
vehicle . flags ,
vehicle . squawk ) ;
}
}
2020-10-06 08:22:16 -03:00
/*
* handle incoming packet UAVIONIX_ADSB_OUT_CFG .
* This allows a GCS to send cfg info through the autopilot to the ADSB hardware .
* This is done indirectly by reading and storing the packet and then another mechanism sends it out periodically
*/
2020-10-28 10:44:49 -03:00
void AP_ADSB : : handle_out_cfg ( const mavlink_uavionix_adsb_out_cfg_t & packet )
2020-10-06 08:22:16 -03:00
{
out_state . cfg . was_set_externally = true ;
out_state . cfg . ICAO_id = packet . ICAO ;
out_state . cfg . ICAO_id_param = out_state . cfg . ICAO_id_param_prev = packet . ICAO & 0x00FFFFFFFF ;
// May contain a non-null value at the end so accept it as-is with memcpy instead of strcpy
memcpy ( out_state . cfg . callsign , packet . callsign , sizeof ( out_state . cfg . callsign ) ) ;
out_state . cfg . emitterType = packet . emitterType ;
out_state . cfg . lengthWidth = packet . aircraftSize ;
2020-10-28 10:44:49 -03:00
out_state . cfg . gpsOffsetLat = packet . gpsOffsetLat ;
out_state . cfg . gpsOffsetLon = packet . gpsOffsetLon ;
2020-10-06 08:22:16 -03:00
out_state . cfg . rfSelect = packet . rfSelect ;
out_state . cfg . stall_speed_cm = packet . stallSpeed ;
// guard against string with non-null end char
const char c = out_state . cfg . callsign [ MAVLINK_MSG_UAVIONIX_ADSB_OUT_CFG_FIELD_CALLSIGN_LEN - 1 ] ;
out_state . cfg . callsign [ MAVLINK_MSG_UAVIONIX_ADSB_OUT_CFG_FIELD_CALLSIGN_LEN - 1 ] = 0 ;
gcs ( ) . send_text ( MAV_SEVERITY_INFO , " ADSB: Using ICAO_id %d and Callsign %s " , ( int ) out_state . cfg . ICAO_id , out_state . cfg . callsign ) ;
out_state . cfg . callsign [ MAVLINK_MSG_UAVIONIX_ADSB_OUT_CFG_FIELD_CALLSIGN_LEN - 1 ] = c ;
// send now
out_state . last_config_ms = 0 ;
}
2021-10-13 20:31:14 -03:00
/*
* handle incoming packet UAVIONIX_ADSB_OUT_CONTROL
* allows a GCS to set the contents of the control message sent by ardupilot to the transponder
*/
void AP_ADSB : : handle_out_control ( const mavlink_uavionix_adsb_out_control_t & packet )
{
out_state . ctrl . baroCrossChecked = packet . state & UAVIONIX_ADSB_OUT_CONTROL_STATE : : UAVIONIX_ADSB_OUT_CONTROL_STATE_EXTERNAL_BARO_CROSSCHECKED ;
out_state . ctrl . airGroundState = packet . state & UAVIONIX_ADSB_OUT_CONTROL_STATE : : UAVIONIX_ADSB_OUT_CONTROL_STATE_ON_GROUND ;
out_state . ctrl . identActive = packet . state & UAVIONIX_ADSB_OUT_CONTROL_STATE : : UAVIONIX_ADSB_OUT_CONTROL_STATE_IDENT_BUTTON_ACTIVE ;
out_state . ctrl . modeAEnabled = packet . state & UAVIONIX_ADSB_OUT_CONTROL_STATE : : UAVIONIX_ADSB_OUT_CONTROL_STATE_MODE_A_ENABLED ;
out_state . ctrl . modeCEnabled = packet . state & UAVIONIX_ADSB_OUT_CONTROL_STATE : : UAVIONIX_ADSB_OUT_CONTROL_STATE_MODE_C_ENABLED ;
out_state . ctrl . modeSEnabled = packet . state & UAVIONIX_ADSB_OUT_CONTROL_STATE : : UAVIONIX_ADSB_OUT_CONTROL_STATE_MODE_S_ENABLED ;
out_state . ctrl . es1090TxEnabled = packet . state & UAVIONIX_ADSB_OUT_CONTROL_STATE : : UAVIONIX_ADSB_OUT_CONTROL_STATE_1090ES_TX_ENABLED ;
out_state . ctrl . externalBaroAltitude_mm = packet . baroAltMSL ;
out_state . ctrl . squawkCode = packet . squawk ;
out_state . ctrl . emergencyState = packet . emergencyStatus ;
memcpy ( out_state . ctrl . callsign , packet . flight_id , sizeof ( out_state . ctrl . callsign ) ) ;
out_state . ctrl . x_bit = packet . x_bit ;
}
2020-10-06 08:22:16 -03:00
/*
* this is a message from the transceiver reporting it ' s health . Using this packet
* we determine which channel is on so we don ' t have to send out_state to all channels
*/
2020-10-28 10:44:49 -03:00
void AP_ADSB : : handle_transceiver_report ( const mavlink_channel_t chan , const mavlink_uavionix_adsb_transceiver_health_report_t & packet )
2020-10-06 08:22:16 -03:00
{
if ( out_state . chan ! = chan ) {
gcs ( ) . send_text ( MAV_SEVERITY_DEBUG , " ADSB: Found transceiver on channel %d " , chan ) ;
}
out_state . chan_last_ms = AP_HAL : : millis ( ) ;
out_state . chan = chan ;
out_state . status = ( UAVIONIX_ADSB_RF_HEALTH ) packet . rfHealth ;
}
2016-07-10 20:53:19 -03:00
2021-10-13 20:31:14 -03:00
/*
* send a periodic report of the ADSB out status
*/
void AP_ADSB : : send_adsb_out_status ( const mavlink_channel_t chan ) const
{
for ( uint8_t i = 0 ; i < ADSB_MAX_INSTANCES ; i + + ) {
if ( _type [ i ] = = ( int8_t ) ( AP_ADSB : : Type : : uAvionix_UCP ) ) {
mavlink_msg_uavionix_adsb_out_status_send_struct ( chan , & out_state . tx_status ) ;
return ;
}
}
}
2016-07-10 20:53:19 -03:00
/*
@ brief Generates pseudorandom ICAO from gps time , lat , and lon .
Reference : DO282B , 2.2 .4 .5 .1 .3 .2
*/
2020-10-28 10:44:49 -03:00
uint32_t AP_ADSB : : genICAO ( const Location & loc ) const
2016-07-10 20:53:19 -03:00
{
2020-10-28 10:44:49 -03:00
// gps_time is used as a pseudo-random number instead of seconds since UTC midnight
2016-07-10 20:53:19 -03:00
// TODO: use UTC time instead of GPS time
2017-12-01 19:44:56 -04:00
const AP_GPS & gps = AP : : gps ( ) ;
2016-07-10 20:53:19 -03:00
const uint64_t gps_time = gps . time_epoch_usec ( ) ;
uint32_t timeSum = 0 ;
2019-02-17 11:43:49 -04:00
const uint32_t M3 = 4096 * ( loc . lat & 0x00000FFF ) + ( loc . lng & 0x00000FFF ) ;
2016-07-10 20:53:19 -03:00
for ( uint8_t i = 0 ; i < 24 ; i + + ) {
timeSum + = ( ( ( gps_time & 0x00FFFFFF ) > > i ) & 0x00000001 ) ;
}
return ( ( timeSum ^ M3 ) & 0x00FFFFFF ) ;
}
// assign a string to out_state.cfg.callsign but ensure it's null terminated
2016-07-12 17:22:28 -03:00
void AP_ADSB : : set_callsign ( const char * str , const bool append_icao )
2016-07-10 20:53:19 -03:00
{
bool zero_char_pad = false ;
// clean slate
memset ( out_state . cfg . callsign , 0 , sizeof ( out_state . cfg . callsign ) ) ;
// copy str to cfg.callsign but we can't use strncpy because we need
2016-07-21 03:19:11 -03:00
// to restrict values to only 'A' - 'Z' and '0' - '9' and pad
2016-07-10 20:53:19 -03:00
for ( uint8_t i = 0 ; i < sizeof ( out_state . cfg . callsign ) - 1 ; i + + ) {
if ( ! str [ i ] | | zero_char_pad ) {
// finish early. Either pad the rest with zero char or null terminate and call it a day
if ( ( append_icao & & i < 4 ) | | zero_char_pad ) {
out_state . cfg . callsign [ i ] = ' 0 ' ;
zero_char_pad = true ;
} else {
// already null terminated via memset so just stop
break ;
}
} else if ( ( ' A ' < = str [ i ] & & str [ i ] < = ' Z ' ) | |
( ' 0 ' < = str [ i ] & & str [ i ] < = ' 9 ' ) ) {
// valid as-is
// spaces are also allowed but are handled in the last else
out_state . cfg . callsign [ i ] = str [ i ] ;
} else if ( ' a ' < = str [ i ] & & str [ i ] < = ' z ' ) {
// toupper()
out_state . cfg . callsign [ i ] = str [ i ] - ( ' a ' - ' A ' ) ;
} else if ( i = = 0 ) {
// invalid, pad to char zero because first index can't be space
out_state . cfg . callsign [ i ] = ' 0 ' ;
} else {
// invalid, pad with space
out_state . cfg . callsign [ i ] = ' ' ;
}
} // for i
if ( append_icao ) {
2020-11-10 11:38:58 -04:00
hal . util - > snprintf ( & out_state . cfg . callsign [ 4 ] , 5 , " %04X " , unsigned ( out_state . cfg . ICAO_id % 0x10000 ) ) ;
2016-07-10 20:53:19 -03:00
}
}
2016-07-22 01:52:29 -03:00
2019-10-02 07:54:35 -03:00
void AP_ADSB : : push_sample ( const adsb_vehicle_t & vehicle )
2016-07-22 01:52:29 -03:00
{
2020-10-28 10:44:49 -03:00
_samples . push ( vehicle ) ;
2016-07-22 01:52:29 -03:00
}
bool AP_ADSB : : next_sample ( adsb_vehicle_t & vehicle )
{
2020-10-28 10:44:49 -03:00
return _samples . pop ( vehicle ) ;
2016-07-22 01:52:29 -03:00
}
2016-08-16 20:18:58 -03:00
2019-04-30 07:22:47 -03:00
void AP_ADSB : : handle_message ( const mavlink_channel_t chan , const mavlink_message_t & msg )
2016-08-16 20:18:58 -03:00
{
2019-04-30 07:22:47 -03:00
switch ( msg . msgid ) {
2021-10-13 20:31:14 -03:00
case MAVLINK_MSG_ID_ADSB_VEHICLE : {
adsb_vehicle_t vehicle { } ;
mavlink_msg_adsb_vehicle_decode ( & msg , & vehicle . info ) ;
vehicle . last_update_ms = AP_HAL : : millis ( ) - uint32_t ( vehicle . info . tslc * 1000U ) ;
handle_adsb_vehicle ( vehicle ) ;
break ;
}
2020-10-28 10:44:49 -03:00
2021-10-13 20:31:14 -03:00
case MAVLINK_MSG_ID_UAVIONIX_ADSB_TRANSCEIVER_HEALTH_REPORT : {
mavlink_uavionix_adsb_transceiver_health_report_t packet { } ;
mavlink_msg_uavionix_adsb_transceiver_health_report_decode ( & msg , & packet ) ;
handle_transceiver_report ( chan , packet ) ;
break ;
}
2016-08-16 20:18:58 -03:00
2021-10-13 20:31:14 -03:00
case MAVLINK_MSG_ID_UAVIONIX_ADSB_OUT_CFG : {
mavlink_uavionix_adsb_out_cfg_t packet { } ;
mavlink_msg_uavionix_adsb_out_cfg_decode ( & msg , & packet ) ;
handle_out_cfg ( packet ) ;
break ;
}
2018-05-22 14:33:53 -03:00
2021-10-13 20:31:14 -03:00
case MAVLINK_MSG_ID_UAVIONIX_ADSB_OUT_DYNAMIC :
// unhandled, this is an outbound packet only
break ;
case MAVLINK_MSG_ID_UAVIONIX_ADSB_OUT_CONTROL : {
mavlink_uavionix_adsb_out_control_t packet { } ;
mavlink_msg_uavionix_adsb_out_control_decode ( & msg , & packet ) ;
handle_out_control ( packet ) ;
break ;
}
2016-08-16 20:18:58 -03:00
}
}
2019-02-17 01:43:27 -04:00
// If that ICAO is found in the database then return true with a fully populated vehicle
bool AP_ADSB : : get_vehicle_by_ICAO ( const uint32_t icao , adsb_vehicle_t & vehicle ) const
{
adsb_vehicle_t temp_vehicle ;
temp_vehicle . info . ICAO_address = icao ;
uint16_t i ;
if ( find_index ( temp_vehicle , & i ) ) {
// vehicle is tracked in list.
// we must memcpy it because the database may reorganize itself and we don't
// want the reference to magically start pointing at a different vehicle
memcpy ( & vehicle , & in_state . vehicle_list [ i ] , sizeof ( adsb_vehicle_t ) ) ;
return true ;
}
return false ;
}
2019-02-23 15:30:49 -04:00
/*
2019-03-28 15:17:27 -03:00
* Write vehicle to log
2019-02-23 15:30:49 -04:00
*/
2020-10-28 10:44:49 -03:00
void AP_ADSB : : write_log ( const adsb_vehicle_t & vehicle ) const
2019-02-23 15:30:49 -04:00
{
switch ( _log ) {
case logging : : SPECIAL_ONLY :
if ( ! is_special_vehicle ( vehicle . info . ICAO_address ) ) {
return ;
}
2020-01-09 02:05:50 -04:00
break ;
2019-02-23 15:30:49 -04:00
case logging : : ALL :
break ;
case logging : : NONE :
default :
return ;
}
struct log_ADSB pkt = {
LOG_PACKET_HEADER_INIT ( LOG_ADSB_MSG ) ,
time_us : AP_HAL : : micros64 ( ) ,
ICAO_address : vehicle . info . ICAO_address ,
lat : vehicle . info . lat ,
lng : vehicle . info . lon ,
alt : vehicle . info . altitude ,
heading : vehicle . info . heading ,
hor_velocity : vehicle . info . hor_velocity ,
ver_velocity : vehicle . info . ver_velocity ,
squawk : vehicle . info . squawk ,
} ;
AP : : logger ( ) . WriteBlock ( & pkt , sizeof ( pkt ) ) ;
}
2019-10-02 07:54:10 -03:00
AP_ADSB * AP : : ADSB ( )
{
return AP_ADSB : : get_singleton ( ) ;
}
2020-10-06 08:32:51 -03:00
# endif // HAL_ADSB_ENABLED