SIM_ADSB.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. */
  13. /*
  14. ADSB peripheral simulator class
  15. */
  16. #pragma once
  17. #include <AP_HAL/utility/Socket.h>
  18. #include "SIM_Aircraft.h"
  19. namespace SITL {
  20. /*
  21. a class for individual simulated vehicles
  22. */
  23. class ADSB_Vehicle {
  24. friend class ADSB;
  25. private:
  26. void update(float delta_t);
  27. Vector3f position; // NED from origin
  28. Vector3f velocity_ef; // NED
  29. char callsign[9];
  30. uint32_t ICAO_address;
  31. bool initialised = false;
  32. };
  33. class ADSB {
  34. public:
  35. ADSB(const struct sitl_fdm &_fdm, const char *home_str);
  36. void update(void);
  37. private:
  38. const char *target_address = "127.0.0.1";
  39. const uint16_t target_port = 5762;
  40. Location home;
  41. uint8_t num_vehicles = 0;
  42. static const uint8_t num_vehicles_MAX = 200;
  43. ADSB_Vehicle vehicles[num_vehicles_MAX];
  44. // reporting period in ms
  45. const float reporting_period_ms = 1000;
  46. uint32_t last_report_us = 0;
  47. uint32_t last_update_us = 0;
  48. uint32_t last_tx_report_ms = 0;
  49. uint32_t last_heartbeat_ms = 0;
  50. bool seen_heartbeat = false;
  51. uint8_t vehicle_system_id;
  52. uint8_t vehicle_component_id;
  53. SocketAPM mav_socket { false };
  54. struct {
  55. // socket to telem2 on aircraft
  56. bool connected;
  57. mavlink_message_t rxmsg;
  58. mavlink_status_t status;
  59. uint8_t seq;
  60. } mavlink {};
  61. void send_report(void);
  62. };
  63. } // namespace SITL