An implementation of the Sirf Binary and NMEA Protocol for gps devices using the SiRFstarIII chipset
GpsInterface.h@0:43da35949666, 2012-06-28 (annotated)
- Committer:
- p3p
- Date:
- Thu Jun 28 21:17:29 2012 +0000
- Revision:
- 0:43da35949666
update to baud selection
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
p3p | 0:43da35949666 | 1 | #ifndef SIRF_PROTOCOL_GPS_INTERFACE |
p3p | 0:43da35949666 | 2 | #define SIRF_PROTOCOL_GPS_INTERFACE |
p3p | 0:43da35949666 | 3 | |
p3p | 0:43da35949666 | 4 | #include "sIRFstarIII.h" |
p3p | 0:43da35949666 | 5 | |
p3p | 0:43da35949666 | 6 | namespace SirfStarIII { |
p3p | 0:43da35949666 | 7 | |
p3p | 0:43da35949666 | 8 | class GpsInterface : public SirfStarIII { |
p3p | 0:43da35949666 | 9 | public: |
p3p | 0:43da35949666 | 10 | GpsInterface(PinName tx, PinName rx); |
p3p | 0:43da35949666 | 11 | virtual ~GpsInterface() {} |
p3p | 0:43da35949666 | 12 | |
p3p | 0:43da35949666 | 13 | void onReceiveGeodeticNavigationData(SimpleSerialProtocol::Packet* packet); |
p3p | 0:43da35949666 | 14 | void onReceiveMeasuredTrackingData(SimpleSerialProtocol::Packet* packet); |
p3p | 0:43da35949666 | 15 | void onReceiveDGPSStatus(SimpleSerialProtocol::Packet* packet); |
p3p | 0:43da35949666 | 16 | void onReceiveRMC(SimpleSerialProtocol::Packet* packet); |
p3p | 0:43da35949666 | 17 | |
p3p | 0:43da35949666 | 18 | class Coordinate { |
p3p | 0:43da35949666 | 19 | public: |
p3p | 0:43da35949666 | 20 | Coordinate() { |
p3p | 0:43da35949666 | 21 | _gps_format = 0; |
p3p | 0:43da35949666 | 22 | _dec_degrees = 0; |
p3p | 0:43da35949666 | 23 | _degrees = 0; |
p3p | 0:43da35949666 | 24 | _minutes = 0; |
p3p | 0:43da35949666 | 25 | _seconds = 0; |
p3p | 0:43da35949666 | 26 | } |
p3p | 0:43da35949666 | 27 | ~Coordinate() {} |
p3p | 0:43da35949666 | 28 | float _gps_format; |
p3p | 0:43da35949666 | 29 | char _indicator; |
p3p | 0:43da35949666 | 30 | float _dec_degrees; |
p3p | 0:43da35949666 | 31 | uint16_t _degrees; |
p3p | 0:43da35949666 | 32 | uint16_t _minutes; |
p3p | 0:43da35949666 | 33 | float _seconds; |
p3p | 0:43da35949666 | 34 | |
p3p | 0:43da35949666 | 35 | void set(float raw, char indicator) { |
p3p | 0:43da35949666 | 36 | if(indicator == '0')return; |
p3p | 0:43da35949666 | 37 | if (raw < 10000) { |
p3p | 0:43da35949666 | 38 | raw = raw / 100; |
p3p | 0:43da35949666 | 39 | } else { |
p3p | 0:43da35949666 | 40 | raw = raw / 1000; |
p3p | 0:43da35949666 | 41 | } |
p3p | 0:43da35949666 | 42 | _gps_format = raw; |
p3p | 0:43da35949666 | 43 | _degrees = static_cast<uint16_t>(raw); |
p3p | 0:43da35949666 | 44 | raw = (raw - _degrees)*100; |
p3p | 0:43da35949666 | 45 | _minutes = static_cast<uint16_t>(raw); |
p3p | 0:43da35949666 | 46 | _seconds = 60 * (raw - _minutes); |
p3p | 0:43da35949666 | 47 | _dec_degrees = _degrees + (float)((float)_minutes/60) + (float)(_seconds/3600); |
p3p | 0:43da35949666 | 48 | _indicator = indicator; |
p3p | 0:43da35949666 | 49 | if(indicator == 'S' || indicator == 'W') _dec_degrees *= -1; |
p3p | 0:43da35949666 | 50 | } |
p3p | 0:43da35949666 | 51 | |
p3p | 0:43da35949666 | 52 | void operator= (float param) { |
p3p | 0:43da35949666 | 53 | _dec_degrees = param; |
p3p | 0:43da35949666 | 54 | } |
p3p | 0:43da35949666 | 55 | |
p3p | 0:43da35949666 | 56 | }; |
p3p | 0:43da35949666 | 57 | |
p3p | 0:43da35949666 | 58 | struct FixData { |
p3p | 0:43da35949666 | 59 | enum Type { |
p3p | 0:43da35949666 | 60 | NoFix, |
p3p | 0:43da35949666 | 61 | Fixed, |
p3p | 0:43da35949666 | 62 | DifFix, |
p3p | 0:43da35949666 | 63 | Reserved1, |
p3p | 0:43da35949666 | 64 | Reserved2, |
p3p | 0:43da35949666 | 65 | Reserved3, |
p3p | 0:43da35949666 | 66 | DeadReckFix |
p3p | 0:43da35949666 | 67 | }; |
p3p | 0:43da35949666 | 68 | uint8_t valid; |
p3p | 0:43da35949666 | 69 | uint8_t fix_type; |
p3p | 0:43da35949666 | 70 | uint8_t sats; |
p3p | 0:43da35949666 | 71 | } _fix; |
p3p | 0:43da35949666 | 72 | |
p3p | 0:43da35949666 | 73 | struct Position { |
p3p | 0:43da35949666 | 74 | Coordinate longitude; |
p3p | 0:43da35949666 | 75 | Coordinate latitude; |
p3p | 0:43da35949666 | 76 | float altitude; |
p3p | 0:43da35949666 | 77 | float speed; |
p3p | 0:43da35949666 | 78 | float course; |
p3p | 0:43da35949666 | 79 | uint8_t fix_type; |
p3p | 0:43da35949666 | 80 | } _position; |
p3p | 0:43da35949666 | 81 | |
p3p | 0:43da35949666 | 82 | struct Time { |
p3p | 0:43da35949666 | 83 | uint16_t year; |
p3p | 0:43da35949666 | 84 | uint8_t month; |
p3p | 0:43da35949666 | 85 | uint8_t day; |
p3p | 0:43da35949666 | 86 | uint8_t hours; |
p3p | 0:43da35949666 | 87 | uint8_t minutes; |
p3p | 0:43da35949666 | 88 | uint8_t seconds; |
p3p | 0:43da35949666 | 89 | } _time; |
p3p | 0:43da35949666 | 90 | |
p3p | 0:43da35949666 | 91 | }; |
p3p | 0:43da35949666 | 92 | |
p3p | 0:43da35949666 | 93 | } |
p3p | 0:43da35949666 | 94 | |
p3p | 0:43da35949666 | 95 | #endif |