gsm3 2.0.0.0
gsm3.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 GSM3_H
29#define GSM3_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 GSM3_CMD_AT "AT"
74#define GSM3_CMD_CFUN "AT+CFUN"
75#define GSM3_CMD_CREG "AT+CREG"
76#define GSM3_CMD_CGDCONT "AT+CGDCONT"
77#define GSM3_CMD_CSQ "AT+CSQ"
78#define GSM3_CMD_COPS "AT+COPS"
79#define GSM3_CMD_CMGS "AT+CMGS"
80#define GSM3_CMD_CMGF "AT+CMGF"
81#define GSM3_CMD_CIPMUX "AT+CIPMUX"
82#define GSM3_CMD_CIPSTART "AT+CIPSTART"
83#define GSM3_CMD_CIPCLOSE "AT+CIPCLOSE"
84#define GSM3_CMD_CIPSEND "AT+CIPSEND"
85#define GSM3_CMD_CIPHEAD "AT+CIPHEAD"
86
91#define GSM3_RSP_OK "OK"
92#define GSM3_RSP_ERROR "ERROR"
93
99#define GSM3_RX_DRV_BUFFER_SIZE 256
100#define GSM3_TX_DRV_BUFFER_SIZE 256
101
102 // gsm3_set
103
118#define GSM3_MAP_MIKROBUS( cfg, mikrobus ) \
119 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
120 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
121 cfg.sta = MIKROBUS( mikrobus, MIKROBUS_AN ); \
122 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
123 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
124 cfg.pwk = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
125 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT )
126
127 // gsm3_map
128 // gsm3
129
134typedef struct
135{
136 // Output pins
137 digital_out_t rst;
138 digital_out_t pwk;
139 digital_out_t rts;
141 // Input pins
142 digital_in_t sta;
143 digital_in_t cts;
145 // Modules
146 uart_t uart;
148 // Buffers
149 uint8_t uart_rx_buffer[ GSM3_RX_DRV_BUFFER_SIZE ];
150 uint8_t uart_tx_buffer[ GSM3_TX_DRV_BUFFER_SIZE ];
152} gsm3_t;
153
158typedef struct
159{
160 // Communication gpio pins
161 pin_name_t rx_pin;
162 pin_name_t tx_pin;
164 // Additional gpio pins
165 pin_name_t rst;
166 pin_name_t pwk;
167 pin_name_t rts;
168 pin_name_t sta;
169 pin_name_t cts;
171 // Static variable
172 uint32_t baud_rate;
174 uart_data_bits_t data_bit;
175 uart_parity_t parity_bit;
176 uart_stop_bits_t stop_bit;
178} gsm3_cfg_t;
179
193
210
224err_t gsm3_init ( gsm3_t *ctx, gsm3_cfg_t *cfg );
225
238err_t gsm3_generic_write ( gsm3_t *ctx, uint8_t *data_in, uint16_t len );
239
252err_t gsm3_generic_read ( gsm3_t *ctx, uint8_t *data_out, uint16_t len );
253
263void gsm3_set_rst_pin ( gsm3_t *ctx, uint8_t state );
264
274void gsm3_set_rts_pin ( gsm3_t *ctx, uint8_t state );
275
285void gsm3_set_pwk_pin ( gsm3_t *ctx, uint8_t state );
286
295uint8_t gsm3_get_cts_pin ( gsm3_t *ctx );
296
305uint8_t gsm3_get_sta_pin ( gsm3_t *ctx );
306
316void gsm3_send_cmd ( gsm3_t *ctx, uint8_t *cmd );
317
328void gsm3_send_cmd_with_par ( gsm3_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf );
329
339void gsm3_send_cmd_check ( gsm3_t *ctx, uint8_t *at_cmd_buf );
340
350void gsm3_send_cmd_par_check ( gsm3_t *ctx, uint8_t *at_cmd_buf );
351
361void gsm3_set_sim_apn ( gsm3_t *ctx, uint8_t *sim_apn );
362
373void gsm3_send_sms_text ( gsm3_t *ctx, uint8_t *phone_number, uint8_t *sms_text );
374
388err_t gsm3_send_sms_pdu ( gsm3_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text );
389
390#ifdef __cplusplus
391}
392#endif
393#endif // GSM3_H
394
395 // gsm3
396
397// ------------------------------------------------------------------------ END
#define GSM3_RX_DRV_BUFFER_SIZE
GSM 3 driver buffer size.
Definition gsm3.h:99
#define GSM3_TX_DRV_BUFFER_SIZE
Definition gsm3.h:100
void gsm3_send_cmd_check(gsm3_t *ctx, uint8_t *at_cmd_buf)
Check the sent command.
void gsm3_send_cmd_par_check(gsm3_t *ctx, uint8_t *at_cmd_buf)
Check the command parameters.
uint8_t gsm3_get_cts_pin(gsm3_t *ctx)
GSM 3 get cts pin function.
void gsm3_send_cmd_with_par(gsm3_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf)
Send command function with parameter.
void gsm3_set_sim_apn(gsm3_t *ctx, uint8_t *sim_apn)
Set sim card APN.
err_t gsm3_init(gsm3_t *ctx, gsm3_cfg_t *cfg)
GSM 3 initialization function.
void gsm3_set_rst_pin(gsm3_t *ctx, uint8_t state)
GSM 3 set rst pin function.
void gsm3_set_rts_pin(gsm3_t *ctx, uint8_t state)
GSM 3 set rts pin function.
err_t gsm3_send_sms_pdu(gsm3_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text)
GSM 3 send SMS in PDU mode.
uint8_t gsm3_get_sta_pin(gsm3_t *ctx)
GSM 3 get sta pin function.
void gsm3_send_sms_text(gsm3_t *ctx, uint8_t *phone_number, uint8_t *sms_text)
GSM 3 send SMS in text mode.
void gsm3_set_pwk_pin(gsm3_t *ctx, uint8_t state)
GSM 3 set pwk pin function.
void gsm3_cfg_setup(gsm3_cfg_t *cfg)
GSM 3 configuration object setup function.
err_t gsm3_generic_write(gsm3_t *ctx, uint8_t *data_in, uint16_t len)
GSM 3 data writing function.
void gsm3_send_cmd(gsm3_t *ctx, uint8_t *cmd)
Send command function.
err_t gsm3_generic_read(gsm3_t *ctx, uint8_t *data_out, uint16_t len)
GSM 3 data reading function.
gsm3_return_value_t
GSM 3 Click return value data.
Definition gsm3.h:185
@ GSM3_ERROR
Definition gsm3.h:187
@ GSM3_OK
Definition gsm3.h:186
@ GSM3_ERROR_TIMEOUT
Definition gsm3.h:188
@ GSM3_ERROR_CMD
Definition gsm3.h:189
@ GSM3_ERROR_UNKNOWN
Definition gsm3.h:190
GSM 3 Click configuration object.
Definition gsm3.h:159
pin_name_t sta
Definition gsm3.h:168
pin_name_t rts
Definition gsm3.h:167
uint32_t baud_rate
Definition gsm3.h:172
pin_name_t pwk
Definition gsm3.h:166
pin_name_t cts
Definition gsm3.h:169
bool uart_blocking
Definition gsm3.h:173
uart_data_bits_t data_bit
Definition gsm3.h:174
pin_name_t tx_pin
Definition gsm3.h:162
pin_name_t rx_pin
Definition gsm3.h:161
uart_stop_bits_t stop_bit
Definition gsm3.h:176
uart_parity_t parity_bit
Definition gsm3.h:175
pin_name_t rst
Definition gsm3.h:165
GSM 3 Click context object.
Definition gsm3.h:135
digital_in_t sta
Definition gsm3.h:142
digital_out_t rts
Definition gsm3.h:139
uart_t uart
Definition gsm3.h:146
digital_in_t cts
Definition gsm3.h:143
digital_out_t pwk
Definition gsm3.h:138
digital_out_t rst
Definition gsm3.h:137