From 09a3c9c3485a023b5ae98652c46129941ca7fd41 Mon Sep 17 00:00:00 2001 From: ckgt Date: Sat, 28 Mar 2015 19:08:43 -0400 Subject: Initial commit. --- demo_simple.cpp | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 demo_simple.cpp (limited to 'demo_simple.cpp') diff --git a/demo_simple.cpp b/demo_simple.cpp new file mode 100644 index 0000000..198017e --- /dev/null +++ b/demo_simple.cpp @@ -0,0 +1,70 @@ + +#include +#include +#include +#include + + + +using namespace std; +using namespace nmea; + +int main(int argc, char** argv){ + + // Fill with your NMEA bytes... make sure it ends with \n + char bytestream[] = "\n"; + + + + // Create a GPS service that will keep track of the fix data. + NMEAParser parser; + GPSService gps(parser); + parser.log = false; + + cout << "Fix Sats Sig\t\tSpeed Dir Lat , Lon Accuracy" << endl; + // Handle any changes to the GPS Fix... This is called whenever it's updated. + gps.onUpdate += [&gps](){ + cout << (gps.fix.locked() ? "[*] " : "[ ] ") << setw(2) << setfill(' ') << gps.fix.trackingSatellites << "/" << setw(2) << setfill(' ') << gps.fix.visibleSatellites << " "; + cout << fixed << setprecision(2) << setw(5) << setfill(' ') << gps.fix.almanac.averageSNR() << " dB "; + cout << fixed << setprecision(2) << setw(6) << setfill(' ') << gps.fix.speed << " km/h [" << GPSFix::travelAngleToCompassDirection(gps.fix.travelAngle, true) << "] "; + cout << fixed << setprecision(6) << gps.fix.latitude << "\xF8 " "N, " << gps.fix.longitude << "\xF8 " "E" << " "; + cout << "+/- " << setprecision(1) << gps.fix.horizontalAccuracy() << "m "; + cout << endl; + }; + + + + // -- STREAM THE DATA --- + + // From a buffer in memory... + parser.readBuffer((uint8_t*)bytestream, sizeof(bytestream)); + + // -- OR -- + // From a device byte stream... + // gps.parser.readByte(byte_from_device); + + // -- OR -- + // From a file + string line; + ifstream file("nmea_log.txt"); + while (getline(file, line)){ + try { + parser.readLine(line); + } + catch (NMEAParseError& e){ + cout << e.message << endl << endl; + // You can keep feeding data to the gps service... + // The previous data is ignored and the parser is reset. + } + } + + + // Show the final fix information + cout << gps.fix.toString() << endl; + + + cin.ignore(); + + + return 0; +} \ No newline at end of file -- cgit v1.2.3