-
Notifications
You must be signed in to change notification settings - Fork 81
/
demo_simple.cpp
74 lines (52 loc) · 1.92 KB
/
demo_simple.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
*
* See the license file included with this source.
*/
#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;
}