GPS Device
Loading...
Searching...
No Matches
neo6.c File Reference

NEO-6M GPS module implementation file. More...

#include <stdint.h>
#include "neo6.h"
#include "cmd.h"
#include "common.h"
#include "err.h"
#include "init.h"
#include "log.h"
#include "modules.h"
#include "stm32f401re_gpio.h"
#include "stm32f401re_usart.h"
#include "cbuf.h"
#include "configuration.h"
Include dependency graph for neo6.c:

Go to the source code of this file.

Classes

struct  neo6_handle_s
 Internal structure representing the NEO-6 hardware instance. More...
struct  internal_state_s
 Internal state of the SysTick driver. More...

Macros

#define VTG_TMG_T_DEGREE_POS   1
#define VTG_TMG_T_POS   2
#define VTG_TMG_M_DEGREE_POS   3
#define VTG_TMG_M_POS   4
#define VTG_SPEED_KNOTS_POS   5
#define VTG_SPEED_N_POS   6
#define VTG_SPEED_OVER_GROUND_POS   7
#define VTG_SPEED_OVER_GROUND_K_POS   8
#define VTG_MODE_INDICATOR_POS   9
#define GGA_UTC_POS   1
#define GGA_LAT_POS   2
#define GGA_LAT_DIR_POS   3
#define GGA_LON_POS   4
#define GGA_LON_DIR_POS   5
#define GGA_QUALITY_FIX_POS   6
#define GGA_NUM_SATS_POS   7
#define GGA_HDOP_POS   8
#define GGA_ORTH_HEIGHT_POS   9
#define GGA_ORTH_HEIGHT_UNIT_POS   10
#define GGA_GEOID_SEP_POS   11
#define GGA_GEOID_SEP_UNIT_POS   12
#define GGA_DATA_REC_AGE_POS   13
#define GGA_REF_STAT_ID_POS   14
#define GSA_MODE_POS   1
#define GSA_FIX_TYPE_POS   2
#define GSA_PRN_NUM_POS   3
#define GSA_PDOP_POS   15
#define GSA_HDOP_POS   16
#define GSA_VDOP_POS   17
#define GSV_NUM_OF_MESSAGES_POS   1
#define GSV_NUM_OF_THIS_MESSAGE_POS   2
#define GSV_NUM_SATS_VISIBLE_POS   3
#define GSV_SV_PRN_NUM_POS   4
#define GSV_ELEVATION_POS   5
#define GSV_AZIMUTH_POS   6
#define GSV_SNR_POS   7

Functions

static ERR_te neo6_calc_checksum (char *msg, uint32_t msg_len, uint8_t *checksum_o)
 Computes the NMEA checksum of a sentence by XORing all bytes between '$' and '*'.
static ERR_te neo6_process_msg (uint8_t *msg, uint32_t msg_len)
 Verifies the checksum of a received NMEA sentence and dispatches it to the appropriate parser.
static ERR_te neo6_process_rmc (char **tokens)
 Parses an RMC sentence and updates time, date, latitude, and longitude.
static ERR_te neo6_process_vtg (char **tokens)
 Parses a VTG sentence and updates movement direction and speed.
static ERR_te neo6_process_gga (char **tokens)
 Parses a GGA sentence and updates fix status, satellites used, orthometric height, and geoid separation.
static ERR_te neo6_process_gsa (char **tokens)
 Parses a GSA sentence and updates fix type, PDOP, HDOP, and VDOP.
static ERR_te neo6_process_gsv (char **tokens)
 Parses a GSV sentence and updates the total satellite count.
static ERR_te neo6_dumpnmea_handler (uint32_t argc, char **argv)
 CLI handler for the "dumpnmea" command. Enables or disables raw NMEA logging.
ERR_te neo6_init_subsys (void)
 Initializes the NEO-6 subsystem.
ERR_te neo6_deinit_subsys (void)
 Deinitializes the NEO-6 subsystem.
ERR_te neo6_start_subsys (void)
 Starts the NEO-6 subsystem.
ERR_te neo6_stop_subsys (void)
 Stops the NEO-6 subsystem.
ERR_te neo6_init_handle (NEO6_CFG_ts *neo6_cfg, NEO6_HANDLE_ts **neo6_handle_o)
 Initializes the NEO-6 hardware handle.
ERR_te neo6_run (void)
 Processes received NMEA data.
ERR_te neo6_get_info (NEO6_INFO_ts **neo6_info_o)
 Returns a pointer to the internal GPS data structure.
void usart6_irq_data_recv_callback (uint8_t data)
 USART RXNE interrupt callback. Writes the received byte into the USART receive buffer.

Variables

static uint8_t usart_data_recv_cbuf_mem [128]
 Backing memory for the USART receive circular buffer.
static uint8_t nmea_cbuf_mem [128]
 Backing memory for the NMEA sentence accumulation buffer.
static struct internal_state_s internal_state
 Singleton instance of the NEO-6 subsystem internal state.
static CMD_INFO_ts neo6_cmds []
 Table of CLI commands registered by the NEO-6 subsystem.
static CMD_CLIENT_INFO_ts neo6_cmd_client_info
 Registration descriptor passed to the command subsystem.

Detailed Description

NEO-6M GPS module implementation file.

Author
github.com/Baksi675
Version
0.1
Date
2026-02-03

Definition in file neo6.c.

Macro Definition Documentation

◆ VTG_TMG_T_DEGREE_POS

#define VTG_TMG_T_DEGREE_POS   1

Track made good in degrees relative to true north.

Definition at line 27 of file neo6.c.

◆ VTG_TMG_T_POS

#define VTG_TMG_T_POS   2

True north indicator.

Definition at line 28 of file neo6.c.

◆ VTG_TMG_M_DEGREE_POS

#define VTG_TMG_M_DEGREE_POS   3

Track made good in degrees relative to magnetic north.

Definition at line 29 of file neo6.c.

◆ VTG_TMG_M_POS

#define VTG_TMG_M_POS   4

Magnetic north indicator.

Definition at line 30 of file neo6.c.

◆ VTG_SPEED_KNOTS_POS

#define VTG_SPEED_KNOTS_POS   5

Speed over ground in knots.

Definition at line 31 of file neo6.c.

◆ VTG_SPEED_N_POS

#define VTG_SPEED_N_POS   6

Knots indicator.

Definition at line 32 of file neo6.c.

◆ VTG_SPEED_OVER_GROUND_POS

#define VTG_SPEED_OVER_GROUND_POS   7

Speed over ground in kph.

Definition at line 33 of file neo6.c.

◆ VTG_SPEED_OVER_GROUND_K_POS

#define VTG_SPEED_OVER_GROUND_K_POS   8

Kph indicator.

Definition at line 34 of file neo6.c.

◆ VTG_MODE_INDICATOR_POS

#define VTG_MODE_INDICATOR_POS   9

Mode indicator.

Definition at line 35 of file neo6.c.

◆ GGA_UTC_POS

#define GGA_UTC_POS   1

UTC time.

Definition at line 38 of file neo6.c.

◆ GGA_LAT_POS

#define GGA_LAT_POS   2

Latitude.

Definition at line 39 of file neo6.c.

◆ GGA_LAT_DIR_POS

#define GGA_LAT_DIR_POS   3

Latitude hemisphere direction.

Definition at line 40 of file neo6.c.

◆ GGA_LON_POS

#define GGA_LON_POS   4

Longitude.

Definition at line 41 of file neo6.c.

◆ GGA_LON_DIR_POS

#define GGA_LON_DIR_POS   5

Longitude hemisphere direction.

Definition at line 42 of file neo6.c.

◆ GGA_QUALITY_FIX_POS

#define GGA_QUALITY_FIX_POS   6

Fix quality indicator.

Definition at line 43 of file neo6.c.

◆ GGA_NUM_SATS_POS

#define GGA_NUM_SATS_POS   7

Number of satellites used for the fix.

Definition at line 44 of file neo6.c.

◆ GGA_HDOP_POS

#define GGA_HDOP_POS   8

Horizontal dilution of precision.

Definition at line 45 of file neo6.c.

◆ GGA_ORTH_HEIGHT_POS

#define GGA_ORTH_HEIGHT_POS   9

Orthometric height above mean sea level.

Definition at line 46 of file neo6.c.

◆ GGA_ORTH_HEIGHT_UNIT_POS

#define GGA_ORTH_HEIGHT_UNIT_POS   10

Unit of orthometric height.

Definition at line 47 of file neo6.c.

◆ GGA_GEOID_SEP_POS

#define GGA_GEOID_SEP_POS   11

Geoid separation.

Definition at line 48 of file neo6.c.

◆ GGA_GEOID_SEP_UNIT_POS

#define GGA_GEOID_SEP_UNIT_POS   12

Unit of geoid separation.

Definition at line 49 of file neo6.c.

◆ GGA_DATA_REC_AGE_POS

#define GGA_DATA_REC_AGE_POS   13

Age of differential GPS data record.

Definition at line 50 of file neo6.c.

◆ GGA_REF_STAT_ID_POS

#define GGA_REF_STAT_ID_POS   14

Reference station ID.

Definition at line 51 of file neo6.c.

◆ GSA_MODE_POS

#define GSA_MODE_POS   1

Selection mode: automatic or manual.

Definition at line 54 of file neo6.c.

◆ GSA_FIX_TYPE_POS

#define GSA_FIX_TYPE_POS   2

Fix type: 1 = none, 2 = 2D, 3 = 3D.

Definition at line 55 of file neo6.c.

◆ GSA_PRN_NUM_POS

#define GSA_PRN_NUM_POS   3

SV pseudorandom noise code number.

Definition at line 56 of file neo6.c.

◆ GSA_PDOP_POS

#define GSA_PDOP_POS   15

Position dilution of precision.

Definition at line 57 of file neo6.c.

◆ GSA_HDOP_POS

#define GSA_HDOP_POS   16

Horizontal dilution of precision.

Definition at line 58 of file neo6.c.

◆ GSA_VDOP_POS

#define GSA_VDOP_POS   17

Vertical dilution of precision.

Definition at line 59 of file neo6.c.

◆ GSV_NUM_OF_MESSAGES_POS

#define GSV_NUM_OF_MESSAGES_POS   1

Total number of GSV messages in this cycle.

Definition at line 62 of file neo6.c.

◆ GSV_NUM_OF_THIS_MESSAGE_POS

#define GSV_NUM_OF_THIS_MESSAGE_POS   2

Message number within the cycle.

Definition at line 63 of file neo6.c.

◆ GSV_NUM_SATS_VISIBLE_POS

#define GSV_NUM_SATS_VISIBLE_POS   3

Total number of satellites in view.

Definition at line 64 of file neo6.c.

◆ GSV_SV_PRN_NUM_POS

#define GSV_SV_PRN_NUM_POS   4

Satellite PRN number.

Definition at line 65 of file neo6.c.

◆ GSV_ELEVATION_POS

#define GSV_ELEVATION_POS   5

Satellite elevation in degrees (max 90).

Definition at line 66 of file neo6.c.

◆ GSV_AZIMUTH_POS

#define GSV_AZIMUTH_POS   6

Azimuth in degrees from true north (000–359).

Definition at line 67 of file neo6.c.

◆ GSV_SNR_POS

#define GSV_SNR_POS   7

Signal-to-noise ratio in dB (null when not tracking).

Definition at line 68 of file neo6.c.

Variable Documentation

◆ usart_data_recv_cbuf_mem

uint8_t usart_data_recv_cbuf_mem[128]
static

Backing memory for the USART receive circular buffer.

Written by the USART ISR callback and drained by neo6_run.

Definition at line 75 of file neo6.c.

◆ nmea_cbuf_mem

uint8_t nmea_cbuf_mem[128]
static

Backing memory for the NMEA sentence accumulation buffer.

Accumulates bytes from the USART buffer until a complete NMEA sentence (terminated by '\n') is available for processing.

Definition at line 83 of file neo6.c.

◆ internal_state

struct internal_state_s internal_state
static

Singleton instance of the NEO-6 subsystem internal state.

Definition at line 156 of file neo6.c.

◆ neo6_cmds

CMD_INFO_ts neo6_cmds[]
static
Initial value:
= {
{
.name = "dumpnmea",
.help = "Dumps raw NMEA messages, usage: neo6 dumpnmea <true|false>",
},
}
static ERR_te neo6_dumpnmea_handler(uint32_t argc, char **argv)
CLI handler for the "dumpnmea" command. Enables or disables raw NMEA logging.
Definition neo6.c:864

Table of CLI commands registered by the NEO-6 subsystem.

Registered with the command subsystem via neo6_cmd_client_info during neo6_init_subsys.

Definition at line 177 of file neo6.c.

177 {
178 {
179 .name = "dumpnmea",
180 .help = "Dumps raw NMEA messages, usage: neo6 dumpnmea <true|false>",
181 .handler = neo6_dumpnmea_handler
182 },
183};

◆ neo6_cmd_client_info

CMD_CLIENT_INFO_ts neo6_cmd_client_info
static
Initial value:
= {
.cmds_ptr = neo6_cmds,
.num_cmds = sizeof(neo6_cmds) / sizeof(neo6_cmds[0]),
.name = "neo6",
.log_level_ptr = &internal_state.log_level
}
static struct internal_state_s internal_state
Singleton instance of the SysTick driver internal state.
static CMD_INFO_ts neo6_cmds[]
Table of CLI commands registered by the NEO-6 subsystem.
Definition neo6.c:177

Registration descriptor passed to the command subsystem.

Bundles the command table, its size, the subsystem name prefix used on the CLI, and a pointer to the runtime log-level variable.

Definition at line 192 of file neo6.c.

192 {
193 .cmds_ptr = neo6_cmds,
194 .num_cmds = sizeof(neo6_cmds) / sizeof(neo6_cmds[0]),
195 .name = "neo6",
196 .log_level_ptr = &internal_state.log_level
197};