2010-09-27 09:28:34 +02:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
* @addtogroup OpenPilotModules OpenPilot Modules
|
2013-05-18 14:17:26 +02:00
|
|
|
* @{
|
2010-09-27 09:28:34 +02:00
|
|
|
* @addtogroup GSPModule GPS Module
|
|
|
|
* @brief Process GPS information
|
2013-05-18 14:17:26 +02:00
|
|
|
* @{
|
2010-09-27 09:28:34 +02:00
|
|
|
*
|
|
|
|
* @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
|
|
|
// ****************
|
|
|
|
|
2013-05-02 23:31:14 +02:00
|
|
|
#include <openpilot.h>
|
2011-02-22 11:16:50 +01:00
|
|
|
|
2013-05-22 21:45:06 +02:00
|
|
|
#include "gpspositionsensor.h"
|
2010-09-27 09:28:34 +02:00
|
|
|
#include "homelocation.h"
|
|
|
|
#include "gpstime.h"
|
2011-08-21 14:23:07 +02:00
|
|
|
#include "gpssatellites.h"
|
2013-05-22 21:45:06 +02:00
|
|
|
#include "gpsvelocitysensor.h"
|
2013-06-30 18:49:29 +02:00
|
|
|
#include "gpssettings.h"
|
2013-05-02 23:31:14 +02:00
|
|
|
#include "taskinfo.h"
|
|
|
|
#include "hwsettings.h"
|
2014-07-17 20:39:47 +02:00
|
|
|
#include "auxmagsensor.h"
|
2010-09-27 09:28:34 +02:00
|
|
|
#include "WorldMagModel.h"
|
|
|
|
#include "CoordinateConversions.h"
|
2014-08-22 02:43:30 +02:00
|
|
|
#include <pios_com.h>
|
2011-09-28 21:09:19 +02:00
|
|
|
|
2013-05-02 23:31:14 +02:00
|
|
|
#include "GPS.h"
|
2012-07-10 16:38:00 +02:00
|
|
|
#include "NMEA.h"
|
|
|
|
#include "UBX.h"
|
2014-08-22 22:34:52 +02:00
|
|
|
#if defined(PIOS_INCLUDE_GPS_UBX_PARSER) && !defined(PIOS_GPS_MINIMAL)
|
2014-08-22 10:10:21 +02:00
|
|
|
#include "inc/ubx_autoconfig.h"
|
2015-05-01 08:46:38 +02:00
|
|
|
//#include "../../libraries/inc/fifo_buffer.h"
|
2014-08-22 22:34:52 +02:00
|
|
|
#endif
|
2010-09-27 09:28:34 +02:00
|
|
|
|
2014-09-27 00:17:00 +02:00
|
|
|
#include <pios_instrumentation_helper.h>
|
|
|
|
PERF_DEFINE_COUNTER(counterBytesIn);
|
|
|
|
PERF_DEFINE_COUNTER(counterRate);
|
|
|
|
PERF_DEFINE_COUNTER(counterParse);
|
2011-02-22 11:16:50 +01:00
|
|
|
// ****************
|
2010-09-27 09:28:34 +02:00
|
|
|
// Private functions
|
|
|
|
|
|
|
|
static void gpsTask(void *parameters);
|
2015-04-30 05:46:47 +02:00
|
|
|
static void updateHwSettings(UAVObjEvent *ev);
|
2011-04-23 16:49:07 +02:00
|
|
|
|
|
|
|
#ifdef PIOS_GPS_SETS_HOMELOCATION
|
2013-05-22 21:45:06 +02:00
|
|
|
static void setHomeLocation(GPSPositionSensorData *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
|
|
|
|
2014-08-22 19:00:46 +02:00
|
|
|
#ifdef PIOS_INCLUDE_GPS_UBX_PARSER
|
|
|
|
void AuxMagSettingsUpdatedCb(UAVObjEvent *ev);
|
2014-08-22 22:34:52 +02:00
|
|
|
#ifndef PIOS_GPS_MINIMAL
|
2014-08-22 19:00:46 +02:00
|
|
|
void updateGpsSettings(UAVObjEvent *ev);
|
|
|
|
#endif
|
2014-08-22 22:34:52 +02:00
|
|
|
#endif
|
2014-08-22 19:00:46 +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
|
|
|
|
2014-05-11 11:38:08 +02:00
|
|
|
#define GPS_TIMEOUT_MS 500
|
2014-05-07 20:20:19 +02:00
|
|
|
// delay from detecting HomeLocation.Set == False before setting new homelocation
|
|
|
|
// this prevent that a save with homelocation.Set = false triggered by gps ends saving
|
|
|
|
// the new location with Set = true.
|
2014-05-11 11:38:08 +02:00
|
|
|
#define GPS_HOMELOCATION_SET_DELAY 5000
|
2011-02-22 13:32:08 +01:00
|
|
|
|
2014-09-27 00:17:00 +02:00
|
|
|
#define GPS_LOOP_DELAY_MS 6
|
|
|
|
|
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
|
2014-05-11 11:38:08 +02:00
|
|
|
#define STACK_SIZE_BYTES 1024
|
2012-06-28 09:02:14 +02:00
|
|
|
#else
|
|
|
|
#if defined(PIOS_GPS_MINIMAL)
|
2014-10-03 11:41:26 +02:00
|
|
|
#define GPS_READ_BUFFER 32
|
2015-02-07 17:02:59 +01:00
|
|
|
|
|
|
|
#ifdef PIOS_INCLUDE_GPS_NMEA_PARSER
|
|
|
|
#define STACK_SIZE_BYTES 580 // NMEA
|
|
|
|
#else
|
|
|
|
#define STACK_SIZE_BYTES 440 // UBX
|
|
|
|
#endif // PIOS_INCLUDE_GPS_NMEA_PARSER
|
2011-02-22 11:16:50 +01:00
|
|
|
#else
|
2014-05-11 11:38:08 +02:00
|
|
|
#define STACK_SIZE_BYTES 650
|
2012-06-28 09:02:14 +02:00
|
|
|
#endif // PIOS_GPS_MINIMAL
|
|
|
|
#endif // PIOS_GPS_SETS_HOMELOCATION
|
2011-02-22 11:16:50 +01:00
|
|
|
|
2014-09-27 22:40:17 +02:00
|
|
|
#ifndef GPS_READ_BUFFER
|
|
|
|
#define GPS_READ_BUFFER 128
|
|
|
|
#endif
|
|
|
|
|
2014-05-11 11:38:08 +02: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
|
|
|
|
2015-04-30 05:46:47 +02:00
|
|
|
static GPSSettingsData gpsSettings;
|
|
|
|
|
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;
|
|
|
|
|
2013-05-18 14:17:26 +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;
|
|
|
|
|
2013-04-30 13:06:42 +02:00
|
|
|
#if defined(PIOS_INCLUDE_GPS_NMEA_PARSER) || defined(PIOS_INCLUDE_GPS_UBX_PARSER)
|
2012-07-19 22:00:24 +02:00
|
|
|
static struct GPS_RX_STATS gpsRxStats;
|
2013-04-30 13:06:42 +02:00
|
|
|
#endif
|
2014-08-22 19:00:46 +02:00
|
|
|
|
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
|
|
|
{
|
2013-05-18 14:17:26 +02:00
|
|
|
if (gpsEnabled) {
|
|
|
|
if (gpsPort) {
|
|
|
|
// Start gps task
|
2014-06-18 01:47:43 +02:00
|
|
|
xTaskCreate(gpsTask, "GPS", STACK_SIZE_BYTES / 4, NULL, TASK_PRIORITY, &gpsTaskHandle);
|
2013-05-18 14:17:26 +02:00
|
|
|
PIOS_TASK_MONITOR_RegisterTask(TASKINFO_RUNNING_GPS, gpsTaskHandle);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
|
*/
|
2015-04-30 05:46:47 +02:00
|
|
|
|
2010-09-27 09:28:34 +02:00
|
|
|
int32_t GPSInitialize(void)
|
|
|
|
{
|
2013-05-18 14:17:26 +02:00
|
|
|
gpsPort = PIOS_COM_GPS;
|
2011-11-13 17:27:52 +01:00
|
|
|
|
2015-04-30 05:46:47 +02:00
|
|
|
HwSettingsInitialize();
|
2012-01-14 22:55:55 +01:00
|
|
|
#ifdef MODULE_GPS_BUILTIN
|
2013-05-18 14:17:26 +02:00
|
|
|
gpsEnabled = true;
|
2012-01-14 22:55:55 +01:00
|
|
|
#else
|
2013-09-01 13:23:20 +02:00
|
|
|
HwSettingsOptionalModulesData optionalModules;
|
2011-11-13 17:27:52 +01:00
|
|
|
|
2013-09-01 13:23:20 +02:00
|
|
|
HwSettingsOptionalModulesGet(&optionalModules);
|
2011-11-13 17:27:52 +01:00
|
|
|
|
2013-09-01 13:23:20 +02:00
|
|
|
if (optionalModules.GPS == HWSETTINGS_OPTIONALMODULES_ENABLED) {
|
2013-05-18 14:17:26 +02:00
|
|
|
gpsEnabled = true;
|
|
|
|
} else {
|
|
|
|
gpsEnabled = false;
|
|
|
|
}
|
2012-01-14 22:55:55 +01:00
|
|
|
#endif
|
2011-09-28 23:41:51 +02:00
|
|
|
|
2012-08-25 20:57:16 +02:00
|
|
|
#if defined(REVOLUTION)
|
2013-05-18 14:17:26 +02:00
|
|
|
// These objects MUST be initialized for Revolution
|
|
|
|
// because the rest of the system expects to just
|
|
|
|
// attach to their queues
|
2013-05-22 21:45:06 +02:00
|
|
|
GPSPositionSensorInitialize();
|
|
|
|
GPSVelocitySensorInitialize();
|
2013-05-18 14:17:26 +02:00
|
|
|
GPSTimeInitialize();
|
|
|
|
GPSSatellitesInitialize();
|
|
|
|
HomeLocationInitialize();
|
2014-07-17 20:43:16 +02:00
|
|
|
#ifdef PIOS_INCLUDE_GPS_UBX_PARSER
|
2014-07-17 20:39:47 +02:00
|
|
|
AuxMagSensorInitialize();
|
2014-08-20 21:05:56 +02:00
|
|
|
AuxMagSettingsInitialize();
|
2014-07-17 20:39:47 +02:00
|
|
|
GPSExtendedStatusInitialize();
|
2012-08-25 20:57:16 +02:00
|
|
|
|
2014-07-17 20:43:16 +02:00
|
|
|
// Initialize mag parameters
|
2014-08-20 21:05:56 +02:00
|
|
|
AuxMagSettingsUpdatedCb(NULL);
|
|
|
|
AuxMagSettingsConnectCallback(AuxMagSettingsUpdatedCb);
|
2014-07-17 20:43:16 +02:00
|
|
|
#endif
|
2015-04-30 05:46:47 +02:00
|
|
|
GPSSettingsInitialize();
|
|
|
|
// updateHwSettings() uses gpsSettings
|
|
|
|
GPSSettingsGet(&gpsSettings);
|
|
|
|
// must updateHwSettings() before updateGpsSettings() so baud rate is set before GPS serial code starts running
|
|
|
|
updateHwSettings(0);
|
2012-08-25 20:57:16 +02:00
|
|
|
#else
|
2013-05-18 14:17:26 +02:00
|
|
|
if (gpsPort && gpsEnabled) {
|
2013-05-22 21:45:06 +02:00
|
|
|
GPSPositionSensorInitialize();
|
|
|
|
GPSVelocitySensorInitialize();
|
2011-08-25 15:44:49 +02:00
|
|
|
#if !defined(PIOS_GPS_MINIMAL)
|
2013-05-18 14:17:26 +02:00
|
|
|
GPSTimeInitialize();
|
|
|
|
GPSSatellitesInitialize();
|
2011-08-25 15:40:45 +02:00
|
|
|
#endif
|
2013-06-30 16:31:19 +02:00
|
|
|
#if defined(PIOS_GPS_SETS_HOMELOCATION)
|
2013-05-18 14:17:26 +02:00
|
|
|
HomeLocationInitialize();
|
2011-08-20 01:25:49 +02:00
|
|
|
#endif
|
2015-04-30 05:46:47 +02:00
|
|
|
GPSSettingsInitialize();
|
|
|
|
// updateHwSettings() uses gpsSettings
|
|
|
|
GPSSettingsGet(&gpsSettings);
|
|
|
|
// must updateHwSettings() before updateGpsSettings() so baud rate is set before GPS serial code starts running
|
|
|
|
updateHwSettings(0);
|
2013-05-18 14:17:26 +02:00
|
|
|
}
|
|
|
|
#endif /* if defined(REVOLUTION) */
|
|
|
|
|
|
|
|
if (gpsPort && gpsEnabled) {
|
2015-04-30 05:46:47 +02:00
|
|
|
#if defined(PIOS_INCLUDE_GPS_NMEA_PARSER) && defined(PIOS_INCLUDE_GPS_UBX_PARSER)
|
|
|
|
gps_rx_buffer = pios_malloc((sizeof(struct UBXPacket) > NMEA_MAX_PACKET_LENGTH) ? sizeof(struct UBXPacket) : NMEA_MAX_PACKET_LENGTH);
|
|
|
|
#elif defined(PIOS_INCLUDE_GPS_UBX_PARSER)
|
|
|
|
gps_rx_buffer = pios_malloc(sizeof(struct UBXPacket));
|
|
|
|
#elif defined(PIOS_INCLUDE_GPS_NMEA_PARSER)
|
|
|
|
gps_rx_buffer = pios_malloc(NMEA_MAX_PACKET_LENGTH);
|
|
|
|
#else
|
|
|
|
gps_rx_buffer = NULL;
|
2015-02-07 17:02:59 +01:00
|
|
|
#endif
|
2015-04-30 05:46:47 +02:00
|
|
|
#if defined(PIOS_INCLUDE_GPS_NMEA_PARSER) || defined(PIOS_INCLUDE_GPS_UBX_PARSER)
|
2013-05-18 14:17:26 +02:00
|
|
|
PIOS_Assert(gps_rx_buffer);
|
2015-04-30 05:46:47 +02:00
|
|
|
#endif
|
2014-08-22 22:34:52 +02:00
|
|
|
#if defined(PIOS_INCLUDE_GPS_UBX_PARSER) && !defined(PIOS_GPS_MINIMAL)
|
2015-04-30 05:46:47 +02:00
|
|
|
HwSettingsConnectCallback(updateHwSettings); // allow changing baud rate even after startup
|
2014-08-22 19:00:46 +02:00
|
|
|
GPSSettingsConnectCallback(updateGpsSettings);
|
2014-08-22 22:34:52 +02:00
|
|
|
#endif
|
2013-05-18 14:17:26 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
2010-09-27 09:28:34 +02:00
|
|
|
}
|
2011-11-13 17:27:52 +01:00
|
|
|
|
2013-06-04 05:37:40 +02: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
|
|
|
|
2013-05-05 09:02:24 +02:00
|
|
|
static void gpsTask(__attribute__((unused)) void *parameters)
|
2010-09-27 09:28:34 +02:00
|
|
|
{
|
2013-05-18 14:17:26 +02:00
|
|
|
portTickType xDelay = 100 / portTICK_RATE_MS;
|
|
|
|
uint32_t timeNowMs = xTaskGetTickCount() * portTICK_RATE_MS;
|
2014-05-12 22:56:28 +02:00
|
|
|
|
2014-05-11 12:37:20 +02:00
|
|
|
#ifdef PIOS_GPS_SETS_HOMELOCATION
|
2014-05-07 20:20:19 +02:00
|
|
|
portTickType homelocationSetDelay = 0;
|
2014-05-11 12:37:20 +02:00
|
|
|
#endif
|
2013-05-22 21:45:06 +02:00
|
|
|
GPSPositionSensorData gpspositionsensor;
|
2012-06-28 09:02:14 +02:00
|
|
|
|
2013-05-18 14:17:26 +02:00
|
|
|
timeOfLastUpdateMs = timeNowMs;
|
|
|
|
timeOfLastCommandMs = timeNowMs;
|
2011-02-22 11:16:50 +01:00
|
|
|
|
2013-05-22 21:45:06 +02:00
|
|
|
GPSPositionSensorGet(&gpspositionsensor);
|
2014-08-22 22:34:52 +02:00
|
|
|
#if defined(PIOS_INCLUDE_GPS_UBX_PARSER) && !defined(PIOS_GPS_MINIMAL)
|
2015-04-30 05:46:47 +02:00
|
|
|
// this should be done in the task because it calls out to actually start the GPS serial reads
|
2014-08-22 19:00:46 +02:00
|
|
|
updateGpsSettings(0);
|
|
|
|
#endif
|
2014-09-27 00:17:00 +02:00
|
|
|
|
|
|
|
TickType_t xLastWakeTime;
|
|
|
|
xLastWakeTime = xTaskGetTickCount();
|
|
|
|
PERF_INIT_COUNTER(counterBytesIn, 0x97510001);
|
|
|
|
PERF_INIT_COUNTER(counterRate, 0x97510002);
|
|
|
|
PERF_INIT_COUNTER(counterParse, 0x97510003);
|
|
|
|
uint8_t c[GPS_READ_BUFFER];
|
|
|
|
|
2013-05-18 14:17:26 +02:00
|
|
|
// Loop forever
|
|
|
|
while (1) {
|
2014-08-22 22:34:52 +02:00
|
|
|
#if defined(PIOS_INCLUDE_GPS_UBX_PARSER) && !defined(PIOS_GPS_MINIMAL)
|
2014-08-22 02:43:30 +02:00
|
|
|
if (gpsSettings.DataProtocol == GPSSETTINGS_DATAPROTOCOL_UBX) {
|
|
|
|
char *buffer = 0;
|
|
|
|
uint16_t count = 0;
|
2015-04-30 05:46:47 +02:00
|
|
|
|
|
|
|
ubx_autoconfig_run(&buffer, &count);
|
2014-08-22 02:43:30 +02:00
|
|
|
// Something to send?
|
|
|
|
if (count) {
|
2015-03-04 19:38:40 +01:00
|
|
|
// clear ack/nak
|
|
|
|
ubxLastAck.clsID = 0x00;
|
|
|
|
ubxLastAck.msgID = 0x00;
|
|
|
|
ubxLastNak.clsID = 0x00;
|
|
|
|
ubxLastNak.msgID = 0x00;
|
|
|
|
|
2014-08-22 02:43:30 +02:00
|
|
|
PIOS_COM_SendBuffer(gpsPort, (uint8_t *)buffer, count);
|
|
|
|
}
|
|
|
|
}
|
2015-04-30 05:46:47 +02:00
|
|
|
|
|
|
|
// need to do this whether there is received data or not, or the status (e.g. gcs) is not always correct
|
|
|
|
int32_t ac_status = ubx_autoconfig_get_status();
|
|
|
|
static uint8_t lastStatus = GPSPOSITIONSENSOR_AUTOCONFIGSTATUS_DISABLED
|
|
|
|
+ GPSPOSITIONSENSOR_AUTOCONFIGSTATUS_RUNNING
|
|
|
|
+ GPSPOSITIONSENSOR_AUTOCONFIGSTATUS_DONE
|
|
|
|
+ GPSPOSITIONSENSOR_AUTOCONFIGSTATUS_ERROR;
|
|
|
|
gpspositionsensor.AutoConfigStatus =
|
|
|
|
ac_status == UBX_AUTOCONFIG_STATUS_DISABLED ? GPSPOSITIONSENSOR_AUTOCONFIGSTATUS_DISABLED :
|
|
|
|
ac_status == UBX_AUTOCONFIG_STATUS_DONE ? GPSPOSITIONSENSOR_AUTOCONFIGSTATUS_DONE :
|
|
|
|
ac_status == UBX_AUTOCONFIG_STATUS_ERROR ? GPSPOSITIONSENSOR_AUTOCONFIGSTATUS_ERROR :
|
|
|
|
GPSPOSITIONSENSOR_AUTOCONFIGSTATUS_RUNNING;
|
|
|
|
if (gpspositionsensor.AutoConfigStatus != lastStatus) {
|
|
|
|
GPSPositionSensorAutoConfigStatusSet(&gpspositionsensor.AutoConfigStatus);
|
|
|
|
lastStatus = gpspositionsensor.AutoConfigStatus;
|
|
|
|
}
|
2014-08-22 02:43:30 +02:00
|
|
|
#endif
|
2015-04-30 05:46:47 +02:00
|
|
|
|
|
|
|
// This blocks the task until there is something on the buffer (or 100ms? passes)
|
2014-09-27 00:17:00 +02:00
|
|
|
uint16_t cnt;
|
2015-04-30 05:46:47 +02:00
|
|
|
cnt = PIOS_COM_ReceiveBuffer(gpsPort, c, GPS_READ_BUFFER, xDelay);
|
|
|
|
if (cnt > 0) {
|
2014-09-27 00:17:00 +02:00
|
|
|
PERF_TIMED_SECTION_START(counterParse);
|
|
|
|
PERF_TRACK_VALUE(counterBytesIn, cnt);
|
|
|
|
PERF_MEASURE_PERIOD(counterRate);
|
2013-05-18 14:17:26 +02:00
|
|
|
int res;
|
2013-06-30 18:49:29 +02:00
|
|
|
switch (gpsSettings.DataProtocol) {
|
2012-06-28 09:02:14 +02:00
|
|
|
#if defined(PIOS_INCLUDE_GPS_NMEA_PARSER)
|
2013-06-30 18:49:29 +02:00
|
|
|
case GPSSETTINGS_DATAPROTOCOL_NMEA:
|
2014-09-27 00:17:00 +02:00
|
|
|
res = parse_nmea_stream(c, cnt, gps_rx_buffer, &gpspositionsensor, &gpsRxStats);
|
2013-05-18 14:17:26 +02:00
|
|
|
break;
|
2012-06-28 09:02:14 +02:00
|
|
|
#endif
|
|
|
|
#if defined(PIOS_INCLUDE_GPS_UBX_PARSER)
|
2014-08-22 22:34:52 +02:00
|
|
|
case GPSSETTINGS_DATAPROTOCOL_UBX:
|
2014-09-27 00:17:00 +02:00
|
|
|
res = parse_ubx_stream(c, cnt, gps_rx_buffer, &gpspositionsensor, &gpsRxStats);
|
2015-04-30 05:46:47 +02:00
|
|
|
break;
|
2012-06-28 09:02:14 +02:00
|
|
|
#endif
|
2013-05-18 14:17:26 +02:00
|
|
|
default:
|
|
|
|
res = NO_PARSER; // this should not happen
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-09-27 00:17:00 +02:00
|
|
|
PERF_TIMED_SECTION_END(counterParse);
|
2013-05-18 14:17:26 +02:00
|
|
|
if (res == PARSER_COMPLETE) {
|
|
|
|
timeNowMs = xTaskGetTickCount() * portTICK_RATE_MS;
|
|
|
|
timeOfLastUpdateMs = timeNowMs;
|
|
|
|
timeOfLastCommandMs = timeNowMs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for GPS timeout
|
|
|
|
timeNowMs = xTaskGetTickCount() * portTICK_RATE_MS;
|
2014-09-24 06:12:48 +02:00
|
|
|
if ((timeNowMs - timeOfLastUpdateMs) >= GPS_TIMEOUT_MS ||
|
|
|
|
(gpsSettings.DataProtocol == GPSSETTINGS_DATAPROTOCOL_UBX && gpspositionsensor.AutoConfigStatus == GPSPOSITIONSENSOR_AUTOCONFIGSTATUS_ERROR)) {
|
2013-05-18 14:17:26 +02: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.
|
2013-05-22 21:45:06 +02:00
|
|
|
uint8_t status = GPSPOSITIONSENSOR_STATUS_NOGPS;
|
|
|
|
GPSPositionSensorStatusSet(&status);
|
2013-05-18 14:17:26 +02:00
|
|
|
AlarmsSet(SYSTEMALARMS_ALARM_GPS, SYSTEMALARMS_ALARM_ERROR);
|
|
|
|
} else {
|
|
|
|
// we appear to be receiving GPS sentences OK, we've had an update
|
|
|
|
// criteria for GPS-OK taken from this post...
|
|
|
|
// http://forums.openpilot.org/topic/1523-professors-insgps-in-svn/page__view__findpost__p__5220
|
2014-09-02 21:26:43 +02:00
|
|
|
if ((gpspositionsensor.PDOP < gpsSettings.MaxPDOP) && (gpspositionsensor.Satellites >= gpsSettings.MinSatellites) &&
|
2013-05-22 23:20:31 +02:00
|
|
|
(gpspositionsensor.Status == GPSPOSITIONSENSOR_STATUS_FIX3D) &&
|
|
|
|
(gpspositionsensor.Latitude != 0 || gpspositionsensor.Longitude != 0)) {
|
2013-05-18 14:17:26 +02:00
|
|
|
AlarmsClear(SYSTEMALARMS_ALARM_GPS);
|
2012-06-28 09:02:14 +02:00
|
|
|
#ifdef PIOS_GPS_SETS_HOMELOCATION
|
2013-05-18 14:17:26 +02:00
|
|
|
HomeLocationData home;
|
|
|
|
HomeLocationGet(&home);
|
2012-06-28 09:02:14 +02:00
|
|
|
|
2013-05-18 14:17:26 +02:00
|
|
|
if (home.Set == HOMELOCATION_SET_FALSE) {
|
2014-05-11 11:38:08 +02:00
|
|
|
if (homelocationSetDelay == 0) {
|
|
|
|
homelocationSetDelay = xTaskGetTickCount();
|
|
|
|
}
|
|
|
|
if (xTaskGetTickCount() - homelocationSetDelay > GPS_HOMELOCATION_SET_DELAY) {
|
|
|
|
setHomeLocation(&gpspositionsensor);
|
|
|
|
homelocationSetDelay = 0;
|
|
|
|
}
|
2014-05-12 22:56:28 +02:00
|
|
|
} else {
|
|
|
|
homelocationSetDelay = 0;
|
2013-05-18 14:17:26 +02:00
|
|
|
}
|
2013-05-22 21:45:06 +02:00
|
|
|
#endif
|
2013-06-09 22:42:14 +02:00
|
|
|
} else if ((gpspositionsensor.Status == GPSPOSITIONSENSOR_STATUS_FIX3D) &&
|
|
|
|
(gpspositionsensor.Latitude != 0 || gpspositionsensor.Longitude != 0)) {
|
2013-05-18 14:17:26 +02:00
|
|
|
AlarmsSet(SYSTEMALARMS_ALARM_GPS, SYSTEMALARMS_ALARM_WARNING);
|
|
|
|
} else {
|
|
|
|
AlarmsSet(SYSTEMALARMS_ALARM_GPS, SYSTEMALARMS_ALARM_CRITICAL);
|
|
|
|
}
|
|
|
|
}
|
2014-09-27 00:17:00 +02:00
|
|
|
vTaskDelayUntil(&xLastWakeTime, GPS_LOOP_DELAY_MS / portTICK_RATE_MS);
|
2013-05-18 14:17:26 +02: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
|
|
|
|
*/
|
2013-05-05 09:02:24 +02:00
|
|
|
static float GravityAccel(float latitude, __attribute__((unused)) float longitude, float altitude)
|
2011-03-21 01:48:32 +01:00
|
|
|
{
|
2013-05-18 14:17:26 +02:00
|
|
|
/* WGS84 gravity model. The effect of gravity over latitude is strong
|
|
|
|
* enough to change the estimated accelerometer bias in those apps. */
|
|
|
|
float sinsq = sinf(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 9.7803267714f * (1.0f + 0.00193185138639f * sinsq) / sqrtf(1.0f - 0.00669437999013f * sinsq)
|
|
|
|
- 3.086e-6f * altitude;
|
2011-03-21 01:48:32 +01:00
|
|
|
}
|
|
|
|
|
2011-02-22 11:16:50 +01:00
|
|
|
// ****************
|
|
|
|
|
2013-05-22 21:45:06 +02:00
|
|
|
static void setHomeLocation(GPSPositionSensorData *gpsData)
|
2010-09-27 09:28:34 +02:00
|
|
|
{
|
2013-05-18 14:17:26 +02:00
|
|
|
HomeLocationData home;
|
|
|
|
|
|
|
|
HomeLocationGet(&home);
|
|
|
|
GPSTimeData gps;
|
|
|
|
GPSTimeGet(&gps);
|
|
|
|
|
|
|
|
if (gps.Year >= 2000) {
|
|
|
|
/* 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
|
|
|
|
* Note that floats are used here - they should give enough precision
|
|
|
|
* for this application.*/
|
|
|
|
|
|
|
|
float LLA[3] = { (home.Latitude) / 10e6f, (home.Longitude) / 10e6f, (home.Altitude) };
|
|
|
|
|
|
|
|
/* Compute magnetic flux direction at home location */
|
|
|
|
if (WMM_GetMagVector(LLA[0], LLA[1], LLA[2], gps.Month, gps.Day, gps.Year, &home.Be[0]) == 0) {
|
|
|
|
/*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]);
|
|
|
|
home.Set = HOMELOCATION_SET_TRUE;
|
|
|
|
HomeLocationSet(&home);
|
|
|
|
}
|
|
|
|
}
|
2010-09-27 09:28:34 +02:00
|
|
|
}
|
2013-05-18 14:17:26 +02:00
|
|
|
#endif /* ifdef PIOS_GPS_SETS_HOMELOCATION */
|
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
|
|
|
*/
|
2015-04-30 05:46:47 +02:00
|
|
|
|
|
|
|
// must updateHwSettings() before updateGpsSettings() so baud rate is set before GPS serial code starts running
|
|
|
|
static void updateHwSettings(UAVObjEvent __attribute__((unused)) *ev)
|
2011-09-28 21:09:19 +02:00
|
|
|
{
|
2015-04-30 05:46:47 +02:00
|
|
|
// with these changes, no one (not even OP board makers) should ever need u-center (the complex UBlox configuration program)
|
|
|
|
// no booting of Revo should be required during any setup or testing, just Send the settings you want to play with
|
|
|
|
// with autoconfig enabled, just change the baud rate in HwSettings and it will change the GPS internal baud and then the Revo port
|
|
|
|
// with autoconfig disabled, it will only change the Revo port, so you can try to find the current GPS baud rate if you don't know it
|
2015-04-30 07:27:19 +02:00
|
|
|
// GPSPositionSensor.SensorType and .UbxAutoConfigStatus now give correct values at all times, so use .SensorType to prove it is
|
|
|
|
// connected, even to an incorrectly configured (e.g. factory default) GPS
|
2015-04-30 05:46:47 +02:00
|
|
|
|
|
|
|
// Use cases:
|
|
|
|
// - the user can plug in a default GPS, use autoconfig-store once and then always use autoconfig-disabled
|
|
|
|
// - the user can plug in a default GPS that can't store settings (defaults to 9600 baud) and always use autoconfig-nostore
|
2015-04-30 07:27:19 +02:00
|
|
|
// - - this is one reason for coding this: cheap eBay GPS's that loose their settings sometimes
|
2015-04-30 05:46:47 +02:00
|
|
|
// - the user can plug in a default GPS that _can_ store settings and always use autoconfig-nostore with that too
|
|
|
|
// - - if settings change in newer releases of OP, this will make sure to use the correct settings with whatever code you are running
|
|
|
|
// - the user can plug in a correctly configured GPS and use autoconfig-disabled
|
|
|
|
// - the user can recover an old or incorrectly configured GPS (internal GPS baud rate or other GPS settings wrong)
|
|
|
|
// - - disable UBX GPS autoconfig
|
|
|
|
// - - set HwSettings GPS baud rate to the current GPS internal baud rate to get it to connect at current (especially non-9600) baud rate
|
|
|
|
// - - - you can tell the baud rate is correct when GPSPositionSensor.SensorType is known (not "Unknown") (e.g. UBX6)
|
|
|
|
// - - - the SensorType and AutoConfigStatus may fail at 9600 and will fail at 4800 or lower if the GPS is configured to send OP data
|
|
|
|
// - - - (way more than default) at 4800 baud or slower
|
|
|
|
// - - enable autoconfig-nostore GPSSettings to set correct messages and enable further magic baud rate settings
|
|
|
|
// - - change the baud rate to what you want in HwSettings (it will change the baud rate in the GPS and then in the Revo port)
|
|
|
|
// - - wait for the baud rate change to complete, GPSPositionSensor.AutoConfigStatus will say "DONE"
|
|
|
|
// - - enable autoconfig-store and it will save the new baud rate and the correct message configuration
|
|
|
|
// - - wait for the store to complete, GPSPositionSensor.AutoConfigStatus will say "DONE"
|
|
|
|
// - - for the new baud rate, the user should either choose 9600 for use with autoconfig-nostore or can choose 57600 for use with autoconfig-disabled
|
|
|
|
// - the user (Dave :)) can configure a whole bunch of default GPS's with no intervention by using autoconfig-store as a saved Revo setting
|
|
|
|
// - - just plug the default (9600 baud) GPS in to an unpowered Revo, power the Revo/GPS through the servo connector, wait some time, unplug
|
|
|
|
// - - or with this code, OP could and even should just ship GPS's with default settings
|
|
|
|
|
2015-04-30 07:27:19 +02:00
|
|
|
// if we add an "initial baud rate" instead of assuming 9600 at boot up for autoconfig-nostore/store
|
2015-04-30 05:46:47 +02:00
|
|
|
// - the user can use the same GPS with both an older release of OP (e.g. GPS settings at 38400) and the current release (autoconfig-nostore)
|
2015-04-30 07:27:19 +02:00
|
|
|
// - the 57600 could be fixed instead of the 9600 as part of autoconfig-store/nostore and the HwSettings.GPSSpeed be the initial baud rate?
|
2015-04-30 05:46:47 +02:00
|
|
|
|
|
|
|
// About using UBlox GPS's with default settings (9600 baud and NEMA data):
|
|
|
|
// - the default uBlox settings (different than OP settings) are NEMA and 9600 baud
|
|
|
|
// - - and that is OK and you use autoconfig-nostore
|
|
|
|
// - - I personally feel that this is the best way to set it up because if OP dev changes GPS settings,
|
|
|
|
// - - you get them automatically changed to match whatever version of OP code you are running
|
2015-04-30 07:27:19 +02:00
|
|
|
// - - but 9600 is only OK for this autoconfig startup
|
2015-04-30 05:46:47 +02:00
|
|
|
// - by my testing, the 9600 initial to 57600 final baud startup takes:
|
2015-04-30 07:27:19 +02:00
|
|
|
// - - 0:10 if the GPS has been configured to send OP data at 9600
|
|
|
|
// - - 0:06 if the GPS has default data settings (NEMA) at 9600
|
|
|
|
// - - reminder that even 0:10 isn't that bad. You need to wait for the GPS to acquire satellites,
|
|
|
|
|
|
|
|
// Some things you want to think about if you want to play around with this:
|
|
|
|
// - don't play with low baud rates, with OP data settings (lots of data) it can take a long time to auto-configure
|
|
|
|
// - - at 2400 it could take a long time to autoconfig or error out
|
|
|
|
// - - at 9600 or lower the autoconfig is skipped and only the baud rate is changed
|
|
|
|
// - if you autoconfigure an OP configuration at 9600 baud or lower
|
|
|
|
// - - it will actually make a factory default configuration (not an OP configuration) at that baud rate
|
2015-04-30 05:46:47 +02:00
|
|
|
// - remember that there are two baud rates (inside the GPS and the Revo port) and you can get them out of sync
|
|
|
|
// - - rebooting the Revo from the Ground Control Station (without powering the GPS down too)
|
2015-04-30 07:27:19 +02:00
|
|
|
// - - can leave the baud rates out of sync if you are using autoconfig
|
2015-04-30 05:46:47 +02:00
|
|
|
// - - just power off and on both the Revo and the GPS
|
2015-04-30 07:27:19 +02:00
|
|
|
// - my OP GPS #2 will NOT save 115200 baud or higher, but it will use all bauds, even 230400
|
|
|
|
// - - so you could use autoconfig.nostore with this high baud rate, but not autoconfig.store (once) followed by autoconfig.disabled
|
|
|
|
// - - I haven't tested other GPS's in regard to this
|
2015-04-30 05:46:47 +02:00
|
|
|
|
2015-04-30 07:27:19 +02:00
|
|
|
// since 9600 baud and lower are not usable, and are best left at NEMA, I could have coded it to do a factory reset
|
|
|
|
// - if set to 9600 baud (or lower)
|
2015-04-30 05:46:47 +02:00
|
|
|
|
2013-05-18 14:17:26 +02:00
|
|
|
if (gpsPort) {
|
|
|
|
uint8_t speed;
|
2015-04-30 05:46:47 +02:00
|
|
|
|
|
|
|
#if defined(PIOS_INCLUDE_GPS_UBX_PARSER) && !defined(PIOS_GPS_MINIMAL)
|
|
|
|
// use 9600 baud during startup if autoconfig is enabled
|
|
|
|
// that is the flag that the code should assumes a factory default baud rate
|
|
|
|
if (ev == NULL && gpsSettings.UbxAutoConfig != GPSSETTINGS_UBXAUTOCONFIG_DISABLED) {
|
|
|
|
speed = HWSETTINGS_GPSSPEED_9600;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
// Retrieve settings
|
|
|
|
HwSettingsGPSSpeedGet(&speed);
|
|
|
|
}
|
|
|
|
|
|
|
|
// must always set the baud here, even if it looks like it is the same
|
|
|
|
// e.g. startup sets 9600 here, ubx_autoconfig sets 57600 there, then the user selects a change back to 9600 here
|
|
|
|
|
|
|
|
// on startup (ev == NULL) we must set the Revo port baud rate
|
|
|
|
// after startup (ev != NULL) we must set the Revo port baud rate only if autoconfig is disabled
|
|
|
|
// always we must set the Revo port baud rate if not using UBX
|
|
|
|
#if defined(PIOS_INCLUDE_GPS_UBX_PARSER) && !defined(PIOS_GPS_MINIMAL)
|
|
|
|
if (ev == NULL || gpsSettings.UbxAutoConfig == GPSSETTINGS_UBXAUTOCONFIG_DISABLED || gpsSettings.DataProtocol != GPSSETTINGS_DATAPROTOCOL_UBX)
|
|
|
|
#endif
|
|
|
|
{
|
2015-05-01 08:49:15 +02:00
|
|
|
// Set Revo port speed
|
2015-04-30 05:46:47 +02:00
|
|
|
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;
|
|
|
|
case HWSETTINGS_GPSSPEED_230400:
|
|
|
|
PIOS_COM_ChangeBaud(gpsPort, 230400);
|
|
|
|
break;
|
|
|
|
}
|
2015-04-30 07:27:19 +02:00
|
|
|
#if defined(PIOS_INCLUDE_GPS_UBX_PARSER) && !defined(PIOS_GPS_MINIMAL)
|
2015-04-30 05:46:47 +02:00
|
|
|
// even changing the baud rate will make it re-verify the sensor type
|
|
|
|
// that way the user can just try some baud rates and it when the sensor type is valid, the baud rate is correct
|
|
|
|
ubx_reset_sensor_type();
|
2015-04-30 07:27:19 +02:00
|
|
|
#endif
|
2013-05-18 14:17:26 +02:00
|
|
|
}
|
2015-04-30 05:46:47 +02:00
|
|
|
#if defined(PIOS_INCLUDE_GPS_UBX_PARSER) && !defined(PIOS_GPS_MINIMAL)
|
|
|
|
else {
|
|
|
|
// it will never do this during startup because ev == NULL
|
|
|
|
ubx_autoconfig_set(NULL);
|
|
|
|
}
|
|
|
|
#endif
|
2013-05-18 14:17:26 +02:00
|
|
|
}
|
2011-09-28 21:09:19 +02:00
|
|
|
}
|
2014-08-22 19:00:46 +02:00
|
|
|
|
2015-02-07 17:02:59 +01:00
|
|
|
#if defined(PIOS_INCLUDE_GPS_UBX_PARSER) && !defined(PIOS_GPS_MINIMAL)
|
2014-08-20 21:05:56 +02:00
|
|
|
void AuxMagSettingsUpdatedCb(__attribute__((unused)) UAVObjEvent *ev)
|
2014-07-17 20:43:16 +02:00
|
|
|
{
|
|
|
|
load_mag_settings();
|
|
|
|
}
|
2015-02-07 17:02:59 +01:00
|
|
|
|
2014-08-22 19:00:46 +02:00
|
|
|
void updateGpsSettings(__attribute__((unused)) UAVObjEvent *ev)
|
|
|
|
{
|
|
|
|
ubx_autoconfig_settings_t newconfig;
|
2015-04-30 05:46:47 +02:00
|
|
|
|
|
|
|
GPSSettingsGet(&gpsSettings);
|
|
|
|
|
|
|
|
newconfig.navRate = gpsSettings.UbxRate;
|
|
|
|
|
|
|
|
newconfig.autoconfigEnabled = gpsSettings.UbxAutoConfig == GPSSETTINGS_UBXAUTOCONFIG_DISABLED ? false : true;
|
|
|
|
newconfig.storeSettings = gpsSettings.UbxAutoConfig == GPSSETTINGS_UBXAUTOCONFIG_CONFIGUREANDSTORE;
|
|
|
|
|
|
|
|
newconfig.dynamicModel = gpsSettings.UbxDynamicModel == GPSSETTINGS_UBXDYNAMICMODEL_PORTABLE ? UBX_DYNMODEL_PORTABLE :
|
|
|
|
gpsSettings.UbxDynamicModel == GPSSETTINGS_UBXDYNAMICMODEL_STATIONARY ? UBX_DYNMODEL_STATIONARY :
|
|
|
|
gpsSettings.UbxDynamicModel == GPSSETTINGS_UBXDYNAMICMODEL_PEDESTRIAN ? UBX_DYNMODEL_PEDESTRIAN :
|
|
|
|
gpsSettings.UbxDynamicModel == GPSSETTINGS_UBXDYNAMICMODEL_AUTOMOTIVE ? UBX_DYNMODEL_AUTOMOTIVE :
|
|
|
|
gpsSettings.UbxDynamicModel == GPSSETTINGS_UBXDYNAMICMODEL_SEA ? UBX_DYNMODEL_SEA :
|
|
|
|
gpsSettings.UbxDynamicModel == GPSSETTINGS_UBXDYNAMICMODEL_AIRBORNE1G ? UBX_DYNMODEL_AIRBORNE1G :
|
|
|
|
gpsSettings.UbxDynamicModel == GPSSETTINGS_UBXDYNAMICMODEL_AIRBORNE2G ? UBX_DYNMODEL_AIRBORNE2G :
|
|
|
|
gpsSettings.UbxDynamicModel == GPSSETTINGS_UBXDYNAMICMODEL_AIRBORNE4G ? UBX_DYNMODEL_AIRBORNE4G :
|
2014-08-22 19:00:46 +02:00
|
|
|
UBX_DYNMODEL_AIRBORNE1G;
|
2014-09-02 21:26:56 +02:00
|
|
|
|
2015-04-30 05:46:47 +02:00
|
|
|
switch ((GPSSettingsUbxSBASModeOptions)gpsSettings.UbxSBASMode) {
|
2014-09-02 21:26:56 +02:00
|
|
|
case GPSSETTINGS_UBXSBASMODE_RANGINGCORRECTION:
|
|
|
|
case GPSSETTINGS_UBXSBASMODE_CORRECTION:
|
|
|
|
case GPSSETTINGS_UBXSBASMODE_RANGINGCORRECTIONINTEGRITY:
|
|
|
|
case GPSSETTINGS_UBXSBASMODE_CORRECTIONINTEGRITY:
|
|
|
|
newconfig.SBASCorrection = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
newconfig.SBASCorrection = false;
|
|
|
|
}
|
|
|
|
|
2015-04-30 05:46:47 +02:00
|
|
|
switch ((GPSSettingsUbxSBASModeOptions)gpsSettings.UbxSBASMode) {
|
2014-09-02 21:26:56 +02:00
|
|
|
case GPSSETTINGS_UBXSBASMODE_RANGING:
|
|
|
|
case GPSSETTINGS_UBXSBASMODE_RANGINGCORRECTION:
|
|
|
|
case GPSSETTINGS_UBXSBASMODE_RANGINGINTEGRITY:
|
|
|
|
case GPSSETTINGS_UBXSBASMODE_RANGINGCORRECTIONINTEGRITY:
|
|
|
|
newconfig.SBASRanging = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
newconfig.SBASRanging = false;
|
|
|
|
}
|
|
|
|
|
2015-04-30 05:46:47 +02:00
|
|
|
switch ((GPSSettingsUbxSBASModeOptions)gpsSettings.UbxSBASMode) {
|
2014-09-02 21:26:56 +02:00
|
|
|
case GPSSETTINGS_UBXSBASMODE_INTEGRITY:
|
|
|
|
case GPSSETTINGS_UBXSBASMODE_RANGINGINTEGRITY:
|
|
|
|
case GPSSETTINGS_UBXSBASMODE_RANGINGCORRECTIONINTEGRITY:
|
|
|
|
case GPSSETTINGS_UBXSBASMODE_CORRECTIONINTEGRITY:
|
|
|
|
newconfig.SBASIntegrity = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
newconfig.SBASIntegrity = false;
|
|
|
|
}
|
|
|
|
|
2015-04-30 05:46:47 +02:00
|
|
|
newconfig.SBASChannelsUsed = gpsSettings.UbxSBASChannelsUsed;
|
2014-09-02 21:26:56 +02:00
|
|
|
|
2015-04-30 05:46:47 +02:00
|
|
|
newconfig.SBASSats = gpsSettings.UbxSBASSats == GPSSETTINGS_UBXSBASSATS_WAAS ? UBX_SBAS_SATS_WAAS :
|
|
|
|
gpsSettings.UbxSBASSats == GPSSETTINGS_UBXSBASSATS_EGNOS ? UBX_SBAS_SATS_EGNOS :
|
|
|
|
gpsSettings.UbxSBASSats == GPSSETTINGS_UBXSBASSATS_MSAS ? UBX_SBAS_SATS_MSAS :
|
|
|
|
gpsSettings.UbxSBASSats == GPSSETTINGS_UBXSBASSATS_GAGAN ? UBX_SBAS_SATS_GAGAN :
|
|
|
|
gpsSettings.UbxSBASSats == GPSSETTINGS_UBXSBASSATS_SDCM ? UBX_SBAS_SATS_SDCM : UBX_SBAS_SATS_AUTOSCAN;
|
2015-02-22 14:30:14 +01:00
|
|
|
|
2015-04-30 05:46:47 +02:00
|
|
|
switch (gpsSettings.UbxGNSSMode) {
|
2015-02-22 14:30:14 +01:00
|
|
|
case GPSSETTINGS_UBXGNSSMODE_GPSGLONASS:
|
|
|
|
newconfig.enableGPS = true;
|
|
|
|
newconfig.enableGLONASS = true;
|
2015-03-01 17:28:43 +01:00
|
|
|
newconfig.enableBeiDou = false;
|
2015-02-22 14:30:14 +01:00
|
|
|
break;
|
|
|
|
case GPSSETTINGS_UBXGNSSMODE_GLONASS:
|
|
|
|
newconfig.enableGPS = false;
|
|
|
|
newconfig.enableGLONASS = true;
|
2015-03-01 17:28:43 +01:00
|
|
|
newconfig.enableBeiDou = false;
|
2015-02-22 14:30:14 +01:00
|
|
|
break;
|
2015-02-28 13:17:22 +01:00
|
|
|
case GPSSETTINGS_UBXGNSSMODE_GPS:
|
2015-02-22 14:30:14 +01:00
|
|
|
newconfig.enableGPS = true;
|
|
|
|
newconfig.enableGLONASS = false;
|
2015-03-01 17:28:43 +01:00
|
|
|
newconfig.enableBeiDou = false;
|
|
|
|
break;
|
|
|
|
case GPSSETTINGS_UBXGNSSMODE_GPSBEIDOU:
|
|
|
|
newconfig.enableGPS = true;
|
|
|
|
newconfig.enableGLONASS = false;
|
|
|
|
newconfig.enableBeiDou = true;
|
|
|
|
break;
|
|
|
|
case GPSSETTINGS_UBXGNSSMODE_GLONASSBEIDOU:
|
|
|
|
newconfig.enableGPS = false;
|
|
|
|
newconfig.enableGLONASS = true;
|
|
|
|
newconfig.enableBeiDou = true;
|
2015-02-22 14:30:14 +01:00
|
|
|
break;
|
2015-02-28 13:17:22 +01:00
|
|
|
default:
|
|
|
|
newconfig.enableGPS = false;
|
|
|
|
newconfig.enableGLONASS = false;
|
2015-03-01 17:28:43 +01:00
|
|
|
newconfig.enableBeiDou = false;
|
2015-02-28 13:17:22 +01:00
|
|
|
break;
|
2015-02-22 14:30:14 +01:00
|
|
|
}
|
|
|
|
|
2015-04-30 05:46:47 +02:00
|
|
|
ubx_autoconfig_set(&newconfig);
|
2014-08-22 19:00:46 +02:00
|
|
|
}
|
2014-08-22 22:34:52 +02:00
|
|
|
#endif /* if defined(PIOS_INCLUDE_GPS_UBX_PARSER) && !defined(PIOS_GPS_MINIMAL) */
|
2013-05-18 14:17:26 +02:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
* @}
|
|
|
|
*/
|