2 * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file MDev_GpsUblox.h
20 #ifndef INC_GPSCOMMON_MDEV_GPS_NMEA_H_
21 #define INC_GPSCOMMON_MDEV_GPS_NMEA_H_
23 /*---------------------------------------------------------------------------*/
26 #include "positioning_def.h"
28 /*---------------------------------------------------------------------------*/
31 #define TEST_NMEA (0) /* 0:Normal mode 1:Testing mode */
33 #define GPS_MAX_NUM_VISIBLE_SATELLITES (20) /* Maximum Number of Visible Satellites *Assume the GSV1~GSV5 */
35 /* UBX command *****************************/
38 #define UBX_CMD_SIZE_CFG_RST (12) /* size of CFG-RST of UBX sentences */
39 #define UBX_CMD_SIZE_CFG_MSG (11) /* size of CFG-MSG of UBX sentences */
40 #define UBX_CMD_SIZE_CFG_NAV5 (44) /* size of CFG-NAV5 of UBX sentences */
41 #define UBX_CMD_SIZE_CFG_NAV5_POLL (8)
42 #define UBX_CMD_SIZE_CFG_NAV5_PLUS_POLL (UBX_CMD_SIZE_CFG_NAV5 + UBX_CMD_SIZE_CFG_NAV5_POLL)
43 #define UBX_CMD_SIZE_CFG_NAVX5_POLL (8)
44 #define UBX_CMD_OFFSET_WKNROLLOVER (18) /* offset from the top of 'payload' */
47 #define UBX_CMD_SIZE_MON_VER (108) /* size of MON-VER of UBX sentences */
48 #define UBX_CMD_SIZE_MON_VER_POLL (8)
49 #define UBX_CMD_SIZE_MON_VER_SW_VER (30)
52 #define UBX_CMD_SIZE_AID_INI (56) /* size of AID-INI of UBX sentences */
53 #define UBX_CMD_SIZE_AID_INI_POLL (8)
54 #define UBX_CMD_SIZE_AID_INI_PLUS_POLL (UBX_CMD_SIZE_AID_INI + UBX_CMD_SIZE_AID_INI_POLL)
57 #define UBX_CMD_OFFSET_ACKNAK (3) /* offset to Ack/Nack Infomation */
60 #define UBX_CMD_MSK_NAV_TIMEUTC_VALID_TOW (1) /* mask bit for 'validTow' of NAV-TIMEUTC */
61 #define UBX_CMD_MSK_NAV_TIMEUTC_VALID_WKN (2) /* mask bit for 'validKwn' of NAV-TIMEUTC */
62 #define UBX_CMD_MSK_NAV_TIMEUTC_VALID_UTC (4) /* mask bit for 'validUtc' of NAV-TIMEUTC */
65 #define UBX_CMD_SIZE_HDR (2) /* size of 'header' of UBX sentence */
66 #define UBX_CMD_SIZE_ID (2) /* size of 'id' of UBX sentence */
67 #define UBX_CMD_SIZE_LEN (2) /* size of 'length' of UBX sentence */
68 #define UBX_CMD_SIZE_MAX (400) /* size of NAV-SVINFO (numCh=32) */
69 #define UBX_CMD_OFFSET_PAYLOAD (UBX_CMD_SIZE_HDR + UBX_CMD_SIZE_ID + UBX_CMD_SIZE_LEN)
70 /* offset to 'payload' of UBX sentence */
72 /* Types of UBX Poll Request Commands ************/
73 #define UBX_POLL_CMD_KIND_AID_INI (1)
74 #define UBX_POLL_CMD_KIND_CFG_NAV5 (2)
76 // GPS-command (_CWORD82_ NMEA) related definitions #GPF_60_024
77 /* Command identification character string */
78 #define GPS_CMD_NMEA_GGA ("$GPGGA") /* GGA/double precision GGAs */
79 #define GPS_CMD_NMEA_VTG ("$GPVTG") /* VTG */
80 #define GPS_CMD_NMEA_RMC ("$GPRMC") /* RMC/double precision RMCs */
81 #define GPS_CMD_NMEA_GLL ("$GPGLL") /* GLL/double precision GLL */
82 #define GPS_CMD_NMEA_GSA ("$GPGSA") /* GSA */
83 #define GPS_CMD_NMEA_GSV_1 ("$GPGSV,*,1") /* GSV(1) */
84 #define GPS_CMD_NMEA_GSV_2 ("$GPGSV,*,2") /* GSV(2) */
85 #define GPS_CMD_NMEA_GSV_3 ("$GPGSV,*,3") /* GSV(3) */
86 #define GPS_CMD_NMEA__CWORD44__GP_3 ("$_CWORD44_,GP,3") /* _CWORD44_,GP,3 */
87 #define GPS_CMD_NMEA__CWORD44__GP_4 ("$_CWORD44_,GP,4") /* _CWORD44_,GP,4 */
88 #define GPS_CMD_NMEA_P_CWORD82_F_GP_0 ("$P_CWORD82_F,GP,0") /* P_CWORD82_F,GP,0 */
89 #define GPS_CMD_NMEA_P_CWORD82_J_GP_1 ("$P_CWORD82_J,GP,1") /* P_CWORD82_J,GP,1 */
90 #define GPS_CMD_NMEA_P_CWORD82_I_GP ("$P_CWORD82_I,GP") /* P_CWORD82_I,GP */
91 #define GPS_CMD_NMEA_P_CWORD82_E_GP_0 ("$P_CWORD82_E,GP,0") /* P_CWORD82_E,GP,0 */
92 #define GPS_CMD_NMEA_P_CWORD82_J_GP_0 ("$P_CWORD82_J,GP,0") /* P_CWORD82_J,GP,0 */
93 #define GPS_CMD_NMEA_P_CWORD82_E_GP_2 ("$P_CWORD82_E,GP,2") /* P_CWORD82_E,GP,2 */
94 #define GPS_CMD_NMEA_P_CWORD82_G_GP_0 ("$P_CWORD82_G,GP,0") /* P_CWORD82_G,GP,0 */
95 #define GPS_CMD_NMEA_P_CWORD82_J_GP_7 ("$P_CWORD82_J,GP,7") /* P_CWORD82_J,GP,7 */
96 #define GPS_CMD_NMEA_P_CWORD82_J_GP_8 ("$P_CWORD82_J,GP,8") /* P_CWORD82_J,GP,8 */
97 #define GPS_CMD_NMEA_GST ("$GPGST") /* GST */
98 #define GPS_CMD_NMEA_GSV_4 ("$GPGSV,*,4") /* GSV(4) */
99 #define GPS_CMD_NMEA_GSV_5 ("$GPGSV,*,5") /* GSV(5) */
101 /*-------------------------------------------------------------------------------
102 * GPS-command (_CWORD82_ Binary) related definitions #GPF_60_024
103 -------------------------------------------------------------------------------*/
104 #define GPS_CMD_BINARY (0xC6) /* Standard binary */
105 #define GPS_CMD_FULLBIN (0xB0) /* FULL binaries */
107 #define ENDMARK "ENDENDEND" /* Table termination */
108 #define GPSCMDANATBL_MAX 25 /* Maximum number of elements in table */
109 #define RCV_CYCLE 0x01 /* Reception type cycle reception command*/
110 #define RCV_RESP 0x02 /* Reception type response command */
112 // Length of FULLBINARY commands
113 #define GPS_CMD_FULLBIN1_SZ 30
114 #define GPS_CMD_FULLBIN2_SZ 160
115 #define GPS_CMD_FULLBIN3_SZ 25
116 #define GPS_CMD_FULLBIN4_SZ 26
117 #define GPS_CMD_FULLBIN5_SZ 14
118 #define GPS_CMD_FULLBIN6_SZ 61
120 /* Start offset of FULLBINARY command */
121 #define GPS_CMD_FULLBIN1_OFFSET 0
122 #define GPS_CMD_FULLBIN2_OFFSET (GPS_CMD_FULLBIN1_OFFSET + GPS_CMD_FULLBIN1_SZ)
123 #define GPS_CMD_FULLBIN3_OFFSET (GPS_CMD_FULLBIN2_OFFSET + GPS_CMD_FULLBIN2_SZ)
124 #define GPS_CMD_FULLBIN4_OFFSET (GPS_CMD_FULLBIN3_OFFSET + GPS_CMD_FULLBIN3_SZ)
125 #define GPS_CMD_FULLBIN5_OFFSET (GPS_CMD_FULLBIN4_OFFSET + GPS_CMD_FULLBIN4_SZ)
126 #define GPS_CMD_FULLBIN6_OFFSET (GPS_CMD_FULLBIN5_OFFSET + GPS_CMD_FULLBIN6_SZ)
129 /* SUM value offset of FULLBINARY commands */
130 #define GPS_CMD_FULLBIN1_SUMOFFSET (GPS_CMD_FULLBIN1_OFFSET + GPS_CMD_FULLBIN1_SZ - 2)
131 #define GPS_CMD_FULLBIN2_SUMOFFSET (GPS_CMD_FULLBIN2_OFFSET + GPS_CMD_FULLBIN2_SZ - 2)
132 #define GPS_CMD_FULLBIN3_SUMOFFSET (GPS_CMD_FULLBIN3_OFFSET + GPS_CMD_FULLBIN3_SZ - 2)
133 #define GPS_CMD_FULLBIN4_SUMOFFSET (GPS_CMD_FULLBIN4_OFFSET + GPS_CMD_FULLBIN4_SZ - 2)
134 #define GPS_CMD_FULLBIN5_SUMOFFSET (GPS_CMD_FULLBIN5_OFFSET + GPS_CMD_FULLBIN5_SZ - 2)
135 #define GPS_CMD_FULLBIN6_SUMOFFSET (GPS_CMD_FULLBIN6_OFFSET + GPS_CMD_FULLBIN6_SZ - 2)
136 #define GPS_CMD_FULLBIN_MASK 0x8F
138 #define GPS_CMD_RESET 1 /* Reset request command */
139 #define GPS_CMD_TIMESET 2 /* Time setting request command */
140 #define GPS_CMD_VERSION 3 /* GPS version request command */
141 #define GPS_CMD_SENTENCEADD_NMEAGST 4 /* Add sentence command NMEA GST */
142 #define GPS_CMD_SENTENCEADD_NAVTIMEUTC 5 /* Add sentence command NAV-TIMEUTC */
143 #define GPS_CMD_SENTENCEADD_NAVCLOCK 6 /* Add sentence command NAV-CLOCK */
144 #define GPS_CMD_SENTENCEADD_RXMRTC5 7 /* Add sentence command RXM-RTC5 */
145 #define GPS_CMD_SENTENCEADD_NAVSVINFO 8 /* Add sentence command NAV-SVINFO */
146 #define GPS_CMD_AUTOMOTIVEMODE 9 /* Automatic mode request command */
147 #define GPS_CMD_WKNROLLOVER 10 /* GPS rollover standard week number request command */
148 #define GPS_CMD_NOTRST 0 /* Other request command */
150 /*---------------------------------------------------------------------------*/
154 @brief UBX command headers
156 typedef struct GpsUbxPacketHeader {
157 u_int8 uc_sync_char1; /* u-blox starts with 2 Bytes 0xB5 0x62 */
158 u_int8 uc_sync_char2; /* u-blox starts with 2 Bytes 0xB5 0x62 */
159 u_int8 uc_class; /* Class */
160 u_int8 uc_id; /* ID */
161 u_int16 us_length; /* Length */
162 } TG_GPS_UBX_PACKET_HEADER;
165 @brief Command-structure without UBX data
167 typedef struct GpsUbxCmdNoData {
168 TG_GPS_UBX_PACKET_HEADER header;
169 u_int8 uc_cka; /* Checksum_A */
170 u_int8 uc_ckb; /* Checksum_B */
171 } TG_GPS_UBX_COMMAND_NO_DATA;
176 typedef struct GpsUbxAidIniPolled {
177 u_int8 uc_sync_char1; /* u-blox starts with 2 Bytes 0xB5 0x62 */
178 u_int8 uc_sync_char2; /* u-blox starts with 2 Bytes 0xB5 0x62 */
179 u_int8 uc_class; /* Class */
180 u_int8 uc_id; /* ID */
181 u_int8 uc_length[2]; /* Length */
182 u_int8 uc_ecefx_or_lat[4]; /* WGS84 ECEF X coordinate or latitude */
183 u_int8 uc_ecefy_or_lon[4]; /* WGS84 ECEF Y coordinate or longitude */
184 u_int8 uc_ecefz_or_alt[4]; /* WGS84 ECEF Z coordinate or altitude */
185 u_int8 uc_pos_acc[4]; /* Position accuracy (stddev) */
186 u_int8 uc_tm_cfg[2]; /* Time mark configuration */
187 u_int8 wn[2]; /* Actual week number */
188 u_int8 tow[4]; /* Actual time of week */
189 u_int8 uc_tow_ns[4]; /* Sub-millisecond part of time of week */
190 u_int8 uc_tacc_ms[4]; /* Milliseconds part of time accuracy */
191 u_int8 uc_tacc_ns[4]; /* Nanoseconds part of time accuracy */
192 u_int8 uc_clk_d_or_freq[4]; /* Clock drift or frequency */
193 u_int8 uc_clk_dacc_or_freqacc[4]; /* Accuracy of clock drift or frequency */
194 u_int8 uc_flags[4]; /* Bitmask with the following flags */
195 u_int8 uc_cka; /* Checksum_A */
196 u_int8 uc_ckb; /* Checksum_B */
197 } TG_GPS_UBX_AID_INI_POLLED;
200 @brief UBX ACK command data structures
202 typedef struct GpsUbxAckData {
203 uint8_t uc_msg_class; /* Message Class */
204 uint8_t uc_msg_id; /* Message Identifier */
205 } TG_GPS_UBX_ACK_DATA;
208 @brief UBX NAV-TIMEUTC command data structures
210 typedef struct GpsUbxNavUTC {
211 uint32_t ul_itow; /* GPS time of week */
212 uint32_t ul_tacc; /* Time accuracy estimate (UTC) */
213 int32_t nano; /* Fraction of second */
214 uint16_t year; /* Year, range 1999..2099 (UTC) */
215 uint8_t month; /* Month, range 1..12 (UTC) */
216 uint8_t day; /* Day of month, range 1..31 (UTC) */
217 uint8_t hour; /* Hour of day, range 0..23 (UTC) */
218 uint8_t min; /* Minute of hour, range 0..59 (UTC) */
219 uint8_t sec; /* Seconds of minute, range 0..60 (UTC) */
220 uint8_t valid; /* Validity Flags */
221 } TG_GPS_UBX_NAV_TIMEUTC_DATA;
224 @brief USB NAV-CLOCK command data structures
226 typedef struct GpsUbxNavClock {
227 uint32_t ul_itow; /**< GPS Time of week */
228 int32_t l_clkb; /**< Clock bias */
229 int32_t l_clkd; /**< Clock drift */
230 uint32_t ul_tacc; /**< Time accuaracy estimate */
231 uint32_t ul_facc; /**< Frequency accuracy estimate */
232 } TG_GPS_UBX_NAV_CLOCK;
235 @brief GPS RXM-RTC5 command data structures
237 typedef struct GpsUbxRxmRtc5 {
238 uint32_t ul_rtag_hw; /**< RTAG high word */
239 uint32_t ul_rtag_lw; /**< RTAG low word */
240 uint32_t freq; /**< Clock frequency */
241 uint32_t ul_freq_frac; /**< Clock frequency fractional part */
242 uint32_t ul_tow_frac; /**< Time of week fractional part */
243 uint32_t tow; /**< Time of week */
244 uint16_t wno; /**< GPS week number */
245 uint8_t uc_tow_valid; /**< TOW is valid flag */
246 uint8_t uc_freq_valid; /**< Frequency is valid flag */
247 } TG_GPS_UBX_RXM_RTC5;
249 /********************************************************************************
250 * TAG :TG_GPS_RCVDATA_NMEA
251 * ABSTRACT :Cyclic data (NMEA) area
252 * NOTE :I/F information between communication management thread and vehicle sensor
253 ********************************************************************************/
254 typedef struct GpsRcvDataNMEA {
255 u_int8 uc_rcv_flag[GPS_NMEA_INDEX_MAX]; /* Receive flag */
256 u_int8 u_reserve[3]; /* Reserved */
257 TG_GPS_NMEA_DAT st_nmea[GPS_NMEA_INDEX_MAX]; /* NMEA data area */
258 } TG_GPS_RCVDATA_NMEA;
260 /********************************************************************************
261 * TAG :TG_GPS_RCVDATA_BINARY
262 * ABSTRACT :Cyclic data (standard binary) area
263 * NOTE :I/F information between communication management thread and vehicle sensor
264 ********************************************************************************/
265 typedef struct GpsRcvDataBinary {
266 u_int8 uc_rcv_flag; /* Receive flag */
267 u_int8 u_reserve[3]; /* Reserved */
268 u_int8 uc_data[GPS_CMD_BINARY_SZ]; /* Standard binary data area */
269 u_int8 u_reserve2[3]; /* Reserved */
270 } TG_GPS_RCVDATA_BINARY;
272 /********************************************************************************
273 * TAG :TG_GPS_RCVDATA_FULLBIN
274 * ABSTRACT :Cyclic data (full binary) area
275 * NOTE :I/F information between communication management thread and vehicle sensor
276 ********************************************************************************/
277 typedef struct GpsRcvDataFullbin {
278 u_int8 uc_rcv_flag; /* Receive flag */
279 u_int8 u_reserve[3]; /* Reserved */
280 u_int8 uc_data[GPS_CMD_FULLBIN_SZ]; /* Full binary data area */
281 u_int8 u_reserve2; /* Reserved */
282 } TG_GPS_RCVDATA_FULLBIN;
284 /********************************************************************************
285 * TAG :TG_GPS_RCVDATA
286 * ABSTRACT :Cyclic data storage area
287 * NOTE :I/F information between communication management thread and vehicle sensor
288 ********************************************************************************/
289 typedef struct GpsRcvData {
290 u_int8 uc_sns_cnt; /* Sensor counter value */
291 u_int8 u_reserve[3]; /* Reserved */
292 TG_GPS_RCVDATA_NMEA st_nmea_data; /* NMEA data area */
293 TG_GPS_RCVDATA_BINARY st_binary_data; /* Standard binary region */
294 TG_GPS_RCVDATA_FULLBIN st_fullbin_data; /* Full binary data area */
297 /*---------------------------------------------------------------------------*/
300 void DevGpsSndCycleDataNmea(void);
301 void DevGpsRcvCyclCmd(void);
302 u_int8 DevGpsGetGpsRcvSts(u_int8 sv);
303 void DevGpsAnalyzeNmea(NAVIINFO_ALL* navilocinfo);
304 void DevGpsCycleDataClear(void);
305 void DevGpsCycleDataSetNmea(const u_int8*, u_int32, ENUM_GPS_NMEA_INDEX);
306 BOOL DevGpsCycleDataGetNmea(u_int8*, u_int32, ENUM_GPS_NMEA_INDEX);
307 void DevGpsCmdEventCheckNmea(void);
308 void DevGpsSetChkSum(u_int8* buffer, u_int32 length);
309 /*---------------------------------------------------------------------------*/
310 #endif // INC_GPSCOMMON_MDEV_GPS_NMEA_H_
312 /*---------------------------------------------------------------------------*/