Improved GPS management routine
This commit is contained in:
parent
23a1a38a3a
commit
42569af38a
|
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
#define KNOTS2KMH 1.852f
|
#define KNOTS2KMH 1.852f
|
||||||
|
|
||||||
static char sentence[MINMEA_MAX_LENGTH + 1];
|
static char sentence[2*MINMEA_MAX_LENGTH];
|
||||||
static bool isRtcSyncronised = false;
|
static bool isRtcSyncronised = false;
|
||||||
static bool gpsEnabled = false;
|
static bool gpsEnabled = false;
|
||||||
static bool readNewSentence = true;
|
static bool readNewSentence = true;
|
||||||
|
|
@ -52,14 +52,22 @@ void gps_taskFunc()
|
||||||
// Acquire a new NMEA sentence from GPS
|
// Acquire a new NMEA sentence from GPS
|
||||||
if(readNewSentence)
|
if(readNewSentence)
|
||||||
{
|
{
|
||||||
int status = gps_getNmeaSentence(sentence, MINMEA_MAX_LENGTH + 1);
|
int status = gps_getNmeaSentence(sentence, 2*MINMEA_MAX_LENGTH);
|
||||||
if(status != 0) return;
|
if(status != 0) return;
|
||||||
readNewSentence = false;
|
readNewSentence = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Waiting for a sentence...
|
||||||
if(gps_nmeaSentenceReady() == false)
|
if(gps_nmeaSentenceReady() == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Discard all non-GPS sentences
|
||||||
|
if((sentence[0] != '$') || (sentence[1] != 'G'))
|
||||||
|
{
|
||||||
|
readNewSentence = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Parse the sentence. Work on a local state copy to minimize the time
|
// Parse the sentence. Work on a local state copy to minimize the time
|
||||||
// spent with the state mutex locked
|
// spent with the state mutex locked
|
||||||
gps_t gps_data;
|
gps_t gps_data;
|
||||||
|
|
|
||||||
|
|
@ -139,26 +139,30 @@ void *dev_task(void *arg)
|
||||||
if(state.gpsDetected) gps_init(9600);
|
if(state.gpsDetected) gps_init(9600);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
uint8_t tick_5ms = 0;
|
||||||
|
|
||||||
while(state.shutdown == false)
|
while(state.shutdown == false)
|
||||||
{
|
{
|
||||||
// Update radio state
|
tick_5ms++;
|
||||||
state_update();
|
|
||||||
|
|
||||||
#if defined(GPS_PRESENT) && !defined(MD3x0_ENABLE_DBG)
|
#if defined(GPS_PRESENT) && !defined(MD3x0_ENABLE_DBG)
|
||||||
if(state.gpsDetected)
|
if(state.gpsDetected)
|
||||||
{
|
|
||||||
gps_taskFunc();
|
gps_taskFunc();
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Signal state update to UI thread
|
// Update radio state and push an event to the UI every 100ms
|
||||||
|
if((tick_5ms % 20) == 0)
|
||||||
|
{
|
||||||
|
state_update();
|
||||||
|
|
||||||
event_t dev_msg;
|
event_t dev_msg;
|
||||||
dev_msg.type = EVENT_STATUS;
|
dev_msg.type = EVENT_STATUS;
|
||||||
dev_msg.payload = 0;
|
dev_msg.payload = 0;
|
||||||
ui_pushEvent(dev_msg);
|
ui_pushEvent(dev_msg);
|
||||||
|
}
|
||||||
|
|
||||||
// 10Hz update rate
|
// Run this loop once every 5ms
|
||||||
sleepFor(0u, 100u);
|
sleepFor(0u, 5u);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(GPS_PRESENT)
|
#if defined(GPS_PRESENT)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue