gsm5 2.1.0.0
gsm5.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 GSM5_H
29#define GSM5_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 GSM5_CMD_AT "AT"
74#define GSM5_CMD_ATI "ATI"
75#define GSM5_CMD_CGMR "AT+CGMR"
76#define GSM5_CMD_CFUN "AT+CFUN"
77#define GSM5_CMD_CREG "AT+CREG"
78#define GSM5_CMD_CGREG "AT+CGREG"
79#define GSM5_CMD_CGDCONT "AT+CGDCONT"
80#define GSM5_CMD_CIMI "AT+CIMI"
81#define GSM5_CMD_CMEE "AT+CMEE"
82#define GSM5_CMD_CGATT "AT+CGATT"
83#define GSM5_CMD_CSQ "AT+CSQ"
84#define GSM5_CMD_COPS "AT+COPS"
85#define GSM5_CMD_CMGS "AT+CMGS"
86#define GSM5_CMD_CMGF "AT+CMGF"
87#define GSM5_CMD_CGACT "AT+CGACT"
88#define GSM5_CMD_UPSDA "AT+UPSDA"
89#define GSM5_CMD_USOCR "AT+USOCR"
90#define GSM5_CMD_USOCO "AT+USOCO"
91#define GSM5_CMD_USOWR "AT+USOWR"
92#define GSM5_CMD_USORD "AT+USORD"
93#define GSM5_CMD_USORF "AT+USORF"
94#define GSM5_CMD_USOCL "AT+USOCL"
95
100#define GSM5_RSP_OK "OK"
101#define GSM5_RSP_ERROR "ERROR"
102
108#define DRV_BUFFER_SIZE 256
109
110 // gsm5_cmd
111
126#define GSM5_MAP_MIKROBUS( cfg, mikrobus ) \
127 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
128 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
129 cfg.on = MIKROBUS( mikrobus, MIKROBUS_AN ); \
130 cfg.off = MIKROBUS( mikrobus, MIKROBUS_RST ); \
131 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
132 cfg.ring = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
133 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT );
134
135 // gsm5_map
136 // gsm5
137
142typedef struct
143{
144 // Output pins
145 digital_out_t on;
146 digital_out_t off;
147 digital_out_t rts;
149 // Input pins
150 digital_in_t ring;
151 digital_in_t cts;
153 // Modules
154 uart_t uart;
156 // Buffers
157 char uart_rx_buffer[ DRV_BUFFER_SIZE ];
158 char uart_tx_buffer[ DRV_BUFFER_SIZE ];
160} gsm5_t;
161
166typedef struct
167{
168 // Communication gpio pins
169 pin_name_t rx_pin;
170 pin_name_t tx_pin;
172 // Additional gpio pins
173 pin_name_t on;
174 pin_name_t off;
175 pin_name_t rts;
176 pin_name_t ring;
177 pin_name_t cts;
179 // Static variable
180 uint32_t baud_rate;
182 uart_data_bits_t data_bit;
183 uart_parity_t parity_bit;
184 uart_stop_bits_t stop_bit;
186} gsm5_cfg_t;
187
201
218
232err_t gsm5_init ( gsm5_t *ctx, gsm5_cfg_t *cfg );
233
246err_t gsm5_generic_write ( gsm5_t *ctx, char *data_buf, uint16_t len );
247
260err_t gsm5_generic_read ( gsm5_t *ctx, char *data_buf, uint16_t len );
261
271void gsm5_set_on_pin ( gsm5_t *ctx, uint8_t state );
272
282void gsm5_set_off_pin ( gsm5_t *ctx, uint8_t state );
283
293void gsm5_set_rts_pin ( gsm5_t *ctx, uint8_t state );
294
304uint8_t gsm5_get_ring_pin ( gsm5_t *ctx );
305
315uint8_t gsm5_get_cts_pin ( gsm5_t *ctx );
316
325
335void gsm5_send_cmd ( gsm5_t *ctx, char *cmd );
336
347void gsm5_send_cmd_with_parameter ( gsm5_t *ctx, char *at_cmd_buf, char *param_buf );
348
358void gsm5_send_cmd_check ( gsm5_t *ctx, char *at_cmd_buf );
359
369void gsm5_send_cmd_parameter_check ( gsm5_t *ctx, char *at_cmd_buf );
370
380void gsm5_set_sim_apn ( gsm5_t *ctx, char *sim_apn );
381
392void gsm5_send_sms_text ( gsm5_t *ctx, char *phone_number, char *sms_text );
393
407err_t gsm5_send_sms_pdu ( gsm5_t *ctx, char *service_center_number, char *phone_number, char *sms_text );
408
409#ifdef __cplusplus
410}
411#endif
412#endif // GSM5_H
413
414 // gsm5
415
416// ------------------------------------------------------------------------ END
#define DRV_BUFFER_SIZE
GSM 5 driver buffer size.
Definition gsm5.h:108
uint8_t gsm5_get_cts_pin(gsm5_t *ctx)
CTS Pin Get function.
err_t gsm5_generic_write(gsm5_t *ctx, char *data_buf, uint16_t len)
GSM 5 data writing function.
void gsm5_set_on_pin(gsm5_t *ctx, uint8_t state)
Sets state of the ON pin.
uint8_t gsm5_get_ring_pin(gsm5_t *ctx)
RING Pin Get function.
void gsm5_send_cmd_with_parameter(gsm5_t *ctx, char *at_cmd_buf, char *param_buf)
Send command function with parameter.
void gsm5_module_power_on(gsm5_t *ctx)
Power ON the module function.
void gsm5_send_sms_text(gsm5_t *ctx, char *phone_number, char *sms_text)
GSM 5 send SMS in text mode.
void gsm5_set_sim_apn(gsm5_t *ctx, char *sim_apn)
Set sim card APN.
void gsm5_set_off_pin(gsm5_t *ctx, uint8_t state)
Sets state of the OFF pin.
void gsm5_send_cmd_check(gsm5_t *ctx, char *at_cmd_buf)
Check the sent command.
err_t gsm5_init(gsm5_t *ctx, gsm5_cfg_t *cfg)
GSM 5 initialization function.
err_t gsm5_generic_read(gsm5_t *ctx, char *data_buf, uint16_t len)
GSM 5 data reading function.
err_t gsm5_send_sms_pdu(gsm5_t *ctx, char *service_center_number, char *phone_number, char *sms_text)
GSM 5 send SMS in PDU mode.
void gsm5_send_cmd(gsm5_t *ctx, char *cmd)
Send command function.
void gsm5_cfg_setup(gsm5_cfg_t *cfg)
GSM 5 configuration object setup function.
void gsm5_send_cmd_parameter_check(gsm5_t *ctx, char *at_cmd_buf)
Check the command parameters.
void gsm5_set_rts_pin(gsm5_t *ctx, uint8_t state)
Sets state of the RTS pin.
gsm5_return_value_t
GSM 5 Click return value data.
Definition gsm5.h:193
@ GSM5_ERROR_UNKNOWN
Definition gsm5.h:198
@ GSM5_OK
Definition gsm5.h:194
@ GSM5_ERROR
Definition gsm5.h:195
@ GSM5_ERROR_CMD
Definition gsm5.h:197
@ GSM5_ERROR_TIMEOUT
Definition gsm5.h:196
GSM 5 Click configuration object.
Definition gsm5.h:167
pin_name_t rts
Definition gsm5.h:175
uint32_t baud_rate
Definition gsm5.h:180
pin_name_t cts
Definition gsm5.h:177
pin_name_t ring
Definition gsm5.h:176
bool uart_blocking
Definition gsm5.h:181
uart_data_bits_t data_bit
Definition gsm5.h:182
pin_name_t on
Definition gsm5.h:173
pin_name_t tx_pin
Definition gsm5.h:170
pin_name_t off
Definition gsm5.h:174
pin_name_t rx_pin
Definition gsm5.h:169
uart_stop_bits_t stop_bit
Definition gsm5.h:184
uart_parity_t parity_bit
Definition gsm5.h:183
GSM 5 Click context object.
Definition gsm5.h:143
digital_out_t on
Definition gsm5.h:145
digital_out_t rts
Definition gsm5.h:147
uart_t uart
Definition gsm5.h:154
digital_out_t off
Definition gsm5.h:146
digital_in_t cts
Definition gsm5.h:151
digital_in_t ring
Definition gsm5.h:150