lteiot6  2.0.0.0
lteiot6.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 LTEIOT6_H
29 #define LTEIOT6_H
30 
35 #ifdef PREINIT_SUPPORTED
36 #include "preinit.h"
37 #endif
38 
39 #ifdef MikroCCoreVersion
40  #if MikroCCoreVersion >= 1
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 
49 
70 #define LTEIOT6_CMD_AT "AT"
71 #define LTEIOT6_CMD_ATI "ATI"
72 #define LTEIOT6_CMD_CGMR "AT+CGMR"
73 #define LTEIOT6_CMD_CFUN "AT+CFUN"
74 #define LTEIOT6_CMD_CREG "AT+CREG"
75 #define LTEIOT6_CMD_CEREG "AT+CEREG"
76 #define LTEIOT6_CMD_CGDCONT "AT+CGDCONT"
77 #define LTEIOT6_CMD_CIMI "AT+CIMI"
78 #define LTEIOT6_CMD_CGATT "AT+CGATT"
79 #define LTEIOT6_CMD_CSQ "AT+CSQ"
80 #define LTEIOT6_CMD_CESQ "AT+CESQ"
81 #define LTEIOT6_CMD_COPS "AT+COPS"
82 #define LTEIOT6_CMD_CMGF "AT+CMGF"
83 #define LTEIOT6_CMD_CMGS "AT+CMGS"
84 #define LTEIOT6_CMD_CSCA "AT+CSCA"
85 #define LTEIOT6_CMD_SQNLED "AT+SQNLED"
86  // lteiot6_cmd
88 
103 #define LTEIOT6_RSP_OK "OK"
104 #define LTEIOT6_RSP_ERROR "ERROR"
105 #define LTEIOT6_RSP_SYSTART "+SYSSTART"
106 
111 #define DRV_BUFFER_SIZE 400
112  // lteiot6_set
114 
129 #define LTEIOT6_MAP_MIKROBUS( cfg, mikrobus ) \
130  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
131  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
132  cfg.pwr = MIKROBUS( mikrobus, MIKROBUS_AN ); \
133  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
134  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
135  cfg.ri = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
136  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT );
137  // lteiot6_map // lteiot6
140 
145 typedef struct
146 {
147  // Output pins
148  digital_out_t pwr;
149  digital_out_t rst;
150  digital_out_t rts;
151 
152  // Input pins
153  digital_in_t ri;
154  digital_in_t cts;
155  digital_in_t rx_pin;
156 
157  // Modules
158 
159  uart_t uart;
160 
161  char uart_rx_buffer[ DRV_BUFFER_SIZE ];
162  char uart_tx_buffer[ DRV_BUFFER_SIZE ];
163 
164 } lteiot6_t;
165 
170 typedef struct
171 {
172  // Communication gpio pins
173  pin_name_t rx_pin;
174  pin_name_t tx_pin;
175 
176  // Additional gpio pins
177  pin_name_t pwr;
178  pin_name_t rst;
179  pin_name_t rts;
180  pin_name_t ri;
181  pin_name_t cts;
182 
183  // static variable
184  uint32_t baud_rate; // Clock speed.
186  uart_data_bits_t data_bit; // Data bits.
187  uart_parity_t parity_bit; // Parity bit.
188  uart_stop_bits_t stop_bit; // Stop bits.
189 
190 } lteiot6_cfg_t;
191 
196 typedef enum
197 {
203 
205 
212 #ifdef __cplusplus
213 extern "C"{
214 #endif
215 
226 
241 err_t lteiot6_init ( lteiot6_t *ctx, lteiot6_cfg_t *cfg );
242 
256 err_t lteiot6_generic_write ( lteiot6_t *ctx, char *data_buf, uint16_t len );
257 
271 err_t lteiot6_generic_read ( lteiot6_t *ctx, char *data_buf, uint16_t max_len );
272 
281 
289 void lteiot6_reset ( lteiot6_t *ctx );
290 
299 void lteiot6_set_pwr ( lteiot6_t *ctx, uint8_t state );
300 
309 void lteiot6_set_rst ( lteiot6_t *ctx, uint8_t state );
310 
319 void lteiot6_set_rts ( lteiot6_t *ctx, uint8_t state );
320 
329 uint8_t lteiot6_get_ri ( lteiot6_t *ctx );
330 
339 uint8_t lteiot6_get_cts ( lteiot6_t *ctx );
340 
352 void lteiot6_send_cmd ( lteiot6_t *ctx, char *cmd );
353 
366 void lteiot6_send_cmd_with_parameter ( lteiot6_t *ctx, char *at_cmd_buf, char *param_buf );
367 
379 void lteiot6_send_cmd_check ( lteiot6_t *ctx, char *at_cmd_buf );
380 
392 void lteiot6_send_cmd_parameter_check ( lteiot6_t *ctx, char *at_cmd_buf );
393 
405 void lteiot6_set_sim_apn ( lteiot6_t *ctx, char *sim_apn );
406 
419 void lteiot6_send_text_message ( lteiot6_t *ctx, char *phone_number, char *message_content );
420 
434 err_t lteiot6_send_sms_pdu ( lteiot6_t *ctx, char *service_center_number, char *phone_number, char *sms_text );
435 
436 #ifdef __cplusplus
437 }
438 #endif
439 #endif // LTEIOT6_H
440  // lteiot6
442 
443 // ------------------------------------------------------------------------ END
lteiot6_cfg_t::uart_blocking
bool uart_blocking
Definition: lteiot6.h:185
lteiot6_t::ri
digital_in_t ri
Definition: lteiot6.h:153
LTEIOT6_ERROR
@ LTEIOT6_ERROR
Definition: lteiot6.h:199
lteiot6_generic_read
err_t lteiot6_generic_read(lteiot6_t *ctx, char *data_buf, uint16_t max_len)
LTE IoT 6 data reading function.
lteiot6_cfg_t::rts
pin_name_t rts
Definition: lteiot6.h:179
lteiot6_set_sim_apn
void lteiot6_set_sim_apn(lteiot6_t *ctx, char *sim_apn)
Set sim card APN.
lteiot6_init
err_t lteiot6_init(lteiot6_t *ctx, lteiot6_cfg_t *cfg)
LTE IoT 6 initialization function.
LTEIOT6_ERROR_UNKNOWN
@ LTEIOT6_ERROR_UNKNOWN
Definition: lteiot6.h:202
lteiot6_cfg_t::cts
pin_name_t cts
Definition: lteiot6.h:181
LTEIOT6_OK
@ LTEIOT6_OK
Definition: lteiot6.h:198
lteiot6_cfg_t::rx_pin
pin_name_t rx_pin
Definition: lteiot6.h:173
lteiot6_t::uart
uart_t uart
Definition: lteiot6.h:159
lteiot6_send_cmd
void lteiot6_send_cmd(lteiot6_t *ctx, char *cmd)
Send command function.
lteiot6_t::rx_pin
digital_in_t rx_pin
Definition: lteiot6.h:155
lteiot6_generic_write
err_t lteiot6_generic_write(lteiot6_t *ctx, char *data_buf, uint16_t len)
LTE IoT 6 data writing function.
lteiot6_cfg_setup
void lteiot6_cfg_setup(lteiot6_cfg_t *cfg)
LTE IoT 6 configuration object setup function.
lteiot6_t
LTE IoT 6 Click context object.
Definition: lteiot6.h:146
lteiot6_cfg_t::pwr
pin_name_t pwr
Definition: lteiot6.h:177
lteiot6_set_pwr
void lteiot6_set_pwr(lteiot6_t *ctx, uint8_t state)
Sets state of the PWR pin.
lteiot6_t::pwr
digital_out_t pwr
Definition: lteiot6.h:148
lteiot6_cfg_t
LTE IoT 6 Click configuration object.
Definition: lteiot6.h:171
DRV_BUFFER_SIZE
#define DRV_BUFFER_SIZE
LTE IoT 6 driver buffer size.
Definition: lteiot6.h:111
lteiot6_t::rts
digital_out_t rts
Definition: lteiot6.h:150
lteiot6_send_cmd_parameter_check
void lteiot6_send_cmd_parameter_check(lteiot6_t *ctx, char *at_cmd_buf)
Check the command parameters.
lteiot6_get_ri
uint8_t lteiot6_get_ri(lteiot6_t *ctx)
RI Pin Get function.
lteiot6_cfg_t::ri
pin_name_t ri
Definition: lteiot6.h:180
lteiot6_set_rts
void lteiot6_set_rts(lteiot6_t *ctx, uint8_t state)
Sets state of the RTS pin.
lteiot6_send_cmd_check
void lteiot6_send_cmd_check(lteiot6_t *ctx, char *at_cmd_buf)
Check the sent command.
lteiot8_return_value_t
lteiot8_return_value_t
LTE IoT 6 Click return value data.
Definition: lteiot6.h:197
lteiot6_power_on
void lteiot6_power_on(lteiot6_t *ctx)
LTE IoT 6 power on.
lteiot6_send_text_message
void lteiot6_send_text_message(lteiot6_t *ctx, char *phone_number, char *message_content)
Send SMS message to number in text mode.
LTEIOT6_ERROR_TIMEOUT
@ LTEIOT6_ERROR_TIMEOUT
Definition: lteiot6.h:200
lteiot6_cfg_t::rst
pin_name_t rst
Definition: lteiot6.h:178
lteiot6_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: lteiot6.h:186
LTEIOT6_ERROR_CMD
@ LTEIOT6_ERROR_CMD
Definition: lteiot6.h:201
lteiot6_send_cmd_with_parameter
void lteiot6_send_cmd_with_parameter(lteiot6_t *ctx, char *at_cmd_buf, char *param_buf)
Send command function with parameter.
lteiot6_get_cts
uint8_t lteiot6_get_cts(lteiot6_t *ctx)
CTS Pin Get function.
lteiot6_t::rst
digital_out_t rst
Definition: lteiot6.h:149
lteiot6_t::cts
digital_in_t cts
Definition: lteiot6.h:154
lteiot6_reset
void lteiot6_reset(lteiot6_t *ctx)
LTE IoT 6 power on.
lteiot6_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: lteiot6.h:188
lteiot6_cfg_t::baud_rate
uint32_t baud_rate
Definition: lteiot6.h:184
lteiot6_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: lteiot6.h:187
lteiot6_send_sms_pdu
err_t lteiot6_send_sms_pdu(lteiot6_t *ctx, char *service_center_number, char *phone_number, char *sms_text)
Send SMS message to number in pdu mode.
lteiot6_set_rst
void lteiot6_set_rst(lteiot6_t *ctx, uint8_t state)
Sets state of the RST pin.
lteiot6_cfg_t::tx_pin
pin_name_t tx_pin
Definition: lteiot6.h:174