Skip to content

Commit

Permalink
AP_GPS: make receiver logging configurable through parameters
Browse files Browse the repository at this point in the history
Add parameters that allow users to configure logging from within their ground
control station software.
  • Loading branch information
flyingthingsintothings committed Mar 7, 2024
1 parent 6905965 commit 50b8066
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 1 deletion.
25 changes: 25 additions & 0 deletions libraries/AP_GPS/AP_GPS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,31 @@ const AP_Param::GroupInfo AP_GPS::var_info[] = {
#endif // GPS_MAX_RECEIVERS > 1
#endif // HAL_ENABLE_DRONECAN_DRIVERS

// @Param: _LOG_HZ
// @DisplayName: Log frequency
// @Description: The frequency with which the receiver logs information.
// @Units: Hz
// @Values: 0:Off, 1:0.1Hz, 2:0.2Hz, 5:0.5Hz, 10:1Hz, 20:2Hz, 50:5Hz, 80:8Hz, 100:10Hz, 200:20Hz
// @RebootRequired: True
// @User: Advanced
AP_GROUPINFO("_LOG_HZ", 32, AP_GPS, _logging_frequency, 1),

// @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", 33, 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", 34, AP_GPS, _logging_overwrite, 0),

AP_GROUPEND
};

Expand Down
25 changes: 25 additions & 0 deletions libraries/AP_GPS/AP_GPS.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,28 @@ class AP_GPS
KNOWN = 3, ///< The full covariance array is reported by the GPS
};

// Interpretation of logging frequency values
enum GPS_Logging_Frequency {
OFF = 0,
HZ_0_1 = 1,
HZ_0_2 = 2,
HZ_0_5 = 5,
HZ_1 = 10,
HZ_2 = 20,
HZ_5 = 50,
HZ_8 = 80,
HZ_10 = 100,
HZ_20 = 200,
};

// 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 @@ -613,6 +635,9 @@ class AP_GPS
AP_Int32 _node_id[GPS_MAX_RECEIVERS];
AP_Int32 _override_node_id[GPS_MAX_RECEIVERS];
#endif
AP_Int16 _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
#if GPS_MOVING_BASELINE
MovingBase mb_params[GPS_MAX_RECEIVERS];
#endif // GPS_MOVING_BASELINE
Expand Down
76 changes: 76 additions & 0 deletions libraries/AP_GPS/AP_GPS_SBF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ do { \
#ifndef GPS_SBF_STREAM_NUMBER
#define GPS_SBF_STREAM_NUMBER 1
#endif
#ifndef GPS_SBF_LOG_STREAM_NUMBER
#define GPS_SBF_LOG_STREAM_NUMBER 2
#endif

#define SBF_EXCESS_COMMAND_BYTES 5 // 2 start bytes + validity byte + space byte + endline byte

Expand Down Expand Up @@ -135,6 +138,76 @@ AP_GPS_SBF::read(void)
extra_config) == -1) {
config_string = nullptr;
}
break;
case Config_State::Log:
if (gps._logging_frequency == AP_GPS::GPS_Logging_Frequency::OFF && gps._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 == AP_GPS::GPS_Logging_Frequency::OFF) {
// 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;
switch (gps._logging_frequency) {
case AP_GPS::GPS_Logging_Frequency::HZ_0_1:
logging_frequency = "sec10";
break;
case AP_GPS::GPS_Logging_Frequency::HZ_0_2:
logging_frequency = "sec5";
break;
case AP_GPS::GPS_Logging_Frequency::HZ_0_5:
logging_frequency = "sec2";
break;
case AP_GPS::GPS_Logging_Frequency::HZ_1:
default:
logging_frequency = "sec1";
break;
case AP_GPS::GPS_Logging_Frequency::HZ_2:
logging_frequency = "msec500";
break;
case AP_GPS::GPS_Logging_Frequency::HZ_5:
logging_frequency = "msec200";
break;
case AP_GPS::GPS_Logging_Frequency::HZ_8:
case AP_GPS::GPS_Logging_Frequency::HZ_10:
logging_frequency = "msec100";
break;
case AP_GPS::GPS_Logging_Frequency::HZ_20:
logging_frequency = "msec50";
break;
}

const char* logged_blocks;
switch (gps._logging_level) {
case AP_GPS::GPS_Logging_Level::LITE:
logged_blocks = "comment+ReceiverStatus";
break;
case AP_GPS::GPS_Logging_Level::BASIC:
logged_blocks = "comment+ReceiverStatus+PostProcess+Event";
break;
case AP_GPS::GPS_Logging_Level::DEFAULT:
default:
logged_blocks = "comment+ReceiverStatus+PostProcess+Event+Support";
break;
case AP_GPS::GPS_Logging_Level::FULL:
logged_blocks = "comment+ReceiverStatus+PostProcess+Event+support+BBSamples";
break;
}

if (asprintf(&config_string, "sso,Stream%d,Dsk1,%s%s,%s\n",
(int)GPS_SBF_LOG_STREAM_NUMBER,
gps._logging_overwrite ? "" : "+",
logged_blocks,
logging_frequency) == -1) {
config_string = nullptr;
}
}

break;
case Config_State::Blob:
if (asprintf(&config_string, "%s\n", _initialisation_blob[_init_blob_index]) == -1) {
Expand Down Expand Up @@ -362,6 +435,9 @@ AP_GPS_SBF::parse(uint8_t temp)
config_step = Config_State::SSO;
break;
case Config_State::SSO:
config_step = Config_State::Log;
break;
case Config_State::Log:
config_step = Config_State::Blob;
break;
case Config_State::Blob:
Expand Down
2 changes: 1 addition & 1 deletion libraries/AP_GPS/AP_GPS_SBF.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class AP_GPS_SBF : public AP_GPS_Backend
enum class Config_State {
Baud_Rate,
SSO,
Log,
Blob,
SBAS,
SGA,
Expand All @@ -84,7 +85,6 @@ class AP_GPS_SBF : public AP_GPS_Backend
"srd,Moderate,UAV",
"sem,PVT,5",
"spm,Rover,all",
"sso,Stream2,Dsk1,postprocess+event+comment+ReceiverStatus,msec100",
#if defined (GPS_SBF_EXTRA_CONFIG)
GPS_SBF_EXTRA_CONFIG
#endif
Expand Down

0 comments on commit 50b8066

Please sign in to comment.