gsm2 2.0.0.0
gsm2.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 GSM2_H
29#define GSM2_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 GSM2_CMD_AT "AT"
74#define GSM2_CMD_ATI "ATI"
75#define GSM2_CMD_CFUN "AT+CFUN"
76#define GSM2_CMD_CREG "AT+CREG"
77#define GSM2_CMD_CGDCONT "AT+CGDCONT"
78#define GSM2_CMD_CSQ "AT+CSQ"
79#define GSM2_CMD_COPS "AT+COPS"
80#define GSM2_CMD_CMGS "AT+CMGS"
81#define GSM2_CMD_CMGF "AT+CMGF"
82#define GSM2_CMD_CGACT "AT+CGACT"
83#define GSM2_CMD_QIMUX "AT+QIMUX"
84#define GSM2_CMD_QIOPEN "AT+QIOPEN"
85#define GSM2_CMD_QICLOSE "AT+QICLOSE"
86#define GSM2_CMD_QISEND "AT+QISEND"
87#define GSM2_CMD_QIRD "AT+QIRD"
88
93#define GSM2_RSP_OK "OK"
94#define GSM2_RSP_ERROR "ERROR"
95
101#define GSM2_RX_DRV_BUFFER_SIZE 256
102#define GSM2_TX_DRV_BUFFER_SIZE 256
103
104 // gsm2_set
105
120#define GSM2_MAP_MIKROBUS( cfg, mikrobus ) \
121 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
122 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
123 cfg.sta = MIKROBUS( mikrobus, MIKROBUS_AN ); \
124 cfg.pwk = MIKROBUS( mikrobus, MIKROBUS_RST ); \
125 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
126 cfg.ring = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
127 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT )
128
129 // gsm2_map
130 // gsm2
131
136typedef struct
137{
138 // Output pins
139 digital_out_t pwk;
140 digital_out_t rts;
142 // Input pins
143 digital_in_t sta;
144 digital_in_t ring;
145 digital_in_t cts;
147 // Modules
148 uart_t uart;
150 // Buffers
151 uint8_t uart_rx_buffer[ GSM2_RX_DRV_BUFFER_SIZE ];
152 uint8_t uart_tx_buffer[ GSM2_TX_DRV_BUFFER_SIZE ];
154} gsm2_t;
155
160typedef struct
161{
162 // Communication gpio pins
163 pin_name_t rx_pin;
164 pin_name_t tx_pin;
166 // Additional gpio pins
167 pin_name_t sta;
168 pin_name_t pwk;
169 pin_name_t rts;
170 pin_name_t ring;
171 pin_name_t cts;
173 // Static variable
174 uint32_t baud_rate;
176 uart_data_bits_t data_bit;
177 uart_parity_t parity_bit;
178 uart_stop_bits_t stop_bit;
180} gsm2_cfg_t;
181
195
212
226err_t gsm2_init ( gsm2_t *ctx, gsm2_cfg_t *cfg );
227
240err_t gsm2_generic_write ( gsm2_t *ctx, uint8_t *data_in, uint16_t len );
241
254err_t gsm2_generic_read ( gsm2_t *ctx, uint8_t *data_out, uint16_t len );
255
265void gsm2_set_rts_pin ( gsm2_t *ctx, uint8_t state );
266
276void gsm2_set_pwk_pin ( gsm2_t *ctx, uint8_t state );
277
286uint8_t gsm2_get_cts_pin ( gsm2_t *ctx );
287
296uint8_t gsm2_get_sta_pin ( gsm2_t *ctx );
297
306uint8_t gsm2_get_ring_pin ( gsm2_t *ctx );
307
317void gsm2_send_cmd ( gsm2_t *ctx, uint8_t *cmd );
318
329void gsm2_send_cmd_with_par ( gsm2_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf );
330
340void gsm2_send_cmd_check ( gsm2_t *ctx, uint8_t *at_cmd_buf );
341
351void gsm2_send_cmd_par_check ( gsm2_t *ctx, uint8_t *at_cmd_buf );
352
362void gsm2_set_sim_apn ( gsm2_t *ctx, uint8_t *sim_apn );
363
374void gsm2_send_sms_text ( gsm2_t *ctx, uint8_t *phone_number, uint8_t *sms_text );
375
389err_t gsm2_send_sms_pdu ( gsm2_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text );
390
391#ifdef __cplusplus
392}
393#endif
394#endif // GSM2_H
395
396 // gsm2
397
398// ------------------------------------------------------------------------ END
#define GSM2_RX_DRV_BUFFER_SIZE
GSM 2 driver buffer size.
Definition gsm2.h:101
#define GSM2_TX_DRV_BUFFER_SIZE
Definition gsm2.h:102
void gsm2_set_pwk_pin(gsm2_t *ctx, uint8_t state)
GSM 2 set pwk pin function.
void gsm2_send_cmd_check(gsm2_t *ctx, uint8_t *at_cmd_buf)
Check the sent command.
void gsm2_send_sms_text(gsm2_t *ctx, uint8_t *phone_number, uint8_t *sms_text)
GSM 2 send SMS in text mode.
void gsm2_send_cmd_par_check(gsm2_t *ctx, uint8_t *at_cmd_buf)
Check the command parameters.
err_t gsm2_send_sms_pdu(gsm2_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text)
GSM 2 send SMS in PDU mode.
uint8_t gsm2_get_ring_pin(gsm2_t *ctx)
GSM 2 get ring pin function.
err_t gsm2_generic_write(gsm2_t *ctx, uint8_t *data_in, uint16_t len)
GSM 2 data writing function.
void gsm2_cfg_setup(gsm2_cfg_t *cfg)
GSM 2 configuration object setup function.
err_t gsm2_init(gsm2_t *ctx, gsm2_cfg_t *cfg)
GSM 2 initialization function.
uint8_t gsm2_get_cts_pin(gsm2_t *ctx)
GSM 2 get cts pin function.
void gsm2_set_rts_pin(gsm2_t *ctx, uint8_t state)
GSM 2 set rts pin function.
void gsm2_send_cmd_with_par(gsm2_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf)
Send command function with parameter.
void gsm2_set_sim_apn(gsm2_t *ctx, uint8_t *sim_apn)
Set sim card APN.
uint8_t gsm2_get_sta_pin(gsm2_t *ctx)
GSM 2 get sta pin function.
void gsm2_send_cmd(gsm2_t *ctx, uint8_t *cmd)
Send command function.
err_t gsm2_generic_read(gsm2_t *ctx, uint8_t *data_out, uint16_t len)
GSM 2 data reading function.
gsm2_return_value_t
GSM 2 Click return value data.
Definition gsm2.h:187
@ GSM2_ERROR_UNKNOWN
Definition gsm2.h:192
@ GSM2_OK
Definition gsm2.h:188
@ GSM2_ERROR
Definition gsm2.h:189
@ GSM2_ERROR_CMD
Definition gsm2.h:191
@ GSM2_ERROR_TIMEOUT
Definition gsm2.h:190
GSM 2 Click configuration object.
Definition gsm2.h:161
pin_name_t sta
Definition gsm2.h:167
pin_name_t rts
Definition gsm2.h:169
uint32_t baud_rate
Definition gsm2.h:174
pin_name_t pwk
Definition gsm2.h:168
pin_name_t cts
Definition gsm2.h:171
pin_name_t ring
Definition gsm2.h:170
bool uart_blocking
Definition gsm2.h:175
uart_data_bits_t data_bit
Definition gsm2.h:176
pin_name_t tx_pin
Definition gsm2.h:164
pin_name_t rx_pin
Definition gsm2.h:163
uart_stop_bits_t stop_bit
Definition gsm2.h:178
uart_parity_t parity_bit
Definition gsm2.h:177
GSM 2 Click context object.
Definition gsm2.h:137
digital_in_t sta
Definition gsm2.h:143
digital_out_t rts
Definition gsm2.h:140
uart_t uart
Definition gsm2.h:148
digital_in_t cts
Definition gsm2.h:145
digital_out_t pwk
Definition gsm2.h:139
digital_in_t ring
Definition gsm2.h:144