blob: ca67bbaeab90a3e15874856ec1c17cd879cf0d9c [file] [log] [blame]
b.liud440f9f2025-04-18 10:44:31 +08001/*-----------------------------------------------------------------------------------------------*/
2/**
3 @file ql_gnss.h
4 @brief GNSS service API
5*/
6/*-----------------------------------------------------------------------------------------------*/
7
8/*-------------------------------------------------------------------------------------------------
9 Copyright (c) 2024 mobiletek Wireless Solution, Co., Ltd. All Rights Reserved.
10 mobiletek Wireless Solution Proprietary and Confidential.
11-------------------------------------------------------------------------------------------------*/
12
13/*-------------------------------------------------------------------------------------------------
14 EDIT HISTORY
15 This section contains comments describing changes made to the file.
16 Notice that changes are listed in reverse chronological order.
17 $Header: $
18 when who what, where, why
19 -------- --------- -----------------------------------------------------------------
20 20241022 yq.wang Created .
21-------------------------------------------------------------------------------------------------*/
22
23
24#ifndef __QL_GNSS_H__
25#define __QL_GNSS_H__
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30
31typedef enum {
32 /** Cold Start Gnss*/
33 QL_GNSS_COLD_START = 0,
34 /** Warm Start Gnss */
35 QL_GNSS_WARM_START,
36 /** Hot Start Gnss*/
37 QL_GNSS_HOT_START,
38}QL_GNSS_START_MODE_E;
39
40typedef enum
41{
42 /** gnss engine is off */
43 QL_GNSS_ENGINE_STATE_OFF = 0,
44 /** gnss engine is on */
45 QL_GNSS_ENGINE_STATE_ON = 1,
46}QL_GNSS_ENGINE_STATE_E;
47
48typedef enum
49{
50 QL_GNSS_EPH_DATA_GPS = 0x01,
51 QL_GNSS_EPH_DATA_BDS = 0x02,
52 QL_GNSS_EPH_DATA_GLO = 0x04,
53 QL_GNSS_EPH_DATA_GAL = 0x08,
54 QL_GNSS_EPH_DATA_QZSS = 0x10,
55}QL_GNSS_EPH_DATA_E;
56
57typedef enum
58{
59 GPS_ONLY = 0x01,
60 BDS_ONLY = 0x02,
61 GPS_BDS = 0x03,
62 GLONASS_ONLY = 0x04,
63 GPS_GLONASS = 0x05,
64 BDS_GLONASS = 0x06,
65 GPS_BDS_GLONASS = 0x07,
66 GPS_SBAS_QZSS = 0x08, /* GPS+SBAS+QZSS */
67 GPS_BDS_GALILEO_SBAS_QZSS = 0x11, /* GPS+BDS+GAL+SBAS+QZSS */
68 GPS_GLONASS_GALILEO_SBAS_QZSS = 0x101 /* Not currently supported */
69} QL_GNSS_CONSTELLATION_MASK_E;
70
71typedef enum
72{
73 QL_GNSS_NMEA_VERSION_V30, /* NMEA 3.0 */
74 QL_GNSS_NMEA_VERSION_V41 /* NMEA 4.1 */
75}QL_GNSS_NMEA_VERSION_ID_E;
76
77typedef enum
78{
79 QL_GNSS_MSG_MIN = 0, /* GNSS MIN MSG */
80 QL_GNSS_NMEA_MSG, /* GNSS NMEA DATA */
81 QL_GNSS_STATUS_MSG, /* GNSS NMEA DATA */
82 QL_GNSS_MSG_MAX /* GNSS MAX MSG */
83}QL_GNSS_IND_MSG_ID_E;
84
85/**
86 * gnss state definition
87 */
88typedef enum
89{
90 QL_GNSS_STATUS_UNDEFINE = 0u, /* Undefined state */
91 QL_GNSS_STATUS_FOTA_START, /* Fota init state */
92 QL_GNSS_STATUS_FOTA_REQ, /* Fota state req */
93 QL_GNSS_STATUS_FOTA_ING, /* Fota progressing */
94 QL_GNSS_STATUS_FOTA_BOOT, /* Fota bootloader */
95 QL_GNSS_STATUS_FOTA_FIRM, /* Fota firmware */
96 QL_GNSS_STATUS_FOTA_END, /* Fota end */
97 QL_GNSS_STATUS_WORKING, /* GNSS working */
98 QL_GNSS_STATUS_MAX, /* Max state */
99}QL_GNSS_STATUS_E;
100
101
102typedef struct
103{
104 char *ptr;
105 size_t len;
106} curl_rsp_msg_t;
107
108typedef struct
109{
110 uint8_t msg_id;
111 uint32_t time;
112 char nmea_sentence[128];
113} nmea_srv_ind_msg;
114
115typedef struct
116{
117 uint8_t msg_id;
118 QL_GNSS_STATUS_E g_status;
119} gnss_status_ind_msg;
120
121typedef struct
122{
123 double latitude;
124 double longitude;
125 double altitude;
126} ql_inject_location_t;
127
128
129typedef struct
130{
131 uint8_t mask;
132 struct
133 {
134 uint8_t gga_nmea_len; /* GGA */
135 char gga_sent[128];
136 }gga_sentences;
137
138 struct
139 {
140 uint8_t rmc_nmea_len; /* RMC */
141 char rmc_sent[128];
142 }rmc_sentences;
143
144 uint8_t gpgsv_lines;
145 struct
146 {
147 uint8_t nmea_sentences_len; /* GPGSV */
148 char gsv_sent[128];
149 }gpgsv_sentences[4];
150
151 uint8_t bdgsv_lines;
152 struct
153 {
154 uint32_t gsv_lines;
155 uint8_t nmea_sentences_len; /* BD/GBGSV */
156 char gsv_sent[128];
157 }bdgsv_sentences[4];
158
159} nmeasrc_sentences;
160
161typedef void (*ql_gnss_ind_cb_f)(void *msg);
162
163typedef void (*ql_gnss_error_cb_f)(int error);
164
165
166/*-----------------------------------------------------------------------------------------------*/
167/**
168 @brief Initialize the gnss client
169 @return
170 QL_ERR_OK - successful
171 QL_ERR_INVALID_ARG - as defined
172 QL_ERR_SERVICE_NOT_READY - service is not ready, need to retry
173 Other - error code defined by ql_type.h
174 */
175/*-----------------------------------------------------------------------------------------------*/
176int ql_gnss_init(void);
177
178/*-----------------------------------------------------------------------------------------------*/
179/**
180 @brief Deinitialize the gnss client
181 @return
182 QL_ERR_OK - successful
183 Other - error code defined by ql_type.h
184 */
185/*-----------------------------------------------------------------------------------------------*/
186int ql_gnss_deinit(void);
187
188/*-----------------------------------------------------------------------------------------------*/
189/**
190 @brief Start gnss
191 @return
192 QL_ERR_OK - successful
193 QL_ERR_NOT_INIT - uninitialized
194 QL_ERR_SERVICE_NOT_READY - service is not ready
195 QL_ERR_INVALID_ARG - Invalid arguments
196 Other - error code defined by ql_type.h
197 */
198/*-----------------------------------------------------------------------------------------------*/
199int ql_gnss_start(void);
200
201/*-----------------------------------------------------------------------------------------------*/
202/**
203 @brief Stop gnss
204 @return
205 QL_ERR_OK - successful
206 QL_ERR_NOT_INIT - uninitialized
207 QL_ERR_SERVICE_NOT_READY - service is not ready
208 QL_ERR_INVALID_ARG - Invalid arguments
209 Other - error code defined by ql_type.h
210 */
211/*-----------------------------------------------------------------------------------------------*/
212int ql_gnss_stop(void);
213
214/*-----------------------------------------------------------------------------------------------*/
215/**
216 @brief Set gnss start mode
217 @param[in] mask Gnss start mode
218 @return
219 QL_ERR_OK - successful
220 QL_ERR_NOT_INIT - uninitialized
221 QL_ERR_SERVICE_NOT_READY - service is not ready
222 QL_ERR_INVALID_ARG - Invalid arguments
223 Other - error code defined by ql_type.h
224 */
225/*-----------------------------------------------------------------------------------------------*/
226int ql_gnss_set_start_mode(QL_GNSS_START_MODE_E mask);
227
228/*-----------------------------------------------------------------------------------------------*/
229/**
230 @brief Get gnss nmea
231 @param[in] nmea_str
232 @return
233 QL_ERR_OK - successful
234 QL_ERR_NOT_INIT - uninitialized
235 QL_ERR_SERVICE_NOT_READY - service is not ready
236 QL_ERR_INVALID_ARG - Invalid arguments
237 Other - error code defined by ql_type.h
238 */
239/*-----------------------------------------------------------------------------------------------*/
240int ql_gnss_qgpsgnmea(nmeasrc_sentences *nmea_str);
241
242/*-----------------------------------------------------------------------------------------------*/
243/**
244 @brief Set gnss qgpscfg
245 @param[in] enable
246 @param[in] str
247 @param[in] len
248 @return
249 QL_ERR_OK - successful
250 QL_ERR_NOT_INIT - uninitialized
251 QL_ERR_SERVICE_NOT_READY - service is not ready
252 QL_ERR_INVALID_ARG - Invalid arguments
253 Other - error code defined by ql_type.h
254 */
255/*-----------------------------------------------------------------------------------------------*/
256int ql_gnss_set_qgpscfg(uint32_t enable, char *str, uint32_t len);
257
258/*-----------------------------------------------------------------------------------------------*/
259/**
260 @brief Get engine state
261 @param[out] state on/ff
262 @return
263 QL_ERR_OK - successful
264 QL_ERR_NOT_INIT - uninitialized
265 QL_ERR_SERVICE_NOT_READY - service is not ready
266 QL_ERR_INVALID_ARG - Invalid arguments
267 Other - error code defined by ql_type.h
268 */
269/*-----------------------------------------------------------------------------------------------*/
270int ql_gnss_get_engine_state(QL_GNSS_ENGINE_STATE_E *state);
271
272/*-----------------------------------------------------------------------------------------------*/
273/**
274 @brief Set Constellation .
275 @param[in] mask GPS/GLO/BDS/GAL/QZSS/SBAS
276 @return
277 QL_ERR_OK - successful
278 QL_ERR_NOT_INIT - uninitialized
279 QL_ERR_SERVICE_NOT_READY - service is not ready
280 QL_ERR_INVALID_ARG - Invalid arguments
281 Other - error code defined by ql_type.h
282 */
283/*-----------------------------------------------------------------------------------------------*/
284int ql_gnss_set_constellation(QL_GNSS_CONSTELLATION_MASK_E mask);
285
286/*-----------------------------------------------------------------------------------------------*/
287/**
288 @brief Get Constellation
289 @param[out] mask GPS/GLO/BDS/GAL/QZSS/SBAS
290 @return
291 QL_ERR_OK - successful
292 QL_ERR_NOT_INIT - uninitialized
293 QL_ERR_SERVICE_NOT_READY - service is not ready
294 QL_ERR_INVALID_ARG - Invalid arguments
295 Other - error code defined by ql_type.h
296 */
297/*-----------------------------------------------------------------------------------------------*/
298int ql_gnss_get_constellation(QL_GNSS_CONSTELLATION_MASK_E *mask);
299
300/*-----------------------------------------------------------------------------------------------*/
301/**
302 @brief Set nmea type
303 @param[in] mask type
304 @return
305 QL_ERR_OK - successful
306 QL_ERR_NOT_INIT - uninitialized
307 QL_ERR_SERVICE_NOT_READY - service is not ready
308 QL_ERR_INVALID_ARG - Invalid arguments
309 Other - error code defined by ql_type.h
310 */
311/*-----------------------------------------------------------------------------------------------*/
312int ql_gnss_set_nmea_type(uint32_t mask);
313
314/*-----------------------------------------------------------------------------------------------*/
315/**
316 @brief Get nmea version
317 @param[out] version nmea version
318 @return
319 QL_ERR_OK - successful
320 QL_ERR_NOT_INIT - uninitialized
321 QL_ERR_SERVICE_NOT_READY - service is not ready
322 QL_ERR_INVALID_ARG - Invalid arguments
323 Other - error code defined by ql_type.h
324 */
325/*-----------------------------------------------------------------------------------------------*/
326int ql_gnss_get_nmea_version(QL_GNSS_NMEA_VERSION_ID_E *version);
327
328/*-----------------------------------------------------------------------------------------------*/
329/**
330 @brief Set nmea version
331 @param[in] version nmea version
332 @return
333 QL_ERR_OK - successful
334 QL_ERR_NOT_INIT - uninitialized
335 QL_ERR_SERVICE_NOT_READY - service is not ready
336 QL_ERR_INVALID_ARG - Invalid arguments
337 Other - error code defined by ql_type.h
338 */
339/*-----------------------------------------------------------------------------------------------*/
340int ql_gnss_set_nmea_version(QL_GNSS_NMEA_VERSION_ID_E version);
341
342/*-----------------------------------------------------------------------------------------------*/
343/**
344 @brief Set gnss agnss mode
345 @param[in] mask Gnss agnss mode
346 @return
347 QL_ERR_OK - successful
348 QL_ERR_NOT_INIT - uninitialized
349 QL_ERR_SERVICE_NOT_READY - service is not ready
350 QL_ERR_INVALID_ARG - Invalid arguments
351 Other - error code defined by ql_type.h
352 */
353/*-----------------------------------------------------------------------------------------------*/
354int ql_gnss_set_agnss_mode(uint32_t mask);
355
356/*-----------------------------------------------------------------------------------------------*/
357/**
358 @brief Inject agnss data
359 @param[in] data agnss data
360 @return
361 QL_ERR_OK - successful
362 QL_ERR_NOT_INIT - uninitialized
363 QL_ERR_SERVICE_NOT_READY - service is not ready
364 QL_ERR_INVALID_ARG - Invalid arguments
365 Other - error code defined by ql_type.h
366 */
367/*-----------------------------------------------------------------------------------------------*/
368int ql_gnss_inject_agnss_data(void);
369
370/*-----------------------------------------------------------------------------------------------*/
371/**
372 @brief Inject UTC time to GNSS Engine.
373 @param[in] timestamp ,unit: ms
374 @return Whether to successfully Start Gnss
375 @retval QL_ERR_OK successful
376 @retval QL_ERR_FAILED Start Gnss Failed
377 @retval Other error code defined by ql_gnss.h
378 */
379/*-----------------------------------------------------------------------------------------------*/
380int ql_gnss_inject_utc_time(uint64_t timestamp);
381
382/*-----------------------------------------------------------------------------------------------*/
383/**
384 @brief Set gnss suspend
385 @return
386 QL_ERR_OK - successful
387 QL_ERR_NOT_INIT - uninitialized
388 QL_ERR_SERVICE_NOT_READY - service is not ready
389 QL_ERR_INVALID_ARG - Invalid arguments
390 Other - error code defined by ql_type.h
391 */
392/*-----------------------------------------------------------------------------------------------*/
393int ql_gnss_suspend(void);
394
395/*-----------------------------------------------------------------------------------------------*/
396/**
397 @brief Set gnss resume
398 @return
399 QL_ERR_OK - successful
400 QL_ERR_NOT_INIT - uninitialized
401 QL_ERR_SERVICE_NOT_READY - service is not ready
402 QL_ERR_INVALID_ARG - Invalid arguments
403 Other - error code defined by ql_type.h
404 */
405/*-----------------------------------------------------------------------------------------------*/
406int ql_gnss_resume(void);
407
408/*-----------------------------------------------------------------------------------------------*/
409/**
410 @brief Register gnss callback
411 @param[in] cb
412 @return
413 QL_ERR_OK - successful
414 QL_ERR_NOT_INIT - uninitialized
415 QL_ERR_SERVICE_NOT_READY - service is not ready
416 QL_ERR_INVALID_ARG - Invalid arguments
417 Other - error code defined by ql_type.h
418 */
419/*-----------------------------------------------------------------------------------------------*/
420int ql_gnss_set_ind_cb(ql_gnss_ind_cb_f cb);
421
422/*-----------------------------------------------------------------------------------------------*/
423/**
424 @brief Registration server error callback. Currently, only if the server exits abnormally,
425 the callback function will be executed, and the error code is QL_ERR_ABORTED;
426 @param[in] cb Callback function
427 @return
428 QL_ERR_OK - successful
429 Other - error code defined by ql_type.h
430 */
431/*-----------------------------------------------------------------------------------------------*/
432int ql_gnss_set_service_error_cb(ql_gnss_error_cb_f cb);
433
434#ifdef __cplusplus
435}
436#endif
437
438#endif
439