diff options
| author | ckgt <ckarlsson25@gmail.com> | 2015-03-28 19:08:43 -0400 |
|---|---|---|
| committer | ckgt <ckarlsson25@gmail.com> | 2015-03-28 19:08:43 -0400 |
| commit | 09a3c9c3485a023b5ae98652c46129941ca7fd41 (patch) | |
| tree | fb3b89f819d54d3efdef291079ddd061c40a4eb5 /demo_simple.cpp | |
| parent | 78627e9bc711b012d38855daeb004fe55b3d4d26 (diff) | |
Initial commit.
Diffstat (limited to 'demo_simple.cpp')
| -rw-r--r-- | demo_simple.cpp | 70 |
1 files changed, 70 insertions, 0 deletions
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 <iostream> +#include <fstream> +#include <iomanip> +#include <nmeaparse/nmea.h> + + + +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 |
