From 4f6653e5c797dc7bc78f09c8cf81d233af8c8747 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 27 May 2024 11:22:18 +1000 Subject: [PATCH] HAL_SITL: avoid std::vector in command line handling use ObjectArray instead --- libraries/AP_HAL_SITL/SITL_State.h | 3 ++- libraries/AP_HAL_SITL/SITL_cmdline.cpp | 6 +++--- libraries/AP_HAL_SITL/Util.cpp | 7 +++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/libraries/AP_HAL_SITL/SITL_State.h b/libraries/AP_HAL_SITL/SITL_State.h index 1a0074f14a..4ff1c0c046 100644 --- a/libraries/AP_HAL_SITL/SITL_State.h +++ b/libraries/AP_HAL_SITL/SITL_State.h @@ -1,6 +1,7 @@ #pragma once #include +#include #if CONFIG_HAL_BOARD == HAL_BOARD_SITL @@ -40,7 +41,7 @@ public: "tcp:7", "tcp:8", }; - std::vector cmdline_param; + ObjectArray cmdline_param{100}; /* parse a home location string */ static bool parse_home(const char *home_str, diff --git a/libraries/AP_HAL_SITL/SITL_cmdline.cpp b/libraries/AP_HAL_SITL/SITL_cmdline.cpp index 2151d5eab4..30cea03245 100644 --- a/libraries/AP_HAL_SITL/SITL_cmdline.cpp +++ b/libraries/AP_HAL_SITL/SITL_cmdline.cpp @@ -384,13 +384,13 @@ void SITL_State::_parse_command_line(int argc, char * const argv[]) case 's': speedup = strtof(gopt.optarg, nullptr); temp_cmdline_param = {"SIM_SPEEDUP", speedup}; - cmdline_param.push_back(temp_cmdline_param); + cmdline_param.push(temp_cmdline_param); printf("Setting SIM_SPEEDUP=%f\n", speedup); break; case 'r': sim_rate_hz = strtof(gopt.optarg, nullptr); temp_cmdline_param = {"SIM_RATE_HZ", sim_rate_hz}; - cmdline_param.push_back(temp_cmdline_param); + cmdline_param.push(temp_cmdline_param); printf("Setting SIM_RATE_HZ=%f\n", sim_rate_hz); break; case 'C': @@ -513,7 +513,7 @@ void SITL_State::_parse_command_line(int argc, char * const argv[]) exit(1); } temp_cmdline_param = {"SYSID_THISMAV", static_cast(sysid)}; - cmdline_param.push_back(temp_cmdline_param); + cmdline_param.push(temp_cmdline_param); printf("Setting SYSID_THISMAV=%d\n", sysid); break; } diff --git a/libraries/AP_HAL_SITL/Util.cpp b/libraries/AP_HAL_SITL/Util.cpp index f5c6bbeeaa..ce51bd8fd3 100644 --- a/libraries/AP_HAL_SITL/Util.cpp +++ b/libraries/AP_HAL_SITL/Util.cpp @@ -160,8 +160,11 @@ enum AP_HAL::Util::safety_state HALSITL::Util::safety_switch_state(void) void HALSITL::Util::set_cmdline_parameters() { - for (auto param: sitlState->cmdline_param) { - AP_Param::set_default_by_name(param.name, param.value); + for (uint16_t i=0; icmdline_param.available(); i++) { + const auto param = sitlState->cmdline_param[i]; + if (param != nullptr) { + AP_Param::set_default_by_name(param->name, param->value); + } } } #endif