c4glteatt  2.0.0.0
c4glteatt.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 C4GLTEATT_H
29 #define C4GLTEATT_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 C4GLTEATT_CMD_AT "AT"
70 #define C4GLTEATT_CMD_ATI "ATI"
71 #define C4GLTEATT_CMD_CGMR "AT+CGMR"
72 #define C4GLTEATT_CMD_CFUN "AT+CFUN"
73 #define C4GLTEATT_CMD_CREG "AT+CREG"
74 #define C4GLTEATT_CMD_CGREG "AT+CGREG"
75 #define C4GLTEATT_CMD_CGDCONT "AT+CGDCONT"
76 #define C4GLTEATT_CMD_CIMI "AT+CIMI"
77 #define C4GLTEATT_CMD_CMEE "AT+CMEE"
78 #define C4GLTEATT_CMD_CGATT "AT+CGATT"
79 #define C4GLTEATT_CMD_CSQ "AT+CSQ"
80 #define C4GLTEATT_CMD_COPS "AT+COPS"
81 #define C4GLTEATT_CMD_CMGS "AT+CMGS"
82 #define C4GLTEATT_CMD_CMGF "AT+CMGF"
83 
88 #define DRV_RX_BUFFER_SIZE 256
89 #define DRV_TX_BUFFER_SIZE 256
90  // c4glteatt_set
92 
107 #define C4GLTEATT_MAP_MIKROBUS( cfg, mikrobus ) \
108  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
109  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
110  cfg.sta = MIKROBUS( mikrobus, MIKROBUS_AN ); \
111  cfg.pwk = MIKROBUS( mikrobus, MIKROBUS_RST ); \
112  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
113  cfg.ring = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
114  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT );
115  // c4glteatt_map // c4glteatt
118 
123 typedef struct
124 {
125  // Output pins
126  digital_out_t pwk;
127  digital_out_t rts;
128 
129  // Input pins
130  digital_in_t sta;
131  digital_in_t ring;
132  digital_in_t cts;
133 
134  // Modules
135  uart_t uart;
137  // Buffers
138  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
139  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
141 } c4glteatt_t;
142 
147 typedef struct
148 {
149  // Communication gpio pins
150  pin_name_t rx_pin;
151  pin_name_t tx_pin;
153  // Additional gpio pins
154  pin_name_t sta;
155  pin_name_t pwk;
156  pin_name_t rts;
157  pin_name_t ring;
158  pin_name_t cts;
159 
160  // Static variable
161  uint32_t baud_rate;
163  uart_data_bits_t data_bit;
164  uart_parity_t parity_bit;
165  uart_stop_bits_t stop_bit;
168 
173 typedef enum
174 {
176  C4GLTEATT_ERROR = -1
177 
179 
196 
212 
222 
236 err_t c4glteatt_generic_write ( c4glteatt_t *ctx, char *data_buf, uint16_t len );
237 
251 err_t c4glteatt_generic_read ( c4glteatt_t *ctx, char *data_buf, uint16_t max_len );
252 
253 
263 void c4glteatt_set_rts_pin ( c4glteatt_t *ctx, uint8_t state );
264 
274 void c4glteatt_set_pwk_pin ( c4glteatt_t *ctx, uint8_t state );
275 
286 
297 
308 
318 void c4glteatt_send_cmd ( c4glteatt_t *ctx, char *cmd );
319 
330 void c4glteatt_send_cmd_with_parameter ( c4glteatt_t *ctx, char *at_cmd_buf, char *param_buf );
331 
341 void c4glteatt_send_cmd_check ( c4glteatt_t *ctx, char *at_cmd_buf );
342 
352 void c4glteatt_send_cmd_parameter_check ( c4glteatt_t *ctx, char *at_cmd_buf );
353 
363 void c4glteatt_set_sim_apn ( c4glteatt_t *ctx, char *sim_apn );
364 
375 void c4glteatt_send_sms_text ( c4glteatt_t *ctx, char *phone_number, char *sms_text );
376 
390 err_t c4glteatt_send_sms_pdu ( c4glteatt_t *ctx, char *service_center_number, char *phone_number, char *sms_text );
391 
392 #ifdef __cplusplus
393 }
394 #endif
395 #endif // C4GLTEATT_H
396  // c4glteatt
398 
399 // ------------------------------------------------------------------------ END
c4glteatt_send_cmd
void c4glteatt_send_cmd(c4glteatt_t *ctx, char *cmd)
Send command function.
c4glteatt_module_power_on
void c4glteatt_module_power_on(c4glteatt_t *ctx)
Power ON the module function.
c4glteatt_cfg_t::sta
pin_name_t sta
Definition: c4glteatt.h:154
c4glteatt_cfg_t::uart_blocking
bool uart_blocking
Definition: c4glteatt.h:162
c4glteatt_set_rts_pin
void c4glteatt_set_rts_pin(c4glteatt_t *ctx, uint8_t state)
Sets state of the RTS pin.
c4glteatt_cfg_t::tx_pin
pin_name_t tx_pin
Definition: c4glteatt.h:151
c4glteatt_cfg_t::pwk
pin_name_t pwk
Definition: c4glteatt.h:155
c4glteatt_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: c4glteatt.h:165
c4glteatt_get_ring_pin
uint8_t c4glteatt_get_ring_pin(c4glteatt_t *ctx)
RING Pin Get function.
c4glteatt_generic_write
err_t c4glteatt_generic_write(c4glteatt_t *ctx, char *data_buf, uint16_t len)
4G LTE-ATT data writing function.
c4glteatt_cfg_t::cts
pin_name_t cts
Definition: c4glteatt.h:158
c4glteatt_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: c4glteatt.h:164
c4glteatt_generic_read
err_t c4glteatt_generic_read(c4glteatt_t *ctx, char *data_buf, uint16_t max_len)
4G LTE-ATT data reading function.
c4glteatt_return_value_t
c4glteatt_return_value_t
4G LTE-ATT Click return value data.
Definition: c4glteatt.h:174
c4glteatt_cfg_t::rx_pin
pin_name_t rx_pin
Definition: c4glteatt.h:150
c4glteatt_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: c4glteatt.h:163
c4glteatt_cfg_t::ring
pin_name_t ring
Definition: c4glteatt.h:157
c4glteatt_send_sms_pdu
err_t c4glteatt_send_sms_pdu(c4glteatt_t *ctx, char *service_center_number, char *phone_number, char *sms_text)
4G LTE-ATT send SMS in PDU mode.
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
4G LTE-ATT driver buffer size.
Definition: c4glteatt.h:88
c4glteatt_set_sim_apn
void c4glteatt_set_sim_apn(c4glteatt_t *ctx, char *sim_apn)
Set sim card APN.
C4GLTEATT_OK
@ C4GLTEATT_OK
Definition: c4glteatt.h:175
c4glteatt_t::uart
uart_t uart
Definition: c4glteatt.h:135
c4glteatt_send_sms_text
void c4glteatt_send_sms_text(c4glteatt_t *ctx, char *phone_number, char *sms_text)
4G LTE-ATT send SMS in text mode.
c4glteatt_cfg_t::rts
pin_name_t rts
Definition: c4glteatt.h:156
c4glteatt_cfg_setup
void c4glteatt_cfg_setup(c4glteatt_cfg_t *cfg)
4G LTE-ATT configuration object setup function.
c4glteatt_set_pwk_pin
void c4glteatt_set_pwk_pin(c4glteatt_t *ctx, uint8_t state)
Sets state of the PWK pin.
c4glteatt_get_sta_pin
uint8_t c4glteatt_get_sta_pin(c4glteatt_t *ctx)
STA Pin Get function.
C4GLTEATT_ERROR
@ C4GLTEATT_ERROR
Definition: c4glteatt.h:176
c4glteatt_get_cts_pin
uint8_t c4glteatt_get_cts_pin(c4glteatt_t *ctx)
CTS Pin Get function.
c4glteatt_t
4G LTE-ATT Click context object.
Definition: c4glteatt.h:124
c4glteatt_cfg_t
4G LTE-ATT Click configuration object.
Definition: c4glteatt.h:148
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
Definition: c4glteatt.h:89
c4glteatt_send_cmd_check
void c4glteatt_send_cmd_check(c4glteatt_t *ctx, char *at_cmd_buf)
Check the sent command.
c4glteatt_t::ring
digital_in_t ring
Definition: c4glteatt.h:131
c4glteatt_init
err_t c4glteatt_init(c4glteatt_t *ctx, c4glteatt_cfg_t *cfg)
4G LTE-ATT initialization function.
c4glteatt_t::cts
digital_in_t cts
Definition: c4glteatt.h:132
c4glteatt_t::pwk
digital_out_t pwk
Definition: c4glteatt.h:126
c4glteatt_t::rts
digital_out_t rts
Definition: c4glteatt.h:127
c4glteatt_send_cmd_with_parameter
void c4glteatt_send_cmd_with_parameter(c4glteatt_t *ctx, char *at_cmd_buf, char *param_buf)
Send command function with parameter.
c4glteatt_cfg_t::baud_rate
uint32_t baud_rate
Definition: c4glteatt.h:161
c4glteatt_t::sta
digital_in_t sta
Definition: c4glteatt.h:130
c4glteatt_send_cmd_parameter_check
void c4glteatt_send_cmd_parameter_check(c4glteatt_t *ctx, char *at_cmd_buf)
Check the command parameters.