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 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_uart.h"
38 
59 #define GSM5_CMD_AT "AT"
60 #define GSM5_CMD_ATI "ATI"
61 #define GSM5_CMD_CGMR "AT+CGMR"
62 #define GSM5_CMD_CFUN "AT+CFUN"
63 #define GSM5_CMD_CREG "AT+CREG"
64 #define GSM5_CMD_CGREG "AT+CGREG"
65 #define GSM5_CMD_CGDCONT "AT+CGDCONT"
66 #define GSM5_CMD_CIMI "AT+CIMI"
67 #define GSM5_CMD_CMEE "AT+CMEE"
68 #define GSM5_CMD_CGATT "AT+CGATT"
69 #define GSM5_CMD_CSQ "AT+CSQ"
70 #define GSM5_CMD_COPS "AT+COPS"
71 #define GSM5_CMD_CMGS "AT+CMGS"
72 #define GSM5_CMD_CMGF "AT+CMGF"
73 #define GSM5_CMD_CGACT "AT+CGACT"
74 #define GSM5_CMD_UPSDA "AT+UPSDA"
75 #define GSM5_CMD_USOCR "AT+USOCR"
76 #define GSM5_CMD_USOCO "AT+USOCO"
77 #define GSM5_CMD_USOWR "AT+USOWR"
78 #define GSM5_CMD_USORD "AT+USORD"
79 #define GSM5_CMD_USORF "AT+USORF"
80 #define GSM5_CMD_USOCL "AT+USOCL"
81 
86 #define GSM5_RSP_OK "OK"
87 #define GSM5_RSP_ERROR "ERROR"
88 
94 #define DRV_BUFFER_SIZE 256
95  // gsm5_cmd
97 
112 #define GSM5_MAP_MIKROBUS( cfg, mikrobus ) \
113  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
114  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
115  cfg.on = MIKROBUS( mikrobus, MIKROBUS_AN ); \
116  cfg.off = MIKROBUS( mikrobus, MIKROBUS_RST ); \
117  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
118  cfg.ring = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
119  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT );
120  // gsm5_map // gsm5
123 
128 typedef struct
129 {
130  // Output pins
131  digital_out_t on;
132  digital_out_t off;
133  digital_out_t rts;
135  // Input pins
136  digital_in_t ring;
137  digital_in_t cts;
139  // Modules
140  uart_t uart;
142  // Buffers
143  char uart_rx_buffer[ DRV_BUFFER_SIZE ];
144  char uart_tx_buffer[ DRV_BUFFER_SIZE ];
146 } gsm5_t;
147 
152 typedef struct
153 {
154  // Communication gpio pins
155  pin_name_t rx_pin;
156  pin_name_t tx_pin;
158  // Additional gpio pins
159  pin_name_t on;
160  pin_name_t off;
161  pin_name_t rts;
162  pin_name_t ring;
163  pin_name_t cts;
165  // Static variable
166  uint32_t baud_rate;
168  uart_data_bits_t data_bit;
169  uart_parity_t parity_bit;
170  uart_stop_bits_t stop_bit;
172 } gsm5_cfg_t;
173 
178 typedef enum
179 {
180  GSM5_OK = 0,
184  GSM5_ERROR_UNKNOWN = -4
185 
187 
204 
218 err_t gsm5_init ( gsm5_t *ctx, gsm5_cfg_t *cfg );
219 
232 err_t gsm5_generic_write ( gsm5_t *ctx, char *data_buf, uint16_t len );
233 
246 err_t gsm5_generic_read ( gsm5_t *ctx, char *data_buf, uint16_t len );
247 
257 void gsm5_set_on_pin ( gsm5_t *ctx, uint8_t state );
258 
268 void gsm5_set_off_pin ( gsm5_t *ctx, uint8_t state );
269 
279 void gsm5_set_rts_pin ( gsm5_t *ctx, uint8_t state );
280 
290 uint8_t gsm5_get_ring_pin ( gsm5_t *ctx );
291 
301 uint8_t gsm5_get_cts_pin ( gsm5_t *ctx );
302 
311 
321 void gsm5_send_cmd ( gsm5_t *ctx, char *cmd );
322 
333 void gsm5_send_cmd_with_parameter ( gsm5_t *ctx, char *at_cmd_buf, char *param_buf );
334 
344 void gsm5_send_cmd_check ( gsm5_t *ctx, char *at_cmd_buf );
345 
355 void gsm5_send_cmd_parameter_check ( gsm5_t *ctx, char *at_cmd_buf );
356 
366 void gsm5_set_sim_apn ( gsm5_t *ctx, char *sim_apn );
367 
378 void gsm5_send_sms_text ( gsm5_t *ctx, char *phone_number, char *sms_text );
379 
393 err_t gsm5_send_sms_pdu ( gsm5_t *ctx, char *service_center_number, char *phone_number, char *sms_text );
394 
395 #ifdef __cplusplus
396 }
397 #endif
398 #endif // GSM5_H
399  // gsm5
401 
402 // ------------------------------------------------------------------------ END
gsm5_cfg_t::ring
pin_name_t ring
Definition: gsm5.h:162
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:137
gsm5_cfg_t::baud_rate
uint32_t baud_rate
Definition: gsm5.h:166
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:129
GSM5_ERROR_UNKNOWN
@ GSM5_ERROR_UNKNOWN
Definition: gsm5.h:184
gsm5_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: gsm5.h:170
gsm5_cfg_t::tx_pin
pin_name_t tx_pin
Definition: gsm5.h:156
gsm5_t::off
digital_out_t off
Definition: gsm5.h:132
gsm5_cfg_t::rx_pin
pin_name_t rx_pin
Definition: gsm5.h:155
gsm5_return_value_t
gsm5_return_value_t
GSM 5 Click return value data.
Definition: gsm5.h:179
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:182
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:133
gsm5_send_cmd
void gsm5_send_cmd(gsm5_t *ctx, char *cmd)
Send command function.
GSM5_ERROR_CMD
@ GSM5_ERROR_CMD
Definition: gsm5.h:183
GSM5_ERROR
@ GSM5_ERROR
Definition: gsm5.h:181
gsm5_t::uart
uart_t uart
Definition: gsm5.h:140
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:131
DRV_BUFFER_SIZE
#define DRV_BUFFER_SIZE
GSM 5 driver buffer size.
Definition: gsm5.h:94
gsm5_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: gsm5.h:168
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:169
gsm5_cfg_t::off
pin_name_t off
Definition: gsm5.h:160
gsm5_cfg_t::rts
pin_name_t rts
Definition: gsm5.h:161
gsm5_cfg_t
GSM 5 Click configuration object.
Definition: gsm5.h:153
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:159
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:136
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:167
gsm5_cfg_t::cts
pin_name_t cts
Definition: gsm5.h:163
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:180