summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/nmeaparse/NMEAParser.h3
-rw-r--r--nmea_log.txt1
-rw-r--r--src/NMEAParser.cpp25
3 files changed, 26 insertions, 3 deletions
diff --git a/include/nmeaparse/NMEAParser.h b/include/nmeaparse/NMEAParser.h
index 65024c4..d57bb20 100644
--- a/include/nmeaparse/NMEAParser.h
+++ b/include/nmeaparse/NMEAParser.h
@@ -42,6 +42,7 @@ public:
std::string name; //name of the command
std::vector<std::string> parameters; //list of parameters from the command
std::string checksum;
+ bool checksumIsCalculated;
uint8_t parsedChecksum;
uint8_t calculatedChecksum;
@@ -57,7 +58,6 @@ public:
};
public:
NMEASentence();
- //NMEASentence(const NMEASentence& ref);
virtual ~NMEASentence();
bool checksumOK() const;
@@ -104,6 +104,7 @@ public:
Event<void(const NMEASentence&)> onSentence; // called every time parser receives any NMEA sentence
void setSentenceHandler(std::string cmdKey, std::function<void(const NMEASentence&)> handler); //one handler called for any named sentence where name is the "cmdKey"
+ std::string getRegisteredSentenceHandlersCSV(); // show a list of message names that currently have handlers.
// Byte streaming functions
void readByte (uint8_t b);
diff --git a/nmea_log.txt b/nmea_log.txt
index 7a178ca..63ddc56 100644
--- a/nmea_log.txt
+++ b/nmea_log.txt
@@ -13,6 +13,7 @@ $GPGSV,3,2,11,02,39,223,16,13,28,070,17,26,23,252,,04,14,186,15*77
$GPGSV,3,3,11,29,09,301,24,16,09,020,,36,,,*76
$GPRMC,092751.000,A,5321.6802,N,00630.3371,W,0.06,31.66,280511,,,A*45
+$GPRMC,173138.000,V,3145.5214,N,09704.5057,W,000.0,000.0,170318,000.0,E,N*00
# Some bad data
$*-->The,following,should,fail
diff --git a/src/NMEAParser.cpp b/src/NMEAParser.cpp
index f646613..4364718 100644
--- a/src/NMEAParser.cpp
+++ b/src/NMEAParser.cpp
@@ -40,7 +40,7 @@ std::string NMEAParseError::what(){
// --------- NMEA SENTENCE --------------
-NMEASentence::NMEASentence() : isvalid(false), calculatedChecksum(0), parsedChecksum(0)
+NMEASentence::NMEASentence() : isvalid(false), checksumIsCalculated(false), calculatedChecksum(0), parsedChecksum(0)
{}
NMEASentence::~NMEASentence()
{}
@@ -48,7 +48,7 @@ bool NMEASentence::valid() const {
return isvalid;
}
bool NMEASentence::checksumOK() const {
- return (parsedChecksum != 0 && calculatedChecksum != 0)
+ return (checksumIsCalculated)
&&
(parsedChecksum == calculatedChecksum);
}
@@ -120,6 +120,26 @@ void NMEAParser::setSentenceHandler(std::string cmdKey, std::function<void(const
//eventTable.insert(entry);
eventTable.insert({ cmdKey, handler });
}
+string NMEAParser::getRegisteredSentenceHandlersCSV()
+{
+ if(eventTable.empty()){
+ return "";
+ }
+
+ ostringstream ss;
+ for( auto it = eventTable.begin(); it != eventTable.end(); it++){
+ ss << it->first;
+
+ if( it->second ){
+ ss << "(not callable)";
+ }
+ }
+ string s = ss.str();
+ if( ! s.empty() ){
+ s.resize(s.size()-1); // chop off comma
+ }
+ return s;
+}
void NMEAParser::readByte(uint8_t b){
uint8_t startbyte = '$';
@@ -434,6 +454,7 @@ void NMEAParser::parseText(NMEASentence& nmea, string txt){
try
{
nmea.parsedChecksum = (uint8_t)parseInt(nmea.checksum, 16);
+ nmea.checksumIsCalculated = true;
}
catch( NumberConversionError& )
{