Skip to content
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
31 changes: 16 additions & 15 deletions demo_advanced.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,23 @@ int main(int argc, char** argv){

// Read the data stream...
// These don't have correct checksums. They're made up.
char data[] = " $MYNMEA,1,3,3,7,Hello*A2\n \
$IRRELEVANT,5,5,5*AA\n \
$ERRORS,:D,\n \
$\n \
$$\n \
$*\n \
$*,\n \
$,\n \
$,*\n \
garbage that will be \
!IgN0r3d @)(&%!!! \
$MYNMEA,1,3,3,7,World!*A2\r\n \
";
for (int i = 0; i < sizeof(data); i++){
const std::string data =
" $MYNMEA,1,3,3,7,Hello*A2\n \
$IRRELEVANT,5,5,5*AA\n \
$ERRORS,:D,\n \
$\n \
$$\n \
$*\n \
$*,\n \
$,\n \
$,*\n \
garbage that will be \
!IgN0r3d @)(&%!!! \
$MYNMEA,1,3,3,7,World!*A2\r\n \
";
for (const char byte : data) {
try {
custom_parser.readByte(data[i]);
custom_parser.readByte(byte);
}
catch (NMEAParseError& e){
cout << e.what() << endl;
Expand Down
2 changes: 1 addition & 1 deletion include/nmeaparse/GPSFix.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ namespace nmea {
public:

GPSFix();
virtual ~GPSFix();
virtual ~GPSFix() = default;


GPSAlmanac almanac;
Expand Down
2 changes: 1 addition & 1 deletion include/nmeaparse/GPSService.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class GPSService {
GPSFix fix;

GPSService(NMEAParser& parser);
virtual ~GPSService();
virtual ~GPSService() = default;

Event<void(bool)> onLockStateChanged; // user assignable handler, called whenever lock changes
Event<void()> onUpdate; // user assignable handler, called whenever fix changes
Expand Down
3 changes: 1 addition & 2 deletions include/nmeaparse/NMEACommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ namespace nmea {
std::string message;
std::string name;
char checksum;
NMEACommand();
virtual ~NMEACommand();
virtual ~NMEACommand() = default;
virtual std::string toString();
std::string addChecksum(std::string s);
};
Expand Down
6 changes: 3 additions & 3 deletions include/nmeaparse/NMEAParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class NMEASentence {
};
public:
NMEASentence();
virtual ~NMEASentence();
virtual ~NMEASentence() = default;

bool checksumOK() const;
bool valid() const;
Expand All @@ -75,7 +75,7 @@ class NMEAParseError : public std::exception {

NMEAParseError(std::string msg);
NMEAParseError(std::string msg, NMEASentence n);
virtual ~NMEAParseError();
virtual ~NMEAParseError() = default;

std::string what();
};
Expand All @@ -98,7 +98,7 @@ class NMEAParser {
public:

NMEAParser();
virtual ~NMEAParser();
virtual ~NMEAParser() = default;

bool log;

Expand Down
16 changes: 7 additions & 9 deletions src/GPSFix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*/

#include <nmeaparse/GPSFix.h>

#include <array>
#include <cmath>
#include <string>
#include <sstream>
Expand Down Expand Up @@ -146,7 +148,7 @@ std::string GPSTimestamp::monthName(uint32_t index){
return ss.str();
}

std::string names[] = {
std::array<std::string, 12> names = {
"January",
"February",
"March",
Expand Down Expand Up @@ -221,7 +223,7 @@ GPSFix::GPSFix() {
status = 'V'; // Void
type = 1; // 1=none, 2=2d, 3=3d

haslock = 0;
haslock = false;

dilution = 0;
horizontalDilution = 0; // Horizontal - Best is 1, >20 is terrible, so 0 means uninitialized
Expand All @@ -237,13 +239,9 @@ GPSFix::GPSFix() {

}

GPSFix::~GPSFix() {
// TODO Auto-generated destructor stub
}

// Returns the duration since the Host has received information
seconds GPSFix::timeSinceLastUpdate(){
time_t now = time(NULL);
time_t now = time(nullptr);
struct tm stamp = { 0 };

stamp.tm_hour = timestamp.hour;
Expand Down Expand Up @@ -297,7 +295,7 @@ std::string GPSFix::travelAngleToCompassDirection(double deg, bool abbrev){
}

if (abbrev){
std::string dirs[] = {
std::array<std::string, 9> dirs = {
"N",
"NE",
"E",
Expand All @@ -311,7 +309,7 @@ std::string GPSFix::travelAngleToCompassDirection(double deg, bool abbrev){
return dirs[r];
}
else {
std::string dirs[] = {
std::array<std::string, 9> dirs = {
"North",
"North East",
"East",
Expand Down
5 changes: 0 additions & 5 deletions src/NMEACommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@
using namespace std;
using namespace nmea;


NMEACommand::NMEACommand(){};

NMEACommand::~NMEACommand(){};

string NMEACommand::toString(){
return addChecksum(message);
}
Expand Down
18 changes: 4 additions & 14 deletions src/NMEAParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@ using namespace nmea;
// --------- NMEA PARSE ERROR--------------

NMEAParseError::NMEAParseError(std::string msg)
: message(msg)
: message(std::move(msg))
{}
NMEAParseError::NMEAParseError(std::string msg, NMEASentence n)
: message(msg), nmea(n)
{}

NMEAParseError::~NMEAParseError()
: message(std::move(msg)), nmea(n)
{}

std::string NMEAParseError::what(){
Expand All @@ -47,9 +44,6 @@ NMEASentence::NMEASentence()
, parsedChecksum(0)
{ }

NMEASentence::~NMEASentence()
{ }

bool NMEASentence::valid() const {
return isvalid;
}
Expand Down Expand Up @@ -114,10 +108,6 @@ NMEAParser::NMEAParser()
, fillingbuffer(false)
{ }

NMEAParser::~NMEAParser()
{ }


void NMEAParser::setSentenceHandler(std::string cmdKey, std::function<void(const NMEASentence&)> handler){
eventTable.erase(cmdKey);
eventTable.insert({ cmdKey, handler });
Expand Down Expand Up @@ -398,7 +388,7 @@ void NMEAParser::parseText(NMEASentence& nmea, string txt){

//comma is the last character/only comma
if (comma + 1 == txt.size()){
nmea.parameters.push_back("");
nmea.parameters.emplace_back("");
nmea.isvalid = true;
return;
}
Expand Down Expand Up @@ -427,7 +417,7 @@ void NMEAParser::parseText(NMEASentence& nmea, string txt){
}

//cout << "NMEA parser Warning: extra comma at end of sentence, but no information...?" << endl; // it's actually standard, if checksum is disabled
nmea.parameters.push_back("");
nmea.parameters.emplace_back("");

stringstream sz;
sz << "Found " << nmea.parameters.size() << " parameters.";
Expand Down