c4gltegnss 2.1.0.0
c4gltegnss.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef C4GLTEGNSS_H
29#define C4GLTEGNSS_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_uart.h"
52
73#define C4GLTEGNSS_CMD_AT "AT"
74#define C4GLTEGNSS_CMD_ATI "ATI"
75#define C4GLTEGNSS_CMD_CGMR "AT+CGMR"
76#define C4GLTEGNSS_CMD_CFUN "AT+CFUN"
77#define C4GLTEGNSS_CMD_CREG "AT+CREG"
78#define C4GLTEGNSS_CMD_CGREG "AT+CGREG"
79#define C4GLTEGNSS_CMD_CGDCONT "AT+CGDCONT"
80#define C4GLTEGNSS_CMD_CIMI "AT+CIMI"
81#define C4GLTEGNSS_CMD_CMEE "AT+CMEE"
82#define C4GLTEGNSS_CMD_CGATT "AT+CGATT"
83#define C4GLTEGNSS_CMD_CSQ "AT+CSQ"
84#define C4GLTEGNSS_CMD_COPS "AT+COPS"
85#define C4GLTEGNSS_CMD_CMGS "AT+CMGS"
86#define C4GLTEGNSS_CMD_CMGF "AT+CMGF"
87#define C4GLTEGNSS_CMD_CGACT "AT+CGACT"
88#define C4GLTEGNSS_CMD_UPSDA "AT+UPSDA"
89#define C4GLTEGNSS_CMD_USOCR "AT+USOCR"
90#define C4GLTEGNSS_CMD_USOCO "AT+USOCO"
91#define C4GLTEGNSS_CMD_USOWR "AT+USOWR"
92#define C4GLTEGNSS_CMD_USORD "AT+USORD"
93#define C4GLTEGNSS_CMD_USORF "AT+USORF"
94#define C4GLTEGNSS_CMD_USOCL "AT+USOCL"
95#define C4GLTEGNSS_CMD_UGPS "AT+UGPS"
96#define C4GLTEGNSS_CMD_UGGGA "AT+UGGGA"
97
102#define C4GLTEGNSS_RSP_OK "OK"
103#define C4GLTEGNSS_RSP_ERROR "ERROR"
104
109#define C4GLTEGNSS_POWER_STATE_OFF 0
110#define C4GLTEGNSS_POWER_STATE_ON 1
111
116#define C4GLTEGNSS_RSP_START "$"
117#define C4GLTEGNSS_RSP_DELIMITER ","
118#define C4GLTEGNSS_RSP_END "\r\n"
119#define C4GLTEGNSS_RSP_GGA "GGA"
120
125#define C4GLTEGNSS_GGA_ELEMENT_SIZE 15
126#define C4GLTEGNSS_GGA_TIME 1
127#define C4GLTEGNSS_GGA_LATITUDE 2
128#define C4GLTEGNSS_GGA_LATITUDE_SIDE 3
129#define C4GLTEGNSS_GGA_LONGITUDE 4
130#define C4GLTEGNSS_GGA_LONGITUDE_SIDE 5
131#define C4GLTEGNSS_GGA_QUALITY_INDICATOR 6
132#define C4GLTEGNSS_GGA_NUMBER_OF_SATELLITES 7
133#define C4GLTEGNSS_GGA_H_DILUTION_OF_POS 8
134#define C4GLTEGNSS_GGA_ALTITUDE 9
135#define C4GLTEGNSS_GGA_ALTITUDE_UNIT 10
136#define C4GLTEGNSS_GGA_GEOIDAL_SEPARATION 11
137#define C4GLTEGNSS_GGA_GEOIDAL_SEPARATION_UNIT 12
138#define C4GLTEGNSS_GGA_TIME_SINCE_LAST_DGPS 13
139#define C4GLTEGNSS_GGA_DGPS_REFERENCE_STATION_ID 14
140
146#define C4GLTEGNSS_TX_DRV_BUFFER_SIZE 256
147#define C4GLTEGNSS_RX_DRV_BUFFER_SIZE 256
148
149 // c4gltegnss_cmd
150
165#define C4GLTEGNSS_MAP_MIKROBUS( cfg, mikrobus ) \
166 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
167 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
168 cfg.pwr = MIKROBUS( mikrobus, MIKROBUS_AN ); \
169 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
170 cfg.ri = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
171 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT );
172
173 // c4gltegnss_map
174 // c4gltegnss
175
180typedef struct
181{
182 // Output pins
183 digital_out_t pwr;
184 digital_out_t rts;
186 // Input pins
187 digital_in_t ri;
188 digital_in_t cts;
190 // Modules
191 uart_t uart;
193 // Buffers
194 uint8_t uart_rx_buffer[ C4GLTEGNSS_RX_DRV_BUFFER_SIZE ];
195 uint8_t uart_tx_buffer[ C4GLTEGNSS_TX_DRV_BUFFER_SIZE ];
198
203typedef struct
204{
205 // Communication gpio pins
206 pin_name_t rx_pin;
207 pin_name_t tx_pin;
209 // Additional gpio pins
210 pin_name_t pwr;
211 pin_name_t rts;
212 pin_name_t ri;
213 pin_name_t cts;
215 // Static variable
216 uint32_t baud_rate;
218 uart_data_bits_t data_bit;
219 uart_parity_t parity_bit;
220 uart_stop_bits_t stop_bit;
223
237
254
269
282err_t c4gltegnss_generic_write ( c4gltegnss_t *ctx, uint8_t *data_in, uint16_t len );
283
296err_t c4gltegnss_generic_read ( c4gltegnss_t *ctx, uint8_t *data_out, uint16_t len );
297
307void c4gltegnss_set_pwr_pin ( c4gltegnss_t *ctx, uint8_t state );
308
318void c4gltegnss_set_rts_pin ( c4gltegnss_t *ctx, uint8_t state );
319
329
339
350void c4gltegnss_set_power_state ( c4gltegnss_t *ctx, uint8_t state );
351
361void c4gltegnss_send_cmd ( c4gltegnss_t *ctx, uint8_t *cmd );
362
373void c4gltegnss_send_cmd_with_par ( c4gltegnss_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf );
374
384void c4gltegnss_send_cmd_check ( c4gltegnss_t *ctx, uint8_t *at_cmd_buf );
385
395void c4gltegnss_send_cmd_par_check ( c4gltegnss_t *ctx, uint8_t *at_cmd_buf );
396
406void c4gltegnss_set_sim_apn ( c4gltegnss_t *ctx, uint8_t *sim_apn );
407
418void c4gltegnss_send_sms_text ( c4gltegnss_t *ctx, uint8_t *phone_number, uint8_t *sms_text );
419
433err_t c4gltegnss_send_sms_pdu ( c4gltegnss_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text );
434
446err_t c4gltegnss_parse_gga ( uint8_t *rsp_buf, uint8_t gga_element, uint8_t *element_data );
447
448#ifdef __cplusplus
449}
450#endif
451#endif // C4GLTEGNSS_H
452
453 // c4gltegnss
454
455// ------------------------------------------------------------------------ END
c4gltegnss_return_value_t
4G LTE GNSS Click return value data.
Definition c4gltegnss.h:229
@ C4GLTEGNSS_ERROR_CMD
Definition c4gltegnss.h:233
@ C4GLTEGNSS_ERROR_TIMEOUT
Definition c4gltegnss.h:232
@ C4GLTEGNSS_ERROR
Definition c4gltegnss.h:231
@ C4GLTEGNSS_ERROR_UNKNOWN
Definition c4gltegnss.h:234
@ C4GLTEGNSS_OK
Definition c4gltegnss.h:230
#define C4GLTEGNSS_TX_DRV_BUFFER_SIZE
4G LTE GNSS driver buffer size.
Definition c4gltegnss.h:146
#define C4GLTEGNSS_RX_DRV_BUFFER_SIZE
Definition c4gltegnss.h:147
err_t c4gltegnss_parse_gga(uint8_t *rsp_buf, uint8_t gga_element, uint8_t *element_data)
4G LTE GNSS parse GGA function.
void c4gltegnss_set_power_state(c4gltegnss_t *ctx, uint8_t state)
4G LTE GNSS set power state function.
void c4gltegnss_send_cmd_with_par(c4gltegnss_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf)
Send command function with parameter.
void c4gltegnss_set_pwr_pin(c4gltegnss_t *ctx, uint8_t state)
4G LTE GNSS set PWR pin function.
err_t c4gltegnss_send_sms_pdu(c4gltegnss_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text)
4G LTE GNSS send SMS in PDU mode.
err_t c4gltegnss_generic_read(c4gltegnss_t *ctx, uint8_t *data_out, uint16_t len)
4G LTE GNSS data reading function.
uint8_t c4gltegnss_get_cts_pin(c4gltegnss_t *ctx)
4G LTE GNSS get cts pin function.
void c4gltegnss_send_cmd(c4gltegnss_t *ctx, uint8_t *cmd)
Send command function.
void c4gltegnss_send_sms_text(c4gltegnss_t *ctx, uint8_t *phone_number, uint8_t *sms_text)
4G LTE GNSS send SMS in text mode.
void c4gltegnss_set_rts_pin(c4gltegnss_t *ctx, uint8_t state)
4G LTE GNSS set rts pin function.
void c4gltegnss_send_cmd_par_check(c4gltegnss_t *ctx, uint8_t *at_cmd_buf)
Check the command parameters.
void c4gltegnss_send_cmd_check(c4gltegnss_t *ctx, uint8_t *at_cmd_buf)
Check the sent command.
void c4gltegnss_set_sim_apn(c4gltegnss_t *ctx, uint8_t *sim_apn)
Set sim card APN.
err_t c4gltegnss_generic_write(c4gltegnss_t *ctx, uint8_t *data_in, uint16_t len)
4G LTE GNSS data writing function.
uint8_t c4gltegnss_get_ri_pin(c4gltegnss_t *ctx)
4G LTE GNSS get RI pin function.
void c4gltegnss_cfg_setup(c4gltegnss_cfg_t *cfg)
4G LTE GNSS configuration object setup function.
err_t c4gltegnss_init(c4gltegnss_t *ctx, c4gltegnss_cfg_t *cfg)
4G LTE GNSS initialization function.
4G LTE GNSS Click configuration object.
Definition c4gltegnss.h:204
pin_name_t rts
Definition c4gltegnss.h:211
uint32_t baud_rate
Definition c4gltegnss.h:216
pin_name_t cts
Definition c4gltegnss.h:213
bool uart_blocking
Definition c4gltegnss.h:217
pin_name_t ri
Definition c4gltegnss.h:212
uart_data_bits_t data_bit
Definition c4gltegnss.h:218
pin_name_t tx_pin
Definition c4gltegnss.h:207
pin_name_t pwr
Definition c4gltegnss.h:210
pin_name_t rx_pin
Definition c4gltegnss.h:206
uart_stop_bits_t stop_bit
Definition c4gltegnss.h:220
uart_parity_t parity_bit
Definition c4gltegnss.h:219
4G LTE GNSS Click context object.
Definition c4gltegnss.h:181
digital_out_t pwr
Definition c4gltegnss.h:183
digital_out_t rts
Definition c4gltegnss.h:184
digital_in_t ri
Definition c4gltegnss.h:187
uart_t uart
Definition c4gltegnss.h:191
digital_in_t cts
Definition c4gltegnss.h:188