mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-24 00:35:39 +03:00
Add NMEA Custom commands (#12591)
* Add NMEA Custom command * Add delay * Remove strdup * more effective way by ledvinap Update src/main/pg/gps.h Co-authored-by: Mark Haslinghuis <mark@numloq.nl> required changes Update src/main/io/gps.c Co-authored-by: Petr Ledvina <ledvinap@gmail.com> Update src/main/io/gps.c Co-authored-by: Jan Post <Rm2k-Freak@web.de> Update src/main/io/gps.c Co-authored-by: Jan Post <Rm2k-Freak@web.de> Update src/main/io/gps.c Co-authored-by: Jan Post <Rm2k-Freak@web.de> Update src/main/cli/settings.c Co-authored-by: Jan Post <Rm2k-Freak@web.de> Update src/main/pg/gps.h Co-authored-by: Jan Post <Rm2k-Freak@web.de> Update src/main/pg/gps.h Co-authored-by: Jan Post <Rm2k-Freak@web.de> fix namings * Update src/main/io/gps.c Co-authored-by: Mark Haslinghuis <mark@numloq.nl> * Update src/main/io/gps.c Co-authored-by: Jan Post <Rm2k-Freak@web.de> --------- Co-authored-by: Mark Haslinghuis <mark@numloq.nl> Co-authored-by: Jan Post <Rm2k-Freak@web.de>
This commit is contained in:
parent
f841367928
commit
7a39c8037f
4 changed files with 38 additions and 2 deletions
|
@ -1008,6 +1008,7 @@ const clivalue_t valueTable[] = {
|
|||
{ PARAM_NAME_GPS_SET_HOME_POINT_ONCE, VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_GPS_CONFIG, offsetof(gpsConfig_t, gps_set_home_point_once) },
|
||||
{ PARAM_NAME_GPS_USE_3D_SPEED, VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_GPS_CONFIG, offsetof(gpsConfig_t, gps_use_3d_speed) },
|
||||
{ PARAM_NAME_GPS_SBAS_INTEGRITY, VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_GPS_CONFIG, offsetof(gpsConfig_t, sbas_integrity) },
|
||||
{ PARAM_NAME_GPS_NMEA_CUSTOM_COMMANDS, VAR_UINT8 | MASTER_VALUE | MODE_STRING, .config.string = { 1, NMEA_CUSTOM_COMMANDS_MAX_LENGTH, STRING_FLAGS_NONE }, PG_GPS_CONFIG, offsetof(gpsConfig_t, nmeaCustomCommands) },
|
||||
|
||||
#ifdef USE_GPS_RESCUE
|
||||
// PG_GPS_RESCUE
|
||||
|
|
|
@ -148,6 +148,7 @@
|
|||
#define PARAM_NAME_GPS_UBLOX_FLIGHT_MODEL "gps_ublox_flight_model"
|
||||
#define PARAM_NAME_GPS_SET_HOME_POINT_ONCE "gps_set_home_point_once"
|
||||
#define PARAM_NAME_GPS_USE_3D_SPEED "gps_use_3d_speed"
|
||||
#define PARAM_NAME_GPS_NMEA_CUSTOM_COMMANDS "gps_nmea_custom_commands"
|
||||
|
||||
#ifdef USE_GPS_RESCUE
|
||||
#define PARAM_NAME_GPS_RESCUE_MIN_START_DIST "gps_rescue_min_start_dist"
|
||||
|
|
|
@ -415,6 +415,7 @@ void gpsInitNmea(void)
|
|||
return;
|
||||
}
|
||||
gpsData.state_ts = now;
|
||||
|
||||
if (gpsData.state_position < GPS_STATE_INITIALIZING) {
|
||||
serialSetBaudRate(gpsPort, baudRates[gpsInitData[gpsData.baudrateIndex].baudrateIndex]);
|
||||
gpsData.state_position++;
|
||||
|
@ -424,9 +425,39 @@ void gpsInitNmea(void)
|
|||
if (!atgmRestartDone) {
|
||||
atgmRestartDone = true;
|
||||
serialPrint(gpsPort, "$PCAS02,100*1E\r\n"); // 10Hz refresh rate
|
||||
serialPrint(gpsPort, "$PCAS10,0*1C\r\n"); // hot restart
|
||||
serialPrint(gpsPort, "$PCAS10,0*1C\r\n"); // hot restart
|
||||
} else {
|
||||
// NMEA custom commands after ATGM336 initialization
|
||||
static int commandOffset = 0;
|
||||
const char *commands = gpsConfig()->nmeaCustomCommands;
|
||||
const char *cmd = commands + commandOffset;
|
||||
|
||||
// skip leading whitespaces and get first command length
|
||||
int commandLen;
|
||||
while (*cmd && (commandLen = strcspn(cmd, " \0")) == 0) {
|
||||
cmd++; // skip separators
|
||||
}
|
||||
|
||||
if (*cmd) {
|
||||
// Send the current command to the GPS
|
||||
serialWriteBuf(gpsPort, (uint8_t *)cmd, commandLen);
|
||||
serialWriteBuf(gpsPort, (uint8_t *)"\r\n", 2);
|
||||
|
||||
// Move to the next command
|
||||
cmd += commandLen;
|
||||
}
|
||||
|
||||
// skip trailing whitespaces
|
||||
while (*cmd && strcspn(cmd, " \0") == 0) cmd++;
|
||||
|
||||
if (*cmd) {
|
||||
// more commands to send
|
||||
commandOffset = cmd - commands;
|
||||
} else {
|
||||
gpsData.state_position++;
|
||||
commandOffset = 0;
|
||||
}
|
||||
}
|
||||
gpsData.state_position++;
|
||||
} else
|
||||
#else
|
||||
{
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
|
||||
#include "pg/pg.h"
|
||||
|
||||
#define NMEA_CUSTOM_COMMANDS_MAX_LENGTH 64
|
||||
|
||||
typedef struct gpsConfig_s {
|
||||
uint8_t provider;
|
||||
uint8_t sbasMode;
|
||||
|
@ -37,6 +39,7 @@ typedef struct gpsConfig_s {
|
|||
bool gps_set_home_point_once;
|
||||
bool gps_use_3d_speed;
|
||||
bool sbas_integrity;
|
||||
char nmeaCustomCommands[NMEA_CUSTOM_COMMANDS_MAX_LENGTH + 1];
|
||||
} gpsConfig_t;
|
||||
|
||||
PG_DECLARE(gpsConfig_t, gpsConfig);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue