Mbed library to handle GPS data reception and parsing
Dependents: GPS_U-blox_NEO-6M_Code
Features
- All positionning parameters are contained into a global data structure.
- Automatic nema string parsing and data structure update.
- GSA,GGA,VTG and RMC
- Convert latitude and longitude to decimal value.
- Converts latittude,longitude and altitude to ECEF coordinates.
Planed developement
- Test library for RTOS use.
- Complete the nema parsing decoders (couple of parameters are not parsed yet and not present in the data structure).
- Add conversion tool to get ENU coordinates.
GPS.cpp@1:fade122a76a8, 2015-04-06 (annotated)
- Committer:
- chris215
- Date:
- Mon Apr 06 17:41:43 2015 +0000
- Revision:
- 1:fade122a76a8
- Parent:
- 0:0c1aa5906cef
- Child:
- 2:72ac4d7044a7
various updates;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chris215 | 0:0c1aa5906cef | 1 | #include "GPS.h" |
chris215 | 0:0c1aa5906cef | 2 | #include "GPSUtils.hpp" |
chris215 | 0:0c1aa5906cef | 3 | |
chris215 | 0:0c1aa5906cef | 4 | GPS::GPS(PinName tx, PinName rx) : RawSerial(tx, rx) |
chris215 | 0:0c1aa5906cef | 5 | { |
chris215 | 1:fade122a76a8 | 6 | RawSerial::baud(115200); |
chris215 | 0:0c1aa5906cef | 7 | attach(this, &GPS::RxIrqHandler); |
chris215 | 0:0c1aa5906cef | 8 | } |
chris215 | 0:0c1aa5906cef | 9 | |
chris215 | 0:0c1aa5906cef | 10 | void GPS::SetBaud(int rate){ |
chris215 | 0:0c1aa5906cef | 11 | RawSerial::baud(rate); |
chris215 | 0:0c1aa5906cef | 12 | } |
chris215 | 0:0c1aa5906cef | 13 | |
chris215 | 0:0c1aa5906cef | 14 | void GPS::RxIrqHandler(void) |
chris215 | 0:0c1aa5906cef | 15 | { |
chris215 | 0:0c1aa5906cef | 16 | char in; |
chris215 | 0:0c1aa5906cef | 17 | while(RawSerial::readable()) |
chris215 | 0:0c1aa5906cef | 18 | { |
chris215 | 0:0c1aa5906cef | 19 | in = RawSerial::getc(); |
chris215 | 0:0c1aa5906cef | 20 | if(in == START_CHAR) |
chris215 | 0:0c1aa5906cef | 21 | { |
chris215 | 0:0c1aa5906cef | 22 | insertIndex = 0; |
chris215 | 0:0c1aa5906cef | 23 | RxMessageBuffer.data[(insertIndex++)%RX_BUFFER_SIZE] = in; |
chris215 | 0:0c1aa5906cef | 24 | } |
chris215 | 0:0c1aa5906cef | 25 | else if(in == END_CHAR) |
chris215 | 0:0c1aa5906cef | 26 | { |
chris215 | 0:0c1aa5906cef | 27 | RxMessageBuffer.data[(insertIndex++)%RX_BUFFER_SIZE] = 0; |
chris215 | 0:0c1aa5906cef | 28 | DecodeMessage(RxMessageBuffer,info); |
chris215 | 0:0c1aa5906cef | 29 | } |
chris215 | 0:0c1aa5906cef | 30 | else |
chris215 | 0:0c1aa5906cef | 31 | RxMessageBuffer.data[(insertIndex++)%RX_BUFFER_SIZE] = in; |
chris215 | 0:0c1aa5906cef | 32 | } |
chris215 | 0:0c1aa5906cef | 33 | } |
chris215 | 0:0c1aa5906cef | 34 | |
chris215 | 0:0c1aa5906cef | 35 | |
chris215 | 0:0c1aa5906cef | 36 | ECEFPoint GPS::ReadPositionECEF(void) |
chris215 | 0:0c1aa5906cef | 37 | { |
chris215 | 0:0c1aa5906cef | 38 | return GeoDesicToECEF(ReadDecGeodLoc()); |
chris215 | 0:0c1aa5906cef | 39 | } |
chris215 | 0:0c1aa5906cef | 40 | ECEFDistance GPS::DistanceBetweenTwoWP(ECEFPoint p1,ECEFPoint p2) |
chris215 | 0:0c1aa5906cef | 41 | { |
chris215 | 0:0c1aa5906cef | 42 | return DistanceBetweenTwoECEFPoints(p1,p2); |
chris215 | 0:0c1aa5906cef | 43 | } |
chris215 | 0:0c1aa5906cef | 44 | |
chris215 | 0:0c1aa5906cef | 45 | geodPoint GPS::ReadDecGeodLoc(void){ |
chris215 | 0:0c1aa5906cef | 46 | geodPoint newLoc; |
chris215 | 0:0c1aa5906cef | 47 | newLoc.latitude = nmea_to_dec(info.latitude,info.latLoc); |
chris215 | 0:0c1aa5906cef | 48 | newLoc.longitude = nmea_to_dec(info.longitude,info.lonLoc); |
chris215 | 0:0c1aa5906cef | 49 | newLoc.altitude = info.GPSAltitude; |
chris215 | 0:0c1aa5906cef | 50 | return newLoc; |
chris215 | 0:0c1aa5906cef | 51 | } |
chris215 | 0:0c1aa5906cef | 52 | |
chris215 | 0:0c1aa5906cef | 53 | geodPoint GPS::ReadRawGeodLoc(void){ |
chris215 | 0:0c1aa5906cef | 54 | geodPoint newLoc; |
chris215 | 0:0c1aa5906cef | 55 | newLoc.latitude = info.latitude; |
chris215 | 0:0c1aa5906cef | 56 | newLoc.longitude = info.longitude; |
chris215 | 0:0c1aa5906cef | 57 | newLoc.altitude = info.GPSAltitude; |
chris215 | 0:0c1aa5906cef | 58 | return newLoc; |
chris215 | 0:0c1aa5906cef | 59 | } |
chris215 | 0:0c1aa5906cef | 60 | |
chris215 | 0:0c1aa5906cef | 61 | |
chris215 | 0:0c1aa5906cef | 62 | bool GPS::FixIs3d(void){ |
chris215 | 0:0c1aa5906cef | 63 | return (info.fix == 3); |
chris215 | 0:0c1aa5906cef | 64 | } |
chris215 | 0:0c1aa5906cef | 65 | bool GPS::FixIs2d(void){ |
chris215 | 0:0c1aa5906cef | 66 | return (FixIs3d() || (info.fix == 2)); |
chris215 | 0:0c1aa5906cef | 67 | } |
chris215 | 0:0c1aa5906cef | 68 | bool GPS::GPSFixValid(void){ |
chris215 | 0:0c1aa5906cef | 69 | return (info.GPSStatus == 'A'); |
chris215 | 0:0c1aa5906cef | 70 | } |
chris215 | 0:0c1aa5906cef | 71 | |
chris215 | 0:0c1aa5906cef | 72 |