2015-11-18 21:20:01 -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/>.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
ADSB peripheral simulator class
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-10-11 01:59:19 -03:00
|
|
|
#include <AP_HAL/AP_HAL_Boards.h>
|
|
|
|
|
|
|
|
#ifndef HAL_SIM_ADSB_ENABLED
|
|
|
|
#define HAL_SIM_ADSB_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAL_SIM_ADSB_ENABLED
|
|
|
|
|
2015-11-18 21:20:01 -04:00
|
|
|
#include <AP_HAL/utility/Socket.h>
|
|
|
|
|
|
|
|
#include "SIM_Aircraft.h"
|
|
|
|
|
|
|
|
namespace SITL {
|
|
|
|
|
|
|
|
/*
|
|
|
|
a class for individual simulated vehicles
|
|
|
|
*/
|
|
|
|
class ADSB_Vehicle {
|
|
|
|
friend class ADSB;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void update(float delta_t);
|
|
|
|
|
|
|
|
Vector3f position; // NED from origin
|
|
|
|
Vector3f velocity_ef; // NED
|
|
|
|
char callsign[9];
|
|
|
|
uint32_t ICAO_address;
|
|
|
|
bool initialised = false;
|
2019-11-18 16:17:51 -04:00
|
|
|
ADSB_EMITTER_TYPE type;
|
2015-11-18 21:20:01 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
class ADSB {
|
|
|
|
public:
|
2021-10-19 22:13:07 -03:00
|
|
|
ADSB(const struct sitl_fdm &_fdm, const Location& _home, const uint8_t _instance) : home(_home), instance(_instance) {};
|
2015-11-18 21:20:01 -04:00
|
|
|
void update(void);
|
|
|
|
|
|
|
|
private:
|
|
|
|
const char *target_address = "127.0.0.1";
|
2021-10-19 22:13:07 -03:00
|
|
|
const uint16_t target_port_base = 5762;
|
|
|
|
|
|
|
|
const uint8_t instance = 0;
|
2015-11-18 21:20:01 -04:00
|
|
|
|
2019-10-24 13:10:49 -03:00
|
|
|
const Location& home;
|
2016-06-15 00:47:19 -03:00
|
|
|
uint8_t num_vehicles = 0;
|
|
|
|
static const uint8_t num_vehicles_MAX = 200;
|
|
|
|
ADSB_Vehicle vehicles[num_vehicles_MAX];
|
2015-11-18 21:20:01 -04:00
|
|
|
|
|
|
|
// reporting period in ms
|
2016-06-15 00:50:32 -03:00
|
|
|
const float reporting_period_ms = 1000;
|
2015-11-18 21:20:01 -04:00
|
|
|
uint32_t last_report_us = 0;
|
|
|
|
uint32_t last_update_us = 0;
|
2016-08-16 18:16:03 -03:00
|
|
|
uint32_t last_tx_report_ms = 0;
|
2015-11-18 21:20:01 -04:00
|
|
|
|
|
|
|
uint32_t last_heartbeat_ms = 0;
|
|
|
|
bool seen_heartbeat = false;
|
|
|
|
uint8_t vehicle_system_id;
|
|
|
|
uint8_t vehicle_component_id;
|
|
|
|
|
|
|
|
SocketAPM mav_socket { false };
|
|
|
|
struct {
|
|
|
|
// socket to telem2 on aircraft
|
|
|
|
bool connected;
|
|
|
|
mavlink_message_t rxmsg;
|
|
|
|
mavlink_status_t status;
|
|
|
|
uint8_t seq;
|
|
|
|
} mavlink {};
|
|
|
|
|
|
|
|
void send_report(void);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace SITL
|
2021-10-11 01:59:19 -03:00
|
|
|
|
|
|
|
#endif // HAL_SIM_ADSB_ENABLED
|