gsmgnss 2.0.0.0
gsmgnss.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef GSMGNSS_H
36#define GSMGNSS_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_uart.h"
55
56
57// -------------------------------------------------------------- PUBLIC MACROS
67#define GSMGNSS_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
69 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
70 cfg.det = MIKROBUS( mikrobus, MIKROBUS_AN ); \
71 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
72 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
73 cfg.ring = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
74 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT )
81#define GSMGNSS_RETVAL uint8_t
88#define GSMGNSS_NMEA_GNGGA 1
89#define GSMGNSS_NMEA_GNGLL 3
90#define GSMGNSS_NMEA_GNGGA_NUM_ELEMENT 15
91#define GSMGNSS_NMEA_GNGLL_NUM_ELEMENT 5
98#define GSMGNSS_GNGGA_TIME 1
99#define GSMGNSS_GNGGA_LATITUDE 2
100#define GSMGNSS_GNGGA_LATITUDE_SIDE 3
101#define GSMGNSS_GNGGA_LONGITUDE 4
102#define GSMGNSS_GNGGA_LONGITUDE_SIDE 5
103#define GSMGNSS_GNGGA_QUALITY_INDICATOR 6
104#define GSMGNSS_GNGGA_NUMBER_OF_SATELLITES 7
105#define GSMGNSS_GNGGA_H_DILUTION_OF_POS 8
106#define GSMGNSS_GNGGA_ALTITUDE 9
107#define GSMGNSS_GNGGA_ALTITUDE_UNIT 10
108#define GSMGNSS_GNGGA_GEOIDAL_SEPARATION 11
109#define GSMGNSS_GNGGA_GEOIDAL_SEPARATION_UNIT 12
110#define GSMGNSS_GNGGA_TIME_SINCE_LAST_DGPS 13
111#define GSMGNSS_GNGGA_DGPS_REFERENCE_STATION_ID 14
118#define GSMGNSS_GNGLL_LATITUDE 1
119#define GSMGNSS_GNGLL_LATITUDE_SIDE 2
120#define GSMGNSS_GNGLL_LONGITUDE 3
121#define GSMGNSS_GNGLL_LONGITUDE_SIDE 4
128#define GSMGNSS_ERROR_COMMAND_OR_ELEMENT 0xFF
129#define GSMGNSS_ERROR_START_OR_END_COMMAND 0x8F
130#define GSMGNSS_ERROR_NEXT_ELEMENT 0x4F
131#define GSMGNSS_ERROR_CURRENT_ELEMENT 0x2F
132#define GSMGNSS_NO_ERROR 0x00
139#define GSMGNSS_MODULE_POWER_ON 1
140#define GSMGNSS_MODULE_POWER_OFF 0
147#define GSMGNSS_CMD_AT "AT"
148#define GSMGNSS_CMD_ATI "ATI"
149#define GSMGNSS_CMD_CGMR "AT+CGMR"
150
151#define GSMGNSS_CMD_CFUN "AT+CFUN"
152#define GSMGNSS_CMD_CREG "AT+CREG"
153#define GSMGNSS_CMD_CGREG "AT+CGREG"
154#define GSMGNSS_CMD_CGDCONT "AT+CGDCONT"
155#define GSMGNSS_CMD_CIMI "AT+CIMI"
156#define GSMGNSS_CMD_CMEE "AT+CMEE"
157#define GSMGNSS_CMD_CGATT "AT+CGATT"
158#define GSMGNSS_CMD_CSQ "AT+CSQ"
159#define GSMGNSS_CMD_COPS "AT+COPS"
160#define GSMGNSS_CMD_CMGS "AT+CMGS"
161#define GSMGNSS_CMD_CMGF "AT+CMGF"
162#define GSMGNSS_CMD_QGNSSC "AT+QGNSSC"
163#define GSMGNSS_CMD_QGNSSRD "AT+QGNSSRD"
170#define DRV_RX_BUFFER_SIZE 256
171#define DRV_TX_BUFFER_SIZE 256
174 // End group macro
175// --------------------------------------------------------------- PUBLIC TYPES
183typedef struct
184{
185 // Output pins
186
187 digital_out_t rst;
188 digital_out_t rts;
189
190 // Input pins
191
192 digital_in_t det;
193 digital_in_t ring;
194 digital_in_t cts;
195
196 // Modules
197
198 uart_t uart;
199
200 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
201 char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
202
203} gsmgnss_t;
204
208typedef struct
209{
210 // Communication gpio pins
211
212 pin_name_t rx_pin;
213 pin_name_t tx_pin;
214
215 // Additional gpio pins
216
217 pin_name_t det;
218 pin_name_t rst;
219 pin_name_t rts;
220 pin_name_t ring;
221 pin_name_t cts;
222
223 // static variable
224
225 uint32_t baud_rate; // Clock speed.
227 uart_data_bits_t data_bit; // Data bits.
228 uart_parity_t parity_bit; // Parity bit.
229 uart_stop_bits_t stop_bit; // Stop bits.
230
232
237typedef enum
238{
240 GSMGNSS_ERROR = -1
241
243
247typedef uint8_t gsmgnss_error_t;
248
249 // End types group
250// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
251
257#ifdef __cplusplus
258extern "C"{
259#endif
260
270
279
285void gsmgnss_module_power ( gsmgnss_t *ctx, uint8_t state );
286
293void gsmgnss_generic_write ( gsmgnss_t *ctx, char *data_buf, uint16_t len );
294
302int32_t gsmgnss_generic_read ( gsmgnss_t *ctx, char *data_buf, uint16_t max_len );
303
312void gsmgnss_set_rts ( gsmgnss_t *ctx, uint8_t state );
313
322uint8_t gsmgnss_get_cts ( gsmgnss_t *ctx );
323
333void gsmgnss_send_cmd ( gsmgnss_t *ctx, char *cmd );
334
345void gsmgnss_send_cmd_with_parameter ( gsmgnss_t *ctx, char *at_cmd_buf, char *param_buf );
346
356void gsmgnss_send_cmd_check ( gsmgnss_t *ctx, char *at_cmd_buf );
357
367void gsmgnss_send_cmd_parameter_check ( gsmgnss_t *ctx, char *at_cmd_buf );
368
378void gsmgnss_set_sim_apn ( gsmgnss_t *ctx, char *sim_apn );
379
390void gsmgnss_send_sms_text ( gsmgnss_t *ctx, char *phone_number, char *sms_text );
391
405err_t gsmgnss_send_sms_pdu ( gsmgnss_t *ctx, char *service_center_number,
406 char *phone_number, char *sms_text );
407
417(
418 char *rsp, uint8_t command,
419 uint8_t element, char *parser_buf
420);
421
422#ifdef __cplusplus
423}
424#endif
425#endif // _GSMGNSS_H_
426
427 // End public_function group
429
430// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition gsmgnss.h:170
#define DRV_TX_BUFFER_SIZE
Definition gsmgnss.h:171
#define GSMGNSS_RETVAL
Definition gsmgnss.h:81
void gsmgnss_send_sms_text(gsmgnss_t *ctx, char *phone_number, char *sms_text)
GSM GNSS send SMS in text mode.
void gsmgnss_set_rts(gsmgnss_t *ctx, uint8_t state)
Sets state of the RTS pin.
void gsmgnss_cfg_setup(gsmgnss_cfg_t *cfg)
Config Object Initialization function.
uint8_t gsmgnss_get_cts(gsmgnss_t *ctx)
CTS Pin Get function.
void gsmgnss_send_cmd(gsmgnss_t *ctx, char *cmd)
Send command function.
int32_t gsmgnss_generic_read(gsmgnss_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
gsmgnss_error_t gsmgnss_generic_parser(char *rsp, uint8_t command, uint8_t element, char *parser_buf)
Generic parser function.
void gsmgnss_send_cmd_parameter_check(gsmgnss_t *ctx, char *at_cmd_buf)
Check the command parameters.
void gsmgnss_module_power(gsmgnss_t *ctx, uint8_t state)
Power ON/OFF the module.
void gsmgnss_set_sim_apn(gsmgnss_t *ctx, char *sim_apn)
Set sim card APN.
void gsmgnss_send_cmd_check(gsmgnss_t *ctx, char *at_cmd_buf)
Check the sent command.
err_t gsmgnss_send_sms_pdu(gsmgnss_t *ctx, char *service_center_number, char *phone_number, char *sms_text)
GSM GNSS send SMS in PDU mode.
GSMGNSS_RETVAL gsmgnss_init(gsmgnss_t *ctx, gsmgnss_cfg_t *cfg)
Initialization function.
void gsmgnss_generic_write(gsmgnss_t *ctx, char *data_buf, uint16_t len)
Generic write function.
void gsmgnss_send_cmd_with_parameter(gsmgnss_t *ctx, char *at_cmd_buf, char *param_buf)
Send command function with parameter.
GSMGNSS_return_value_t
GSM GNSS Click return value data.
Definition gsmgnss.h:238
uint8_t gsmgnss_error_t
Error type.
Definition gsmgnss.h:247
@ GSMGNSS_OK
Definition gsmgnss.h:239
@ GSMGNSS_ERROR
Definition gsmgnss.h:240
Click configuration structure definition.
Definition gsmgnss.h:209
pin_name_t rts
Definition gsmgnss.h:219
pin_name_t det
Definition gsmgnss.h:217
uint32_t baud_rate
Definition gsmgnss.h:225
pin_name_t cts
Definition gsmgnss.h:221
pin_name_t ring
Definition gsmgnss.h:220
bool uart_blocking
Definition gsmgnss.h:226
uart_data_bits_t data_bit
Definition gsmgnss.h:227
pin_name_t tx_pin
Definition gsmgnss.h:213
pin_name_t rx_pin
Definition gsmgnss.h:212
uart_stop_bits_t stop_bit
Definition gsmgnss.h:229
uart_parity_t parity_bit
Definition gsmgnss.h:228
pin_name_t rst
Definition gsmgnss.h:218
Click ctx object definition.
Definition gsmgnss.h:184
digital_out_t rts
Definition gsmgnss.h:188
uart_t uart
Definition gsmgnss.h:198
digital_in_t cts
Definition gsmgnss.h:194
digital_out_t rst
Definition gsmgnss.h:187
digital_in_t ring
Definition gsmgnss.h:193
digital_in_t det
Definition gsmgnss.h:192