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 
31 #include "drv_digital_out.h"
32 #include "drv_digital_in.h"
33 #include "drv_uart.h"
34 
35 
56 #define LTEIOT6_CMD_AT "AT"
57 #define LTEIOT6_CMD_ATI "ATI"
58 
59 #define LTEIOT6_CMD_CFUN "AT+CFUN"
60 #define LTEIOT6_CMD_CREG "AT+CREG"
61 #define LTEIOT6_CMD_CGDCONT "AT+CGDCONT"
62 #define LTEIOT6_CMD_CIMI "AT+CIMI"
63 #define LTEIOT6_CMD_CGATT "AT+CGATT"
64 #define LTEIOT6_CMD_CSQ "AT+CSQ"
65 #define LTEIOT6_CMD_COPS "AT+COPS"
66  // lteiot6_reg
68 
83 #define LTEIOT6_SET_DESCRIPTION 0x00
84 
85 #define LTEIOT6_MOBILE_OPERATOR_APN "vpi.iot"
86 
91 #define DRV_BUFFER_SIZE 500
92  // lteiot6_set
94 
109 #define LTEIOT6_MAP_MIKROBUS( cfg, mikrobus ) \
110  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
111  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
112  cfg.pwr = MIKROBUS( mikrobus, MIKROBUS_AN ); \
113  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
114  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
115  cfg.ri = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
116  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT );
117  // lteiot6_map // lteiot6
120 
125 typedef struct
126 {
127  // Output pins
128  digital_out_t pwr;
129  digital_out_t rst;
130  digital_out_t rts;
131 
132  // Input pins
133  digital_in_t ri;
134  digital_in_t cts;
135 
136  // Modules
137 
138  uart_t uart;
139 
140  char uart_rx_buffer[ DRV_BUFFER_SIZE ];
141  char uart_tx_buffer[ DRV_BUFFER_SIZE ];
142 
143 } lteiot6_t;
144 
149 typedef struct
150 {
151  // Communication gpio pins
152  pin_name_t rx_pin;
153  pin_name_t tx_pin;
154 
155  // Additional gpio pins
156  pin_name_t pwr;
157  pin_name_t rst;
158  pin_name_t rts;
159  pin_name_t ri;
160  pin_name_t cts;
161 
162  // static variable
163  uint32_t baud_rate; // Clock speed.
164  bool uart_blocking;
165  uart_data_bits_t data_bit; // Data bits.
166  uart_parity_t parity_bit; // Parity bit.
167  uart_stop_bits_t stop_bit; // Stop bits.
168 
169 } lteiot6_cfg_t;
170 
177 #ifdef __cplusplus
178 extern "C"{
179 #endif
180 
190 void lteiot6_cfg_setup ( lteiot6_cfg_t *cfg );
191 
206 err_t lteiot6_init ( lteiot6_t *ctx, lteiot6_cfg_t *cfg );
207 
221 err_t lteiot6_generic_write ( lteiot6_t *ctx, char *data_buf, uint16_t len );
222 
236 err_t lteiot6_generic_read ( lteiot6_t *ctx, char *data_buf, uint16_t max_len );
237 
245 void lteiot6_power_on ( lteiot6_t *ctx );
246 
254 void lteiot6_reset ( lteiot6_t *ctx );
255 
264 void lteiot6_set_pwr ( lteiot6_t *ctx, uint8_t state );
265 
274 void lteiot6_set_rst ( lteiot6_t *ctx, uint8_t state );
275 
284 void lteiot6_set_rts ( lteiot6_t *ctx, uint8_t state );
285 
294 uint8_t lteiot6_get_ri ( lteiot6_t *ctx );
295 
304 uint8_t lteiot6_get_cts ( lteiot6_t *ctx );
305 
317 void lteiot6_send_cmd ( lteiot6_t *ctx, char *cmd );
318 
331 void lteiot6_send_cmd_with_parameter ( lteiot6_t *ctx, char *at_cmd_buf, char *param_buf );
332 
344 void lteiot6_send_cmd_check ( lteiot6_t *ctx, char *at_cmd_buf );
345 
357 void lteiot6_send_cmd_parameter_check ( lteiot6_t *ctx, char *at_cmd_buf );
358 
370 void lteiot6_set_sim_apn ( lteiot6_t *ctx, char *sim_apn );
371 
382 void lteiot6_send_text_message ( lteiot6_t *ctx, char *phone_number, char *message_context );
383 
384 #ifdef __cplusplus
385 }
386 #endif
387 #endif // LTEIOT6_H
388  // lteiot6
390 
391 // ------------------------------------------------------------------------ END
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_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_send_cmd
void lteiot6_send_cmd(lteiot6_t *ctx, char *cmd)
Send command function.
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:124
lteiot6_set_pwr
void lteiot6_set_pwr(lteiot6_t *ctx, uint8_t state)
Sets state of the PWR pin.
lteiot6_cfg_t
LTE IoT 6 Click configuration object.
Definition: lteiot6.h:148
DRV_BUFFER_SIZE
#define DRV_BUFFER_SIZE
LTE IoT 6 driver buffer size.
Definition: lteiot6.h:90
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_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.
lteiot6_power_on
void lteiot6_power_on(lteiot6_t *ctx)
LTE IoT 6 power on.
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_send_text_message
void lteiot6_send_text_message(lteiot6_t *ctx, char *phone_number, char *message_context)
LTE IoT 6 send text message.
lteiot6_reset
void lteiot6_reset(lteiot6_t *ctx)
LTE IoT 6 power on.
lteiot6_set_rst
void lteiot6_set_rst(lteiot6_t *ctx, uint8_t state)
Sets state of the RST pin.