An implementation of the Sirf Binary and NMEA Protocol for gps devices using the SiRFstarIII chipset
BinaryPackets.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_BINARY_PACKETS |
p3p | 0:43da35949666 | 2 | #define SIRF_PROTOCOL_BINARY_PACKETS |
p3p | 0:43da35949666 | 3 | |
p3p | 0:43da35949666 | 4 | namespace SirfStarIII { |
p3p | 0:43da35949666 | 5 | |
p3p | 0:43da35949666 | 6 | namespace BinaryPacket { |
p3p | 0:43da35949666 | 7 | |
p3p | 0:43da35949666 | 8 | enum PacketNames { |
p3p | 0:43da35949666 | 9 | //inbound |
p3p | 0:43da35949666 | 10 | ID_MeasuredTrackingData = 4, |
p3p | 0:43da35949666 | 11 | ID_DGPSStatus = 27, |
p3p | 0:43da35949666 | 12 | ID_GeodeticNavigationData = 41, |
p3p | 0:43da35949666 | 13 | //outbound |
p3p | 0:43da35949666 | 14 | ID_ConfigureNMEA = 129, |
p3p | 0:43da35949666 | 15 | ID_SetBinarySerialPort = 134, |
p3p | 0:43da35949666 | 16 | ID_SetProtocol = 135 |
p3p | 0:43da35949666 | 17 | }; |
p3p | 0:43da35949666 | 18 | |
p3p | 0:43da35949666 | 19 | class SetProtocol : public SimpleSerialProtocol::Packet { |
p3p | 0:43da35949666 | 20 | public: |
p3p | 0:43da35949666 | 21 | SetProtocol(uint8_t _protocol) { |
p3p | 0:43da35949666 | 22 | interface.protocol = _protocol; |
p3p | 0:43da35949666 | 23 | } |
p3p | 0:43da35949666 | 24 | |
p3p | 0:43da35949666 | 25 | #pragma pack(push, 1) |
p3p | 0:43da35949666 | 26 | struct Interface { |
p3p | 0:43da35949666 | 27 | Interface() { |
p3p | 0:43da35949666 | 28 | message_id = ID_SetProtocol; |
p3p | 0:43da35949666 | 29 | } |
p3p | 0:43da35949666 | 30 | uint8_t message_id; |
p3p | 0:43da35949666 | 31 | uint8_t protocol; |
p3p | 0:43da35949666 | 32 | } interface; |
p3p | 0:43da35949666 | 33 | #pragma pack(pop) |
p3p | 0:43da35949666 | 34 | |
p3p | 0:43da35949666 | 35 | }; |
p3p | 0:43da35949666 | 36 | |
p3p | 0:43da35949666 | 37 | class SetBinarySerialPort : public SimpleSerialProtocol::Packet { |
p3p | 0:43da35949666 | 38 | public: |
p3p | 0:43da35949666 | 39 | SetBinarySerialPort(uint32_t _bitrate) { |
p3p | 0:43da35949666 | 40 | interface.bitrate = swapEndian(_bitrate); |
p3p | 0:43da35949666 | 41 | } |
p3p | 0:43da35949666 | 42 | #pragma pack(push, 1) |
p3p | 0:43da35949666 | 43 | struct Interface { |
p3p | 0:43da35949666 | 44 | Interface() { |
p3p | 0:43da35949666 | 45 | message_id = ID_SetBinarySerialPort; |
p3p | 0:43da35949666 | 46 | data_bits = 8; |
p3p | 0:43da35949666 | 47 | stop_bit = 1; |
p3p | 0:43da35949666 | 48 | parity = 0; |
p3p | 0:43da35949666 | 49 | } |
p3p | 0:43da35949666 | 50 | uint8_t message_id; |
p3p | 0:43da35949666 | 51 | uint32_t bitrate; |
p3p | 0:43da35949666 | 52 | uint8_t data_bits; |
p3p | 0:43da35949666 | 53 | uint8_t stop_bit; |
p3p | 0:43da35949666 | 54 | uint8_t parity; |
p3p | 0:43da35949666 | 55 | uint8_t padding; |
p3p | 0:43da35949666 | 56 | } interface; |
p3p | 0:43da35949666 | 57 | #pragma pack(pop) |
p3p | 0:43da35949666 | 58 | }; |
p3p | 0:43da35949666 | 59 | |
p3p | 0:43da35949666 | 60 | class ConfigureNMEA : public SimpleSerialProtocol::Packet { |
p3p | 0:43da35949666 | 61 | public: |
p3p | 0:43da35949666 | 62 | ConfigureNMEA(uint16_t _bitrate) { |
p3p | 0:43da35949666 | 63 | interface.bitrate = swapEndian(_bitrate);; |
p3p | 0:43da35949666 | 64 | } |
p3p | 0:43da35949666 | 65 | |
p3p | 0:43da35949666 | 66 | #pragma pack(push, 1) |
p3p | 0:43da35949666 | 67 | struct Interface { |
p3p | 0:43da35949666 | 68 | Interface() { |
p3p | 0:43da35949666 | 69 | message_id = ID_ConfigureNMEA; |
p3p | 0:43da35949666 | 70 | mode = 2; |
p3p | 0:43da35949666 | 71 | gga_message = 0; |
p3p | 0:43da35949666 | 72 | gga_checksum = 1; |
p3p | 0:43da35949666 | 73 | gll_message = 0; |
p3p | 0:43da35949666 | 74 | gll_checksum = 1; |
p3p | 0:43da35949666 | 75 | gsa_message = 0; |
p3p | 0:43da35949666 | 76 | gsa_checksum = 1; |
p3p | 0:43da35949666 | 77 | gsv_message = 0; |
p3p | 0:43da35949666 | 78 | gsv_checksum = 1; |
p3p | 0:43da35949666 | 79 | rmc_message = 1; |
p3p | 0:43da35949666 | 80 | rmc_checksum = 1; |
p3p | 0:43da35949666 | 81 | vtg_message = 0; |
p3p | 0:43da35949666 | 82 | vtg_checksum = 1; |
p3p | 0:43da35949666 | 83 | mss_message = 0; |
p3p | 0:43da35949666 | 84 | mss_checksum = 1; |
p3p | 0:43da35949666 | 85 | epe_message = 0; |
p3p | 0:43da35949666 | 86 | epe_checksum = 0; |
p3p | 0:43da35949666 | 87 | zda_message = 0; |
p3p | 0:43da35949666 | 88 | zda_checksum = 1; |
p3p | 0:43da35949666 | 89 | padding = 0; |
p3p | 0:43da35949666 | 90 | } |
p3p | 0:43da35949666 | 91 | uint8_t message_id; |
p3p | 0:43da35949666 | 92 | uint8_t mode; |
p3p | 0:43da35949666 | 93 | uint8_t gga_message; |
p3p | 0:43da35949666 | 94 | uint8_t gga_checksum; |
p3p | 0:43da35949666 | 95 | uint8_t gll_message; |
p3p | 0:43da35949666 | 96 | uint8_t gll_checksum; |
p3p | 0:43da35949666 | 97 | uint8_t gsa_message; |
p3p | 0:43da35949666 | 98 | uint8_t gsa_checksum; |
p3p | 0:43da35949666 | 99 | uint8_t gsv_message; |
p3p | 0:43da35949666 | 100 | uint8_t gsv_checksum; |
p3p | 0:43da35949666 | 101 | uint8_t rmc_message; |
p3p | 0:43da35949666 | 102 | uint8_t rmc_checksum; |
p3p | 0:43da35949666 | 103 | uint8_t vtg_message; |
p3p | 0:43da35949666 | 104 | uint8_t vtg_checksum; |
p3p | 0:43da35949666 | 105 | uint8_t mss_message; |
p3p | 0:43da35949666 | 106 | uint8_t mss_checksum; |
p3p | 0:43da35949666 | 107 | uint8_t epe_message; |
p3p | 0:43da35949666 | 108 | uint8_t epe_checksum; |
p3p | 0:43da35949666 | 109 | uint8_t zda_message; |
p3p | 0:43da35949666 | 110 | uint8_t zda_checksum; |
p3p | 0:43da35949666 | 111 | uint16_t padding; |
p3p | 0:43da35949666 | 112 | uint16_t bitrate; |
p3p | 0:43da35949666 | 113 | } interface; |
p3p | 0:43da35949666 | 114 | #pragma pack(pop) |
p3p | 0:43da35949666 | 115 | |
p3p | 0:43da35949666 | 116 | }; |
p3p | 0:43da35949666 | 117 | |
p3p | 0:43da35949666 | 118 | class MeasuredTrackingData : public SimpleSerialProtocol::Packet { |
p3p | 0:43da35949666 | 119 | public: |
p3p | 0:43da35949666 | 120 | MeasuredTrackingData() {} |
p3p | 0:43da35949666 | 121 | |
p3p | 0:43da35949666 | 122 | #pragma pack(push, 1) |
p3p | 0:43da35949666 | 123 | struct Interface { |
p3p | 0:43da35949666 | 124 | uint8_t message_id; |
p3p | 0:43da35949666 | 125 | int16_t gps_week; |
p3p | 0:43da35949666 | 126 | uint32_t gps_time_of_week; |
p3p | 0:43da35949666 | 127 | uint8_t channels; |
p3p | 0:43da35949666 | 128 | struct { |
p3p | 0:43da35949666 | 129 | uint8_t svid; |
p3p | 0:43da35949666 | 130 | uint8_t azimuth; |
p3p | 0:43da35949666 | 131 | uint8_t elevation; |
p3p | 0:43da35949666 | 132 | uint16_t state; |
p3p | 0:43da35949666 | 133 | uint8_t c_no_1; |
p3p | 0:43da35949666 | 134 | uint8_t c_no_2; |
p3p | 0:43da35949666 | 135 | uint8_t c_no_3; |
p3p | 0:43da35949666 | 136 | uint8_t c_no_4; |
p3p | 0:43da35949666 | 137 | uint8_t c_no_5; |
p3p | 0:43da35949666 | 138 | uint8_t c_no_6; |
p3p | 0:43da35949666 | 139 | uint8_t c_no_7; |
p3p | 0:43da35949666 | 140 | uint8_t c_no_8; |
p3p | 0:43da35949666 | 141 | uint8_t c_no_9; |
p3p | 0:43da35949666 | 142 | uint8_t c_no_10; |
p3p | 0:43da35949666 | 143 | } channel_data[12]; |
p3p | 0:43da35949666 | 144 | }; |
p3p | 0:43da35949666 | 145 | #pragma pack(pop) |
p3p | 0:43da35949666 | 146 | |
p3p | 0:43da35949666 | 147 | static void swapByteOrder(Interface* interface) { |
p3p | 0:43da35949666 | 148 | interface->gps_week = swapEndian(interface->gps_week); |
p3p | 0:43da35949666 | 149 | interface->gps_time_of_week = swapEndian(interface->gps_time_of_week); |
p3p | 0:43da35949666 | 150 | for (int i = 0; i < 12; i++) { |
p3p | 0:43da35949666 | 151 | interface->channel_data[i].state = swapEndian(interface->channel_data[i].state); |
p3p | 0:43da35949666 | 152 | } |
p3p | 0:43da35949666 | 153 | } |
p3p | 0:43da35949666 | 154 | }; |
p3p | 0:43da35949666 | 155 | |
p3p | 0:43da35949666 | 156 | class DGPSStatus : public SimpleSerialProtocol::Packet { |
p3p | 0:43da35949666 | 157 | public: |
p3p | 0:43da35949666 | 158 | #pragma pack(push, 1) |
p3p | 0:43da35949666 | 159 | struct Interface { |
p3p | 0:43da35949666 | 160 | uint8_t message_id; |
p3p | 0:43da35949666 | 161 | uint8_t dgps_source; |
p3p | 0:43da35949666 | 162 | union { |
p3p | 0:43da35949666 | 163 | struct { |
p3p | 0:43da35949666 | 164 | int32_t beacon_frequency; |
p3p | 0:43da35949666 | 165 | uint8_t beacon_bitrate; |
p3p | 0:43da35949666 | 166 | uint8_t status; |
p3p | 0:43da35949666 | 167 | int32_t signal_magnitude; |
p3p | 0:43da35949666 | 168 | int16_t signal_strength; |
p3p | 0:43da35949666 | 169 | int16_t signal_noise_ratio; |
p3p | 0:43da35949666 | 170 | }; |
p3p | 0:43da35949666 | 171 | struct { |
p3p | 0:43da35949666 | 172 | uint8_t correction_age[12]; |
p3p | 0:43da35949666 | 173 | uint16_t reserved; |
p3p | 0:43da35949666 | 174 | }; |
p3p | 0:43da35949666 | 175 | }; |
p3p | 0:43da35949666 | 176 | struct { |
p3p | 0:43da35949666 | 177 | uint8_t satalite_prn_code; |
p3p | 0:43da35949666 | 178 | int16_t dgps_correction; |
p3p | 0:43da35949666 | 179 | } satalite_corrections[12]; |
p3p | 0:43da35949666 | 180 | }; |
p3p | 0:43da35949666 | 181 | #pragma pack(pop) |
p3p | 0:43da35949666 | 182 | |
p3p | 0:43da35949666 | 183 | static void swapByteOrder(Interface* interface) { |
p3p | 0:43da35949666 | 184 | for (int i = 0; i < 12; i++) { |
p3p | 0:43da35949666 | 185 | interface->satalite_corrections[i].dgps_correction = swapEndian(interface->satalite_corrections[i].dgps_correction); |
p3p | 0:43da35949666 | 186 | } |
p3p | 0:43da35949666 | 187 | } |
p3p | 0:43da35949666 | 188 | }; |
p3p | 0:43da35949666 | 189 | |
p3p | 0:43da35949666 | 190 | class GeodeticNavigationData : public SimpleSerialProtocol::Packet { |
p3p | 0:43da35949666 | 191 | public: |
p3p | 0:43da35949666 | 192 | #pragma pack(push, 1) |
p3p | 0:43da35949666 | 193 | struct Interface { |
p3p | 0:43da35949666 | 194 | uint8_t message_id; |
p3p | 0:43da35949666 | 195 | uint16_t nav_valid; |
p3p | 0:43da35949666 | 196 | uint16_t nav_type; |
p3p | 0:43da35949666 | 197 | uint16_t week_number; |
p3p | 0:43da35949666 | 198 | uint32_t time_of_week; |
p3p | 0:43da35949666 | 199 | uint16_t year; |
p3p | 0:43da35949666 | 200 | uint8_t month; |
p3p | 0:43da35949666 | 201 | uint8_t day; |
p3p | 0:43da35949666 | 202 | uint8_t hour; |
p3p | 0:43da35949666 | 203 | uint8_t minute; |
p3p | 0:43da35949666 | 204 | uint16_t second; |
p3p | 0:43da35949666 | 205 | uint32_t satalite_id_list; |
p3p | 0:43da35949666 | 206 | int32_t latitude; |
p3p | 0:43da35949666 | 207 | int32_t longitude; |
p3p | 0:43da35949666 | 208 | int32_t altitude_elipsoid; |
p3p | 0:43da35949666 | 209 | int32_t altitude_MSL; |
p3p | 0:43da35949666 | 210 | int8_t map_datum; |
p3p | 0:43da35949666 | 211 | uint16_t speed_over_ground; |
p3p | 0:43da35949666 | 212 | uint16_t course_over_ground; |
p3p | 0:43da35949666 | 213 | int16_t magnetic_variation; |
p3p | 0:43da35949666 | 214 | int16_t climb_rate; |
p3p | 0:43da35949666 | 215 | int16_t heading_rate; |
p3p | 0:43da35949666 | 216 | uint32_t est_h_position_error; |
p3p | 0:43da35949666 | 217 | uint32_t est_v_position_error; |
p3p | 0:43da35949666 | 218 | uint32_t est_time_error; |
p3p | 0:43da35949666 | 219 | uint16_t est_h_velocity_error; |
p3p | 0:43da35949666 | 220 | int32_t clock_bias; |
p3p | 0:43da35949666 | 221 | uint32_t clock_bias_error; |
p3p | 0:43da35949666 | 222 | int32_t clock_drift; |
p3p | 0:43da35949666 | 223 | uint32_t clock_drift_error; |
p3p | 0:43da35949666 | 224 | uint32_t distance; |
p3p | 0:43da35949666 | 225 | uint16_t distance_error; |
p3p | 0:43da35949666 | 226 | uint16_t heading_error; |
p3p | 0:43da35949666 | 227 | uint8_t satalites_in_fix; |
p3p | 0:43da35949666 | 228 | uint8_t horizontal_dilution_of_presision; |
p3p | 0:43da35949666 | 229 | uint8_t additional_mode_info; |
p3p | 0:43da35949666 | 230 | }; |
p3p | 0:43da35949666 | 231 | #pragma pack(pop) |
p3p | 0:43da35949666 | 232 | |
p3p | 0:43da35949666 | 233 | static void swapByteOrder(Interface* interface) { |
p3p | 0:43da35949666 | 234 | interface->nav_valid = swapEndian(interface->nav_valid); |
p3p | 0:43da35949666 | 235 | interface->nav_type = swapEndian(interface->nav_type); |
p3p | 0:43da35949666 | 236 | interface->week_number = swapEndian(interface->week_number); |
p3p | 0:43da35949666 | 237 | interface->time_of_week = swapEndian(interface->time_of_week); |
p3p | 0:43da35949666 | 238 | interface->year = swapEndian(interface->year); |
p3p | 0:43da35949666 | 239 | interface->second = swapEndian(interface->second); |
p3p | 0:43da35949666 | 240 | interface->satalite_id_list = swapEndian(interface->satalite_id_list); |
p3p | 0:43da35949666 | 241 | interface->latitude = swapEndian(interface->latitude); |
p3p | 0:43da35949666 | 242 | interface->longitude = swapEndian(interface->longitude); |
p3p | 0:43da35949666 | 243 | interface->altitude_elipsoid = swapEndian(interface->altitude_elipsoid); |
p3p | 0:43da35949666 | 244 | interface->altitude_MSL = swapEndian(interface->altitude_MSL); |
p3p | 0:43da35949666 | 245 | interface->speed_over_ground = swapEndian(interface->speed_over_ground); |
p3p | 0:43da35949666 | 246 | interface->course_over_ground = swapEndian(interface->course_over_ground); |
p3p | 0:43da35949666 | 247 | interface->magnetic_variation = swapEndian(interface->magnetic_variation); |
p3p | 0:43da35949666 | 248 | interface->climb_rate = swapEndian(interface->climb_rate); |
p3p | 0:43da35949666 | 249 | interface->heading_rate = swapEndian(interface->heading_rate); |
p3p | 0:43da35949666 | 250 | interface->est_h_position_error = swapEndian(interface->est_h_position_error); |
p3p | 0:43da35949666 | 251 | interface->est_v_position_error = swapEndian(interface->est_v_position_error); |
p3p | 0:43da35949666 | 252 | interface->est_time_error = swapEndian(interface->est_time_error); |
p3p | 0:43da35949666 | 253 | interface->est_h_velocity_error = swapEndian(interface->est_h_velocity_error); |
p3p | 0:43da35949666 | 254 | interface->clock_bias = swapEndian(interface->clock_bias); |
p3p | 0:43da35949666 | 255 | interface->clock_bias_error = swapEndian(interface->clock_bias_error); |
p3p | 0:43da35949666 | 256 | interface->clock_drift = swapEndian(interface->clock_drift); |
p3p | 0:43da35949666 | 257 | interface->clock_drift_error = swapEndian(interface->clock_drift_error); |
p3p | 0:43da35949666 | 258 | interface->distance = swapEndian(interface->distance); |
p3p | 0:43da35949666 | 259 | interface->distance_error = swapEndian(interface->distance_error); |
p3p | 0:43da35949666 | 260 | interface->heading_error = swapEndian(interface->heading_error); |
p3p | 0:43da35949666 | 261 | } |
p3p | 0:43da35949666 | 262 | }; |
p3p | 0:43da35949666 | 263 | |
p3p | 0:43da35949666 | 264 | } |
p3p | 0:43da35949666 | 265 | |
p3p | 0:43da35949666 | 266 | } |
p3p | 0:43da35949666 | 267 | |
p3p | 0:43da35949666 | 268 | #endif |