2010-09-27 09:28:34 +02:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
* @addtogroup OpenPilotModules OpenPilot Modules
|
|
|
|
* @{
|
|
|
|
* @addtogroup GSPModule GPS Module
|
|
|
|
* @brief Process GPS information
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file GPS.c
|
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
|
|
|
* @brief GPS module, handles GPS and NMEA stream
|
|
|
|
* @see The GNU Public License (GPL) Version 3
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2011-02-22 11:16:50 +01:00
|
|
|
// ****************
|
|
|
|
|
2010-09-27 09:28:34 +02:00
|
|
|
#include "openpilot.h"
|
|
|
|
#include "GPS.h"
|
2011-02-22 11:16:50 +01:00
|
|
|
|
2010-09-27 09:28:34 +02:00
|
|
|
#include <stdbool.h>
|
2011-02-22 11:16:50 +01:00
|
|
|
|
2011-08-25 14:46:30 +02:00
|
|
|
#include "NMEA.h"
|
2011-02-22 11:16:50 +01:00
|
|
|
|
2010-09-27 09:28:34 +02:00
|
|
|
#include "gpsposition.h"
|
|
|
|
#include "homelocation.h"
|
|
|
|
#include "gpstime.h"
|
2011-08-21 14:23:07 +02:00
|
|
|
#include "gpssatellites.h"
|
2010-09-27 09:28:34 +02:00
|
|
|
#include "WorldMagModel.h"
|
|
|
|
#include "CoordinateConversions.h"
|
2011-09-28 21:09:19 +02:00
|
|
|
#include "hwsettings.h"
|
|
|
|
|
2010-09-27 09:28:34 +02:00
|
|
|
|
2011-02-22 11:16:50 +01:00
|
|
|
// ****************
|
2010-09-27 09:28:34 +02:00
|
|
|
// Private functions
|
|
|
|
|
|
|
|
static void gpsTask(void *parameters);
|
2011-09-28 21:09:19 +02:00
|
|
|
static void updateSettings();
|
2011-04-23 16:49:07 +02:00
|
|
|
|
|
|
|
#ifdef PIOS_GPS_SETS_HOMELOCATION
|
2010-09-27 09:28:34 +02:00
|
|
|
static void setHomeLocation(GPSPositionData * gpsData);
|
2011-03-21 01:48:32 +01:00
|
|
|
static float GravityAccel(float latitude, float longitude, float altitude);
|
2011-04-23 16:49:07 +02:00
|
|
|
#endif
|
2010-09-27 09:28:34 +02:00
|
|
|
|
2011-02-22 11:16:50 +01:00
|
|
|
// ****************
|
2010-09-27 09:28:34 +02:00
|
|
|
// Private constants
|
2011-02-22 11:16:50 +01:00
|
|
|
|
2011-02-22 13:32:08 +01:00
|
|
|
#define GPS_TIMEOUT_MS 500
|
2011-08-25 14:46:30 +02:00
|
|
|
#define NMEA_MAX_PACKET_LENGTH 96 // 82 max NMEA msg size plus 12 margin (because some vendors add custom crap) plus CR plus Linefeed
|
|
|
|
// same as in COM buffer
|
|
|
|
|
2011-02-22 13:32:08 +01:00
|
|
|
|
2011-04-23 16:49:07 +02:00
|
|
|
#ifdef PIOS_GPS_SETS_HOMELOCATION
|
2010-09-27 09:28:34 +02:00
|
|
|
// Unfortunately need a good size stack for the WMM calculation
|
2011-08-25 14:46:30 +02:00
|
|
|
#define STACK_SIZE_BYTES 800
|
2011-02-22 11:16:50 +01:00
|
|
|
#else
|
2011-08-25 14:46:30 +02:00
|
|
|
#define STACK_SIZE_BYTES 650
|
2011-02-22 11:16:50 +01:00
|
|
|
#endif
|
|
|
|
|
2011-02-22 13:32:08 +01:00
|
|
|
#define TASK_PRIORITY (tskIDLE_PRIORITY + 1)
|
2010-09-27 09:28:34 +02:00
|
|
|
|
2011-02-22 11:16:50 +01:00
|
|
|
// ****************
|
2010-09-27 09:28:34 +02:00
|
|
|
// Private variables
|
2011-02-22 11:16:50 +01:00
|
|
|
|
2011-02-22 11:55:01 +01:00
|
|
|
static uint32_t gpsPort;
|
2011-11-13 04:25:17 +01:00
|
|
|
static bool gpsEnabled = false;
|
2011-02-22 11:16:50 +01:00
|
|
|
|
2010-09-27 09:28:34 +02:00
|
|
|
static xTaskHandle gpsTaskHandle;
|
|
|
|
|
2011-08-25 14:46:30 +02:00
|
|
|
static char* gps_rx_buffer;
|
2011-02-22 11:16:50 +01:00
|
|
|
|
|
|
|
static uint32_t timeOfLastCommandMs;
|
2010-09-27 09:28:34 +02:00
|
|
|
static uint32_t timeOfLastUpdateMs;
|
|
|
|
static uint32_t numUpdates;
|
|
|
|
static uint32_t numChecksumErrors;
|
|
|
|
static uint32_t numParsingErrors;
|
|
|
|
|
2011-02-22 11:16:50 +01:00
|
|
|
// ****************
|
2010-09-27 09:28:34 +02:00
|
|
|
/**
|
|
|
|
* Initialise the gps module
|
|
|
|
* \return -1 if initialisation failed
|
|
|
|
* \return 0 on success
|
|
|
|
*/
|
2011-02-22 11:16:50 +01:00
|
|
|
|
2011-06-20 07:35:40 +02:00
|
|
|
int32_t GPSStart(void)
|
2010-09-27 09:28:34 +02:00
|
|
|
{
|
2011-11-11 11:39:57 +01:00
|
|
|
if (gpsEnabled) {
|
|
|
|
if (gpsPort) {
|
|
|
|
// Start gps task
|
|
|
|
xTaskCreate(gpsTask, (signed char *)"GPS", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &gpsTaskHandle);
|
|
|
|
TaskMonitorAdd(TASKINFO_RUNNING_GPS, gpsTaskHandle);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
AlarmsSet(SYSTEMALARMS_ALARM_GPS, SYSTEMALARMS_ALARM_CRITICAL);
|
2011-09-28 23:41:51 +02:00
|
|
|
}
|
|
|
|
return -1;
|
2011-06-20 07:35:40 +02:00
|
|
|
}
|
2011-09-28 23:41:51 +02:00
|
|
|
|
2011-06-20 07:35:40 +02:00
|
|
|
/**
|
|
|
|
* Initialise the gps module
|
|
|
|
* \return -1 if initialisation failed
|
|
|
|
* \return 0 on success
|
|
|
|
*/
|
2010-09-27 09:28:34 +02:00
|
|
|
int32_t GPSInitialize(void)
|
|
|
|
{
|
2011-09-28 23:41:51 +02:00
|
|
|
gpsPort = PIOS_COM_GPS;
|
2011-11-13 17:27:52 +01:00
|
|
|
|
2012-01-14 22:55:55 +01:00
|
|
|
#ifdef MODULE_GPS_BUILTIN
|
|
|
|
gpsEnabled = true;
|
|
|
|
#else
|
2011-11-11 11:39:57 +01:00
|
|
|
HwSettingsInitialize();
|
|
|
|
uint8_t optionalModules[HWSETTINGS_OPTIONALMODULES_NUMELEM];
|
2011-11-13 17:27:52 +01:00
|
|
|
|
2011-11-11 11:39:57 +01:00
|
|
|
HwSettingsOptionalModulesGet(optionalModules);
|
2011-11-13 17:27:52 +01:00
|
|
|
|
2012-02-14 20:42:09 +01:00
|
|
|
//if (optionalModules[HWSETTINGS_OPTIONALMODULES_GPS] == HWSETTINGS_OPTIONALMODULES_ENABLED)
|
2011-11-13 04:25:17 +01:00
|
|
|
gpsEnabled = true;
|
2012-02-14 20:42:09 +01:00
|
|
|
//else
|
|
|
|
// gpsEnabled = false;
|
2012-01-14 22:55:55 +01:00
|
|
|
#endif
|
2011-09-28 23:41:51 +02:00
|
|
|
|
2011-11-11 11:39:57 +01:00
|
|
|
if (gpsPort && gpsEnabled) {
|
2011-09-28 23:41:51 +02:00
|
|
|
GPSPositionInitialize();
|
2011-08-25 15:44:49 +02:00
|
|
|
#if !defined(PIOS_GPS_MINIMAL)
|
2011-09-28 23:41:51 +02:00
|
|
|
GPSTimeInitialize();
|
|
|
|
GPSSatellitesInitialize();
|
2011-08-25 15:40:45 +02:00
|
|
|
#endif
|
2011-08-21 14:23:07 +02:00
|
|
|
#ifdef PIOS_GPS_SETS_HOMELOCATION
|
2011-09-28 23:41:51 +02:00
|
|
|
HomeLocationInitialize();
|
2011-08-20 01:25:49 +02:00
|
|
|
#endif
|
2012-02-14 20:42:09 +01:00
|
|
|
//updateSettings();
|
2011-09-28 21:09:19 +02:00
|
|
|
|
2011-09-28 23:41:51 +02:00
|
|
|
gps_rx_buffer = pvPortMalloc(NMEA_MAX_PACKET_LENGTH);
|
|
|
|
PIOS_Assert(gps_rx_buffer);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2011-08-25 14:46:30 +02:00
|
|
|
|
2011-09-28 23:41:51 +02:00
|
|
|
return -1;
|
2010-09-27 09:28:34 +02:00
|
|
|
}
|
2011-11-13 17:27:52 +01:00
|
|
|
|
2011-11-11 11:39:57 +01:00
|
|
|
MODULE_INITCALL(GPSInitialize, GPSStart)
|
2010-09-27 09:28:34 +02:00
|
|
|
|
2011-02-22 11:16:50 +01:00
|
|
|
// ****************
|
2010-09-27 09:28:34 +02:00
|
|
|
/**
|
2011-02-22 11:16:50 +01:00
|
|
|
* Main gps task. It does not return.
|
2010-09-27 09:28:34 +02:00
|
|
|
*/
|
2011-02-22 11:16:50 +01:00
|
|
|
|
2010-09-27 09:28:34 +02:00
|
|
|
static void gpsTask(void *parameters)
|
|
|
|
{
|
2011-02-22 11:55:01 +01:00
|
|
|
portTickType xDelay = 100 / portTICK_RATE_MS;
|
|
|
|
uint32_t timeNowMs = xTaskGetTickCount() * portTICK_RATE_MS;;
|
|
|
|
GPSPositionData GpsData;
|
2010-10-30 20:15:52 +02:00
|
|
|
|
2011-02-22 11:55:01 +01:00
|
|
|
uint8_t rx_count = 0;
|
|
|
|
bool start_flag = false;
|
|
|
|
bool found_cr = false;
|
|
|
|
int32_t gpsRxOverflow = 0;
|
2010-10-30 20:15:52 +02:00
|
|
|
|
2011-02-22 11:16:50 +01:00
|
|
|
numUpdates = 0;
|
|
|
|
numChecksumErrors = 0;
|
|
|
|
numParsingErrors = 0;
|
|
|
|
|
|
|
|
timeOfLastUpdateMs = timeNowMs;
|
|
|
|
timeOfLastCommandMs = timeNowMs;
|
|
|
|
|
2010-09-27 09:28:34 +02:00
|
|
|
// Loop forever
|
2011-02-22 11:16:50 +01:00
|
|
|
while (1)
|
|
|
|
{
|
2011-08-25 12:20:19 +02:00
|
|
|
uint8_t c;
|
2011-08-25 14:46:30 +02:00
|
|
|
// NMEA or SINGLE-SENTENCE GPS mode
|
|
|
|
|
|
|
|
// This blocks the task until there is something on the buffer
|
|
|
|
while (PIOS_COM_ReceiveBuffer(gpsPort, &c, 1, xDelay) > 0)
|
|
|
|
{
|
|
|
|
|
|
|
|
// detect start while acquiring stream
|
|
|
|
if (!start_flag && (c == '$'))
|
2011-02-22 11:16:50 +01:00
|
|
|
{
|
2011-08-25 14:46:30 +02:00
|
|
|
start_flag = true;
|
|
|
|
found_cr = false;
|
|
|
|
rx_count = 0;
|
2010-10-30 20:15:52 +02:00
|
|
|
}
|
2011-08-25 14:46:30 +02:00
|
|
|
else
|
|
|
|
if (!start_flag)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (rx_count >= NMEA_MAX_PACKET_LENGTH)
|
2011-02-22 11:16:50 +01:00
|
|
|
{
|
2011-08-25 14:46:30 +02:00
|
|
|
// The buffer is already full and we haven't found a valid NMEA sentence.
|
|
|
|
// Flush the buffer and note the overflow event.
|
|
|
|
gpsRxOverflow++;
|
|
|
|
start_flag = false;
|
|
|
|
found_cr = false;
|
|
|
|
rx_count = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gps_rx_buffer[rx_count] = c;
|
|
|
|
rx_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// look for ending '\r\n' sequence
|
|
|
|
if (!found_cr && (c == '\r') )
|
|
|
|
found_cr = true;
|
|
|
|
else
|
|
|
|
if (found_cr && (c != '\n') )
|
|
|
|
found_cr = false; // false end flag
|
|
|
|
else
|
|
|
|
if (found_cr && (c == '\n') )
|
|
|
|
{
|
|
|
|
// The NMEA functions require a zero-terminated string
|
|
|
|
// As we detected \r\n, the string as for sure 2 bytes long, we will also strip the \r\n
|
|
|
|
gps_rx_buffer[rx_count-2] = 0;
|
|
|
|
|
|
|
|
// prepare to parse next sentence
|
|
|
|
start_flag = false;
|
|
|
|
found_cr = false;
|
|
|
|
rx_count = 0;
|
|
|
|
// Our rxBuffer must look like this now:
|
|
|
|
// [0] = '$'
|
|
|
|
// ... = zero or more bytes of sentence payload
|
|
|
|
// [end_pos - 1] = '\r'
|
|
|
|
// [end_pos] = '\n'
|
|
|
|
//
|
|
|
|
// Prepare to consume the sentence from the buffer
|
2010-10-30 20:15:52 +02:00
|
|
|
|
2011-08-25 14:46:30 +02:00
|
|
|
// Validate the checksum over the sentence
|
|
|
|
if (!NMEA_checksum(&gps_rx_buffer[1]))
|
|
|
|
{ // Invalid checksum. May indicate dropped characters on Rx.
|
|
|
|
//PIOS_DEBUG_PinHigh(2);
|
|
|
|
++numChecksumErrors;
|
|
|
|
//PIOS_DEBUG_PinLow(2);
|
2011-02-22 11:16:50 +01:00
|
|
|
}
|
|
|
|
else
|
2011-08-25 14:46:30 +02:00
|
|
|
{ // Valid checksum, use this packet to update the GPS position
|
|
|
|
if (!NMEA_update_position(&gps_rx_buffer[1])) {
|
2011-03-12 09:55:45 +01:00
|
|
|
//PIOS_DEBUG_PinHigh(2);
|
2011-08-25 14:46:30 +02:00
|
|
|
++numParsingErrors;
|
2011-03-12 09:55:45 +01:00
|
|
|
//PIOS_DEBUG_PinLow(2);
|
2011-02-22 11:16:50 +01:00
|
|
|
}
|
|
|
|
else
|
2011-08-25 14:46:30 +02:00
|
|
|
++numUpdates;
|
|
|
|
|
|
|
|
timeNowMs = xTaskGetTickCount() * portTICK_RATE_MS;
|
|
|
|
timeOfLastUpdateMs = timeNowMs;
|
|
|
|
timeOfLastCommandMs = timeNowMs;
|
2010-09-27 09:28:34 +02:00
|
|
|
}
|
|
|
|
}
|
2011-08-25 14:46:30 +02:00
|
|
|
}
|
2011-02-12 23:19:43 +01:00
|
|
|
|
2010-09-27 09:28:34 +02:00
|
|
|
// Check for GPS timeout
|
|
|
|
timeNowMs = xTaskGetTickCount() * portTICK_RATE_MS;
|
2011-02-24 11:55:45 +01:00
|
|
|
if ((timeNowMs - timeOfLastUpdateMs) >= GPS_TIMEOUT_MS)
|
2011-02-22 13:32:08 +01:00
|
|
|
{ // 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.
|
|
|
|
|
2010-09-27 09:28:34 +02:00
|
|
|
GPSPositionGet(&GpsData);
|
|
|
|
GpsData.Status = GPSPOSITION_STATUS_NOGPS;
|
|
|
|
GPSPositionSet(&GpsData);
|
2010-12-27 20:59:43 +01:00
|
|
|
AlarmsSet(SYSTEMALARMS_ALARM_GPS, SYSTEMALARMS_ALARM_ERROR);
|
2011-02-22 11:16:50 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
else
|
2011-02-22 13:32:08 +01:00
|
|
|
{ // we appear to be receiving GPS sentences OK, we've had an update
|
|
|
|
|
2011-04-25 18:37:28 +02:00
|
|
|
GPSPositionGet(&GpsData);
|
|
|
|
|
2011-04-23 16:49:07 +02:00
|
|
|
#ifdef PIOS_GPS_SETS_HOMELOCATION
|
2010-09-27 09:28:34 +02:00
|
|
|
HomeLocationData home;
|
|
|
|
HomeLocationGet(&home);
|
2011-02-12 23:19:43 +01:00
|
|
|
|
2011-02-22 11:16:50 +01:00
|
|
|
if ((GpsData.Status == GPSPOSITION_STATUS_FIX3D) && (home.Set == HOMELOCATION_SET_FALSE))
|
2010-09-27 09:28:34 +02:00
|
|
|
setHomeLocation(&GpsData);
|
2011-04-23 16:49:07 +02:00
|
|
|
#endif
|
2010-12-27 20:59:43 +01:00
|
|
|
|
|
|
|
//criteria for GPS-OK taken from this post...
|
|
|
|
//http://forums.openpilot.org/topic/1523-professors-insgps-in-svn/page__view__findpost__p__5220
|
2011-02-22 11:16:50 +01:00
|
|
|
if ((GpsData.PDOP < 3.5) && (GpsData.Satellites >= 7))
|
|
|
|
AlarmsClear(SYSTEMALARMS_ALARM_GPS);
|
|
|
|
else
|
|
|
|
if (GpsData.Status == GPSPOSITION_STATUS_FIX3D)
|
|
|
|
AlarmsSet(SYSTEMALARMS_ALARM_GPS, SYSTEMALARMS_ALARM_WARNING);
|
|
|
|
else
|
|
|
|
AlarmsSet(SYSTEMALARMS_ALARM_GPS, SYSTEMALARMS_ALARM_CRITICAL);
|
2010-09-27 09:28:34 +02:00
|
|
|
}
|
2011-02-12 23:19:43 +01:00
|
|
|
|
2010-09-27 09:28:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-23 16:49:07 +02:00
|
|
|
#ifdef PIOS_GPS_SETS_HOMELOCATION
|
2011-03-21 01:48:32 +01:00
|
|
|
/*
|
|
|
|
* Estimate the acceleration due to gravity for a particular location in LLA
|
|
|
|
*/
|
|
|
|
static float GravityAccel(float latitude, float longitude, float altitude)
|
|
|
|
{
|
|
|
|
// WGS84 gravity model. The effect of gravity over latitude is strong
|
|
|
|
// enough to change the estimated accelerometer bias in those apps.
|
|
|
|
double sinsq = sin((double)latitude);
|
|
|
|
sinsq *= sinsq;
|
|
|
|
// Likewise, over the altitude range of a high-altitude balloon, the effect
|
|
|
|
// due to change in altitude can also affect the model.
|
|
|
|
return (float)(9.7803267714 * (1 + 0.00193185138639*sinsq) / sqrt(1 - 0.00669437999013*sinsq)
|
|
|
|
- 3.086e-6*altitude);
|
|
|
|
}
|
|
|
|
|
2011-02-22 11:16:50 +01:00
|
|
|
// ****************
|
|
|
|
|
2010-09-27 09:28:34 +02:00
|
|
|
static void setHomeLocation(GPSPositionData * gpsData)
|
|
|
|
{
|
|
|
|
HomeLocationData home;
|
|
|
|
HomeLocationGet(&home);
|
|
|
|
GPSTimeData gps;
|
|
|
|
GPSTimeGet(&gps);
|
|
|
|
|
2011-02-22 11:16:50 +01:00
|
|
|
if (gps.Year >= 2000)
|
|
|
|
{
|
2010-09-27 09:28:34 +02:00
|
|
|
// Store LLA
|
|
|
|
home.Latitude = gpsData->Latitude;
|
|
|
|
home.Longitude = gpsData->Longitude;
|
|
|
|
home.Altitude = gpsData->Altitude + gpsData->GeoidSeparation;
|
|
|
|
|
|
|
|
// Compute home ECEF coordinates and the rotation matrix into NED
|
|
|
|
double LLA[3] = { ((double)home.Latitude) / 10e6, ((double)home.Longitude) / 10e6, ((double)home.Altitude) };
|
|
|
|
double ECEF[3];
|
|
|
|
RneFromLLA(LLA, (float (*)[3])home.RNE);
|
|
|
|
LLA2ECEF(LLA, ECEF);
|
|
|
|
// TODO: Currently UAVTalk only supports float but these conversions use double
|
|
|
|
// need to find out if they require that precision and if so extend UAVTAlk
|
|
|
|
home.ECEF[0] = (int32_t) (ECEF[0] * 100);
|
|
|
|
home.ECEF[1] = (int32_t) (ECEF[1] * 100);
|
|
|
|
home.ECEF[2] = (int32_t) (ECEF[2] * 100);
|
|
|
|
|
|
|
|
// Compute magnetic flux direction at home location
|
2011-01-11 12:15:27 +01:00
|
|
|
if (WMM_GetMagVector(LLA[0], LLA[1], LLA[2], gps.Month, gps.Day, gps.Year, &home.Be[0]) >= 0)
|
|
|
|
{ // calculations appeared to go OK
|
2011-03-21 01:48:32 +01:00
|
|
|
|
|
|
|
// Compute local acceleration due to gravity. Vehicles that span a very large
|
|
|
|
// range of altitude (say, weather balloons) may need to update this during the
|
|
|
|
// flight.
|
|
|
|
home.g_e = GravityAccel(LLA[0], LLA[1], LLA[2]);
|
2011-03-28 12:40:26 +02:00
|
|
|
home.Set = HOMELOCATION_SET_TRUE;
|
|
|
|
HomeLocationSet(&home);
|
2011-01-11 12:15:27 +01:00
|
|
|
}
|
2010-09-27 09:28:34 +02:00
|
|
|
}
|
|
|
|
}
|
2011-04-23 16:49:07 +02:00
|
|
|
#endif
|
2010-09-27 09:28:34 +02:00
|
|
|
|
2011-09-28 21:09:19 +02:00
|
|
|
/**
|
2011-10-31 22:04:17 +01:00
|
|
|
* Update the GPS settings, called on startup.
|
|
|
|
* FIXME: This should be in the GPSSettings object. But objects have
|
|
|
|
* too much overhead yet. Also the GPS has no any specific settings
|
|
|
|
* like protocol, etc. Thus the HwSettings object which contains the
|
|
|
|
* GPS port speed is used for now.
|
2011-09-28 21:09:19 +02:00
|
|
|
*/
|
|
|
|
static void updateSettings()
|
|
|
|
{
|
|
|
|
if (gpsPort) {
|
|
|
|
|
|
|
|
// Retrieve settings
|
|
|
|
uint8_t speed;
|
|
|
|
HwSettingsGPSSpeedGet(&speed);
|
|
|
|
|
|
|
|
// Set port speed
|
|
|
|
switch (speed) {
|
|
|
|
case HWSETTINGS_GPSSPEED_2400:
|
|
|
|
PIOS_COM_ChangeBaud(gpsPort, 2400);
|
|
|
|
break;
|
|
|
|
case HWSETTINGS_GPSSPEED_4800:
|
|
|
|
PIOS_COM_ChangeBaud(gpsPort, 4800);
|
|
|
|
break;
|
|
|
|
case HWSETTINGS_GPSSPEED_9600:
|
|
|
|
PIOS_COM_ChangeBaud(gpsPort, 9600);
|
|
|
|
break;
|
|
|
|
case HWSETTINGS_GPSSPEED_19200:
|
|
|
|
PIOS_COM_ChangeBaud(gpsPort, 19200);
|
|
|
|
break;
|
|
|
|
case HWSETTINGS_GPSSPEED_38400:
|
|
|
|
PIOS_COM_ChangeBaud(gpsPort, 38400);
|
|
|
|
break;
|
|
|
|
case HWSETTINGS_GPSSPEED_57600:
|
|
|
|
PIOS_COM_ChangeBaud(gpsPort, 57600);
|
|
|
|
break;
|
|
|
|
case HWSETTINGS_GPSSPEED_115200:
|
|
|
|
PIOS_COM_ChangeBaud(gpsPort, 115200);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-27 09:28:34 +02:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
* @}
|
2012-02-14 20:42:09 +01:00
|
|
|
*/
|