dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages

Process GPS information. More...

Files

file  GPS.c
 GPS module, handles UBX and NMEA streams from GPS.
 
file  GPS.h
 Include file of the GPS module.
 
file  NMEA.h
 Include file to process NMEA data.
 
file  UBX.h
 Include file for UBX processing.
 
file  ubx_cfg.h
 Include file for UBX configuration.
 
file  NMEA.c
 NMEA parser.
 
file  UBX.c
 Process UBX data.
 
file  ubx_cfg.h
 Include file for UBX configuration.
 

Data Structures

struct  GPS_RX_STATS
 
struct  UBX_NAV_POSLLH
 
struct  UBX_NAV_STATUS
 
struct  UBX_NAV_DOP
 
struct  UBX_NAV_SOL
 
struct  UBX_NAV_VELNED
 
struct  UBX_NAV_TIMEUTC
 
struct  UBX_NAV_SVINFO_SV
 
struct  UBX_NAV_SVINFO
 
struct  UBX_MON_VER
 
union  UBXPayload
 
struct  UBXHeader
 
struct  UBXPacket
 

Macros

#define GPS_TIMEOUT_MS   750
 
#define GPS_COM_TIMEOUT_MS   100
 
#define STACK_SIZE_BYTES   850
 
#define TASK_PRIORITY   PIOS_THREAD_PRIO_LOW
 
#define NO_PARSER   -3
 
#define PARSER_OVERRUN   -2
 
#define PARSER_ERROR   -1
 
#define PARSER_INCOMPLETE   0
 
#define PARSER_COMPLETE   1
 
#define NMEA_MAX_PACKET_LENGTH   96
 
#define UBX_SYNC1   0xb5
 
#define UBX_SYNC2   0x62
 
#define UBX_CLASS_NAV   0x01
 
#define UBX_ID_POSLLH   0x02
 
#define UBX_ID_STATUS   0x03
 
#define UBX_ID_DOP   0x04
 
#define UBX_ID_SOL   0x06
 
#define UBX_ID_VELNED   0x12
 
#define UBX_ID_TIMEUTC   0x21
 
#define UBX_ID_SVINFO   0x30
 
#define UBX_CLASS_MON   0x0A
 
#define UBX_ID_MONVER   0x04
 
#define STATUS_GPSFIX_NOFIX   0x00
 
#define STATUS_GPSFIX_DRONLY   0x01
 
#define STATUS_GPSFIX_2DFIX   0x02
 
#define STATUS_GPSFIX_3DFIX   0x03
 
#define STATUS_GPSFIX_GPSDR   0x04
 
#define STATUS_GPSFIX_TIMEONLY   0x05
 
#define STATUS_FLAGS_GPSFIX_OK   (1 << 0)
 
#define STATUS_FLAGS_DIFFSOLN   (1 << 1)
 
#define STATUS_FLAGS_WKNSET   (1 << 2)
 
#define STATUS_FLAGS_TOWSET   (1 << 3)
 
#define TIMEUTC_VALIDTOW   (1 << 0)
 
#define TIMEUTC_VALIDWKN   (1 << 1)
 
#define TIMEUTC_VALIDUTC   (1 << 2)
 
#define SVUSED   (1 << 0)
 
#define DIFFCORR   (1 << 1)
 
#define ORBITAVAIL   (1 << 2)
 
#define ORBITEPH   (1 << 3)
 
#define UNHEALTHY   (1 << 4)
 
#define ORBITALM   (1 << 5)
 
#define ORBITAOP   (1 << 6)
 
#define SMOOTHED   (1 << 7)
 
#define MAX_SVS   32
 
#define UBLOX_SYNC1   0xB5
 
#define UBLOX_SYNC2   0x62
 
#define UBLOX_NAV_CLASS   0x01
 
#define UBLOX_RXM_CLASS   0x02
 
#define UBLOX_CFG_CLASS   0x06
 
#define UBLOX_MON_CLASS   0x0a
 
#define UBLOX_AID_CLASS   0x0b
 
#define UBLOX_TIM_CLASS   0x0d
 
#define UBLOX_NAV_POSLLH   0x02
 
#define UBLOX_NAV_STATUS   0x03
 
#define UBLOX_NAV_DOP   0x04
 
#define UBLOX_NAV_SOL   0x06
 
#define UBLOX_NAV_VELNED   0x12
 
#define UBLOX_NAV_TIMEUTC   0x21
 
#define UBLOX_NAV_SBAS   0x32
 
#define UBLOX_NAV_SVINFO   0x30
 
#define UBLOX_AID_REQ   0x00
 
#define UBLOX_RXM_RAW   0x10
 
#define UBLOX_RXM_SFRB   0x11
 
#define UBLOX_MON_VER   0x04
 
#define UBLOX_MON_HW   0x09
 
#define UBLOX_TIM_TP   0x01
 
#define UBLOX_CFG_MSG   0x01
 
#define UBLOX_CFG_TP   0x07
 
#define UBLOX_CFG_RATE   0x08
 
#define UBLOX_CFG_CFG   0x09
 
#define UBLOX_CFG_SBAS   0x16
 
#define UBLOX_CFG_NAV5   0x24
 
#define UBLOX_CFG_GNSS   0x3E
 
#define UBLOX_SBAS_AUTO   0x00000000
 
#define UBLOX_SBAS_WAAS   0x0004E004
 
#define UBLOX_SBAS_EGNOS   0x00000851
 
#define UBLOX_SBAS_MSAS   0x00020200
 
#define UBLOX_SBAS_GAGAN   0x00000108
 
#define UBLOX_DYN_PORTABLE   0
 
#define UBLOX_DYN_STATIONARY   2
 
#define UBLOX_DYN_PED   3
 
#define UBLOX_DYN_AUTOMOTIVE   4
 
#define UBLOX_DYN_SEA   5
 
#define UBLOX_DYN_AIR1G   6
 
#define UBLOX_DYN_AIR2G   7
 
#define UBLOX_DYN_AIR4G   8
 
#define UBLOX_GNSSID_GPS   0
 
#define UBLOX_GNSSID_SBAS   1
 
#define UBLOX_GNSSID_BEIDOU   3
 
#define UBLOX_GNSSID_QZSS   5
 
#define UBLOX_GNSSID_GLONASS   6
 
#define UBLOX_MAX_PAYLOAD   384
 
#define UBLOX_WAIT_MS   50
 
#define MAX_CH_PER_CATEGORY   16
 

Functions

static void gpsTask (void *parameters)
 
static void updateSettings ()
 
int32_t GPSStart (void)
 
int32_t GPSInitialize (void)
 
 MODULE_INITCALL (GPSInitialize, GPSStart)
 
static void gpsConfigure (uint8_t gpsProtocol)
 
bool NMEA_update_position (char *nmea_sentence, GPSPositionData *GpsData)
 
bool NMEA_checksum (char *nmea_sentence)
 
int parse_nmea_stream (uint8_t, char *, GPSPositionData *, struct GPS_RX_STATS *)
 
int parse_ubx_stream (uint8_t, char *, GPSPositionData *, struct GPS_RX_STATS *)
 
void ubx_cfg_send_configuration (uintptr_t gps_port, char *buffer, ModuleSettingsGPSConstellationOptions constellation, ModuleSettingsGPSSBASConstellationOptions sbas_const, ModuleSettingsGPSDynamicsModeOptions dyn_mode)
 
void ubx_cfg_set_baudrate (uintptr_t gps_port, ModuleSettingsGPSSpeedOptions baud_rate)
 Make sure the GPS is set to the same baud. More...
 
static void ubx_cfg_send_checksummed (uintptr_t gps_port, const uint8_t *dat, uint16_t len)
 Send a stream of data followed by checksum. More...
 
static void ubloxTxChecksumReset (void)
 Reset the TX checksum calculation. More...
 
static void ubloxTxChecksum (uint8_t c)
 Update the checksum calculation. More...
 
static void ubx_cfg_enable_message (uintptr_t gps_port, uint8_t c, uint8_t i, uint8_t rate)
 Enable the selected UBX message at the specified rate. More...
 
static void ubx_cfg_set_rate (uintptr_t gps_port, uint16_t ms)
 Set the rate of all messages. More...
 
static void ubx_cfg_set_mode (uintptr_t gps_port, ModuleSettingsGPSDynamicsModeOptions dyn_mode)
 Configure the navigation mode and minimum fix. More...
 
static void ubx_cfg_set_timepulse (uintptr_t gps_port)
 Configure the timepulse output pin. More...
 
static void ubx_cfg_set_sbas (uintptr_t gps_port, ModuleSettingsGPSSBASConstellationOptions sbas_const)
 Enable or disable SBAS satellites. More...
 
static void ubx_cfg_clear_cfg (uintptr_t gps_port)
 
static void ubx_cfg_poll_version (uintptr_t gps_port)
 Request a MON-VER message with the firmware version. More...
 
static void ubx_cfg_set_constellation (uintptr_t gps_port, ModuleSettingsGPSConstellationOptions constellation, ModuleSettingsGPSSBASConstellationOptions sbas_const)
 
static void ubx_cfg_version_specific (uintptr_t gps_port, uint8_t ver, ModuleSettingsGPSConstellationOptions constellation, ModuleSettingsGPSSBASConstellationOptions sbas_const)
 Apply firmware version specific configuration tweaks. More...
 
static void ubx_cfg_pause_parse (uintptr_t gps_port, uint32_t delay_ticks)
 Parse incoming data while paused. More...
 

Variables

static uintptr_t gpsPort
 
static bool module_enabled = false
 
static struct pios_thread * gpsTaskHandle
 
static char * gps_rx_buffer
 
static struct GPS_RX_STATS gpsRxStats
 
uint8_t ubloxTxCK_A
 
uint8_t ubloxTxCK_B
 
static char * gps_rx_buffer
 

Detailed Description

Process GPS information.

Macro Definition Documentation

#define DIFFCORR   (1 << 1)

Definition at line 166 of file UBX.h.

#define GPS_COM_TIMEOUT_MS   100

Definition at line 71 of file GPS.c.

#define GPS_TIMEOUT_MS   750

Definition at line 70 of file GPS.c.

#define MAX_CH_PER_CATEGORY   16

Definition at line 328 of file ubx_cfg.c.

#define MAX_SVS   32

Definition at line 186 of file UBX.h.

#define NMEA_MAX_PACKET_LENGTH   96

Definition at line 37 of file NMEA.h.

#define NO_PARSER   -3

Definition at line 38 of file GPS.h.

#define ORBITALM   (1 << 5)

Definition at line 170 of file UBX.h.

#define ORBITAOP   (1 << 6)

Definition at line 171 of file UBX.h.

#define ORBITAVAIL   (1 << 2)

Definition at line 167 of file UBX.h.

#define ORBITEPH   (1 << 3)

Definition at line 168 of file UBX.h.

#define PARSER_COMPLETE   1

Definition at line 42 of file GPS.h.

#define PARSER_ERROR   -1

Definition at line 40 of file GPS.h.

#define PARSER_INCOMPLETE   0

Definition at line 41 of file GPS.h.

#define PARSER_OVERRUN   -2

Definition at line 39 of file GPS.h.

#define SMOOTHED   (1 << 7)

Definition at line 172 of file UBX.h.

#define STACK_SIZE_BYTES   850

Definition at line 72 of file GPS.c.

#define STATUS_FLAGS_DIFFSOLN   (1 << 1)

Definition at line 80 of file UBX.h.

#define STATUS_FLAGS_GPSFIX_OK   (1 << 0)

Definition at line 79 of file UBX.h.

#define STATUS_FLAGS_TOWSET   (1 << 3)

Definition at line 82 of file UBX.h.

#define STATUS_FLAGS_WKNSET   (1 << 2)

Definition at line 81 of file UBX.h.

#define STATUS_GPSFIX_2DFIX   0x02

Definition at line 74 of file UBX.h.

#define STATUS_GPSFIX_3DFIX   0x03

Definition at line 75 of file UBX.h.

#define STATUS_GPSFIX_DRONLY   0x01

Definition at line 73 of file UBX.h.

#define STATUS_GPSFIX_GPSDR   0x04

Definition at line 76 of file UBX.h.

#define STATUS_GPSFIX_NOFIX   0x00

Definition at line 72 of file UBX.h.

#define STATUS_GPSFIX_TIMEONLY   0x05

Definition at line 77 of file UBX.h.

#define SVUSED   (1 << 0)

Definition at line 165 of file UBX.h.

#define TASK_PRIORITY   PIOS_THREAD_PRIO_LOW

Definition at line 74 of file GPS.c.

#define TIMEUTC_VALIDTOW   (1 << 0)

Definition at line 144 of file UBX.h.

#define TIMEUTC_VALIDUTC   (1 << 2)

Definition at line 146 of file UBX.h.

#define TIMEUTC_VALIDWKN   (1 << 1)

Definition at line 145 of file UBX.h.

#define UBLOX_AID_CLASS   0x0b

Definition at line 67 of file ubx_cfg.c.

#define UBLOX_AID_REQ   0x00

Definition at line 79 of file ubx_cfg.c.

#define UBLOX_CFG_CFG   0x09

Definition at line 92 of file ubx_cfg.c.

#define UBLOX_CFG_CLASS   0x06

Definition at line 65 of file ubx_cfg.c.

#define UBLOX_CFG_GNSS   0x3E

Definition at line 95 of file ubx_cfg.c.

#define UBLOX_CFG_MSG   0x01

Definition at line 89 of file ubx_cfg.c.

#define UBLOX_CFG_NAV5   0x24

Definition at line 94 of file ubx_cfg.c.

#define UBLOX_CFG_RATE   0x08

Definition at line 91 of file ubx_cfg.c.

#define UBLOX_CFG_SBAS   0x16

Definition at line 93 of file ubx_cfg.c.

#define UBLOX_CFG_TP   0x07

Definition at line 90 of file ubx_cfg.c.

#define UBLOX_DYN_AIR1G   6

Definition at line 110 of file ubx_cfg.c.

#define UBLOX_DYN_AIR2G   7

Definition at line 111 of file ubx_cfg.c.

#define UBLOX_DYN_AIR4G   8

Definition at line 112 of file ubx_cfg.c.

#define UBLOX_DYN_AUTOMOTIVE   4

Definition at line 108 of file ubx_cfg.c.

#define UBLOX_DYN_PED   3

Definition at line 107 of file ubx_cfg.c.

#define UBLOX_DYN_PORTABLE   0

Definition at line 105 of file ubx_cfg.c.

#define UBLOX_DYN_SEA   5

Definition at line 109 of file ubx_cfg.c.

#define UBLOX_DYN_STATIONARY   2

Definition at line 106 of file ubx_cfg.c.

#define UBLOX_GNSSID_BEIDOU   3

Definition at line 116 of file ubx_cfg.c.

#define UBLOX_GNSSID_GLONASS   6

Definition at line 118 of file ubx_cfg.c.

#define UBLOX_GNSSID_GPS   0

Definition at line 114 of file ubx_cfg.c.

#define UBLOX_GNSSID_QZSS   5

Definition at line 117 of file ubx_cfg.c.

#define UBLOX_GNSSID_SBAS   1

Definition at line 115 of file ubx_cfg.c.

#define UBLOX_MAX_PAYLOAD   384

Definition at line 120 of file ubx_cfg.c.

#define UBLOX_MON_CLASS   0x0a

Definition at line 66 of file ubx_cfg.c.

#define UBLOX_MON_HW   0x09

Definition at line 85 of file ubx_cfg.c.

#define UBLOX_MON_VER   0x04

Definition at line 84 of file ubx_cfg.c.

#define UBLOX_NAV_CLASS   0x01

Definition at line 63 of file ubx_cfg.c.

#define UBLOX_NAV_DOP   0x04

Definition at line 72 of file ubx_cfg.c.

#define UBLOX_NAV_POSLLH   0x02

Definition at line 70 of file ubx_cfg.c.

#define UBLOX_NAV_SBAS   0x32

Definition at line 76 of file ubx_cfg.c.

#define UBLOX_NAV_SOL   0x06

Definition at line 73 of file ubx_cfg.c.

#define UBLOX_NAV_STATUS   0x03

Definition at line 71 of file ubx_cfg.c.

#define UBLOX_NAV_SVINFO   0x30

Definition at line 77 of file ubx_cfg.c.

#define UBLOX_NAV_TIMEUTC   0x21

Definition at line 75 of file ubx_cfg.c.

#define UBLOX_NAV_VELNED   0x12

Definition at line 74 of file ubx_cfg.c.

#define UBLOX_RXM_CLASS   0x02

Definition at line 64 of file ubx_cfg.c.

#define UBLOX_RXM_RAW   0x10

Definition at line 81 of file ubx_cfg.c.

#define UBLOX_RXM_SFRB   0x11

Definition at line 82 of file ubx_cfg.c.

#define UBLOX_SBAS_AUTO   0x00000000

Definition at line 97 of file ubx_cfg.c.

#define UBLOX_SBAS_EGNOS   0x00000851

Definition at line 101 of file ubx_cfg.c.

#define UBLOX_SBAS_GAGAN   0x00000108

Definition at line 103 of file ubx_cfg.c.

#define UBLOX_SBAS_MSAS   0x00020200

Definition at line 102 of file ubx_cfg.c.

#define UBLOX_SBAS_WAAS   0x0004E004

Definition at line 100 of file ubx_cfg.c.

#define UBLOX_SYNC1   0xB5

Definition at line 60 of file ubx_cfg.c.

#define UBLOX_SYNC2   0x62

Definition at line 61 of file ubx_cfg.c.

#define UBLOX_TIM_CLASS   0x0d

Definition at line 68 of file ubx_cfg.c.

#define UBLOX_TIM_TP   0x01

Definition at line 87 of file ubx_cfg.c.

#define UBLOX_WAIT_MS   50

Definition at line 121 of file ubx_cfg.c.

#define UBX_CLASS_MON   0x0A

Definition at line 54 of file UBX.h.

#define UBX_CLASS_NAV   0x01

Definition at line 43 of file UBX.h.

#define UBX_ID_DOP   0x04

Definition at line 48 of file UBX.h.

#define UBX_ID_MONVER   0x04

Definition at line 56 of file UBX.h.

#define UBX_ID_POSLLH   0x02

Definition at line 46 of file UBX.h.

#define UBX_ID_SOL   0x06

Definition at line 49 of file UBX.h.

#define UBX_ID_STATUS   0x03

Definition at line 47 of file UBX.h.

#define UBX_ID_SVINFO   0x30

Definition at line 52 of file UBX.h.

#define UBX_ID_TIMEUTC   0x21

Definition at line 51 of file UBX.h.

#define UBX_ID_VELNED   0x12

Definition at line 50 of file UBX.h.

#define UBX_SYNC1   0xb5

Definition at line 37 of file UBX.h.

#define UBX_SYNC2   0x62

Definition at line 38 of file UBX.h.

#define UNHEALTHY   (1 << 4)

Definition at line 169 of file UBX.h.

Function Documentation

static void gpsConfigure ( uint8_t  gpsProtocol)
static

Definition at line 180 of file GPS.c.

int32_t GPSInitialize ( void  )

Initialise the gps module

Returns
-1 if initialisation failed
0 on success

Definition at line 115 of file GPS.c.

int32_t GPSStart ( void  )

Initialise the gps module

Returns
-1 if initialisation failed
0 on success

Definition at line 95 of file GPS.c.

static void gpsTask ( void *  parameters)
static

Main gps task. It does not return.

Definition at line 227 of file GPS.c.

MODULE_INITCALL ( GPSInitialize  ,
GPSStart   
)
bool NMEA_checksum ( char *  nmea_sentence)
bool NMEA_update_position ( char *  nmea_sentence,
GPSPositionData *  GpsData 
)
int parse_nmea_stream ( uint8_t  ,
char *  ,
GPSPositionData *  ,
struct GPS_RX_STATS  
)
int parse_ubx_stream ( uint8_t  ,
char *  ,
GPSPositionData *  ,
struct GPS_RX_STATS  
)
static void ubloxTxChecksum ( uint8_t  c)
static

Update the checksum calculation.

Definition at line 135 of file ubx_cfg.c.

static void ubloxTxChecksumReset ( void  )
static

Reset the TX checksum calculation.

Definition at line 129 of file ubx_cfg.c.

static void ubx_cfg_clear_cfg ( uintptr_t  gps_port)
static

Erases the internal storage for message and navigation configuration. Does not do anything until UBX reboot though.

Definition at line 302 of file ubx_cfg.c.

static void ubx_cfg_enable_message ( uintptr_t  gps_port,
uint8_t  c,
uint8_t  i,
uint8_t  rate 
)
static

Enable the selected UBX message at the specified rate.

Definition at line 141 of file ubx_cfg.c.

static void ubx_cfg_pause_parse ( uintptr_t  gps_port,
uint32_t  delay_ticks 
)
static

Parse incoming data while paused.

Definition at line 440 of file ubx_cfg.c.

static void ubx_cfg_poll_version ( uintptr_t  gps_port)
static

Request a MON-VER message with the firmware version.

Definition at line 323 of file ubx_cfg.c.

static void ubx_cfg_send_checksummed ( uintptr_t  gps_port,
const uint8_t *  dat,
uint16_t  len 
)
static

Send a stream of data followed by checksum.

Definition at line 456 of file ubx_cfg.c.

void ubx_cfg_send_configuration ( uintptr_t  gps_port,
char *  buffer,
ModuleSettingsGPSConstellationOptions  constellation,
ModuleSettingsGPSSBASConstellationOptions  sbas_const,
ModuleSettingsGPSDynamicsModeOptions  dyn_mode 
)

Completely configure a UBX GPS with the messages we expect in NAV5 mode at the appropriate rate.

Definition at line 479 of file ubx_cfg.c.

void ubx_cfg_set_baudrate ( uintptr_t  gps_port,
ModuleSettingsGPSSpeedOptions  baud_rate 
)

Make sure the GPS is set to the same baud.

Definition at line 523 of file ubx_cfg.c.

static void ubx_cfg_set_constellation ( uintptr_t  gps_port,
ModuleSettingsGPSConstellationOptions  constellation,
ModuleSettingsGPSSBASConstellationOptions  sbas_const 
)
static

Definition at line 329 of file ubx_cfg.c.

static void ubx_cfg_set_mode ( uintptr_t  gps_port,
ModuleSettingsGPSDynamicsModeOptions  dyn_mode 
)
static

Configure the navigation mode and minimum fix.

Definition at line 175 of file ubx_cfg.c.

static void ubx_cfg_set_rate ( uintptr_t  gps_port,
uint16_t  ms 
)
static

Set the rate of all messages.

Definition at line 157 of file ubx_cfg.c.

static void ubx_cfg_set_sbas ( uintptr_t  gps_port,
ModuleSettingsGPSSBASConstellationOptions  sbas_const 
)
static

Enable or disable SBAS satellites.

Definition at line 252 of file ubx_cfg.c.

static void ubx_cfg_set_timepulse ( uintptr_t  gps_port)
static

Configure the timepulse output pin.

Definition at line 222 of file ubx_cfg.c.

static void ubx_cfg_version_specific ( uintptr_t  gps_port,
uint8_t  ver,
ModuleSettingsGPSConstellationOptions  constellation,
ModuleSettingsGPSSBASConstellationOptions  sbas_const 
)
static

Apply firmware version specific configuration tweaks.

Definition at line 410 of file ubx_cfg.c.

static void updateSettings ( )
static

Update the GPS settings, called on startup.

Definition at line 324 of file GPS.c.

Variable Documentation

char* gps_rx_buffer
static

Definition at line 84 of file GPS.c.

char* gps_rx_buffer
static

Definition at line 124 of file ubx_cfg.c.

uintptr_t gpsPort
static

Definition at line 79 of file GPS.c.

struct GPS_RX_STATS gpsRxStats
static

Definition at line 86 of file GPS.c.

struct pios_thread* gpsTaskHandle
static

Definition at line 82 of file GPS.c.

bool module_enabled = false
static

Definition at line 80 of file GPS.c.

uint8_t ubloxTxCK_A

Definition at line 123 of file ubx_cfg.c.

uint8_t ubloxTxCK_B

Definition at line 123 of file ubx_cfg.c.