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"
|
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) {}
|
|
|
|
|
2018-11-07 06:59:48 -04:00
|
|
|
bool run_debug_shell(AP_HAL::BetterStream *stream) override {
|
2015-05-04 21:59:07 -03:00
|
|
|
return false;
|
|
|
|
}
|
2015-11-05 00:41:46 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
how much free memory do we have in bytes.
|
|
|
|
*/
|
|
|
|
uint32_t available_memory(void) override {
|
|
|
|
// SITL is assumed to always have plenty of memory. Return 128k for now
|
|
|
|
return 0x20000;
|
|
|
|
}
|
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
|
|
|
|
|
|
|
#ifdef ENABLE_HEAP
|
|
|
|
// heap functions, note that a heap once alloc'd cannot be dealloc'd
|
2019-06-17 20:15:25 -03:00
|
|
|
void *allocate_heap_memory(size_t size) override;
|
2022-12-22 18:50:37 -04:00
|
|
|
void *heap_realloc(void *heap, void *ptr, size_t old_size, size_t new_size) override;
|
2018-12-08 22:34:54 -04:00
|
|
|
#endif // ENABLE_HEAP
|
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
|
|
|
|
|
2018-12-08 22:34:54 -04:00
|
|
|
#ifdef ENABLE_HEAP
|
|
|
|
struct heap_allocation_header {
|
|
|
|
size_t allocation_size; // size of allocated block, not including this header
|
|
|
|
};
|
|
|
|
|
|
|
|
struct heap {
|
|
|
|
size_t scripting_max_heap_size;
|
|
|
|
size_t current_heap_usage;
|
|
|
|
};
|
|
|
|
#endif // ENABLE_HEAP
|
2020-11-08 17:48:25 -04:00
|
|
|
|
|
|
|
int saved_argc;
|
|
|
|
char *const *saved_argv;
|
2012-12-18 21:13:01 -04:00
|
|
|
};
|