rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Data Structures | Typedefs | Enumerations | Functions
nmea.h File Reference

Data Structures

struct  GPSlocation
 

Typedefs

typedef struct GPSlocation loc_t
 

Enumerations

enum  nmea_message_type { NMEA_UNKNOWN = 0x00 , NMEA_GPRMC = 0x01 , NMEA_GPGGA = 0x02 }
 

Functions

nmea_message_type nmea_get_message_type (const char *)
 
int nmea_valid_checksum (const char *)
 
void gps_location (loc_t *, char const *const)
 
static int str2int (const char *a, const int len)
 

Typedef Documentation

◆ loc_t

typedef struct GPSlocation loc_t

Definition at line 40 of file nmea.h.

Enumeration Type Documentation

◆ nmea_message_type

Enumerator
NMEA_UNKNOWN 
NMEA_GPRMC 
NMEA_GPGGA 

Definition at line 13 of file nmea.h.

13 {
14 NMEA_UNKNOWN = 0x00,
15 NMEA_GPRMC = 0x01,
16 NMEA_GPGGA = 0x02
nmea_message_type
Definition nmea.h:13
@ NMEA_UNKNOWN
Definition nmea.h:14
@ NMEA_GPGGA
Definition nmea.h:16
@ NMEA_GPRMC
Definition nmea.h:15

Function Documentation

◆ gps_location()

void gps_location ( loc_t coord,
char const * const  buffer 
)

Definition at line 298 of file nmea.cpp.

298 {
300
301 switch (coord->type) {
302 case NMEA_GPGGA:
303 nmea_parse_gpgga(buffer, coord);
304 gps_convert_deg_to_dec(&(coord->latitude), coord->lat, &(coord->longitude), coord->lon);
305 break;
306 case NMEA_GPRMC:
307 nmea_parse_gprmc(buffer, coord);
308 break;
309 case NMEA_UNKNOWN:
310 // unknown message type
311 break;
312 }
313}
static void nmea_parse_gprmc(char const *const nmea, loc_t *loc)
Definition nmea.cpp:172
static void nmea_parse_gpgga(char const *const nmea, loc_t *loc)
Definition nmea.cpp:95
nmea_message_type nmea_get_message_type(const char *message)
Definition nmea.cpp:259
static void gps_convert_deg_to_dec(float *latitude, char ns, float *longitude, char we)
Definition nmea.cpp:54
char lat
Definition nmea.h:37
float latitude
Definition nmea.h:28
nmea_message_type type
Definition nmea.h:34
float longitude
Definition nmea.h:29
char lon
Definition nmea.h:38
static BigBufferHandle buffer

Referenced by onGpsMessage().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nmea_get_message_type()

nmea_message_type nmea_get_message_type ( const char message)

Get the message type (GPGGA, GPRMC, etc..)

This function filters out also wrong packages (invalid checksum)

Parameters
messageThe NMEA message
Returns
The type of message if it is valid

Definition at line 259 of file nmea.cpp.

259 {
260 int checksum = nmea_valid_checksum(message);
261 if (checksum != _EMPTY) {
262 return static_cast<nmea_message_type>(checksum);
263 }
264
265 if (strstr(message, NMEA_GPGGA_STR) != NULL) {
266 return NMEA_GPGGA;
267 }
268
269 if (strstr(message, NMEA_GPRMC_STR) != NULL) {
270 return NMEA_GPRMC;
271 }
272
273 return NMEA_UNKNOWN;
274}
int nmea_valid_checksum(char const *message)
Definition nmea.cpp:276

Referenced by gps_location().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nmea_valid_checksum()

int nmea_valid_checksum ( const char message)

Definition at line 276 of file nmea.cpp.

276 {
277 char p;
278 int sum = 0;
279 const char* starPtr = strrchr(message, '*');
280 if (!starPtr) {
281 return NMEA_CHECKSUM_ERR;
282 }
283 const char* int_message = starPtr + 1;
284 long checksum = hex2int(int_message, 2);
285
286 ++message;
287 while ((p = *message++) != '*') {
288 sum ^= p;
289 }
290
291 if (sum != checksum) {
292 return NMEA_CHECKSUM_ERR;
293 }
294 return _EMPTY;
295}
static long hex2int(const char *a, const int len)
Definition nmea.cpp:28

Referenced by nmea_get_message_type().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ str2int()

static int str2int ( const char a,
const int  len 
)
static

Definition at line 48 of file nmea.h.

48 {
49 int i = 0, k = 0;
50 while (i < len) {
51 k = (k << 3) + (k << 1) + (*a) - '0';
52 a++;
53 i++;
54 }
55 return k;
56}

Referenced by nmea_parse_gprmc().

Here is the caller graph for this function:

Go to the source code of this file.