LCOV - code coverage report
Current view: top level - SITL - SIM_ADSB.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 1 1 100.0 %
Date: 2026-09-09 11:02:08 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :    This program is free software: you can redistribute it and/or modify
       3             :    it under the terms of the GNU General Public License as published by
       4             :    the Free Software Foundation, either version 3 of the License, or
       5             :    (at your option) any later version.
       6             : 
       7             :    This program is distributed in the hope that it will be useful,
       8             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
       9             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      10             :    GNU General Public License for more details.
      11             : 
      12             :    You should have received a copy of the GNU General Public License
      13             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      14             :  */
      15             : /*
      16             :   ADSB peripheral simulator class
      17             : */
      18             : 
      19             : #pragma once
      20             : 
      21             : #include "SIM_config.h"
      22             : 
      23             : #if AP_SIM_ADSB_ENABLED
      24             : 
      25             : #include <AP_HAL/utility/Socket_native.h>
      26             : 
      27             : #include "SIM_Aircraft.h"
      28             : 
      29             : namespace SITL {
      30             : 
      31             : /*
      32             :   a class for individual simulated vehicles
      33             : */
      34             : class ADSB_Vehicle {
      35             :     friend class ADSB;
      36             : 
      37             : public:
      38             :     bool initialised = false;
      39             : 
      40             :     const Location &get_location() const;  // return vehicle absolute location
      41             :     // return earth-frame vehicle velocity:
      42             :     bool velocity(Vector3F &ret) const { ret = velocity_ef; return true; }
      43             : 
      44             :     uint32_t ICAO_address;
      45             :     Vector3F velocity_ef; // NED
      46             :     char callsign[9];
      47             : 
      48             : private:
      49             :     void update(const class Aircraft &aircraft, float delta_t);
      50             : 
      51             :     Vector3p position; // NED from origin
      52             :     Location location;
      53             : 
      54             :     ADSB_EMITTER_TYPE type;
      55             :     uint64_t stationary_object_created_ms; // allows expiring of slow/stationary objects
      56             : 
      57             : };
      58             : 
      59             : class ADSB : public SerialDevice {
      60             : public:
      61         402 :     ADSB() {};
      62             :     void update(const class Aircraft &aircraft);
      63             : 
      64             :     uint8_t num_vehicles;
      65             :     static const uint8_t num_vehicles_MAX = 200;
      66             :     ADSB_Vehicle vehicles[num_vehicles_MAX];
      67             : 
      68             : private:
      69             :     void update_simulated_vehicles(const class Aircraft &aircraft);
      70             : 
      71             :     // reporting period in ms
      72             :     const float reporting_period_ms = 1000;
      73             :     uint32_t last_report_us;
      74             :     uint32_t last_update_us;
      75             :     uint32_t last_tx_report_ms;
      76             :     
      77             :     uint32_t last_heartbeat_ms;
      78             :     bool seen_heartbeat = false;
      79             :     uint8_t vehicle_system_id;
      80             :     uint8_t vehicle_component_id;
      81             : 
      82             :     struct {
      83             :         // socket to telem2 on aircraft
      84             :         mavlink_message_t rxmsg;
      85             :         mavlink_status_t status;
      86             :         uint8_t seq;
      87             :     } mavlink {};
      88             : 
      89             :     void send_report(const SITL::Aircraft&);
      90             : };
      91             : 
      92             : }  // namespace SITL
      93             : 
      94             : #endif  // AP_SIM_ADSB_ENABLED

Generated by: LCOV version 1.14