Skip to content

Commit

Permalink
AP_GPS: make SBF specific parameters private to SBF backend
Browse files Browse the repository at this point in the history
this avoids exposing them to all users, and allows different logging
for each SBF receiver
  • Loading branch information
tridge committed Aug 7, 2024
1 parent f3c9c60 commit 9ec00d2
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 53 deletions.
26 changes: 0 additions & 26 deletions libraries/AP_GPS/AP_GPS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down
16 changes: 4 additions & 12 deletions libraries/AP_GPS/AP_GPS.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

class AP_GPS_Backend;
class RTCM3_Parser;
class AP_GPS_SBF;

/// @class AP_GPS
/// GPS driver main class
Expand Down Expand Up @@ -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[];
};

Expand Down Expand Up @@ -184,14 +187,6 @@ class AP_GPS
KNOWN = 3, ///< The full covariance array is reported by the GPS
};

// GPS receiver log level which determines what data is logged
enum GPS_Logging_Level {
LITE = 0,
BASIC = 1,
DEFAULT = 2,
FULL = 3,
};

/*
The GPS_State structure is filled in by the backend driver as it
parses each message from the GPS.
Expand Down Expand Up @@ -629,9 +624,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;

Expand Down
7 changes: 7 additions & 0 deletions libraries/AP_GPS/AP_GPS_Params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = {
Expand Down Expand Up @@ -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
};

Expand Down
67 changes: 52 additions & 15 deletions libraries/AP_GPS/AP_GPS_SBF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down Expand Up @@ -142,57 +179,57 @@ 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;
}
} 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) {
case AP_GPS::GPS_Logging_Level::LITE:
switch (GPS_Logging_Level(_logging_level.get())) {
case GPS_Logging_Level::LITE:
logged_blocks = "PostProcess+Event";
break;
case AP_GPS::GPS_Logging_Level::BASIC:
case GPS_Logging_Level::BASIC:
logged_blocks = "PostProcess+Event+Comment+ReceiverStatus";
break;
case AP_GPS::GPS_Logging_Level::DEFAULT:
case GPS_Logging_Level::DEFAULT:
default:
logged_blocks = "Support+Event+Comment";
break;
case AP_GPS::GPS_Logging_Level::FULL:
case GPS_Logging_Level::FULL:
logged_blocks = "Support+Event+Comment+BBSamples";
break;
}

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;
Expand Down
15 changes: 15 additions & 0 deletions libraries/AP_GPS/AP_GPS_SBF.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -77,6 +79,19 @@ class AP_GPS_SBF : public AP_GPS_Backend
static const uint8_t SBF_PREAMBLE1 = '$';
static const uint8_t SBF_PREAMBLE2 = '@';

// GPS receiver log level which determines what data is logged
enum class GPS_Logging_Level : uint8_t {
LITE = 0,
BASIC = 1,
DEFAULT = 2,
FULL = 3,
};

// SBF specific parameters
AP_Float _logging_frequency; // frequency at which the receiver should log messages
AP_Enum<GPS_Logging_Level> _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 {
Expand Down

0 comments on commit 9ec00d2

Please sign in to comment.