gps autoconfigure: wait 100ms between baud changes

This commit is contained in:
Kemal Hadimli 2013-12-24 01:48:11 +02:00
parent 1cbbe0b110
commit 51b8a9e365
1 changed files with 7 additions and 0 deletions

View File

@ -9,6 +9,7 @@
#define GPS_TIMEOUT (2500)
// How many entries in gpsInitData array below
#define GPS_INIT_ENTRIES (5)
#define GPS_BAUD_DELAY (100)
typedef struct gpsInitData_t {
uint32_t baudrate;
@ -70,6 +71,7 @@ typedef struct gpsData_t {
uint32_t lastLastMessage; // last-last valid GPS message. Used to calculate delta.
uint32_t state_position; // incremental variable for loops
uint32_t state_ts; // timestamp for last state_position increment
} gpsData_t;
@ -83,6 +85,7 @@ static void gpsSetState(uint8_t state)
{
gpsData.state = state;
gpsData.state_position = 0;
gpsData.state_ts = millis();
}
void gpsInit(uint8_t baudrate)
@ -124,6 +127,9 @@ void gpsInitHardware(void)
break;
if (gpsData.state == GPS_INITIALIZING) {
uint32_t m = millis();
if (m - gpsData.state_ts < GPS_BAUD_DELAY) return;
if (gpsData.state_position < GPS_INIT_ENTRIES) {
// try different speed to INIT
serialSetBaudRate(core.gpsport, gpsInitData[gpsData.state_position].baudrate);
@ -131,6 +137,7 @@ void gpsInitHardware(void)
serialPrint(core.gpsport, gpsInitData[mcfg.gps_baudrate].ubx);
gpsData.state_position++;
gpsData.state_ts = m;
} else {
// we're now (hopefully) at the correct rate, next state will switch to it
gpsData.baudrateIndex = mcfg.gps_baudrate;