Skip to content

Commit

Permalink
Update gps parser for new NMEA protocol #182
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyLindsay committed May 22, 2019
1 parent 9a9ba3b commit b4bd12a
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 18 deletions.
Binary file modified Learn/Simple Libraries/Sensor/libgps/cmm/libgps.a
Binary file not shown.
20 changes: 14 additions & 6 deletions Learn/Simple Libraries/Sensor/libgps/gps.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
/**
* @file gps.h
*
* @author Daniel Harris
* @author Daniel Harris, Matthew Matz
*
* @copyright
* Copyright (C) Parallax, Inc. 2014. All Rights MIT Licensed.
* Copyright (C) Parallax, Inc. 2019. All Rights MIT Licensed.
*
* @brief This library provides basic NMEA parsing capabilities. It is designed to take raw NMEA strings,
parse the data out of them, and make the data available to a parent application through accessor
functions.
* parse the data out of them, and make the data available to a parent application through accessor
* functions.
*
* @par Core Usage
* Each call to rfid_open launches a serial communication process into another core.
*
* @par Memory Models
* Use with CMM or LMM.
*
* @version 0.50
* @version 0.6
*/

#ifndef __SIMPLE_NMEA_PARSER__
Expand Down Expand Up @@ -57,6 +56,7 @@ typedef struct nmea_data_s
float date; //current date, raw format with tenths of second, as float
int time; //current UTC time, raw format, as integer
float mag_var; //current magnetic variation, as float
char talker_ids[65]; //constellation ('P'=GPS, 'N'=GLONASS, Galileo, BeiDou, etc.) codes from the last positioning reads)

} nmea_data;

Expand Down Expand Up @@ -194,6 +194,14 @@ float gps_magneticVariation();
*/
void gps_txByte(int txByte);


/**
* @brief Provides the caller with a string containing the sources (Talker IDs) of the last 64 positioning reads. The most recent read is stored at character 0.
*
* @returns A string of length 65 (including null terminator) containing the second letter of the source's talker-ID. See http://catb.org/gpsd/NMEA.html#_talker_ids for more info.
*/
char* gps_sources();

#if defined(__cplusplus)
}
#endif
Expand Down
49 changes: 41 additions & 8 deletions Learn/Simple Libraries/Sensor/libgps/gps_run.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ gps_byte_t *ptrBuff;

fdserial *gps_ser;


void ParseTID(char tid);
void ParseRMC();
void ParseGGA();
void PrepBuff();
Expand All @@ -31,6 +31,10 @@ void gps_run(void *par)
gps_byte_t tempBuff[16];
gps_byte_t ch;
int idx;

// Set the string of constellation sources read to all <space> characters
memset(gps_data.talker_ids, ' ', sizeof(gps_data.talker_ids));
gps_data.talker_ids[64] = 0;

gps_ser = fdserial_open(_gps_rx_pin, _gps_tx_pin, 0, _gps_baud);
for(;;)
Expand All @@ -54,20 +58,51 @@ void gps_run(void *par)
{
ch = fdserial_rxChar(gps_ser);
inBuff[idx++] = ch;
}while(ch != 13);
} while(ch != 13);
inBuff[idx] = 0; //null terminate

//got the full sentence, do a little prep work to get ready for parsing.
//modifies inBuff!
PrepBuff();

if(strncmp(inBuff, "GPRMC", 5) == 0)
ParseRMC();
if(strncmp(inBuff, "GPGGA", 5) == 0)
ParseGGA();
// Determine Constellation/Transmission Source:
// More info here: http://catb.org/gpsd/NMEA.html#_talker_ids
if(inBuff[0] == 'G' || inBuff[0] == 'B' || inBuff[0] == 'Q')
{
if(inBuff[0] == 'B' && inBuff[1] == 'D')
{
// BeiDou has two different codes
// this sets the second char to 'B' if it's BeiDou.
inBuff[1] = 'B';
}

if(inBuff[2] == 'R' && inBuff[3] == 'M' && inBuff[4] == 'C')
{
ParseTID(inBuff[1]);
ParseRMC();
}

if(inBuff[2] == 'G' && inBuff[3] == 'G' && inBuff[4] == 'A')
{
ParseTID(inBuff[1]);
ParseGGA();
}
}
}
}

void ParseTID(char tid)
{
int gcr;
// Copy the letter-code for the constellation read from into the string
for (gcr = 0; gcr < 64; gcr++)
{
gps_data.talker_ids[gcr + 1] = gps_data.talker_ids[gcr];
}
gps_data.talker_ids[64] = 0;
gps_data.talker_ids[0] = tid;
}

void ParseRMC()
{
int i;
Expand Down Expand Up @@ -131,8 +166,6 @@ void ParseRMC()
ptrBuff = strtok(NULL,",");
i++;
}


}

void ParseGGA()
Expand Down
39 changes: 39 additions & 0 deletions Learn/Simple Libraries/Sensor/libgps/gps_sources.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* @author Matthew Matz
*
* @copyright
* Copyright (C) Parallax, Inc. 2019. All Rights MIT Licensed.
*
* @version 0.60
*/

#include "gps.h"

volatile nmea_data gps_data;

char* gps_sources()
{
return(gps_data.talker_ids);
}

/**
* TERMS OF USE: MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
6 changes: 3 additions & 3 deletions Learn/Simple Libraries/Sensor/libgps/libgps.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
//#define ENABLE_LCD
#define ENABLE_PC

#define GPS_RXIN_PIN 0
#define GPS_TXOUT_PIN 1
#define GPS_RXIN_PIN 13
#define GPS_TXOUT_PIN -1
#define GPS_BAUD 9600

#define LCD_PIN 14
Expand Down Expand Up @@ -86,7 +86,7 @@ int main() // main() function
print("%f %f", gps_latitude(), gps_longitude());

//sleep for 1/4 second
usleep(250000);
pause(250);

#endif //end ENABLE_PC

Expand Down
1 change: 1 addition & 0 deletions Learn/Simple Libraries/Sensor/libgps/libgps.side
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ gps_satsTracked.c
gps_velocity.c
gps.h
gps_txByte.c
gps_sources.c
>compiler=C
>memtype=cmm main ram compact
>optimize=-Os
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.4.116
v1.4.117

0 comments on commit b4bd12a

Please sign in to comment.