b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 1 | /* |
| 2 | * gnss_info.h |
| 3 | * |
| 4 | * GNSS informations header. |
| 5 | * |
| 6 | * Author : lb |
| 7 | * Date : 2024/5/20 15:22:46 |
| 8 | */ |
| 9 | #ifndef _GNSS_INFO_H |
| 10 | #define _GNSS_INFO_H |
| 11 | #include "mbtk_type.h" |
| 12 | |
| 13 | #define GNSS_ID_6228 "6228" |
| 14 | #define GNSS_ID_5311 "5311" |
b.liu | f9fbfa1 | 2024-06-14 15:53:59 +0800 | [diff] [blame] | 15 | #define GNSS_ID_8122 "8122" |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 16 | |
| 17 | #define GNSS_PRINT_PORT_UART1 1 // 1 |
| 18 | #define GNSS_PRINT_PORT_USB_NMEA (1<<1) // 2 |
| 19 | #define GNSS_PRINT_PORT_USB_AT (1<<2) // 4 |
| 20 | #define GNSS_PRINT_PORT_TTY_AT (1<<3) // 8 |
| 21 | |
b.liu | d0ba715 | 2024-06-19 14:47:21 +0800 | [diff] [blame] | 22 | #define GNSS_SET_SYSCFG_GPS (1) |
| 23 | #define GNSS_SET_SYSCFG_BDS (1<<1) |
| 24 | #define GNSS_SET_SYSCFG_GLO (1<<2) |
| 25 | #define GNSS_SET_SYSCFG_GAL (1<<3) |
| 26 | |
| 27 | #define GNSS_SET_MSGCFG_RMC (1) |
| 28 | #define GNSS_SET_MSGCFG_VTG (1<<1) |
| 29 | #define GNSS_SET_MSGCFG_GGA (1<<2) |
| 30 | #define GNSS_SET_MSGCFG_GSA (1<<3) |
| 31 | #define GNSS_SET_MSGCFG_GSV (1<<4) |
| 32 | #define GNSS_SET_MSGCFG_GLL (1<<5) |
| 33 | #define GNSS_SET_MSGCFG_ZDA (1<<6) |
| 34 | #define GNSS_SET_MSGCFG_GST (1<<7) |
| 35 | #define GNSS_SET_MSGCFG_GRS (1<<8) |
| 36 | #define GNSS_SET_MSGCFG_TXT (1<<9) |
| 37 | #define GNSS_SET_MSGCFG_DHV (1<<10) |
| 38 | #define GNSS_SET_MSGCFG_DTM (1<<11) |
| 39 | #define GNSS_SET_MSGCFG_NAVPOS (1<<12) |
| 40 | #define GNSS_SET_MSGCFG_NAVVEL (1<<13) |
| 41 | #define GNSS_SET_MSGCFG_NAVTIME (1<<14) |
| 42 | #define GNSS_SET_MSGCFG_NAVACC (1<<15) |
| 43 | #define GNSS_SET_MSGCFG_LSF (1<<16) |
| 44 | #define GNSS_SET_MSGCFG_ANTSTAT (1<<17) |
| 45 | #define GNSS_SET_MSGCFG_ANTSTAT1 (1<<18) |
| 46 | #define GNSS_SET_MSGCFG_NOTICE (1<<19) |
| 47 | #define GNSS_SET_MSGCFG_ABNORMAL (1<<20) |
| 48 | #define GNSS_SET_MSGCFG_EPHABNORMAL (1<<21) |
| 49 | |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 50 | typedef enum { |
| 51 | GNSS_ERR_OK, |
| 52 | GNSS_ERR_UNSUPPORT, |
| 53 | GNSS_ERR_TIMEOUT, |
| 54 | GNSS_ERR_ARG, |
| 55 | GNSS_ERR_CHECKSUM, |
b.liu | 5f950c5 | 2024-06-15 20:13:12 +0800 | [diff] [blame] | 56 | GNSS_ERR_SET_BUSY, |
b.liu | dbc3f4b | 2024-06-25 18:22:24 +0800 | [diff] [blame^] | 57 | GNSS_ERR_DL_FW, |
| 58 | GNSS_ERR_OPEN_DEV, |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 59 | |
| 60 | GNSS_ERR_UNKNOWN |
| 61 | } gnss_err_enum; |
| 62 | |
b.liu | d0ba715 | 2024-06-19 14:47:21 +0800 | [diff] [blame] | 63 | typedef enum { |
| 64 | GNSS_RESET_TYPE_HOT = 1, |
| 65 | GNSS_RESET_TYPE_WARM, |
| 66 | GNSS_RESET_TYPE_COLD |
| 67 | } gnss_reset_type_enum; |
| 68 | |
| 69 | typedef enum { |
| 70 | GNSS_MEMAVER_TYPE_3_0 = 0, |
| 71 | GNSS_MEMAVER_TYPE_4_0, |
| 72 | GNSS_MEMAVER_TYPE_4_1 |
| 73 | } gnss_memaver_type_enum; |
| 74 | |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 75 | typedef int (*gnss_dev_open_func)(); |
| 76 | typedef int (*gnss_dev_close_func)(); |
| 77 | typedef int (*gnss_open_func)(const char *dev); |
| 78 | typedef int (*gnss_close_func)(int fd); |
b.liu | dbc3f4b | 2024-06-25 18:22:24 +0800 | [diff] [blame^] | 79 | typedef int (*gnss_fw_dl_func)(int fd, const char *fw_name, const char *dev); |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 80 | typedef void (*gnss_dl_read_cb_func)(const void *data, int data_len); |
| 81 | typedef gnss_err_enum (*gnss_set_func)(int fd, const char *cmd, void *cmd_rsp, int cmd_rsp_len); |
| 82 | typedef void (*gnss_set_cb_func)(const void *data, int data_len); |
| 83 | |
| 84 | typedef enum { |
| 85 | GNSS_TYPE_6228 = 0, |
| 86 | GNSS_TYPE_5311, |
b.liu | f9fbfa1 | 2024-06-14 15:53:59 +0800 | [diff] [blame] | 87 | GNSS_TYPE_8122 |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 88 | } gnss_id_enum; |
| 89 | |
| 90 | typedef enum { |
| 91 | GNSS_STATE_CLOSE, // GNSS is closed. |
| 92 | GNSS_STATE_CLOSING, // GNSS is closing. |
| 93 | GNSS_STATE_OPEN, // GNSS is opened. |
| 94 | GNSS_STATE_DOWNLOAD, // GNSS is downloading. |
| 95 | GNSS_STATE_READY, // GNSS is ready. |
| 96 | } gnss_state_enum; |
| 97 | |
wangyouqiang | 9ee6eaa | 2024-06-17 13:43:45 +0800 | [diff] [blame] | 98 | typedef enum { |
| 99 | GNSS_RESULT_STATE_OPEN_SUCCESS, |
| 100 | GNSS_RESULT_STATE_OPEN_FAIL, |
| 101 | GNSS_RESULT_STATE_CLOSE_SUCCESS, |
| 102 | GNSS_RESULT_STATE_CLOSE_FAIL, |
| 103 | GNSS_RESULT_STATE_SET_SUCCESS, |
| 104 | GNSS_RESULT_STATE_SET_FAIL, |
| 105 | GNSS_RESULT_STATE_UNSUPPORT, |
| 106 | GNSS_RESULT_STATE_UNKNOWN_ERROR, |
| 107 | } gnss_result_enum; |
| 108 | |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 109 | typedef struct { |
| 110 | gnss_id_enum gnss_id; |
| 111 | char dev_name[32]; |
| 112 | bool auto_open; // Should auto open gnss? |
| 113 | bool auto_dl_fw; // Should download firmware int the first? |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 114 | bool dl_befor_open; // Should download firmware before open device? |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 115 | int fd; // GNSS uart fd. |
| 116 | int exit_fd[2]; // Use to exit thread. |
| 117 | gnss_state_enum state; |
| 118 | uint32 print_port; |
| 119 | pthread_t read_pid; // Read NMEA thread. |
| 120 | |
| 121 | // GNSS functions. |
| 122 | gnss_dev_open_func gnss_dev_open; |
| 123 | gnss_dev_close_func gnss_dev_close; |
| 124 | gnss_open_func gnss_open; |
| 125 | gnss_close_func gnss_close; |
| 126 | gnss_fw_dl_func gnss_fw_dl; |
| 127 | gnss_dl_read_cb_func gnss_dl_read_cb; |
| 128 | gnss_set_func gnss_set; |
| 129 | gnss_set_cb_func gnss_set_cb; |
| 130 | } gnss_info_t; |
| 131 | |
b.liu | 5f950c5 | 2024-06-15 20:13:12 +0800 | [diff] [blame] | 132 | int gnss_init(uint32 print_port); |
| 133 | |
| 134 | int gnss_deinit(); |
| 135 | |
| 136 | int gnss_set(const void* buf, unsigned int buf_len, void *cmd_rsp, int cmd_rsp_len); |
| 137 | |
b.liu | dbc3f4b | 2024-06-25 18:22:24 +0800 | [diff] [blame^] | 138 | int gnss_dl_fw(const char* fw_name, void *rsp, int rsp_len); |
| 139 | |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 140 | #endif /* _GNSS_INFO_H */ |