gsm2  2.0.0.0
gsm2.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 GSM2_H
29 #define GSM2_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 GSM2_CMD_AT "AT"
70 #define GSM2_CMD_ATI "ATI"
71 #define GSM2_CMD_CFUN "AT+CFUN"
72 #define GSM2_CMD_CREG "AT+CREG"
73 #define GSM2_CMD_CGDCONT "AT+CGDCONT"
74 #define GSM2_CMD_CSQ "AT+CSQ"
75 #define GSM2_CMD_COPS "AT+COPS"
76 #define GSM2_CMD_CMGS "AT+CMGS"
77 #define GSM2_CMD_CMGF "AT+CMGF"
78 #define GSM2_CMD_CGACT "AT+CGACT"
79 #define GSM2_CMD_QIMUX "AT+QIMUX"
80 #define GSM2_CMD_QIOPEN "AT+QIOPEN"
81 #define GSM2_CMD_QICLOSE "AT+QICLOSE"
82 #define GSM2_CMD_QISEND "AT+QISEND"
83 #define GSM2_CMD_QIRD "AT+QIRD"
84 
89 #define GSM2_RSP_OK "OK"
90 #define GSM2_RSP_ERROR "ERROR"
91 
97 #define GSM2_RX_DRV_BUFFER_SIZE 256
98 #define GSM2_TX_DRV_BUFFER_SIZE 256
99  // gsm2_set
101 
116 #define GSM2_MAP_MIKROBUS( cfg, mikrobus ) \
117  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
118  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
119  cfg.sta = MIKROBUS( mikrobus, MIKROBUS_AN ); \
120  cfg.pwk = MIKROBUS( mikrobus, MIKROBUS_RST ); \
121  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
122  cfg.ring = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
123  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT )
124  // gsm2_map // gsm2
127 
132 typedef struct
133 {
134  // Output pins
135  digital_out_t pwk;
136  digital_out_t rts;
138  // Input pins
139  digital_in_t sta;
140  digital_in_t ring;
141  digital_in_t cts;
143  // Modules
144  uart_t uart;
146  // Buffers
147  uint8_t uart_rx_buffer[ GSM2_RX_DRV_BUFFER_SIZE ];
148  uint8_t uart_tx_buffer[ GSM2_TX_DRV_BUFFER_SIZE ];
150 } gsm2_t;
151 
156 typedef struct
157 {
158  // Communication gpio pins
159  pin_name_t rx_pin;
160  pin_name_t tx_pin;
162  // Additional gpio pins
163  pin_name_t sta;
164  pin_name_t pwk;
165  pin_name_t rts;
166  pin_name_t ring;
167  pin_name_t cts;
169  // Static variable
170  uint32_t baud_rate;
172  uart_data_bits_t data_bit;
173  uart_parity_t parity_bit;
174  uart_stop_bits_t stop_bit;
176 } gsm2_cfg_t;
177 
182 typedef enum
183 {
184  GSM2_OK = 0,
188  GSM2_ERROR_UNKNOWN = -4
189 
191 
208 
222 err_t gsm2_init ( gsm2_t *ctx, gsm2_cfg_t *cfg );
223 
236 err_t gsm2_generic_write ( gsm2_t *ctx, uint8_t *data_in, uint16_t len );
237 
250 err_t gsm2_generic_read ( gsm2_t *ctx, uint8_t *data_out, uint16_t len );
251 
261 void gsm2_set_rts_pin ( gsm2_t *ctx, uint8_t state );
262 
272 void gsm2_set_pwk_pin ( gsm2_t *ctx, uint8_t state );
273 
282 uint8_t gsm2_get_cts_pin ( gsm2_t *ctx );
283 
292 uint8_t gsm2_get_sta_pin ( gsm2_t *ctx );
293 
302 uint8_t gsm2_get_ring_pin ( gsm2_t *ctx );
303 
313 void gsm2_send_cmd ( gsm2_t *ctx, uint8_t *cmd );
314 
325 void gsm2_send_cmd_with_par ( gsm2_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf );
326 
336 void gsm2_send_cmd_check ( gsm2_t *ctx, uint8_t *at_cmd_buf );
337 
347 void gsm2_send_cmd_par_check ( gsm2_t *ctx, uint8_t *at_cmd_buf );
348 
358 void gsm2_set_sim_apn ( gsm2_t *ctx, uint8_t *sim_apn );
359 
370 void gsm2_send_sms_text ( gsm2_t *ctx, uint8_t *phone_number, uint8_t *sms_text );
371 
385 err_t gsm2_send_sms_pdu ( gsm2_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text );
386 
387 #ifdef __cplusplus
388 }
389 #endif
390 #endif // GSM2_H
391  // gsm2
393 
394 // ------------------------------------------------------------------------ END
gsm2_t::uart
uart_t uart
Definition: gsm2.h:144
GSM2_ERROR_UNKNOWN
@ GSM2_ERROR_UNKNOWN
Definition: gsm2.h:188
gsm2_get_sta_pin
uint8_t gsm2_get_sta_pin(gsm2_t *ctx)
GSM 2 get sta pin function.
GSM2_ERROR_CMD
@ GSM2_ERROR_CMD
Definition: gsm2.h:187
gsm2_cfg_t::tx_pin
pin_name_t tx_pin
Definition: gsm2.h:160
gsm2_send_cmd
void gsm2_send_cmd(gsm2_t *ctx, uint8_t *cmd)
Send command function.
gsm2_t
GSM 2 Click context object.
Definition: gsm2.h:133
gsm2_cfg_t::cts
pin_name_t cts
Definition: gsm2.h:167
gsm2_t::ring
digital_in_t ring
Definition: gsm2.h:140
gsm2_t::sta
digital_in_t sta
Definition: gsm2.h:139
gsm2_set_pwk_pin
void gsm2_set_pwk_pin(gsm2_t *ctx, uint8_t state)
GSM 2 set pwk pin function.
gsm2_init
err_t gsm2_init(gsm2_t *ctx, gsm2_cfg_t *cfg)
GSM 2 initialization function.
gsm2_get_cts_pin
uint8_t gsm2_get_cts_pin(gsm2_t *ctx)
GSM 2 get cts pin function.
gsm2_cfg_t::rx_pin
pin_name_t rx_pin
Definition: gsm2.h:159
gsm2_generic_write
err_t gsm2_generic_write(gsm2_t *ctx, uint8_t *data_in, uint16_t len)
GSM 2 data writing function.
GSM2_ERROR
@ GSM2_ERROR
Definition: gsm2.h:185
gsm2_cfg_t::baud_rate
uint32_t baud_rate
Definition: gsm2.h:170
gsm2_t::pwk
digital_out_t pwk
Definition: gsm2.h:135
GSM2_RX_DRV_BUFFER_SIZE
#define GSM2_RX_DRV_BUFFER_SIZE
GSM 2 driver buffer size.
Definition: gsm2.h:97
gsm2_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: gsm2.h:173
gsm2_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: gsm2.h:174
gsm2_cfg_t::rts
pin_name_t rts
Definition: gsm2.h:165
gsm2_t::cts
digital_in_t cts
Definition: gsm2.h:141
gsm2_set_sim_apn
void gsm2_set_sim_apn(gsm2_t *ctx, uint8_t *sim_apn)
Set sim card APN.
gsm2_send_cmd_with_par
void gsm2_send_cmd_with_par(gsm2_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf)
Send command function with parameter.
gsm2_cfg_t::uart_blocking
bool uart_blocking
Definition: gsm2.h:171
gsm2_cfg_setup
void gsm2_cfg_setup(gsm2_cfg_t *cfg)
GSM 2 configuration object setup function.
gsm2_cfg_t
GSM 2 Click configuration object.
Definition: gsm2.h:157
gsm2_get_ring_pin
uint8_t gsm2_get_ring_pin(gsm2_t *ctx)
GSM 2 get ring pin function.
gsm2_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: gsm2.h:172
gsm2_send_sms_pdu
err_t gsm2_send_sms_pdu(gsm2_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text)
GSM 2 send SMS in PDU mode.
gsm2_send_cmd_check
void gsm2_send_cmd_check(gsm2_t *ctx, uint8_t *at_cmd_buf)
Check the sent command.
gsm2_send_cmd_par_check
void gsm2_send_cmd_par_check(gsm2_t *ctx, uint8_t *at_cmd_buf)
Check the command parameters.
gsm2_cfg_t::ring
pin_name_t ring
Definition: gsm2.h:166
gsm2_send_sms_text
void gsm2_send_sms_text(gsm2_t *ctx, uint8_t *phone_number, uint8_t *sms_text)
GSM 2 send SMS in text mode.
gsm2_return_value_t
gsm2_return_value_t
GSM 2 Click return value data.
Definition: gsm2.h:183
GSM2_ERROR_TIMEOUT
@ GSM2_ERROR_TIMEOUT
Definition: gsm2.h:186
gsm2_set_rts_pin
void gsm2_set_rts_pin(gsm2_t *ctx, uint8_t state)
GSM 2 set rts pin function.
gsm2_t::rts
digital_out_t rts
Definition: gsm2.h:136
gsm2_generic_read
err_t gsm2_generic_read(gsm2_t *ctx, uint8_t *data_out, uint16_t len)
GSM 2 data reading function.
gsm2_cfg_t::sta
pin_name_t sta
Definition: gsm2.h:163
GSM2_OK
@ GSM2_OK
Definition: gsm2.h:184
GSM2_TX_DRV_BUFFER_SIZE
#define GSM2_TX_DRV_BUFFER_SIZE
Definition: gsm2.h:98
gsm2_cfg_t::pwk
pin_name_t pwk
Definition: gsm2.h:164