-
Notifications
You must be signed in to change notification settings - Fork 0
/
gps.cpp
52 lines (44 loc) · 1.54 KB
/
gps.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
#include <math.h>
#include "gps.h"
namespace FCAero {
GPS::GPS(HardwareSerial *ser) {
ser->begin(9600);
this->gps = new Adafruit_GPS(ser);
}
bool GPS::init() {
gps->begin(9600);
gps->sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
gps->sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
return true; // should actually ask for firmware version (PMTK_Q_RELEASE) and verify response
}
bool GPS::available() {
// we should also flush GPS here; read a char at a time until nothing is available
while (gps->available()) {
gps->read();
}
return gps->newNMEAreceived() && gps->parse(gps->lastNMEA());
}
GPSPosition GPS::read() {
GPSPosition pos;
// if GPS.latitude = 12220.3, actual latitude is 122° 20.3'
pos.latDeg = gps->latitude / 100;
pos.longDeg = gps->longitude / 100;
pos.latMin = fabsf(fmodf(gps->latitude, 100.0f));
pos.longMin = fabsf(fmodf(gps->longitude, 100.0f));
pos.satellites = gps->satellites;
return pos;
}
void GPS::writeReport(GPSPosition data) {
Serial.print("{\"position\":{\"latDeg\":");
Serial.print(data.latDeg);
Serial.print(",\"latMin\":");
Serial.print(data.latMin);
Serial.print(",\"longDeg\":");
Serial.print(data.longDeg);
Serial.print(",\"longMin\":");
Serial.print(data.longMin);
Serial.print(",\"satellites\":");
Serial.print(data.satellites);
Serial.println("}}");
}
}