From 402669f269928515cebd267477b14fd98b1915f8 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Tue, 5 Oct 2021 17:29:45 +1100 Subject: [PATCH] AP_HAL_SITL: add and use HAL_SITL &hal_sitl analogous to our normal "extern hal" stuff but removes need for casting --- libraries/AP_HAL_SITL/HAL_SITL_Class.cpp | 2 ++ libraries/AP_HAL_SITL/SITL_cmdline.cpp | 6 +++--- libraries/AP_HAL_SITL/Storage.cpp | 10 +++++----- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/libraries/AP_HAL_SITL/HAL_SITL_Class.cpp b/libraries/AP_HAL_SITL/HAL_SITL_Class.cpp index 0016036501..56455f23cb 100644 --- a/libraries/AP_HAL_SITL/HAL_SITL_Class.cpp +++ b/libraries/AP_HAL_SITL/HAL_SITL_Class.cpp @@ -31,6 +31,8 @@ using namespace HALSITL; +HAL_SITL& hal_sitl = (HAL_SITL&)AP_HAL::get_HAL(); + static Storage sitlStorage; static SITL_State sitlState; static Scheduler sitlScheduler(&sitlState); diff --git a/libraries/AP_HAL_SITL/SITL_cmdline.cpp b/libraries/AP_HAL_SITL/SITL_cmdline.cpp index 7ae0bb3846..6b7a778dec 100644 --- a/libraries/AP_HAL_SITL/SITL_cmdline.cpp +++ b/libraries/AP_HAL_SITL/SITL_cmdline.cpp @@ -44,7 +44,7 @@ #include #include -extern const AP_HAL::HAL& hal; +extern HAL_SITL& hal; using namespace HALSITL; using namespace SITL; @@ -556,8 +556,8 @@ void SITL_State::_parse_command_line(int argc, char * const argv[]) AP::sitl()->start_time_UTC = start_time_UTC; } - ((HAL_SITL&)hal).set_storage_posix_enabled(storage_posix_enabled); - ((HAL_SITL&)hal).set_storage_flash_enabled(storage_flash_enabled); + hal.set_storage_posix_enabled(storage_posix_enabled); + hal.set_storage_flash_enabled(storage_flash_enabled); if (erase_all_storage) { AP_Param::erase_all(); diff --git a/libraries/AP_HAL_SITL/Storage.cpp b/libraries/AP_HAL_SITL/Storage.cpp index 9e468e2ecd..3e9762f1c5 100644 --- a/libraries/AP_HAL_SITL/Storage.cpp +++ b/libraries/AP_HAL_SITL/Storage.cpp @@ -23,7 +23,7 @@ using namespace HALSITL; -extern const AP_HAL::HAL& hal; +extern HAL_SITL& hal; /* emulate flash sector sizes @@ -56,7 +56,7 @@ void Storage::_storage_open(void) _dirty_mask.clearall(); #if STORAGE_USE_FLASH - if (((HAL_SITL&)hal).get_storage_flash_enabled()) { + if (hal.get_storage_flash_enabled()) { // load from storage backend _flash_load(); _initialisedType = StorageBackend::Flash; @@ -65,7 +65,7 @@ void Storage::_storage_open(void) #endif // STORAGE_USE_FLASH #if STORAGE_USE_POSIX - if (((HAL_SITL&)hal).get_storage_posix_enabled()) { + if (hal.get_storage_posix_enabled()) { // if we have failed filesystem init don't try again (this is // initialised to zero in the constructor) if (log_fd == -1) { @@ -168,7 +168,7 @@ void Storage::_timer_tick(void) } #if STORAGE_USE_POSIX - if (((HAL_SITL&)hal).get_storage_posix_enabled()) { + if (hal.get_storage_posix_enabled()) { if (log_fd != -1) { const off_t offset = STORAGE_LINE_SIZE*i; if (lseek(log_fd, offset, SEEK_SET) != offset) { @@ -184,7 +184,7 @@ void Storage::_timer_tick(void) #endif #if STORAGE_USE_FLASH - if (((HAL_SITL&)hal).get_storage_flash_enabled()) { + if (hal.get_storage_flash_enabled()) { // save to storage backend _flash_write(i); return;