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
32 extern "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  // 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  // gsm5_map // gsm5
137 
142 typedef 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 
166 typedef 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 
192 typedef enum
193 {
194  GSM5_OK = 0,
198  GSM5_ERROR_UNKNOWN = -4
199 
201 
218 
232 err_t gsm5_init ( gsm5_t *ctx, gsm5_cfg_t *cfg );
233 
246 err_t gsm5_generic_write ( gsm5_t *ctx, char *data_buf, uint16_t len );
247 
260 err_t gsm5_generic_read ( gsm5_t *ctx, char *data_buf, uint16_t len );
261 
271 void gsm5_set_on_pin ( gsm5_t *ctx, uint8_t state );
272 
282 void gsm5_set_off_pin ( gsm5_t *ctx, uint8_t state );
283 
293 void gsm5_set_rts_pin ( gsm5_t *ctx, uint8_t state );
294 
304 uint8_t gsm5_get_ring_pin ( gsm5_t *ctx );
305 
315 uint8_t gsm5_get_cts_pin ( gsm5_t *ctx );
316 
325 
335 void gsm5_send_cmd ( gsm5_t *ctx, char *cmd );
336 
347 void gsm5_send_cmd_with_parameter ( gsm5_t *ctx, char *at_cmd_buf, char *param_buf );
348 
358 void gsm5_send_cmd_check ( gsm5_t *ctx, char *at_cmd_buf );
359 
369 void gsm5_send_cmd_parameter_check ( gsm5_t *ctx, char *at_cmd_buf );
370 
380 void gsm5_set_sim_apn ( gsm5_t *ctx, char *sim_apn );
381 
392 void gsm5_send_sms_text ( gsm5_t *ctx, char *phone_number, char *sms_text );
393 
407 err_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  // gsm5
415 
416 // ------------------------------------------------------------------------ END
gsm5_cfg_t::ring
pin_name_t ring
Definition: gsm5.h:176
gsm5_send_cmd_parameter_check
void gsm5_send_cmd_parameter_check(gsm5_t *ctx, char *at_cmd_buf)
Check the command parameters.
gsm5_get_ring_pin
uint8_t gsm5_get_ring_pin(gsm5_t *ctx)
RING Pin Get function.
gsm5_t::cts
digital_in_t cts
Definition: gsm5.h:151
gsm5_cfg_t::baud_rate
uint32_t baud_rate
Definition: gsm5.h:180
gsm5_set_rts_pin
void gsm5_set_rts_pin(gsm5_t *ctx, uint8_t state)
Sets state of the RTS pin.
gsm5_t
GSM 5 Click context object.
Definition: gsm5.h:143
GSM5_ERROR_UNKNOWN
@ GSM5_ERROR_UNKNOWN
Definition: gsm5.h:198
gsm5_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: gsm5.h:184
gsm5_cfg_t::tx_pin
pin_name_t tx_pin
Definition: gsm5.h:170
gsm5_t::off
digital_out_t off
Definition: gsm5.h:146
gsm5_cfg_t::rx_pin
pin_name_t rx_pin
Definition: gsm5.h:169
gsm5_return_value_t
gsm5_return_value_t
GSM 5 Click return value data.
Definition: gsm5.h:193
gsm5_generic_read
err_t gsm5_generic_read(gsm5_t *ctx, char *data_buf, uint16_t len)
GSM 5 data reading function.
GSM5_ERROR_TIMEOUT
@ GSM5_ERROR_TIMEOUT
Definition: gsm5.h:196
gsm5_set_off_pin
void gsm5_set_off_pin(gsm5_t *ctx, uint8_t state)
Sets state of the OFF pin.
gsm5_t::rts
digital_out_t rts
Definition: gsm5.h:147
gsm5_send_cmd
void gsm5_send_cmd(gsm5_t *ctx, char *cmd)
Send command function.
GSM5_ERROR_CMD
@ GSM5_ERROR_CMD
Definition: gsm5.h:197
GSM5_ERROR
@ GSM5_ERROR
Definition: gsm5.h:195
gsm5_t::uart
uart_t uart
Definition: gsm5.h:154
gsm5_init
err_t gsm5_init(gsm5_t *ctx, gsm5_cfg_t *cfg)
GSM 5 initialization function.
gsm5_t::on
digital_out_t on
Definition: gsm5.h:145
DRV_BUFFER_SIZE
#define DRV_BUFFER_SIZE
GSM 5 driver buffer size.
Definition: gsm5.h:108
gsm5_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: gsm5.h:182
gsm5_cfg_setup
void gsm5_cfg_setup(gsm5_cfg_t *cfg)
GSM 5 configuration object setup function.
gsm5_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: gsm5.h:183
gsm5_cfg_t::off
pin_name_t off
Definition: gsm5.h:174
gsm5_cfg_t::rts
pin_name_t rts
Definition: gsm5.h:175
gsm5_cfg_t
GSM 5 Click configuration object.
Definition: gsm5.h:167
gsm5_send_sms_pdu
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.
gsm5_cfg_t::on
pin_name_t on
Definition: gsm5.h:173
gsm5_module_power_on
void gsm5_module_power_on(gsm5_t *ctx)
Power ON the module function.
gsm5_t::ring
digital_in_t ring
Definition: gsm5.h:150
gsm5_send_cmd_check
void gsm5_send_cmd_check(gsm5_t *ctx, char *at_cmd_buf)
Check the sent command.
gsm5_set_sim_apn
void gsm5_set_sim_apn(gsm5_t *ctx, char *sim_apn)
Set sim card APN.
gsm5_send_cmd_with_parameter
void gsm5_send_cmd_with_parameter(gsm5_t *ctx, char *at_cmd_buf, char *param_buf)
Send command function with parameter.
gsm5_set_on_pin
void gsm5_set_on_pin(gsm5_t *ctx, uint8_t state)
Sets state of the ON pin.
gsm5_generic_write
err_t gsm5_generic_write(gsm5_t *ctx, char *data_buf, uint16_t len)
GSM 5 data writing function.
gsm5_cfg_t::uart_blocking
bool uart_blocking
Definition: gsm5.h:181
gsm5_cfg_t::cts
pin_name_t cts
Definition: gsm5.h:177
gsm5_send_sms_text
void gsm5_send_sms_text(gsm5_t *ctx, char *phone_number, char *sms_text)
GSM 5 send SMS in text mode.
gsm5_get_cts_pin
uint8_t gsm5_get_cts_pin(gsm5_t *ctx)
CTS Pin Get function.
GSM5_OK
@ GSM5_OK
Definition: gsm5.h:194