diff --git a/docs/Gps.md b/docs/Gps.md new file mode 100644 index 000000000..815aad401 --- /dev/null +++ b/docs/Gps.md @@ -0,0 +1,28 @@ +# GPS + +Two GPS protocols are supported. NMEA text and UBLOX Binary. + +## GPS Provider + +Set the `gps_provider` appropriately. + +| Value | Meaning | +| ----- | -------- | +| 0 | NMEA | +| 1 | UBLOX | + +## SBAS + +When using a UBLOX GPS the SBAS mode can be configured using `gps_sbas_mode`. + +The default is AUTO. + +| Value | Meaning | Region | +| ----- | -------- | ------------- | +| 0 | AUTO | Global | +| 1 | EGNOS | Europe | +| 2 | WAAS | North America | +| 3 | MSAS | Asia | +| 4 | GAGAN | India | + +If you use a regional specific setting you may achieve a faster GPS lock than using AUTO. diff --git a/src/main/config/config.c b/src/main/config/config.c index 6bcd9d829..cdee7d059 100755 --- a/src/main/config/config.c +++ b/src/main/config/config.c @@ -235,7 +235,8 @@ static void resetConf(void) masterConfig.servo_pwm_rate = 50; // gps/nav stuff - masterConfig.gps_provider = GPS_NMEA; + masterConfig.gpsConfig.provider = GPS_NMEA; + masterConfig.gpsConfig.sbasMode = SBAS_AUTO; resetSerialConfig(&masterConfig.serialConfig); diff --git a/src/main/config/config_master.h b/src/main/config/config_master.h index 6efb7ed04..160824c96 100644 --- a/src/main/config/config_master.h +++ b/src/main/config/config_master.h @@ -46,8 +46,7 @@ typedef struct master_t { airplaneConfig_t airplaneConfig; int8_t fixedwing_althold_dir; // +1 or -1 for pitch/althold gain. later check if need more than just sign - // gps-related stuff - gpsProvider_e gps_provider; + gpsConfig_t gpsConfig; serialConfig_t serialConfig; diff --git a/src/main/io/gps.c b/src/main/io/gps.c index f31ae823d..b83693415 100644 --- a/src/main/io/gps.c +++ b/src/main/io/gps.c @@ -60,7 +60,7 @@ static int16_t nav_rated[2]; // Adding a rate controller to the na int8_t nav_mode = NAV_MODE_NONE; // Navigation mode -static uint8_t gpsProvider; +static gpsConfig_t *gpsConfig; // GPS timeout for wrong baud rate/disconnection/etc in milliseconds (default 2.5second) #define GPS_TIMEOUT (2500) @@ -113,20 +113,13 @@ static const uint8_t ubloxInit[] = { // 31.21 CFG-SBAS (0x06 0x16), Page 142/210 // A.10 SBAS Configuration (UBX-CFG-SBAS), Page 198/210 - GPS.G6-SW-10018-F -typedef enum { - SBAS_AUTO = 0, - SBAS_EGNOS, - SBAS_WAAS, - SBAS_MSAS, - SBAS_GAGAN -} sbasMode_e; - #define UBLOX_SBAS_MESSAGE_LENGTH 16 typedef struct ubloxSbas_s { sbasMode_e mode; uint8_t message[UBLOX_SBAS_MESSAGE_LENGTH]; } ubloxSbas_t; +// Note: these must be defined in the same order is sbasMode_e since no lookup table is used. static const ubloxSbas_t ubloxSbas[] = { { SBAS_AUTO, { 0xB5, 0x62, 0x06, 0x16, 0x08, 0x00, 0x03, 0x07, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x31, 0xE5}}, { SBAS_EGNOS, { 0xB5, 0x62, 0x06, 0x16, 0x08, 0x00, 0x03, 0x07, 0x03, 0x00, 0x51, 0x08, 0x00, 0x00, 0x8A, 0x41}}, @@ -188,7 +181,7 @@ void gpsUseProfile(gpsProfile_t *gpsProfileToUse) } // When using PWM input GPS usage reduces number of available channels by 2 - see pwm_common.c/pwmInit() -void gpsInit(serialConfig_t *initialSerialConfig, uint8_t initialGpsProvider, gpsProfile_t *initialGpsProfile, pidProfile_t *pidProfile) +void gpsInit(serialConfig_t *initialSerialConfig, gpsConfig_t *initialGpsConfig, gpsProfile_t *initialGpsProfile, pidProfile_t *pidProfile) { serialConfig = initialSerialConfig; @@ -201,7 +194,7 @@ void gpsInit(serialConfig_t *initialSerialConfig, uint8_t initialGpsProvider, gp } } - gpsProvider = initialGpsProvider; + gpsConfig = initialGpsConfig; gpsUseProfile(initialGpsProfile); // init gpsData structure. if we're not actually enabled, don't bother doing anything else @@ -212,7 +205,7 @@ void gpsInit(serialConfig_t *initialSerialConfig, uint8_t initialGpsProvider, gp portMode_t mode = MODE_RXTX; // only RX is needed for NMEA-style GPS - if (gpsProvider == GPS_NMEA) + if (gpsConfig->provider == GPS_NMEA) mode = MODE_RX; gpsUsePIDs(pidProfile); @@ -289,9 +282,8 @@ void gpsInitUblox(void) } if (gpsData.messageState == GPS_MESSAGE_STATE_SBAS) { - uint8_t sbasIndex = SBAS_AUTO; // TODO allow configuration if (gpsData.state_position < UBLOX_SBAS_MESSAGE_LENGTH) { - serialWrite(gpsPort, ubloxSbas[sbasIndex].message[gpsData.state_position]); + serialWrite(gpsPort, ubloxSbas[gpsConfig->sbasMode].message[gpsData.state_position]); gpsData.state_position++; } else { gpsData.messageState++; @@ -308,7 +300,7 @@ void gpsInitUblox(void) void gpsInitHardware(void) { - switch (gpsProvider) { + switch (gpsConfig->provider) { case GPS_NMEA: gpsInitNmea(); break; @@ -365,9 +357,8 @@ void gpsThread(void) static bool gpsNewFrame(uint8_t c) { - switch (gpsProvider) { + switch (gpsConfig->provider) { case GPS_NMEA: // NMEA - case GPS_MTK_NMEA: // MTK in NMEA mode return gpsNewFrameNMEA(c); case GPS_UBLOX: // UBX binary return gpsNewFrameUBLOX(c); diff --git a/src/main/io/gps.h b/src/main/io/gps.h index df3c13f32..f88abe974 100644 --- a/src/main/io/gps.h +++ b/src/main/io/gps.h @@ -5,20 +5,31 @@ typedef enum { GPS_NMEA = 0, - GPS_UBLOX, - GPS_MTK_NMEA, - GPS_PROVIDER_MAX = GPS_MTK_NMEA, + GPS_UBLOX } gpsProvider_e; +#define GPS_PROVIDER_MAX GPS_UBLOX + +typedef enum { + SBAS_AUTO = 0, + SBAS_EGNOS, + SBAS_WAAS, + SBAS_MSAS, + SBAS_GAGAN +} sbasMode_e; + +#define SBAS_MODE_MAX SBAS_GAGAN + typedef enum { GPS_BAUDRATE_115200 = 0, GPS_BAUDRATE_57600, GPS_BAUDRATE_38400, GPS_BAUDRATE_19200, - GPS_BAUDRATE_9600, - GPS_BAUDRATE_MAX = GPS_BAUDRATE_9600 + GPS_BAUDRATE_9600 } gpsBaudRate_e; +#define GPS_BAUDRATE_MAX GPS_BAUDRATE_9600 + // Serial GPS only variables // navigation mode typedef enum { @@ -37,6 +48,11 @@ typedef struct gpsProfile_s { uint16_t ap_mode; // Temporarily Disables GPS_HOLD_MODE to be able to make it possible to adjust the Hold-position when moving the sticks, creating a deadspan for GPS } gpsProfile_t; +typedef struct gpsConfig_s { + gpsProvider_e provider; + sbasMode_e sbasMode; +} gpsConfig_t; + typedef enum { GPS_PASSTHROUGH_ENABLED = 1, GPS_PASSTHROUGH_NO_GPS, diff --git a/src/main/io/serial_cli.c b/src/main/io/serial_cli.c index b2e772646..bd54be336 100644 --- a/src/main/io/serial_cli.c +++ b/src/main/io/serial_cli.c @@ -173,6 +173,9 @@ const clivalue_t valueTable[] = { { "serial_port_2_scenario", VAR_UINT8, &masterConfig.serialConfig.serial_port_2_scenario, 0, SERIAL_PORT_SCENARIO_MAX }, { "serial_port_3_scenario", VAR_UINT8, &masterConfig.serialConfig.serial_port_3_scenario, 0, SERIAL_PORT_SCENARIO_MAX }, { "serial_port_4_scenario", VAR_UINT8, &masterConfig.serialConfig.serial_port_4_scenario, 0, SERIAL_PORT_SCENARIO_MAX }, +#if (SERIAL_PORT_COUNT > 4) + { "serial_port_5_scenario", VAR_UINT8, &masterConfig.serialConfig.serial_port_5_scenario, 0, SERIAL_PORT_SCENARIO_MAX }, +#endif { "reboot_character", VAR_UINT8, &masterConfig.serialConfig.reboot_character, 48, 126 }, { "msp_baudrate", VAR_UINT32, &masterConfig.serialConfig.msp_baudrate, 1200, 115200 }, @@ -180,7 +183,8 @@ const clivalue_t valueTable[] = { { "gps_baudrate", VAR_UINT32, &masterConfig.serialConfig.gps_baudrate, 0, 115200 }, { "gps_passthrough_baudrate", VAR_UINT32, &masterConfig.serialConfig.gps_passthrough_baudrate, 1200, 115200 }, - { "gps_provider", VAR_UINT8, &masterConfig.gps_provider, 0, GPS_PROVIDER_MAX }, + { "gps_provider", VAR_UINT8, &masterConfig.gpsConfig.provider, 0, GPS_PROVIDER_MAX }, + { "gps_sbas_mode", VAR_UINT8, &masterConfig.gpsConfig.sbasMode, 0, SBAS_MODE_MAX }, { "serialrx_provider", VAR_UINT8, &masterConfig.rxConfig.serialrx_provider, 0, SERIALRX_PROVIDER_MAX }, diff --git a/src/main/main.c b/src/main/main.c index 503117a24..eeef54971 100755 --- a/src/main/main.c +++ b/src/main/main.c @@ -62,7 +62,7 @@ failsafe_t* failsafeInit(rxConfig_t *intialRxConfig); void pwmInit(drv_pwm_config_t *init); void rxInit(rxConfig_t *rxConfig, failsafe_t *failsafe); void buzzerInit(failsafe_t *initialFailsafe); -void gpsInit(serialConfig_t *serialConfig, uint8_t initialGpsProvider, gpsProfile_t *initialGpsProfile, pidProfile_t *pidProfile); +void gpsInit(serialConfig_t *serialConfig, gpsConfig_t *initialGpsConfig, gpsProfile_t *initialGpsProfile, pidProfile_t *pidProfile); bool sensorsAutodetect(sensorAlignmentConfig_t *sensorAlignmentConfig, uint16_t gyroLpf, uint8_t accHardwareToUse, int16_t magDeclinationFromConfig); void imuInit(void); @@ -183,7 +183,7 @@ void init(void) if (feature(FEATURE_GPS)) { gpsInit( &masterConfig.serialConfig, - masterConfig.gps_provider, + &masterConfig.gpsConfig, ¤tProfile.gpsProfile, ¤tProfile.pidProfile );