APM:Libraries
SIM_ADSB.h
Go to the documentation of this file.
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 <AP_HAL/utility/Socket.h>
22 
23 #include "SIM_Aircraft.h"
24 
25 namespace SITL {
26 
27 /*
28  a class for individual simulated vehicles
29 */
30 class ADSB_Vehicle {
31  friend class ADSB;
32 
33 private:
34  void update(float delta_t);
35 
36  Vector3f position; // NED from origin
38  char callsign[9];
39  uint32_t ICAO_address;
40  bool initialised = false;
41 };
42 
43 class ADSB {
44 public:
45  ADSB(const struct sitl_fdm &_fdm, const char *home_str);
46  void update(void);
47 
48 private:
49  const char *target_address = "127.0.0.1";
50  const uint16_t target_port = 5762;
51 
53  uint8_t num_vehicles = 0;
54  static const uint8_t num_vehicles_MAX = 200;
55  ADSB_Vehicle vehicles[num_vehicles_MAX];
56 
57  // reporting period in ms
58  const float reporting_period_ms = 1000;
59  uint32_t last_report_us = 0;
60  uint32_t last_update_us = 0;
61  uint32_t last_tx_report_ms = 0;
62 
63  uint32_t last_heartbeat_ms = 0;
64  bool seen_heartbeat = false;
67 
68  SocketAPM mav_socket { false };
69  struct {
70  // socket to telem2 on aircraft
71  bool connected;
72  mavlink_message_t rxmsg;
73  mavlink_status_t status;
74  uint8_t seq;
75  } mavlink {};
76 
77  void send_report(void);
78 };
79 
80 } // namespace SITL
friend class ADSB
Definition: SIM_ADSB.h:31
mavlink_status_t status
Definition: SIM_ADSB.h:73
char callsign[9]
Definition: SIM_ADSB.h:38
uint8_t seq
Definition: SIM_ADSB.h:74
Location home
Definition: SIM_ADSB.h:52
Vector3f position
Definition: SIM_ADSB.h:36
Vector3f velocity_ef
Definition: SIM_ADSB.h:37
bool connected
Definition: SIM_ADSB.h:71
void update(float delta_t)
Definition: SIM_ADSB.cpp:40
uint8_t vehicle_system_id
Definition: SIM_ADSB.h:65
uint8_t vehicle_component_id
Definition: SIM_ADSB.h:66
uint32_t ICAO_address
Definition: SIM_ADSB.h:39
mavlink_message_t rxmsg
Definition: SIM_ADSB.h:72