lteiot 2.0.0.0
lteiot.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef LTEIOT_H
36#define LTEIOT_H
37
38#include "drv_digital_out.h"
39#include "drv_digital_in.h"
40#include "drv_uart.h"
41
42// -------------------------------------------------------------- PUBLIC MACROS
52#define LTEIOT_MAP_MIKROBUS( cfg, mikrobus ) \
53 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
54 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
55 cfg.pwr = MIKROBUS( mikrobus, MIKROBUS_AN ); \
56 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
57 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
58 cfg.ri = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
59 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT )
66#define LTEIOT_RETVAL uint8_t
67
68#define LTEIOT_OK 0x00
69#define LTEIOT_INIT_ERROR 0xFF
76#define LTEIOT_MODULE_POWER_ON 1
77#define LTEIOT_MODULE_POWER_OFF 0
84#define LTEIOT_CMD_AT "AT"
85#define LTEIOT_CMD_ATI "ATI"
86#define LTEIOT_CMD_CGMR "AT+CGMR"
87
88#define LTEIOT_CMD_CFUN "AT+CFUN"
89#define LTEIOT_CMD_CREG "AT+CREG"
90#define LTEIOT_CMD_CEREG "AT+CEREG"
91#define LTEIOT_CMD_CGDCONT "AT+CGDCONT"
92#define LTEIOT_CMD_CIMI "AT+CIMI"
93#define LTEIOT_CMD_CGATT "AT+CGATT"
94#define LTEIOT_CMD_CSQ "AT+CSQ"
95#define LTEIOT_CMD_CESQ "AT+CESQ"
96#define LTEIOT_CMD_COPS "AT+COPS"
103#define DRV_RX_BUFFER_SIZE 500
104#define DRV_TX_BUFFER_SIZE 100 // End group macro
108// --------------------------------------------------------------- PUBLIC TYPES
116typedef struct
117{
118 // Output pins
119
120 digital_out_t pwr;
121 digital_out_t rst;
122 digital_out_t rts;
123
124 // Input pins
125
126 digital_in_t ri;
127 digital_in_t cts;
128
129 // Modules
130
131 uart_t uart;
132
133 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
134 char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
135
136} lteiot_t;
137
141typedef struct
142{
143 // Communication gpio pins
144
145 pin_name_t rx_pin;
146 pin_name_t tx_pin;
147
148 // Additional gpio pins
149
150 pin_name_t pwr;
151 pin_name_t rst;
152 pin_name_t cts;
153 pin_name_t ri;
154 pin_name_t rts;
155
156 // static variable
157
158 uint32_t baud_rate; // Clock speed.
160 uart_data_bits_t data_bit; // Data bits.
161 uart_parity_t parity_bit; // Parity bit.
162 uart_stop_bits_t stop_bit; // Stop bits.
163
165 // End types group
167// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
168
174#ifdef __cplusplus
175extern "C"{
176#endif
177
188
203err_t lteiot_init ( lteiot_t *ctx, lteiot_cfg_t *cfg );
204
218err_t lteiot_generic_write ( lteiot_t *ctx, char *data_buf, uint16_t len );
219
233err_t lteiot_generic_read ( lteiot_t *ctx, char *data_buf, uint16_t max_len );
234
243
252void lteiot_set_rst ( lteiot_t *ctx, uint8_t state );
253
262void lteiot_set_rts ( lteiot_t *ctx, uint8_t state );
263
272uint8_t lteiot_get_cts ( lteiot_t *ctx );
273
283void lteiot_send_cmd ( lteiot_t *ctx, char *cmd );
284
295void lteiot_send_cmd_with_parameter ( lteiot_t *ctx, char *at_cmd_buf, char *param_buf );
296
306void lteiot_send_cmd_check ( lteiot_t *ctx, char *at_cmd_buf );
307
317void lteiot_send_cmd_parameter_check ( lteiot_t *ctx, char *at_cmd_buf );
318
328void lteiot_set_sim_apn ( lteiot_t *ctx, char *sim_apn );
329
340void lteiot_send_text_message ( lteiot_t *ctx, char *phone_number, char *message_context );
341
342#ifdef __cplusplus
343}
344#endif
345#endif // _LTEIOT_H_
346 // End public_function group
349
350// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition: lteiot.h:103
#define DRV_TX_BUFFER_SIZE
Definition: lteiot.h:104
void lteiot_set_sim_apn(lteiot_t *ctx, char *sim_apn)
Set sim card APN.
void lteiot_send_text_message(lteiot_t *ctx, char *phone_number, char *message_context)
LTE IoT send text message.
void lteiot_send_cmd_check(lteiot_t *ctx, char *at_cmd_buf)
Check the sent command.
err_t lteiot_init(lteiot_t *ctx, lteiot_cfg_t *cfg)
LTE IoT initialization function.
uint8_t lteiot_get_cts(lteiot_t *ctx)
CTS Pin Get function.
void lteiot_send_cmd_parameter_check(lteiot_t *ctx, char *at_cmd_buf)
Check the command parameters.
void lteiot_cfg_setup(lteiot_cfg_t *cfg)
LTE IoT configuration object setup function.
void lteiot_send_cmd_with_parameter(lteiot_t *ctx, char *at_cmd_buf, char *param_buf)
Send command function with parameter.
err_t lteiot_generic_read(lteiot_t *ctx, char *data_buf, uint16_t max_len)
LTE IoT data reading function.
void lteiot_set_rts(lteiot_t *ctx, uint8_t state)
Sets state of the RTS pin.
void lteiot_send_cmd(lteiot_t *ctx, char *cmd)
Send command function.
void lteiot_power_on(lteiot_t *ctx)
LTE IoT module power on.
err_t lteiot_generic_write(lteiot_t *ctx, char *data_buf, uint16_t len)
LTE IoT data writing function.
void lteiot_set_rst(lteiot_t *ctx, uint8_t state)
Sets state of the RST pin.
Click configuration structure definition.
Definition: lteiot.h:142
pin_name_t rts
Definition: lteiot.h:154
uint32_t baud_rate
Definition: lteiot.h:158
pin_name_t cts
Definition: lteiot.h:152
bool uart_blocking
Definition: lteiot.h:159
pin_name_t ri
Definition: lteiot.h:153
uart_data_bits_t data_bit
Definition: lteiot.h:160
pin_name_t tx_pin
Definition: lteiot.h:146
pin_name_t pwr
Definition: lteiot.h:150
pin_name_t rx_pin
Definition: lteiot.h:145
uart_stop_bits_t stop_bit
Definition: lteiot.h:162
uart_parity_t parity_bit
Definition: lteiot.h:161
pin_name_t rst
Definition: lteiot.h:151
Click ctx object definition.
Definition: lteiot.h:117
digital_out_t pwr
Definition: lteiot.h:120
digital_out_t rts
Definition: lteiot.h:122
digital_in_t ri
Definition: lteiot.h:126
uart_t uart
Definition: lteiot.h:131
digital_in_t cts
Definition: lteiot.h:127
digital_out_t rst
Definition: lteiot.h:121