From 08c963c49f5b91f158c509d2e1d0fd3fa7025237 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 7 Aug 2024 19:34:51 +1000 Subject: [PATCH] AP_GPS: make SBF specific parameters private to SBF backend this avoids exposing them to all users, and allows different logging for each SBF receiver --- libraries/AP_GPS/AP_GPS.cpp | 26 ------------- libraries/AP_GPS/AP_GPS.h | 8 ++-- libraries/AP_GPS/AP_GPS_Params.cpp | 7 ++++ libraries/AP_GPS/AP_GPS_SBF.cpp | 59 ++++++++++++++++++++++++------ libraries/AP_GPS/AP_GPS_SBF.h | 7 ++++ 5 files changed, 66 insertions(+), 41 deletions(-) diff --git a/libraries/AP_GPS/AP_GPS.cpp b/libraries/AP_GPS/AP_GPS.cpp index 7d5b4bb59ffe19..d6a541a06d058d 100644 --- a/libraries/AP_GPS/AP_GPS.cpp +++ b/libraries/AP_GPS/AP_GPS.cpp @@ -274,32 +274,6 @@ const AP_Param::GroupInfo AP_GPS::var_info[] = { AP_SUBGROUPINFO(params[1], "2_", 33, AP_GPS, AP_GPS::Params), #endif - // @Param: _LOG_HZ - // @DisplayName: Log frequency - // @Description: The frequency with which the receiver logs information. - // @Units: Hz - // @Increment: 0.1 - // @Range: 0 20 - // @RebootRequired: True - // @User: Advanced - AP_GROUPINFO("_LOG_HZ", 34, AP_GPS, _logging_frequency, 1.0f), - - // @Param: _LOG_LEVEL - // @DisplayName: Log level - // @Description: The level of detail the receiver should log. - // @Values: 0:Lite, 1:Basic, 2:Default, 3:Full - // @RebootRequired: True - // @User: Advanced - AP_GROUPINFO("_LOG_LEVEL", 35, AP_GPS, _logging_level, 2), - - // @Param: _LOG_FORCE - // @DisplayName: Log overwrite - // @Description: Whether logging setup should overwrite existing logging on the receiver. - // @Values: 0:Disabled, 1:Enabled - // @RebootRequired: True - // @User: Advanced - AP_GROUPINFO("_LOG_FORCE", 36, AP_GPS, _logging_overwrite, 0), - AP_GROUPEND }; diff --git a/libraries/AP_GPS/AP_GPS.h b/libraries/AP_GPS/AP_GPS.h index 9331b1733d0c14..d3dc3fad48e80b 100644 --- a/libraries/AP_GPS/AP_GPS.h +++ b/libraries/AP_GPS/AP_GPS.h @@ -47,6 +47,7 @@ class AP_GPS_Backend; class RTCM3_Parser; +class AP_GPS_SBF; /// @class AP_GPS /// GPS driver main class @@ -139,7 +140,9 @@ class AP_GPS #if GPS_MOVING_BASELINE MovingBase mb_params; #endif // GPS_MOVING_BASELINE - +#if AP_GPS_SBF_ENABLED + AP_GPS_SBF *sbf_backend; +#endif static const struct AP_Param::GroupInfo var_info[]; }; @@ -629,9 +632,6 @@ class AP_GPS AP_Int8 _blend_mask; AP_Int16 _driver_options; AP_Int8 _primary; - AP_Float _logging_frequency; // frequency at which the receiver should log messages - AP_Int8 _logging_level; // amount of details the receiver should log - AP_Int8 _logging_overwrite; // whether to override existing logging on the receiver or add to it uint32_t _log_gps_bit = -1; diff --git a/libraries/AP_GPS/AP_GPS_Params.cpp b/libraries/AP_GPS/AP_GPS_Params.cpp index f7fc29ead97478..152d7e846a3bef 100644 --- a/libraries/AP_GPS/AP_GPS_Params.cpp +++ b/libraries/AP_GPS/AP_GPS_Params.cpp @@ -19,6 +19,7 @@ #if AP_GPS_ENABLED #include "AP_GPS.h" +#include "AP_GPS_SBF.h" // table of user settable parameters const AP_Param::GroupInfo AP_GPS::Params::var_info[] = { @@ -113,6 +114,12 @@ const AP_Param::GroupInfo AP_GPS::Params::var_info[] = { AP_GROUPINFO("CAN_OVRIDE", 9, AP_GPS::Params, override_node_id, 0), #endif +#if AP_GPS_SBF_ENABLED + // @Group: + // @Path: ./SIM_GPS_SBF.cpp + AP_SUBGROUPPTR(sbf_backend, "", 10, AP_GPS::Params, AP_GPS_SBF), +#endif + AP_GROUPEND }; diff --git a/libraries/AP_GPS/AP_GPS_SBF.cpp b/libraries/AP_GPS/AP_GPS_SBF.cpp index 33877a00bf6a4e..2fe5937e3b374c 100644 --- a/libraries/AP_GPS/AP_GPS_SBF.cpp +++ b/libraries/AP_GPS/AP_GPS_SBF.cpp @@ -61,6 +61,38 @@ constexpr const char *AP_GPS_SBF::portIdentifiers[]; constexpr const char* AP_GPS_SBF::_initialisation_blob[]; constexpr const char* AP_GPS_SBF::sbas_on_blob[]; +// table of user settable parameters +const AP_Param::GroupInfo AP_GPS_SBF::var_info[] = { + + // @Param: LOG_HZ + // @DisplayName: Log frequency + // @Description: The frequency with which the receiver logs information. + // @Units: Hz + // @Increment: 0.1 + // @Range: 0 20 + // @RebootRequired: True + // @User: Advanced + AP_GROUPINFO("LOG_HZ", 1, AP_GPS_SBF, _logging_frequency, 1.0f), + + // @Param: LOG_LEVEL + // @DisplayName: Log level + // @Description: The level of detail the receiver should log. + // @Values: 0:Lite, 1:Basic, 2:Default, 3:Full + // @RebootRequired: True + // @User: Advanced + AP_GROUPINFO("LOG_LEVEL", 2, AP_GPS_SBF, _logging_level, 2), + + // @Param: _LOG_FORCE + // @DisplayName: Log overwrite + // @Description: Whether logging setup should overwrite existing logging on the receiver. + // @Values: 0:Disabled, 1:Enabled + // @RebootRequired: True + // @User: Advanced + AP_GROUPINFO("LOG_FORCE", 3, AP_GPS_SBF, _logging_overwrite, 0), + + AP_GROUPEND +}; + AP_GPS_SBF::AP_GPS_SBF(AP_GPS &_gps, AP_GPS::Params &_params, AP_GPS::GPS_State &_state, @@ -79,6 +111,11 @@ AP_GPS_SBF::AP_GPS_SBF(AP_GPS &_gps, (get_type() == AP_GPS::GPS_Type::GPS_TYPE_SBF_DUAL_ANTENNA)) { state.gps_yaw_configured = true; } + + // set ptr in params so private parameters are accessible + _params.sbf_backend = this; + + AP_Param::setup_object_defaults(this, var_info); } AP_GPS_SBF::~AP_GPS_SBF (void) { @@ -142,12 +179,12 @@ AP_GPS_SBF::read(void) } break; case Config_State::Log: - if (gps._logging_frequency <= 0.0f && gps._logging_overwrite) { + if (_logging_frequency <= 0.0f && _logging_overwrite) { // hard-disable logging, clear existing stream if (asprintf(&config_string, "sso,Stream%d,none,none,off\n", (int)GPS_SBF_LOG_STREAM_NUMBER) == -1) { config_string = nullptr; } - } else if (gps._logging_frequency <= 0.0f) { + } else if (_logging_frequency <= 0.0f) { // soft-disable logging, keep existing stream if (asprintf(&config_string, "sso,Stream%d,,,off\n", (int)GPS_SBF_LOG_STREAM_NUMBER) == -1) { config_string = nullptr; @@ -155,26 +192,26 @@ AP_GPS_SBF::read(void) } else { // enable logging const char* logging_frequency; - if (gps._logging_frequency <= 0.1f) { + if (_logging_frequency <= 0.1f) { logging_frequency = SBF_0_1_HZ; - } else if (gps._logging_frequency <= 0.2f) { + } else if (_logging_frequency <= 0.2f) { logging_frequency = SBF_0_2_HZ; - } else if (gps._logging_frequency <= 0.5f) { + } else if (_logging_frequency <= 0.5f) { logging_frequency = SBF_0_5_HZ; - } else if (gps._logging_frequency <= 1.0f) { + } else if (_logging_frequency <= 1.0f) { logging_frequency = SBF_1_0_HZ; - } else if (gps._logging_frequency <= 2.0f) { + } else if (_logging_frequency <= 2.0f) { logging_frequency = SBF_2_0_HZ; - } else if (gps._logging_frequency <= 5.0f) { + } else if (_logging_frequency <= 5.0f) { logging_frequency = SBF_5_0_HZ; - } else if (gps._logging_frequency <= 10.0f) { + } else if (_logging_frequency <= 10.0f) { logging_frequency = SBF_10_0_HZ; } else { logging_frequency = SBF_20_0_HZ; } const char* logged_blocks; - switch (gps._logging_level) { + switch (_logging_level) { case AP_GPS::GPS_Logging_Level::LITE: logged_blocks = "PostProcess+Event"; break; @@ -192,7 +229,7 @@ AP_GPS_SBF::read(void) if (asprintf(&config_string, "sso,Stream%d,Dsk1,%s%s,%s\nsfn,DSK1,Incremental,'ardup'\n", (int)GPS_SBF_LOG_STREAM_NUMBER, - gps._logging_overwrite ? "" : "+", + _logging_overwrite ? "" : "+", logged_blocks, logging_frequency) == -1) { config_string = nullptr; diff --git a/libraries/AP_GPS/AP_GPS_SBF.h b/libraries/AP_GPS/AP_GPS_SBF.h index 20a94941d3d34d..8bd8e9f8f09282 100644 --- a/libraries/AP_GPS/AP_GPS_SBF.h +++ b/libraries/AP_GPS/AP_GPS_SBF.h @@ -69,6 +69,8 @@ class AP_GPS_SBF : public AP_GPS_Backend bool get_error_codes(uint32_t &error_codes) const override { error_codes = RxError; return true; }; + static const struct AP_Param::GroupInfo var_info[]; + private: bool parse(uint8_t temp); @@ -77,6 +79,11 @@ class AP_GPS_SBF : public AP_GPS_Backend static const uint8_t SBF_PREAMBLE1 = '$'; static const uint8_t SBF_PREAMBLE2 = '@'; + // SBF specific parameters + AP_Float _logging_frequency; // frequency at which the receiver should log messages + AP_Int8 _logging_level; // amount of details the receiver should log + AP_Int8 _logging_overwrite; // whether to override existing logging on the receiver or add to it + uint8_t _init_blob_index; uint32_t _init_blob_time; enum class Config_State {