An implementation of the Sirf Binary and NMEA Protocol for gps devices using the SiRFstarIII chipset

Committer:
p3p
Date:
Thu Jun 28 21:17:29 2012 +0000
Revision:
0:43da35949666
update to baud selection

Who changed what in which revision?

UserRevisionLine numberNew contents of line
p3p 0:43da35949666 1 #include "GpsInterface.h"
p3p 0:43da35949666 2
p3p 0:43da35949666 3 namespace SirfStarIII {
p3p 0:43da35949666 4
p3p 0:43da35949666 5 GpsInterface::GpsInterface(PinName tx, PinName rx) : SirfStarIII(tx, rx) {
p3p 0:43da35949666 6 receiveCallback(BinaryPacket::ID_GeodeticNavigationData, this, &GpsInterface::onReceiveGeodeticNavigationData);
p3p 0:43da35949666 7 receiveCallback(BinaryPacket::ID_MeasuredTrackingData, this, &GpsInterface::onReceiveMeasuredTrackingData);
p3p 0:43da35949666 8 receiveCallback(BinaryPacket::ID_DGPSStatus, this, &GpsInterface::onReceiveDGPSStatus);
p3p 0:43da35949666 9 receiveCallback(NMEAPacket::ID_RMC, this, &GpsInterface::onReceiveRMC);
p3p 0:43da35949666 10 }
p3p 0:43da35949666 11
p3p 0:43da35949666 12 void GpsInterface::onReceiveGeodeticNavigationData(SimpleSerialProtocol::Packet* packet) {
p3p 0:43da35949666 13 if(!packet)return;
p3p 0:43da35949666 14
p3p 0:43da35949666 15 if (packet->_valid) {
p3p 0:43da35949666 16 BinaryPacket::GeodeticNavigationData::Interface* interface = packet->interpretData<BinaryPacket::GeodeticNavigationData::Interface>();
p3p 0:43da35949666 17 if (interface) {
p3p 0:43da35949666 18 BinaryPacket::GeodeticNavigationData::swapByteOrder(interface);
p3p 0:43da35949666 19 _fix.sats = interface->satalites_in_fix;
p3p 0:43da35949666 20 _position.longitude = (((float)interface->longitude)/10000000);
p3p 0:43da35949666 21 _position.latitude = (((float)interface->latitude)/10000000);
p3p 0:43da35949666 22
p3p 0:43da35949666 23 _time.year = interface->year;
p3p 0:43da35949666 24 _time.month = interface->month;
p3p 0:43da35949666 25 _time.day = interface->day;
p3p 0:43da35949666 26 _time.hours = interface->hour;
p3p 0:43da35949666 27 _time.minutes = interface->minute;
p3p 0:43da35949666 28 _time.seconds = interface->second/1000;
p3p 0:43da35949666 29 }
p3p 0:43da35949666 30 }
p3p 0:43da35949666 31 return;
p3p 0:43da35949666 32 }
p3p 0:43da35949666 33
p3p 0:43da35949666 34 void GpsInterface::onReceiveMeasuredTrackingData(SimpleSerialProtocol::Packet* packet) {
p3p 0:43da35949666 35 if(!packet)return;
p3p 0:43da35949666 36
p3p 0:43da35949666 37 if (packet->_valid) {
p3p 0:43da35949666 38 BinaryPacket::MeasuredTrackingData::Interface* interface = packet->interpretData<BinaryPacket::MeasuredTrackingData::Interface>();
p3p 0:43da35949666 39 if (interface) {
p3p 0:43da35949666 40
p3p 0:43da35949666 41 }
p3p 0:43da35949666 42 }
p3p 0:43da35949666 43 return;
p3p 0:43da35949666 44 }
p3p 0:43da35949666 45
p3p 0:43da35949666 46 void GpsInterface::onReceiveDGPSStatus(SimpleSerialProtocol::Packet* packet) {
p3p 0:43da35949666 47 if(!packet)return;
p3p 0:43da35949666 48
p3p 0:43da35949666 49 if (packet->_valid) {
p3p 0:43da35949666 50 BinaryPacket::DGPSStatus::Interface* interface = packet->interpretData<BinaryPacket::DGPSStatus::Interface>();
p3p 0:43da35949666 51 if (interface) {
p3p 0:43da35949666 52
p3p 0:43da35949666 53 }
p3p 0:43da35949666 54 }
p3p 0:43da35949666 55 return;
p3p 0:43da35949666 56 }
p3p 0:43da35949666 57
p3p 0:43da35949666 58 void GpsInterface::onReceiveRMC(SimpleSerialProtocol::Packet* packet) {
p3p 0:43da35949666 59 if(!packet)return;
p3p 0:43da35949666 60
p3p 0:43da35949666 61 NMEAPacket::NMEAPacket nmeaPacket;
p3p 0:43da35949666 62 if (packet->_valid) {
p3p 0:43da35949666 63 nmeaPacket.interpretData(packet);
p3p 0:43da35949666 64 float time = atof(nmeaPacket._fields[1].c_str());
p3p 0:43da35949666 65 _time.seconds = (int)time % 100;
p3p 0:43da35949666 66 _time.minutes = (int)(time / 100)%100;
p3p 0:43da35949666 67 _time.hours = (int)(time / 10000);
p3p 0:43da35949666 68
p3p 0:43da35949666 69 // 2 Time Status
p3p 0:43da35949666 70 _position.latitude.set(atof(nmeaPacket._fields[3].c_str()), (char)nmeaPacket._fields[4].c_str()[0]);
p3p 0:43da35949666 71 _position.longitude.set(atof(nmeaPacket._fields[5].c_str()), (char)nmeaPacket._fields[6].c_str()[0]);
p3p 0:43da35949666 72 _position.speed = atof(nmeaPacket._fields[7].c_str());
p3p 0:43da35949666 73 _position.course = atof(nmeaPacket._fields[8].c_str());
p3p 0:43da35949666 74
p3p 0:43da35949666 75 uint32_t date = atoi(nmeaPacket._fields[9].c_str());
p3p 0:43da35949666 76 _time.year = 2000 + (date % 100);
p3p 0:43da35949666 77 date /= 100;
p3p 0:43da35949666 78 _time.month = date % 100;
p3p 0:43da35949666 79 _time.day = date / 100;
p3p 0:43da35949666 80
p3p 0:43da35949666 81 // 10 magnetic variation
p3p 0:43da35949666 82 // 11 mode
p3p 0:43da35949666 83 }
p3p 0:43da35949666 84
p3p 0:43da35949666 85 return;
p3p 0:43da35949666 86 }
p3p 0:43da35949666 87
p3p 0:43da35949666 88 }