gsmgnss2 2.0.0.0
gsmgnss2.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 GSMGNSS2_H
29#define GSMGNSS2_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 GSMGNSS2_CMD_AT "AT"
74#define GSMGNSS2_CMD_ATI "ATI"
75#define GSMGNSS2_CMD_CGMR "AT+CGMR"
76#define GSMGNSS2_CMD_CFUN "AT+CFUN"
77#define GSMGNSS2_CMD_CREG "AT+CREG"
78#define GSMGNSS2_CMD_CGREG "AT+CGREG"
79#define GSMGNSS2_CMD_CGDCONT "AT+CGDCONT"
80#define GSMGNSS2_CMD_CIMI "AT+CIMI"
81#define GSMGNSS2_CMD_CMEE "AT+CMEE"
82#define GSMGNSS2_CMD_CGATT "AT+CGATT"
83#define GSMGNSS2_CMD_CSQ "AT+CSQ"
84#define GSMGNSS2_CMD_COPS "AT+COPS"
85#define GSMGNSS2_CMD_CMGS "AT+CMGS"
86#define GSMGNSS2_CMD_CMGF "AT+CMGF"
87#define GSMGNSS2_CMD_CGNSPWR "AT+CGNSPWR"
88#define GSMGNSS2_CMD_CGNSTST "AT+CGNSTST"
89
94#define GSMGNSS2_RSP_START "$"
95#define GSMGNSS2_RSP_DELIMITER ","
96#define GSMGNSS2_RSP_GNGGA "$GNGGA"
97
102#define GSMGNSS2_GNGGA_ELEMENT_SIZE 15
103#define GSMGNSS2_GNGGA_TIME 1
104#define GSMGNSS2_GNGGA_LATITUDE 2
105#define GSMGNSS2_GNGGA_LATITUDE_SIDE 3
106#define GSMGNSS2_GNGGA_LONGITUDE 4
107#define GSMGNSS2_GNGGA_LONGITUDE_SIDE 5
108#define GSMGNSS2_GNGGA_QUALITY_INDICATOR 6
109#define GSMGNSS2_GNGGA_NUMBER_OF_SATELLITES 7
110#define GSMGNSS2_GNGGA_H_DILUTION_OF_POS 8
111#define GSMGNSS2_GNGGA_ALTITUDE 9
112#define GSMGNSS2_GNGGA_ALTITUDE_UNIT 10
113#define GSMGNSS2_GNGGA_GEOIDAL_SEPARATION 11
114#define GSMGNSS2_GNGGA_GEOIDAL_SEPARATION_UNIT 12
115#define GSMGNSS2_GNGGA_TIME_SINCE_LAST_DGPS 13
116#define GSMGNSS2_GNGGA_DGPS_REFERENCE_STATION_ID 14
117
122#define GSMGNSS2_MODULE_POWER_ON 1
123#define GSMGNSS2_MODULE_POWER_OFF 0
124
130#define DRV_BUFFER_SIZE_RX 256
131#define DRV_BUFFER_SIZE_TX 256
132
133 // gsmgnss2_cmd
134
149#define GSMGNSS2_MAP_MIKROBUS( cfg, mikrobus ) \
150 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
151 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
152 cfg.det = MIKROBUS( mikrobus, MIKROBUS_AN ); \
153 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
154 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
155 cfg.ring = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
156 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT )
157
158 // gsmgnss2_map
159 // gsmgnss2
160
165typedef struct
166{
167 // Output pins
168
169 digital_out_t rst;
170 digital_out_t rts;
171
172 // Input pins
173
174 digital_in_t det;
175 digital_in_t ring;
176 digital_in_t cts;
177
178 // Modules
179 uart_t uart;
181 // Buffers
182 char uart_rx_buffer[ DRV_BUFFER_SIZE_RX ];
183 char uart_tx_buffer[ DRV_BUFFER_SIZE_TX ];
185} gsmgnss2_t;
186
191typedef struct
192{
193 // Communication gpio pins
194 pin_name_t rx_pin;
195 pin_name_t tx_pin;
197 // Additional gpio pins
198
199 pin_name_t det;
200 pin_name_t rst;
201 pin_name_t rts;
202 pin_name_t ring;
203 pin_name_t cts;
204
205 // Static variable
206 uint32_t baud_rate;
208 uart_data_bits_t data_bit;
209 uart_parity_t parity_bit;
210 uart_stop_bits_t stop_bit;
213
218typedef enum
219{
221 GSMGNSS2_ERROR = -1
222
224
241
256
262void gsmgnss2_module_power ( gsmgnss2_t *ctx, uint8_t state );
263
276err_t gsmgnss2_generic_write ( gsmgnss2_t *ctx, char *data_buf, uint16_t len );
277
290err_t gsmgnss2_generic_read ( gsmgnss2_t *ctx, char *data_buf, uint16_t max_len );
291
300void gsmgnss2_send_cmd ( gsmgnss2_t *ctx, char *cmd );
301
311void gsmgnss2_send_cmd_with_parameter ( gsmgnss2_t *ctx, char *at_cmd_buf, char *param_buf );
312
321void gsmgnss2_send_cmd_check ( gsmgnss2_t *ctx, char *at_cmd_buf );
322
331void gsmgnss2_send_cmd_parameter_check ( gsmgnss2_t *ctx, char *at_cmd_buf );
332
341void gsmgnss2_set_sim_apn ( gsmgnss2_t *ctx, char *sim_apn );
342
352void gsmgnss2_send_sms_text ( gsmgnss2_t *ctx, char *phone_number, char *sms_text );
353
366err_t gsmgnss2_send_sms_pdu ( gsmgnss2_t *ctx, char *service_center_number,
367 char *phone_number, char *sms_text );
368
380err_t gsmgnss2_parse_gngga ( char *rsp_buf, uint8_t gngga_element, char *element_data );
381
382#ifdef __cplusplus
383}
384#endif
385#endif // GSMGNSS2_H
386
387 // gsmgnss2
388
389// ------------------------------------------------------------------------ END
#define DRV_BUFFER_SIZE_TX
Definition gsmgnss2.h:131
#define DRV_BUFFER_SIZE_RX
GSM/GNSS 2 driver buffer size.
Definition gsmgnss2.h:130
void gsmgnss2_send_cmd(gsmgnss2_t *ctx, char *cmd)
Send command function.
void gsmgnss2_send_cmd_parameter_check(gsmgnss2_t *ctx, char *at_cmd_buf)
Check the command parameters.
void gsmgnss2_set_sim_apn(gsmgnss2_t *ctx, char *sim_apn)
Set sim card APN.
void gsmgnss2_module_power(gsmgnss2_t *ctx, uint8_t state)
Power ON/OFF the module.
void gsmgnss2_send_cmd_with_parameter(gsmgnss2_t *ctx, char *at_cmd_buf, char *param_buf)
Send command function with parameter.
err_t gsmgnss2_parse_gngga(char *rsp_buf, uint8_t gngga_element, char *element_data)
GSM GNSS 2 parse GNGGA function.
void gsmgnss2_send_cmd_check(gsmgnss2_t *ctx, char *at_cmd_buf)
Check the sent command.
void gsmgnss2_cfg_setup(gsmgnss2_cfg_t *cfg)
GSM/GNSS 2 configuration object setup function.
err_t gsmgnss2_generic_write(gsmgnss2_t *ctx, char *data_buf, uint16_t len)
GSM/GNSS 2 data writing function.
err_t gsmgnss2_send_sms_pdu(gsmgnss2_t *ctx, char *service_center_number, char *phone_number, char *sms_text)
GSM GNSS 2 send SMS in PDU mode.
void gsmgnss2_send_sms_text(gsmgnss2_t *ctx, char *phone_number, char *sms_text)
GSM GNSS 2 send SMS in text mode.
err_t gsmgnss2_init(gsmgnss2_t *ctx, gsmgnss2_cfg_t *cfg)
GSM/GNSS 2 initialization function.
err_t gsmgnss2_generic_read(gsmgnss2_t *ctx, char *data_buf, uint16_t max_len)
GSM/GNSS 2 data reading function.
gsmgnss2_return_value_t
GSM/GNSS 2 Click return value data.
Definition gsmgnss2.h:219
@ GSMGNSS2_OK
Definition gsmgnss2.h:220
@ GSMGNSS2_ERROR
Definition gsmgnss2.h:221
GSM/GNSS 2 Click configuration object.
Definition gsmgnss2.h:192
pin_name_t rts
Definition gsmgnss2.h:201
pin_name_t det
Definition gsmgnss2.h:199
uint32_t baud_rate
Definition gsmgnss2.h:206
pin_name_t cts
Definition gsmgnss2.h:203
pin_name_t ring
Definition gsmgnss2.h:202
bool uart_blocking
Definition gsmgnss2.h:207
uart_data_bits_t data_bit
Definition gsmgnss2.h:208
pin_name_t tx_pin
Definition gsmgnss2.h:195
pin_name_t rx_pin
Definition gsmgnss2.h:194
uart_stop_bits_t stop_bit
Definition gsmgnss2.h:210
uart_parity_t parity_bit
Definition gsmgnss2.h:209
pin_name_t rst
Definition gsmgnss2.h:200
GSM/GNSS 2 Click context object.
Definition gsmgnss2.h:166
digital_out_t rts
Definition gsmgnss2.h:170
uart_t uart
Definition gsmgnss2.h:179
digital_in_t cts
Definition gsmgnss2.h:176
digital_out_t rst
Definition gsmgnss2.h:169
digital_in_t ring
Definition gsmgnss2.h:175
digital_in_t det
Definition gsmgnss2.h:174