polytech umpc project
Fork of SerialGPS by
SerialGPS.h@0:3d0c5d7e5d0a, 2010-09-20 (annotated)
- Committer:
- shintamainjp
- Date:
- Mon Sep 20 06:03:38 2010 +0000
- Revision:
- 0:3d0c5d7e5d0a
- Child:
- 1:a5b887e09aa4
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shintamainjp | 0:3d0c5d7e5d0a | 1 | /** |
shintamainjp | 0:3d0c5d7e5d0a | 2 | * Serial GPS module interface driver class (Version 0.0.1) |
shintamainjp | 0:3d0c5d7e5d0a | 3 | * This interface driver supports NMEA-0183 serial based modules. |
shintamainjp | 0:3d0c5d7e5d0a | 4 | * |
shintamainjp | 0:3d0c5d7e5d0a | 5 | * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems) |
shintamainjp | 0:3d0c5d7e5d0a | 6 | * http://shinta.main.jp/ |
shintamainjp | 0:3d0c5d7e5d0a | 7 | */ |
shintamainjp | 0:3d0c5d7e5d0a | 8 | #include "mbed.h" |
shintamainjp | 0:3d0c5d7e5d0a | 9 | #include "SerialBuffered.h" |
shintamainjp | 0:3d0c5d7e5d0a | 10 | |
shintamainjp | 0:3d0c5d7e5d0a | 11 | /** |
shintamainjp | 0:3d0c5d7e5d0a | 12 | * Serial GPS module interface driver class (Version 0.0.1) |
shintamainjp | 0:3d0c5d7e5d0a | 13 | * This interface driver supports NMEA-0183 serial based modules. |
shintamainjp | 0:3d0c5d7e5d0a | 14 | * |
shintamainjp | 0:3d0c5d7e5d0a | 15 | * = A list of NMEA-0183 Based GPS modules = |
shintamainjp | 0:3d0c5d7e5d0a | 16 | * GT-720F : http://akizukidenshi.com/catalog/g/gM-02711/ |
shintamainjp | 0:3d0c5d7e5d0a | 17 | * |
shintamainjp | 0:3d0c5d7e5d0a | 18 | * = References = |
shintamainjp | 0:3d0c5d7e5d0a | 19 | * NMEA Reference Manual (January 2005) - SiRF Technology, Inc. |
shintamainjp | 0:3d0c5d7e5d0a | 20 | */ |
shintamainjp | 0:3d0c5d7e5d0a | 21 | class SerialGPS { |
shintamainjp | 0:3d0c5d7e5d0a | 22 | public: |
shintamainjp | 0:3d0c5d7e5d0a | 23 | |
shintamainjp | 0:3d0c5d7e5d0a | 24 | /** |
shintamainjp | 0:3d0c5d7e5d0a | 25 | * Create. |
shintamainjp | 0:3d0c5d7e5d0a | 26 | * |
shintamainjp | 0:3d0c5d7e5d0a | 27 | * @param tx A pin of transmit. |
shintamainjp | 0:3d0c5d7e5d0a | 28 | * @param rx A pin of receive. |
shintamainjp | 0:3d0c5d7e5d0a | 29 | * @param baud Baud rate. (Default = 9600) |
shintamainjp | 0:3d0c5d7e5d0a | 30 | */ |
shintamainjp | 0:3d0c5d7e5d0a | 31 | SerialGPS(PinName tx, PinName rx, int baud = 9600); |
shintamainjp | 0:3d0c5d7e5d0a | 32 | |
shintamainjp | 0:3d0c5d7e5d0a | 33 | /** |
shintamainjp | 0:3d0c5d7e5d0a | 34 | * Destroy. |
shintamainjp | 0:3d0c5d7e5d0a | 35 | */ |
shintamainjp | 0:3d0c5d7e5d0a | 36 | ~SerialGPS(); |
shintamainjp | 0:3d0c5d7e5d0a | 37 | |
shintamainjp | 0:3d0c5d7e5d0a | 38 | /** |
shintamainjp | 0:3d0c5d7e5d0a | 39 | * GGA - Global Positioning System Fixed Data. |
shintamainjp | 0:3d0c5d7e5d0a | 40 | * |
shintamainjp | 0:3d0c5d7e5d0a | 41 | * $GPGGA,161229.487,3723.2475,N,12158.3416,W,1,07,1.0,9.0,M, , , ,0000*18 |
shintamainjp | 0:3d0c5d7e5d0a | 42 | */ |
shintamainjp | 0:3d0c5d7e5d0a | 43 | typedef struct { |
shintamainjp | 0:3d0c5d7e5d0a | 44 | int hour; |
shintamainjp | 0:3d0c5d7e5d0a | 45 | int min; |
shintamainjp | 0:3d0c5d7e5d0a | 46 | int sec; |
shintamainjp | 0:3d0c5d7e5d0a | 47 | double latitude; |
shintamainjp | 0:3d0c5d7e5d0a | 48 | char ns; |
shintamainjp | 0:3d0c5d7e5d0a | 49 | double longitude; |
shintamainjp | 0:3d0c5d7e5d0a | 50 | char ew; |
shintamainjp | 0:3d0c5d7e5d0a | 51 | int position_fix; |
shintamainjp | 0:3d0c5d7e5d0a | 52 | int satellites_used; |
shintamainjp | 0:3d0c5d7e5d0a | 53 | double hdop; |
shintamainjp | 0:3d0c5d7e5d0a | 54 | int altitude; |
shintamainjp | 0:3d0c5d7e5d0a | 55 | char altitude_unit; |
shintamainjp | 0:3d0c5d7e5d0a | 56 | } gps_gga_t; |
shintamainjp | 0:3d0c5d7e5d0a | 57 | |
shintamainjp | 0:3d0c5d7e5d0a | 58 | /** |
shintamainjp | 0:3d0c5d7e5d0a | 59 | * GSAâ€hGNSS DOP and Active Satellites. |
shintamainjp | 0:3d0c5d7e5d0a | 60 | * |
shintamainjp | 0:3d0c5d7e5d0a | 61 | * $GPGSA,A,3,07,02,26,27,09,04,15, , , , , ,1.8,1.0,1.5*33 |
shintamainjp | 0:3d0c5d7e5d0a | 62 | */ |
shintamainjp | 0:3d0c5d7e5d0a | 63 | typedef struct { |
shintamainjp | 0:3d0c5d7e5d0a | 64 | char selmode; |
shintamainjp | 0:3d0c5d7e5d0a | 65 | int fix; |
shintamainjp | 0:3d0c5d7e5d0a | 66 | } gps_gsa_t; |
shintamainjp | 0:3d0c5d7e5d0a | 67 | |
shintamainjp | 0:3d0c5d7e5d0a | 68 | /** |
shintamainjp | 0:3d0c5d7e5d0a | 69 | * for RMC: |
shintamainjp | 0:3d0c5d7e5d0a | 70 | * Time, date, position, course and speed data. |
shintamainjp | 0:3d0c5d7e5d0a | 71 | */ |
shintamainjp | 0:3d0c5d7e5d0a | 72 | typedef struct { |
shintamainjp | 0:3d0c5d7e5d0a | 73 | int hour; |
shintamainjp | 0:3d0c5d7e5d0a | 74 | int min; |
shintamainjp | 0:3d0c5d7e5d0a | 75 | int sec; |
shintamainjp | 0:3d0c5d7e5d0a | 76 | char status; |
shintamainjp | 0:3d0c5d7e5d0a | 77 | double nl; |
shintamainjp | 0:3d0c5d7e5d0a | 78 | double el; |
shintamainjp | 0:3d0c5d7e5d0a | 79 | } gps_rmc_t; |
shintamainjp | 0:3d0c5d7e5d0a | 80 | |
shintamainjp | 0:3d0c5d7e5d0a | 81 | /** |
shintamainjp | 0:3d0c5d7e5d0a | 82 | * for GSV: |
shintamainjp | 0:3d0c5d7e5d0a | 83 | * The number of GPS satellites in view satellite ID numbers, |
shintamainjp | 0:3d0c5d7e5d0a | 84 | * elevation, azimuth, and SNR values. |
shintamainjp | 0:3d0c5d7e5d0a | 85 | */ |
shintamainjp | 0:3d0c5d7e5d0a | 86 | typedef struct { |
shintamainjp | 0:3d0c5d7e5d0a | 87 | int num; |
shintamainjp | 0:3d0c5d7e5d0a | 88 | int elevation; |
shintamainjp | 0:3d0c5d7e5d0a | 89 | int azimuth; |
shintamainjp | 0:3d0c5d7e5d0a | 90 | int snr; |
shintamainjp | 0:3d0c5d7e5d0a | 91 | } gps_gsv_satellite_t; |
shintamainjp | 0:3d0c5d7e5d0a | 92 | |
shintamainjp | 0:3d0c5d7e5d0a | 93 | /** |
shintamainjp | 0:3d0c5d7e5d0a | 94 | * for GSV: |
shintamainjp | 0:3d0c5d7e5d0a | 95 | * The number of GPS satellites in view satellite ID numbers, |
shintamainjp | 0:3d0c5d7e5d0a | 96 | * elevation, azimuth, and SNR values. |
shintamainjp | 0:3d0c5d7e5d0a | 97 | */ |
shintamainjp | 0:3d0c5d7e5d0a | 98 | typedef struct { |
shintamainjp | 0:3d0c5d7e5d0a | 99 | int msgcnt; |
shintamainjp | 0:3d0c5d7e5d0a | 100 | int msgnum; |
shintamainjp | 0:3d0c5d7e5d0a | 101 | int satcnt; |
shintamainjp | 0:3d0c5d7e5d0a | 102 | gps_gsv_satellite_t satellite[4]; |
shintamainjp | 0:3d0c5d7e5d0a | 103 | } gps_gsv_t; |
shintamainjp | 0:3d0c5d7e5d0a | 104 | |
shintamainjp | 0:3d0c5d7e5d0a | 105 | /** |
shintamainjp | 0:3d0c5d7e5d0a | 106 | * Callback function structure. |
shintamainjp | 0:3d0c5d7e5d0a | 107 | */ |
shintamainjp | 0:3d0c5d7e5d0a | 108 | typedef struct { |
shintamainjp | 0:3d0c5d7e5d0a | 109 | /** |
shintamainjp | 0:3d0c5d7e5d0a | 110 | * A callback function for logging data. |
shintamainjp | 0:3d0c5d7e5d0a | 111 | */ |
shintamainjp | 0:3d0c5d7e5d0a | 112 | void (*cbfunc_log)(char *str); |
shintamainjp | 0:3d0c5d7e5d0a | 113 | |
shintamainjp | 0:3d0c5d7e5d0a | 114 | /** |
shintamainjp | 0:3d0c5d7e5d0a | 115 | * A callback function for GGA. |
shintamainjp | 0:3d0c5d7e5d0a | 116 | * |
shintamainjp | 0:3d0c5d7e5d0a | 117 | * GGA - Global Positioning System Fixed Data. |
shintamainjp | 0:3d0c5d7e5d0a | 118 | */ |
shintamainjp | 0:3d0c5d7e5d0a | 119 | void (*cbfunc_gga)(gps_gga_t *p); |
shintamainjp | 0:3d0c5d7e5d0a | 120 | |
shintamainjp | 0:3d0c5d7e5d0a | 121 | /** |
shintamainjp | 0:3d0c5d7e5d0a | 122 | * A callback function for GLL. |
shintamainjp | 0:3d0c5d7e5d0a | 123 | * |
shintamainjp | 0:3d0c5d7e5d0a | 124 | * GLL - Geographic Position - Latitude/Longitude. |
shintamainjp | 0:3d0c5d7e5d0a | 125 | */ |
shintamainjp | 0:3d0c5d7e5d0a | 126 | // TODO |
shintamainjp | 0:3d0c5d7e5d0a | 127 | |
shintamainjp | 0:3d0c5d7e5d0a | 128 | /** |
shintamainjp | 0:3d0c5d7e5d0a | 129 | * A callback function for GSA. |
shintamainjp | 0:3d0c5d7e5d0a | 130 | * |
shintamainjp | 0:3d0c5d7e5d0a | 131 | * GSA - GNSS DOP and Active Satellites. |
shintamainjp | 0:3d0c5d7e5d0a | 132 | */ |
shintamainjp | 0:3d0c5d7e5d0a | 133 | void (*cbfunc_gsa)(gps_gsa_t *p); |
shintamainjp | 0:3d0c5d7e5d0a | 134 | |
shintamainjp | 0:3d0c5d7e5d0a | 135 | /** |
shintamainjp | 0:3d0c5d7e5d0a | 136 | * A callback function for GSV. |
shintamainjp | 0:3d0c5d7e5d0a | 137 | * |
shintamainjp | 0:3d0c5d7e5d0a | 138 | * GSV - GNSS Satellites in View. |
shintamainjp | 0:3d0c5d7e5d0a | 139 | */ |
shintamainjp | 0:3d0c5d7e5d0a | 140 | void (*cbfunc_gsv)(gps_gsv_t *p); |
shintamainjp | 0:3d0c5d7e5d0a | 141 | |
shintamainjp | 0:3d0c5d7e5d0a | 142 | /** |
shintamainjp | 0:3d0c5d7e5d0a | 143 | * A callback function for MSS. |
shintamainjp | 0:3d0c5d7e5d0a | 144 | * |
shintamainjp | 0:3d0c5d7e5d0a | 145 | * MSS - MSK Receiver Signal. |
shintamainjp | 0:3d0c5d7e5d0a | 146 | */ |
shintamainjp | 0:3d0c5d7e5d0a | 147 | // TODO |
shintamainjp | 0:3d0c5d7e5d0a | 148 | |
shintamainjp | 0:3d0c5d7e5d0a | 149 | /** |
shintamainjp | 0:3d0c5d7e5d0a | 150 | * A callback function for RMC. |
shintamainjp | 0:3d0c5d7e5d0a | 151 | * |
shintamainjp | 0:3d0c5d7e5d0a | 152 | * RMC - Recommended Minimum Specific GNSS Data. |
shintamainjp | 0:3d0c5d7e5d0a | 153 | */ |
shintamainjp | 0:3d0c5d7e5d0a | 154 | void (*cbfunc_rmc)(gps_rmc_t *p); |
shintamainjp | 0:3d0c5d7e5d0a | 155 | |
shintamainjp | 0:3d0c5d7e5d0a | 156 | /** |
shintamainjp | 0:3d0c5d7e5d0a | 157 | * A callback function for VTG. |
shintamainjp | 0:3d0c5d7e5d0a | 158 | * |
shintamainjp | 0:3d0c5d7e5d0a | 159 | * VTG - Course Over Ground and Ground Speed. |
shintamainjp | 0:3d0c5d7e5d0a | 160 | */ |
shintamainjp | 0:3d0c5d7e5d0a | 161 | // TODO |
shintamainjp | 0:3d0c5d7e5d0a | 162 | |
shintamainjp | 0:3d0c5d7e5d0a | 163 | /** |
shintamainjp | 0:3d0c5d7e5d0a | 164 | * A callback function for ZDA. |
shintamainjp | 0:3d0c5d7e5d0a | 165 | * |
shintamainjp | 0:3d0c5d7e5d0a | 166 | * ZDA - SiRF Timing Message. |
shintamainjp | 0:3d0c5d7e5d0a | 167 | */ |
shintamainjp | 0:3d0c5d7e5d0a | 168 | // TODO |
shintamainjp | 0:3d0c5d7e5d0a | 169 | |
shintamainjp | 0:3d0c5d7e5d0a | 170 | } gps_callback_t; |
shintamainjp | 0:3d0c5d7e5d0a | 171 | |
shintamainjp | 0:3d0c5d7e5d0a | 172 | /** |
shintamainjp | 0:3d0c5d7e5d0a | 173 | * Processing. |
shintamainjp | 0:3d0c5d7e5d0a | 174 | */ |
shintamainjp | 0:3d0c5d7e5d0a | 175 | bool processing(); |
shintamainjp | 0:3d0c5d7e5d0a | 176 | |
shintamainjp | 0:3d0c5d7e5d0a | 177 | /** |
shintamainjp | 0:3d0c5d7e5d0a | 178 | * Attach a callback function. |
shintamainjp | 0:3d0c5d7e5d0a | 179 | * |
shintamainjp | 0:3d0c5d7e5d0a | 180 | * @param cbfuncs A pointer to a call back function structure. |
shintamainjp | 0:3d0c5d7e5d0a | 181 | */ |
shintamainjp | 0:3d0c5d7e5d0a | 182 | void attach(gps_callback_t *cbfuncs); |
shintamainjp | 0:3d0c5d7e5d0a | 183 | |
shintamainjp | 0:3d0c5d7e5d0a | 184 | /** |
shintamainjp | 0:3d0c5d7e5d0a | 185 | * Detach a callback function. |
shintamainjp | 0:3d0c5d7e5d0a | 186 | */ |
shintamainjp | 0:3d0c5d7e5d0a | 187 | void detach(void); |
shintamainjp | 0:3d0c5d7e5d0a | 188 | |
shintamainjp | 0:3d0c5d7e5d0a | 189 | private: |
shintamainjp | 0:3d0c5d7e5d0a | 190 | SerialBuffered ser; |
shintamainjp | 0:3d0c5d7e5d0a | 191 | gps_callback_t *cbfuncs; |
shintamainjp | 0:3d0c5d7e5d0a | 192 | static const int PARAM_TXTMAXLEN = 64; |
shintamainjp | 0:3d0c5d7e5d0a | 193 | static const int PARAM_ARRAYSIZE = 64; |
shintamainjp | 0:3d0c5d7e5d0a | 194 | static bool exists(char c, char *buf) { |
shintamainjp | 0:3d0c5d7e5d0a | 195 | const size_t n = strlen(buf); |
shintamainjp | 0:3d0c5d7e5d0a | 196 | for (int i = 0; i < n; i++) { |
shintamainjp | 0:3d0c5d7e5d0a | 197 | if (c == buf[i]) { |
shintamainjp | 0:3d0c5d7e5d0a | 198 | return true; |
shintamainjp | 0:3d0c5d7e5d0a | 199 | } |
shintamainjp | 0:3d0c5d7e5d0a | 200 | } |
shintamainjp | 0:3d0c5d7e5d0a | 201 | return false; |
shintamainjp | 0:3d0c5d7e5d0a | 202 | } |
shintamainjp | 0:3d0c5d7e5d0a | 203 | static char *parse(char *src, char *des, size_t siz, char *delim); |
shintamainjp | 0:3d0c5d7e5d0a | 204 | static int parseAndCallbackGGA(char *src, gps_callback_t *cbfuncs); |
shintamainjp | 0:3d0c5d7e5d0a | 205 | static int parseAndCallbackGSA(char *src, gps_callback_t *cbfuncs); |
shintamainjp | 0:3d0c5d7e5d0a | 206 | static int parseAndCallbackRMC(char *src, gps_callback_t *cbfuncs); |
shintamainjp | 0:3d0c5d7e5d0a | 207 | static int parseAndCallbackGSV(char *src, gps_callback_t *cbfuncs); |
shintamainjp | 0:3d0c5d7e5d0a | 208 | static int parseAndCallbackUnknown(char *src, gps_callback_t *cbfuncs); |
shintamainjp | 0:3d0c5d7e5d0a | 209 | static uint8_t calcCheckSum(char *buf, size_t siz); |
shintamainjp | 0:3d0c5d7e5d0a | 210 | }; |