2016-02-17 21:25:28 -04:00
|
|
|
#pragma once
|
2012-12-18 21:13:01 -04:00
|
|
|
|
2015-08-11 03:28:43 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2015-05-04 03:15:12 -03:00
|
|
|
#include "AP_HAL_SITL_Namespace.h"
|
2018-08-07 03:39:42 -03:00
|
|
|
#include "AP_HAL_SITL.h"
|
2015-12-20 16:33:11 -04:00
|
|
|
#include "Semaphores.h"
|
2019-03-19 23:19:41 -03:00
|
|
|
#include "ToneAlarm_SF.h"
|
2024-04-06 13:12:19 -03:00
|
|
|
#include <AP_Logger/AP_Logger_config.h>
|
2012-12-18 21:13:01 -04:00
|
|
|
|
2019-04-01 05:39:16 -03:00
|
|
|
#if !defined(__CYGWIN__) && !defined(__CYGWIN64__)
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#endif
|
|
|
|
|
2016-01-10 02:23:32 -04:00
|
|
|
class HALSITL::Util : public AP_HAL::Util {
|
2012-12-18 21:13:01 -04:00
|
|
|
public:
|
2016-01-10 02:23:32 -04:00
|
|
|
Util(SITL_State *_sitlState) :
|
2016-01-06 18:09:40 -04:00
|
|
|
sitlState(_sitlState) {}
|
|
|
|
|
2015-11-05 00:41:46 -04:00
|
|
|
/**
|
|
|
|
how much free memory do we have in bytes.
|
|
|
|
*/
|
|
|
|
uint32_t available_memory(void) override {
|
2024-11-17 00:56:45 -04:00
|
|
|
// SITL is assumed to always have plenty of memory. Return 512k for now
|
|
|
|
return 512*1024;
|
2015-11-05 00:41:46 -04:00
|
|
|
}
|
2015-12-20 16:33:11 -04:00
|
|
|
|
2016-01-06 18:09:40 -04:00
|
|
|
// get path to custom defaults file for AP_Param
|
|
|
|
const char* get_custom_defaults_file() const override {
|
|
|
|
return sitlState->defaults_path;
|
|
|
|
}
|
2018-04-24 09:25:25 -03:00
|
|
|
|
2020-11-08 17:48:25 -04:00
|
|
|
/**
|
|
|
|
return commandline arguments, if available
|
|
|
|
*/
|
|
|
|
void commandline_arguments(uint8_t &argc, char * const *&argv) override;
|
|
|
|
|
2018-04-24 09:25:25 -03:00
|
|
|
uint64_t get_hw_rtc() const override;
|
2021-11-22 22:40:40 -04:00
|
|
|
void set_hw_rtc(uint64_t time_utc_usec) override { /* fail silently */ }
|
|
|
|
|
2018-04-24 09:25:25 -03:00
|
|
|
|
2022-09-18 14:04:23 -03:00
|
|
|
bool get_system_id(char buf[50]) override;
|
2018-11-16 17:32:38 -04:00
|
|
|
bool get_system_id_unformatted(uint8_t buf[], uint8_t &len) override;
|
2019-06-10 23:15:27 -03:00
|
|
|
void dump_stack_trace();
|
2018-12-08 22:34:54 -04:00
|
|
|
|
2019-03-19 23:19:41 -03:00
|
|
|
#ifdef WITH_SITL_TONEALARM
|
2021-04-28 17:50:09 -03:00
|
|
|
bool toneAlarm_init(uint8_t types) override { return _toneAlarm.init(); }
|
2019-03-19 23:19:41 -03:00
|
|
|
void toneAlarm_set_buzzer_tone(float frequency, float volume, uint32_t duration_ms) override {
|
|
|
|
_toneAlarm.set_buzzer_tone(frequency, volume, duration_ms);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-05-09 05:48:37 -03:00
|
|
|
// return true if the reason for the reboot was a watchdog reset
|
|
|
|
bool was_watchdog_reset() const override { return getenv("SITL_WATCHDOG_RESET") != nullptr; }
|
2019-11-25 03:02:11 -04:00
|
|
|
|
2020-09-12 16:04:38 -03:00
|
|
|
#if !defined(HAL_BUILD_AP_PERIPH)
|
2019-11-25 03:02:11 -04:00
|
|
|
enum safety_state safety_switch_state(void) override;
|
2020-09-12 15:58:10 -03:00
|
|
|
void set_cmdline_parameters() override;
|
2020-09-12 16:04:38 -03:00
|
|
|
#endif
|
2019-11-25 03:02:11 -04:00
|
|
|
|
2019-04-01 05:39:16 -03:00
|
|
|
bool trap() const override {
|
|
|
|
#if defined(__CYGWIN__) || defined(__CYGWIN64__)
|
|
|
|
return false;
|
|
|
|
#else
|
|
|
|
if (kill(0, SIGTRAP) == -1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-11-08 17:48:25 -04:00
|
|
|
void init(int argc, char *const *argv) {
|
|
|
|
saved_argc = argc;
|
|
|
|
saved_argv = argv;
|
|
|
|
}
|
|
|
|
|
2021-06-24 13:50:23 -03:00
|
|
|
// fills data with random values of requested size
|
|
|
|
bool get_random_vals(uint8_t* data, size_t size) override;
|
|
|
|
|
2016-01-06 18:09:40 -04:00
|
|
|
private:
|
|
|
|
SITL_State *sitlState;
|
2018-12-08 22:34:54 -04:00
|
|
|
|
2019-03-19 23:19:41 -03:00
|
|
|
#ifdef WITH_SITL_TONEALARM
|
|
|
|
static ToneAlarm_SF _toneAlarm;
|
|
|
|
#endif
|
|
|
|
|
2020-11-08 17:48:25 -04:00
|
|
|
int saved_argc;
|
|
|
|
char *const *saved_argv;
|
2024-03-15 11:25:18 -03:00
|
|
|
|
|
|
|
#if HAL_UART_STATS_ENABLED
|
|
|
|
// request information on uart I/O
|
|
|
|
void uart_info(ExpandingString &str) override;
|
2024-04-06 13:12:19 -03:00
|
|
|
|
|
|
|
#if HAL_LOGGING_ENABLED
|
|
|
|
// Log UART message for each serial port
|
|
|
|
void uart_log() override;
|
2024-03-15 11:25:18 -03:00
|
|
|
#endif
|
2024-04-06 13:12:19 -03:00
|
|
|
#endif // HAL_UART_STATS_ENABLED
|
2024-03-15 11:25:18 -03:00
|
|
|
|
|
|
|
private:
|
|
|
|
#if HAL_UART_STATS_ENABLED
|
|
|
|
// UART stats tracking helper
|
2024-04-06 13:12:19 -03:00
|
|
|
struct uart_stats {
|
2024-03-15 11:25:18 -03:00
|
|
|
AP_HAL::UARTDriver::StatsTracker serial[AP_HAL::HAL::num_serial];
|
|
|
|
uint32_t last_ms;
|
2024-04-06 13:12:19 -03:00
|
|
|
};
|
|
|
|
uart_stats sys_uart_stats;
|
|
|
|
#if HAL_LOGGING_ENABLED
|
|
|
|
uart_stats log_uart_stats;
|
2024-03-15 11:25:18 -03:00
|
|
|
#endif
|
2024-04-06 13:12:19 -03:00
|
|
|
#endif // HAL_UART_STATS_ENABLED
|
2012-12-18 21:13:01 -04:00
|
|
|
};
|