41 #include "gpsposition.h"
42 #include "airspeedactual.h"
43 #include "homelocation.h"
45 #include "gpssatellites.h"
46 #include "gpsvelocity.h"
47 #include "modulesettings.h"
57 #if defined(PIOS_GPS_PROVIDES_AIRSPEED)
64 static void gpsTask(
void *parameters);
70 #define GPS_TIMEOUT_MS 750
71 #define GPS_COM_TIMEOUT_MS 100
72 #define STACK_SIZE_BYTES 850
74 #define TASK_PRIORITY PIOS_THREAD_PRIO_LOW
105 AlarmsSet(SYSTEMALARMS_ALARM_GPS, SYSTEMALARMS_ALARM_ERROR);
120 #ifdef MODULE_GPS_BUILTIN
128 if (GPSPositionInitialize() == -1 \
129 || GPSVelocityInitialize() == -1) {
133 if (GPSTimeInitialize() == -1 \
134 || GPSSatellitesInitialize() == -1 \
135 || HomeLocationInitialize() == -1 \
136 || UBloxInfoInitialize() == -1) {
140 #if defined(PIOS_GPS_PROVIDES_AIRSPEED)
141 if (AirspeedActualInitialize() == -1) {
149 ModuleSettingsGPSDataProtocolGet(&gpsProtocol);
150 switch (gpsProtocol) {
151 case MODULESETTINGS_GPSDATAPROTOCOL_NMEA:
154 AlarmsSet(SYSTEMALARMS_ALARM_GPS, SYSTEMALARMS_ALARM_ERROR);
158 case MODULESETTINGS_GPSDATAPROTOCOL_UBX:
161 AlarmsSet(SYSTEMALARMS_ALARM_GPS, SYSTEMALARMS_ALARM_ERROR);
182 ModuleSettingsGPSAutoConfigureOptions gpsAutoConfigure;
183 ModuleSettingsGPSAutoConfigureGet(&gpsAutoConfigure);
185 if (gpsAutoConfigure != MODULESETTINGS_GPSAUTOCONFIGURE_TRUE) {
189 switch (gpsProtocol) {
190 #if defined(PIOS_INCLUDE_GPS_UBX_PARSER)
191 case MODULESETTINGS_GPSDATAPROTOCOL_UBX:
199 ModuleSettingsGPSSpeedOptions baud_rate;
200 ModuleSettingsGPSConstellationOptions constellation;
201 ModuleSettingsGPSSBASConstellationOptions sbas_const;
202 ModuleSettingsGPSDynamicsModeOptions dyn_mode;
204 ModuleSettingsGPSSpeedGet(&baud_rate);
205 ModuleSettingsGPSConstellationGet(&constellation);
206 ModuleSettingsGPSSBASConstellationGet(&sbas_const);
207 ModuleSettingsGPSDynamicsModeGet(&dyn_mode);
214 constellation, sbas_const, dyn_mode);
229 GPSPositionData gpsposition;
231 uint32_t timeOfLastUpdateMs = 0;
232 uint32_t timeOfConfigAttemptMs = 0;
236 #ifdef PIOS_GPS_PROVIDES_AIRSPEED
237 gps_airspeed_initialize();
240 GPSPositionGet(&gpsposition);
252 if (!timeOfConfigAttemptMs) {
253 ModuleSettingsGPSDataProtocolGet(&gpsProtocol);
267 switch (gpsProtocol) {
268 #if defined(PIOS_INCLUDE_GPS_NMEA_PARSER)
269 case MODULESETTINGS_GPSDATAPROTOCOL_NMEA:
273 #if defined(PIOS_INCLUDE_GPS_UBX_PARSER)
274 case MODULESETTINGS_GPSDATAPROTOCOL_UBX:
284 timeOfLastUpdateMs = loopTimeMs;
295 uint8_t
status = GPSPOSITION_STATUS_NOGPS;
296 GPSPositionStatusSet(&status);
297 AlarmsSet(SYSTEMALARMS_ALARM_GPS, SYSTEMALARMS_ALARM_ERROR);
300 timeOfConfigAttemptMs = 0;
305 if (gpsposition.PDOP < 3.5f &&
306 gpsposition.Satellites >= 7 &&
307 (gpsposition.Status == GPSPOSITION_STATUS_FIX3D ||
308 gpsposition.Status == GPSPOSITION_STATUS_DIFF3D)) {
310 }
else if (gpsposition.Status == GPSPOSITION_STATUS_FIX3D ||
311 gpsposition.Status == GPSPOSITION_STATUS_DIFF3D)
312 AlarmsSet(SYSTEMALARMS_ALARM_GPS, SYSTEMALARMS_ALARM_WARNING);
314 AlarmsSet(SYSTEMALARMS_ALARM_GPS, SYSTEMALARMS_ALARM_CRITICAL);
330 ModuleSettingsGPSSpeedGet(&speed);
uint32_t PIOS_Thread_Systime(void)
static char * gps_rx_buffer
static bool module_enabled
#define GPS_COM_TIMEOUT_MS
void ubx_cfg_send_configuration(uintptr_t gps_port, char *buffer, ModuleSettingsGPSConstellationOptions constellation, ModuleSettingsGPSSBASConstellationOptions sbas_const, ModuleSettingsGPSDynamicsModeOptions dyn_mode)
bool PIOS_Modules_IsEnabled(enum pios_modules module)
static void updateSettings()
void * PIOS_malloc(size_t size)
int32_t AlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity)
MODULE_INITCALL(GPSInitialize, GPSStart)
void PIOS_HAL_ConfigureSerialSpeed(uintptr_t com_id, HwSharedSpeedBpsOptions speed)
Airspeed module, reads temperature and pressure from BMP085.
uint16_t PIOS_COM_ReceiveBuffer(uintptr_t com_id, uint8_t *buf, uint16_t buf_len, uint32_t timeout_ms)
struct pios_thread * PIOS_Thread_Create(void(*fp)(void *), const char *namep, size_t stack_bytes, void *argp, enum pios_thread_prio_e prio)
static struct pios_thread * gpsTaskHandle
Include file of the GPS module.
void ubx_cfg_set_baudrate(uintptr_t gps_port, ModuleSettingsGPSSpeedOptions baud_rate)
Make sure the GPS is set to the same baud.
int32_t TaskMonitorAdd(TaskInfoRunningElem task, struct pios_thread *threadp)
int parse_ubx_stream(uint8_t, char *, GPSPositionData *, struct GPS_RX_STATS *)
void PIOS_Thread_Sleep(uint32_t time_ms)
static void gpsTask(void *parameters)
Include file to process NMEA data.
Include file for UBX configuration.
int parse_nmea_stream(uint8_t, char *, GPSPositionData *, struct GPS_RX_STATS *)
Includes PiOS and core architecture components.
int32_t AlarmsClear(SystemAlarmsAlarmElem alarm)
Include file for UBX processing.
static struct GPS_RX_STATS gpsRxStats
static void gpsConfigure(uint8_t gpsProtocol)
int32_t GPSInitialize(void)
#define NMEA_MAX_PACKET_LENGTH
#define PIOS_Assert(test)