Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Non-GPS Messages v2 #25

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/nmeaparse/GPSService.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class GPSService {
void read_GPGSV (const NMEASentence& nmea);
void read_GPRMC (const NMEASentence& nmea);
void read_GPVTG (const NMEASentence& nmea);
void read_GPGLL (const NMEASentence& nmea);

public:
GPSFix fix;
Expand Down
153 changes: 152 additions & 1 deletion src/GPSService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,64 @@ void GPSService::attachToParser(NMEAParser& _parser){
_parser.setSentenceHandler("GPVTG", [this](const NMEASentence& nmea){
this->read_GPVTG(nmea);
});

_parser.setSentenceHandler("GPGLL", [this](const NMEASentence& nmea){
this->read_GPGLL(nmea);
});

// https://gpsd.gitlab.io/gpsd/NMEA.html
// * GP for GPS only solutions
// * GL for GLONASS only solutions
// * GA for GALILEO only solutions
// * GN for multi GNSS solutions

_parser.setSentenceHandler("GLGGA", [this](const NMEASentence& nmea){
this->read_GPGGA(nmea);
});
_parser.setSentenceHandler("GLGSA", [this](const NMEASentence& nmea){
this->read_GPGSA(nmea);
});
_parser.setSentenceHandler("GLGSV", [this](const NMEASentence& nmea){
this->read_GPGSV(nmea);
});
_parser.setSentenceHandler("GLRMC", [this](const NMEASentence& nmea){
this->read_GPRMC(nmea);
});
_parser.setSentenceHandler("GLVTG", [this](const NMEASentence& nmea){
this->read_GPVTG(nmea);
});
_parser.setSentenceHandler("GAGGA", [this](const NMEASentence& nmea){
this->read_GPGGA(nmea);
});
_parser.setSentenceHandler("GAGSA", [this](const NMEASentence& nmea){
this->read_GPGSA(nmea);
});
_parser.setSentenceHandler("GAGSV", [this](const NMEASentence& nmea){
this->read_GPGSV(nmea);
});
_parser.setSentenceHandler("GARMC", [this](const NMEASentence& nmea){
this->read_GPRMC(nmea);
});
_parser.setSentenceHandler("GAVTG", [this](const NMEASentence& nmea){
this->read_GPVTG(nmea);
});
_parser.setSentenceHandler("GNGGA", [this](const NMEASentence& nmea){
this->read_GPGGA(nmea);
});
_parser.setSentenceHandler("GNGSA", [this](const NMEASentence& nmea){
this->read_GPGSA(nmea);
});
_parser.setSentenceHandler("GNGSV", [this](const NMEASentence& nmea){
this->read_GPGSV(nmea);
});
_parser.setSentenceHandler("GNRMC", [this](const NMEASentence& nmea){
this->read_GPRMC(nmea);
});
_parser.setSentenceHandler("GNVTG", [this](const NMEASentence& nmea){
this->read_GPVTG(nmea);
});
_parser.setSentenceHandler("GNGLL", [this](const NMEASentence& nmea){
this->read_GPGLL(nmea);
});
}


Expand Down Expand Up @@ -509,3 +566,97 @@ void GPSService::read_GPVTG(const NMEASentence& nmea){
}
}

void GPSService::read_GPGLL(const NMEASentence& nmea){
/*
$GPGLL,3723.2475,N,12158.3416,W,161229.487,A,A*41

Where:
GLL GLL protocol header (Geographic Position - Latitude/Longitude)
[0] 3723.2475 Latitude 37 deg 23.2475' N (ddmm.mmmm)
[1] N Latitude Direction: N = North (N=north or S=south)
[2] 12158.3416 Longitude 121 deg 58.3416' W (ddmm.mmmm)
[3] W Longitude Direction: W = West (E=east or W=west)
[4] 161229.487 Fix taken at 16:12:29.487 UTC (hhmmss.sss)
[5] A Status: A = Data valid (A=data valid or V=data not valid)
[6] A Mode: A = Autonomous (A=Autonomous, D=DGPS, E=DR (Only present in NMEA v3.00))
[7] *41 The checksum data, always begins with *
*/

try
{
if (!nmea.checksumOK()){
throw NMEAParseError("Checksum is invalid!");
}

if (nmea.parameters.size() < 7){
throw NMEAParseError("GPS data is missing parameters.");
}

string sll;
string dir;
// LAT
sll = nmea.parameters[0];
dir = nmea.parameters[1];
if (!sll.empty()){
this->fix.latitude = convertLatLongToDeg(sll, dir);
}

// LONG
sll = nmea.parameters[2];
dir = nmea.parameters[3];
if (!sll.empty()){
this->fix.longitude = convertLatLongToDeg(sll, dir);
}

// TIMESTAMP
this->fix.timestamp.setTime(parseDouble(nmea.parameters[4]));

// ACTIVE
bool lockupdate = false;
char status = 'V';
if (!nmea.parameters[5].empty()){
status = nmea.parameters[5][0];
}
this->fix.status = status;
if (status == 'V'){
lockupdate = this->fix.setlock(false);
}
else if (status == 'A') {
lockupdate = this->fix.setlock(true);
}
else {
lockupdate = this->fix.setlock(false); //not A or V, so must be wrong... no lock
}

if (!nmea.parameters[6].empty()){
if (nmea.parameters[6] == "A"){
this->fix.quality = 1;
}
else if (nmea.parameters[6] == "D"){
this->fix.quality = 2;
}
else if (nmea.parameters[6] == "E"){
this->fix.quality = 6;
}
else {}
}

else {}
//calling handlers
if (lockupdate){
this->onLockStateChanged(this->fix.haslock);
}
this->onUpdate();
}
catch (NumberConversionError& ex)
{
NMEAParseError pe("GPS Number Bad Format [$GPGLL] :: " + ex.message, nmea);
throw pe;
}
catch (NMEAParseError& ex)
{
NMEAParseError pe("GPS Data Bad Format [$GPGLL] :: " + ex.message, nmea);
throw pe;
}
}

9 changes: 8 additions & 1 deletion src/NMEAParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ void NMEAParser::parseText(NMEASentence& nmea, string txt){
onInfo(nmea, sz.str());

//possible checksum at end...
string tmp_str;
size_t endi = nmea.parameters.size() - 1;
size_t checki = nmea.parameters[endi].find_last_of('*');
if (checki != string::npos){
Expand All @@ -450,7 +451,13 @@ void NMEAParser::parseText(NMEASentence& nmea, string txt){
onError(nmea, "Checksum '*' character at end, but no data.");
}
else{
nmea.checksum = last.substr(checki + 1, last.size() - checki); //extract checksum without '*'
//extract checksum without '*' and \n,\r
// copy into temporary string
tmp_str = last.substr(checki + 1, last.size() - checki);
// remove superflous line breaks and carriage returns
tmp_str.erase(std::remove(tmp_str.begin(), tmp_str.end(), '\n'),tmp_str.end());
tmp_str.erase(std::remove(tmp_str.begin(), tmp_str.end(), '\r'),tmp_str.end());
nmea.checksum = tmp_str;

onInfo(nmea, string("Found checksum. (\"*") + nmea.checksum + "\")");

Expand Down