Util.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #pragma once
  2. #include <AP_HAL/AP_HAL.h>
  3. #include "AP_HAL_SITL_Namespace.h"
  4. #include "AP_HAL_SITL.h"
  5. #include "Semaphores.h"
  6. #include "ToneAlarm_SF.h"
  7. class HALSITL::Util : public AP_HAL::Util {
  8. public:
  9. Util(SITL_State *_sitlState) :
  10. sitlState(_sitlState) {}
  11. bool run_debug_shell(AP_HAL::BetterStream *stream) override {
  12. return false;
  13. }
  14. /**
  15. how much free memory do we have in bytes.
  16. */
  17. uint32_t available_memory(void) override {
  18. // SITL is assumed to always have plenty of memory. Return 128k for now
  19. return 0x20000;
  20. }
  21. // get path to custom defaults file for AP_Param
  22. const char* get_custom_defaults_file() const override {
  23. return sitlState->defaults_path;
  24. }
  25. uint64_t get_hw_rtc() const override;
  26. bool get_system_id(char buf[40]) override;
  27. bool get_system_id_unformatted(uint8_t buf[], uint8_t &len) override;
  28. void dump_stack_trace();
  29. #ifdef ENABLE_HEAP
  30. // heap functions, note that a heap once alloc'd cannot be dealloc'd
  31. void *allocate_heap_memory(size_t size) override;
  32. void *heap_realloc(void *heap, void *ptr, size_t new_size) override;
  33. #endif // ENABLE_HEAP
  34. #ifdef WITH_SITL_TONEALARM
  35. bool toneAlarm_init() override { return _toneAlarm.init(); }
  36. void toneAlarm_set_buzzer_tone(float frequency, float volume, uint32_t duration_ms) override {
  37. _toneAlarm.set_buzzer_tone(frequency, volume, duration_ms);
  38. }
  39. #endif
  40. // return true if the reason for the reboot was a watchdog reset
  41. bool was_watchdog_reset() const override { return getenv("SITL_WATCHDOG_RESET") != nullptr; }
  42. private:
  43. SITL_State *sitlState;
  44. #ifdef WITH_SITL_TONEALARM
  45. static ToneAlarm_SF _toneAlarm;
  46. #endif
  47. #ifdef ENABLE_HEAP
  48. struct heap_allocation_header {
  49. size_t allocation_size; // size of allocated block, not including this header
  50. };
  51. struct heap {
  52. size_t scripting_max_heap_size;
  53. size_t current_heap_usage;
  54. };
  55. #endif // ENABLE_HEAP
  56. };