1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-17 02:52:12 +01:00

Reduced GPS command resend to 2 second time-out, a few more white space corrections.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2844 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
pip 2011-02-22 12:32:08 +00:00 committed by pip
parent 3881c652c1
commit 9da0fb47e2
2 changed files with 26 additions and 30 deletions

View File

@ -49,14 +49,6 @@
#include "WorldMagModel.h"
#include "CoordinateConversions.h"
//#define FULL_COLD_RESTART // uncomment this to tell the GPS to do a FULL COLD restart
//#define DISABLE_GPS_TRESHOLD //
// ****************
// constants/macros/typdefs
#define GPS_TIMEOUT_MS 500
// ****************
// Private functions
@ -66,17 +58,20 @@ static void setHomeLocation(GPSPositionData * gpsData);
// ****************
// Private constants
//#define FULL_COLD_RESTART // uncomment this to tell the GPS to do a FULL COLD restart
//#define DISABLE_GPS_TRESHOLD //
#define GPS_TIMEOUT_MS 500
#define GPS_COMMAND_RESEND_TIMEOUT_MS 2000
// Unfortunately need a good size stack for the WMM calculation
#ifdef ENABLE_GPS_BINARY_GTOP
#define STACK_SIZE_BYTES 800
#define STACK_SIZE_BYTES 800
#else
#define STACK_SIZE_BYTES 800
#define STACK_SIZE_BYTES 800
#endif
#define TASK_PRIORITY (tskIDLE_PRIORITY + 1)
// ****************
// Private types
#define TASK_PRIORITY (tskIDLE_PRIORITY + 1)
// ****************
// Private variables
@ -271,14 +266,17 @@ static void gpsTask(void *parameters)
// Check for GPS timeout
timeNowMs = xTaskGetTickCount() * portTICK_RATE_MS;
if ((timeNowMs - timeOfLastUpdateMs) > GPS_TIMEOUT_MS)
{
{ // we have not received any valid GPS sentences for a while.
// either the GPS is not plugged in or a hardware problem or the GPS has locked up.
GPSPositionGet(&GpsData);
GpsData.Status = GPSPOSITION_STATUS_NOGPS;
GPSPositionSet(&GpsData);
AlarmsSet(SYSTEMALARMS_ALARM_GPS, SYSTEMALARMS_ALARM_ERROR);
if ((timeNowMs - timeOfLastCommandMs) > 5000) /// 5000ms
{ // resend the command .. just case the gps has only just been plugged in or the gps did not get our last command
if ((timeNowMs - timeOfLastCommandMs) >= GPS_COMMAND_RESEND_TIMEOUT_MS)
{ // resend the command .. just incase the gps has only just been plugged in or the gps did not get our last command
timeOfLastCommandMs = timeNowMs;
#ifdef ENABLE_GPS_BINARY_GTOP
GTOP_BIN_init();
@ -299,13 +297,11 @@ static void gpsTask(void *parameters)
#ifdef DISABLE_GPS_TRESHOLD
PIOS_COM_SendStringNonBlocking(gpsPort,"$PMTK397,0*23\r\n");
#endif
timeOfLastCommandMs = timeNowMs;
}
}
else
{
// Had an update
{ // we appear to be receiving GPS sentences OK, we've had an update
HomeLocationData home;
HomeLocationGet(&home);

View File

@ -34,7 +34,6 @@
#include "gpsposition.h"
#include "gpstime.h"
//#include <stdbool.h>
#include <string.h> // memmove
#ifdef ENABLE_GPS_BINARY_GTOP
@ -84,9 +83,10 @@ typedef struct
// ************
// buffer that holds the binary packet
// buffer that holds the incoming binary packet
static uint8_t gps_rx_buffer[sizeof(t_gps_bin_packet)] __attribute__ ((aligned(4)));
// number of bytes currently in the binary packet buffer
static uint8_t gps_rx_buffer_wr = 0;
// ************
@ -137,9 +137,8 @@ int GTOP_BIN_update_position(uint8_t b, volatile uint32_t *chksum_errors, volati
if (rx_packet->header == 0x2404)
break; // found a valid header marker
// remove oldest byte from buffer
if (gps_rx_buffer_wr > 1)
memmove(gps_rx_buffer, gps_rx_buffer + 1, gps_rx_buffer_wr - 1);
// shift all the bytes down one position
memmove(gps_rx_buffer, gps_rx_buffer + 1, gps_rx_buffer_wr - 1);
gps_rx_buffer_wr--;
}
@ -150,6 +149,7 @@ int GTOP_BIN_update_position(uint8_t b, volatile uint32_t *chksum_errors, volati
// we have enough bytes for a complete binary packet
// check to see if certain params are valid
if (rx_packet->header != 0x2404 ||
rx_packet->end_word != 0x0A0D ||
rx_packet->asterisk != 0x2A ||
@ -159,6 +159,7 @@ int GTOP_BIN_update_position(uint8_t b, volatile uint32_t *chksum_errors, volati
(rx_packet->data.fix_type < 1 || rx_packet->data.fix_type > 3) )
{ // invalid packet
if (parsing_errors) *parsing_errors++;
// shift all the bytes down one position
memmove(gps_rx_buffer, gps_rx_buffer + 1, gps_rx_buffer_wr - 1);
gps_rx_buffer_wr--;
continue;
@ -173,14 +174,13 @@ int GTOP_BIN_update_position(uint8_t b, volatile uint32_t *chksum_errors, volati
if (checksum != rx_packet->checksum)
{ // checksum error
if (chksum_errors) *chksum_errors++;
// shift all the bytes down one position
memmove(gps_rx_buffer, gps_rx_buffer + 1, gps_rx_buffer_wr - 1);
gps_rx_buffer_wr--;
continue;
}
}
// checksum appears correct
//
// we now have a valid complete binary packet, update the GpsData and GpsTime objects
// correct the endian order of the parameters
@ -237,10 +237,10 @@ int GTOP_BIN_update_position(uint8_t b, volatile uint32_t *chksum_errors, volati
else
gps_rx_buffer_wr = 0;
return 0; // found a valid packet
return 0; // found a valid packet
}
return -1; // no valid packet found
return -1; // no valid packet found
}
// ************