Colin Stearns
/
qcControl
QC Control software
Fork of dgps by
Diff: handle/handleGPS.cpp
- Revision:
- 9:da906eeac51e
- Parent:
- 8:28b866df62cf
- Child:
- 14:6be57da62283
--- a/handle/handleGPS.cpp Tue Apr 01 17:58:35 2014 +0000 +++ b/handle/handleGPS.cpp Thu Apr 03 17:15:29 2014 +0000 @@ -1,40 +1,39 @@ -#include "mbed.h" +#include "handleGPS.h" -Serial gps(p28,p27); +//Serial gps(p28,p27); void GPSHandle::setup(){ - gps.baud(57600); + gps.getSerial().baud(57600); sendGpsCommand("PMTK301,1"); - gps.attach(this, &handleUpdate, Serial::RxIrq); + //gps.getSerial().attach(this, handleUpdate, Serial::RxIrq); //cs: Send other standard init commands? Not strictly speaking necessary, // but forces "up to date documentation" in the form of always knowing // gps config. } void GPSHandle::handleUpdate(){ - { static bool reading = false; - static stringstream line; + static std::stringstream line; - char c = gps.getc(); + char c = gps.getSerial().getc(); if (reading) { if (c == '*') { //sentence buffer complete; we're ignoring the checksum - string field; + std::string field; std::getline(line, field, ','); //GPGGA std::getline(line, field, ','); //time - gpsData.time = stringToDecimal(field); + double time = atof(field.c_str()); std::getline(line, field, ','); //latitude - gpsData.latitude = stringToDecimal(field); + double latitude = atof(field.c_str()); std::getline(line, field, ','); //N or S std::getline(line, field, ','); //longitude - gpsData.longitude = stringToDecimal(field); + double longitude = atof(field.c_str()); std::getline(line, field, ','); //E or W std::getline(line, field, ','); //skip std::getline(line, field, ','); //skip std::getline(line, field, ','); //skip std::getline(line, field, ','); //altitude - gpsData.altitude = stringToDecimal(field); + double altitude = atof(field.c_str()); //update whatever needs updating when gps updates // pc.printf("My GPS data: Lat: %d, Lon: %d, Alt: %d, Time:%d\r\n", @@ -54,21 +53,20 @@ } //sends: "$<command>*<checksum>\r\l" -void sendGpsCommand(string command) -{ +void GPSHandle::sendGpsCommand(std::string command){ uint8_t checksum = 0; - pc.printf("Sending command to gps: "); - gps.putc('$'); - pc.putc('$'); + //pc.printf("Sending command to gps: "); + gps.getSerial().putc('$'); + //pc.putc('$'); char c; for (int i = 0; i < command.length(); i++) { c = command[i]; checksum ^= c; - gps.putc(c); - pc.putc(c); + gps.getSerial().putc(c); + //pc.putc(c); } - gps.putc('*'); - pc.putc('*'); + gps.getSerial().putc('*'); + //pc.putc('*'); string checkSumString; while (checksum > 0) { uint8_t checksumChar = checksum & 0x0F; @@ -83,13 +81,13 @@ } for (int i = checkSumString.length() - 1; i >= 0; i--) { - gps.putc(checkSumString[i]); - pc.putc(checkSumString[i]); + gps.getSerial().putc(checkSumString[i]); + //pc.putc(checkSumString[i]); } - gps.putc('\r'); - pc.putc('\r'); - gps.putc('\n'); - pc.putc('\n'); + gps.getSerial().putc('\r'); + //pc.putc('\r'); + gps.getSerial().putc('\n'); + //pc.putc('\n'); } int stringToDecimal(string s)