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 "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_uart.h"
48 
69 #define GSM5_CMD_AT "AT"
70 #define GSM5_CMD_ATI "ATI"
71 #define GSM5_CMD_CGMR "AT+CGMR"
72 #define GSM5_CMD_CFUN "AT+CFUN"
73 #define GSM5_CMD_CREG "AT+CREG"
74 #define GSM5_CMD_CGREG "AT+CGREG"
75 #define GSM5_CMD_CGDCONT "AT+CGDCONT"
76 #define GSM5_CMD_CIMI "AT+CIMI"
77 #define GSM5_CMD_CMEE "AT+CMEE"
78 #define GSM5_CMD_CGATT "AT+CGATT"
79 #define GSM5_CMD_CSQ "AT+CSQ"
80 #define GSM5_CMD_COPS "AT+COPS"
81 #define GSM5_CMD_CMGS "AT+CMGS"
82 #define GSM5_CMD_CMGF "AT+CMGF"
83 #define GSM5_CMD_CGACT "AT+CGACT"
84 #define GSM5_CMD_UPSDA "AT+UPSDA"
85 #define GSM5_CMD_USOCR "AT+USOCR"
86 #define GSM5_CMD_USOCO "AT+USOCO"
87 #define GSM5_CMD_USOWR "AT+USOWR"
88 #define GSM5_CMD_USORD "AT+USORD"
89 #define GSM5_CMD_USORF "AT+USORF"
90 #define GSM5_CMD_USOCL "AT+USOCL"
91 
96 #define GSM5_RSP_OK "OK"
97 #define GSM5_RSP_ERROR "ERROR"
98 
104 #define DRV_BUFFER_SIZE 256
105  // gsm5_cmd
107 
122 #define GSM5_MAP_MIKROBUS( cfg, mikrobus ) \
123  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
124  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
125  cfg.on = MIKROBUS( mikrobus, MIKROBUS_AN ); \
126  cfg.off = MIKROBUS( mikrobus, MIKROBUS_RST ); \
127  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
128  cfg.ring = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
129  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT );
130  // gsm5_map // gsm5
133 
138 typedef struct
139 {
140  // Output pins
141  digital_out_t on;
142  digital_out_t off;
143  digital_out_t rts;
145  // Input pins
146  digital_in_t ring;
147  digital_in_t cts;
149  // Modules
150  uart_t uart;
152  // Buffers
153  char uart_rx_buffer[ DRV_BUFFER_SIZE ];
154  char uart_tx_buffer[ DRV_BUFFER_SIZE ];
156 } gsm5_t;
157 
162 typedef struct
163 {
164  // Communication gpio pins
165  pin_name_t rx_pin;
166  pin_name_t tx_pin;
168  // Additional gpio pins
169  pin_name_t on;
170  pin_name_t off;
171  pin_name_t rts;
172  pin_name_t ring;
173  pin_name_t cts;
175  // Static variable
176  uint32_t baud_rate;
178  uart_data_bits_t data_bit;
179  uart_parity_t parity_bit;
180  uart_stop_bits_t stop_bit;
182 } gsm5_cfg_t;
183 
188 typedef enum
189 {
190  GSM5_OK = 0,
194  GSM5_ERROR_UNKNOWN = -4
195 
197 
214 
228 err_t gsm5_init ( gsm5_t *ctx, gsm5_cfg_t *cfg );
229 
242 err_t gsm5_generic_write ( gsm5_t *ctx, char *data_buf, uint16_t len );
243 
256 err_t gsm5_generic_read ( gsm5_t *ctx, char *data_buf, uint16_t len );
257 
267 void gsm5_set_on_pin ( gsm5_t *ctx, uint8_t state );
268 
278 void gsm5_set_off_pin ( gsm5_t *ctx, uint8_t state );
279 
289 void gsm5_set_rts_pin ( gsm5_t *ctx, uint8_t state );
290 
300 uint8_t gsm5_get_ring_pin ( gsm5_t *ctx );
301 
311 uint8_t gsm5_get_cts_pin ( gsm5_t *ctx );
312 
321 
331 void gsm5_send_cmd ( gsm5_t *ctx, char *cmd );
332 
343 void gsm5_send_cmd_with_parameter ( gsm5_t *ctx, char *at_cmd_buf, char *param_buf );
344 
354 void gsm5_send_cmd_check ( gsm5_t *ctx, char *at_cmd_buf );
355 
365 void gsm5_send_cmd_parameter_check ( gsm5_t *ctx, char *at_cmd_buf );
366 
376 void gsm5_set_sim_apn ( gsm5_t *ctx, char *sim_apn );
377 
388 void gsm5_send_sms_text ( gsm5_t *ctx, char *phone_number, char *sms_text );
389 
403 err_t gsm5_send_sms_pdu ( gsm5_t *ctx, char *service_center_number, char *phone_number, char *sms_text );
404 
405 #ifdef __cplusplus
406 }
407 #endif
408 #endif // GSM5_H
409  // gsm5
411 
412 // ------------------------------------------------------------------------ END
gsm5_cfg_t::ring
pin_name_t ring
Definition: gsm5.h:172
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:147
gsm5_cfg_t::baud_rate
uint32_t baud_rate
Definition: gsm5.h:176
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:139
GSM5_ERROR_UNKNOWN
@ GSM5_ERROR_UNKNOWN
Definition: gsm5.h:194
gsm5_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: gsm5.h:180
gsm5_cfg_t::tx_pin
pin_name_t tx_pin
Definition: gsm5.h:166
gsm5_t::off
digital_out_t off
Definition: gsm5.h:142
gsm5_cfg_t::rx_pin
pin_name_t rx_pin
Definition: gsm5.h:165
gsm5_return_value_t
gsm5_return_value_t
GSM 5 Click return value data.
Definition: gsm5.h:189
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:192
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:143
gsm5_send_cmd
void gsm5_send_cmd(gsm5_t *ctx, char *cmd)
Send command function.
GSM5_ERROR_CMD
@ GSM5_ERROR_CMD
Definition: gsm5.h:193
GSM5_ERROR
@ GSM5_ERROR
Definition: gsm5.h:191
gsm5_t::uart
uart_t uart
Definition: gsm5.h:150
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:141
DRV_BUFFER_SIZE
#define DRV_BUFFER_SIZE
GSM 5 driver buffer size.
Definition: gsm5.h:104
gsm5_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: gsm5.h:178
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:179
gsm5_cfg_t::off
pin_name_t off
Definition: gsm5.h:170
gsm5_cfg_t::rts
pin_name_t rts
Definition: gsm5.h:171
gsm5_cfg_t
GSM 5 Click configuration object.
Definition: gsm5.h:163
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:169
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:146
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:177
gsm5_cfg_t::cts
pin_name_t cts
Definition: gsm5.h:173
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:190