lteiot3  2.0.0.0
lteiot3.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 LTEIOT3_H
29 #define LTEIOT3_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_uart.h"
38 
59 #define LTEIOT3_CMD_AT "AT"
60 #define LTEIOT3_CMD_ATI "ATI"
61 #define LTEIOT3_CMD_CGMR "AT+CGMR"
62 #define LTEIOT3_CMD_CFUN "AT+CFUN"
63 #define LTEIOT3_CMD_CREG "AT+CREG"
64 #define LTEIOT3_CMD_CEREG "AT+CEREG"
65 #define LTEIOT3_CMD_CGDCONT "AT+CGDCONT"
66 #define LTEIOT3_CMD_CIMI "AT+CIMI"
67 #define LTEIOT3_CMD_CGATT "AT+CGATT"
68 #define LTEIOT3_CMD_CSQ "AT+CSQ"
69 #define LTEIOT3_CMD_CESQ "AT+CESQ"
70 #define LTEIOT3_CMD_COPS "AT+COPS"
71 #define LTEIOT3_CMD_URAT "AT+URAT"
72 #define LTEIOT3_CMD_UBANDMASK "AT+UBANDMASK"
73 #define LTEIOT3_CMD_URATCONF "AT+URATCONF"
74 #define LTEIOT3_CMD_UAUTHREQ "AT+UAUTHREQ"
75 #define LTEIOT3_CMD_UUICC "AT+UUICC"
76 #define LTEIOT3_CMD_UCGED "AT+UCGED"
77 #define LTEIOT3_CMD_UCELLINFO "AT+UCELLINFO"
78 #define LTEIOT3_CMD_UANTR "AT+UANTR"
79 #define LTEIOT3_CMD_CMGF "AT+CMGF"
80 
85 #define LTEIOT3_GNSS_GPGGA "GPGGA"
86 #define LTEIOT3_GNSS_START '$'
87 #define LTEIOT3_GNSS_SEPARATOR ','
88 
93 #define LTEIOT3_GPGGA_LATITUDE 2
94 #define LTEIOT3_GPGGA_LONGITUDE 4
95 #define LTEIOT3_GPGGA_ALTITUDE 9
96 
101 #define LTEIOT3_SYSSTART "^SYSSTART"
102 
107 #define LTEIOT3_RSP_OK "OK"
108 #define LTEIOT3_RSP_ERROR "ERROR"
109 
115 #define DRV_TX_BUFFER_SIZE 200
116 #define DRV_RX_BUFFER_SIZE 550
117  // lteiot3_cmd
119 
134 #define LTEIOT3_MAP_MIKROBUS( cfg, mikrobus ) \
135  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
136  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
137  cfg.smi = MIKROBUS( mikrobus, MIKROBUS_AN ); \
138  cfg.on = MIKROBUS( mikrobus, MIKROBUS_RST ); \
139  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
140  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
141  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT );
142  // lteiot3_map // lteiot3
145 
150 typedef struct
151 {
152  // Output pins
153  digital_out_t smi;
154  digital_out_t on;
155  digital_out_t cs;
156  digital_out_t rts;
158  // Input pins
159  digital_in_t cts;
161  // Modules
162  uart_t uart;
164  // Buffers
165  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
166  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
168 } lteiot3_t;
169 
174 typedef struct
175 {
176  // Communication gpio pins
177  pin_name_t rx_pin;
178  pin_name_t tx_pin;
180  // Additional gpio pins
181  pin_name_t smi;
182  pin_name_t on;
183  pin_name_t cts;
184  pin_name_t cs;
185  pin_name_t rts;
187  // Static variable
188  uint32_t baud_rate;
190  uart_data_bits_t data_bit;
191  uart_parity_t parity_bit;
192  uart_stop_bits_t stop_bit;
194 } lteiot3_cfg_t;
195 
200 typedef enum
201 {
206 
208 
225 
239 err_t lteiot3_init ( lteiot3_t *ctx, lteiot3_cfg_t *cfg );
240 
255 
268 err_t lteiot3_generic_write ( lteiot3_t *ctx, char *data_buf, uint16_t len );
269 
282 err_t lteiot3_generic_read ( lteiot3_t *ctx, char *data_buf, uint16_t max_len );
283 
292 void lteiot3_set_pin_on ( lteiot3_t *ctx, uint8_t state );
293 
302 void lteiot3_send_cmd ( lteiot3_t *ctx, char *cmd );
303 
313 void lteiot3_send_cmd_with_parameter ( lteiot3_t *ctx, char *at_cmd_buf, char *param_buf );
314 
323 void lteiot3_send_cmd_check ( lteiot3_t *ctx, char *at_cmd_buf );
324 
333 void lteiot3_send_cmd_parameter_check ( lteiot3_t *ctx, char *at_cmd_buf );
334 
343 void lteiot3_set_sim_apn ( lteiot3_t *ctx, char *sim_apn );
344 
354 void lteiot3_send_text_message ( lteiot3_t *ctx, char *phone_number, char *message_context );
355 
356 #ifdef __cplusplus
357 }
358 #endif
359 #endif // LTEIOT3_H
360  // lteiot3
362 
363 // ------------------------------------------------------------------------ END
lteiot3_send_cmd_parameter_check
void lteiot3_send_cmd_parameter_check(lteiot3_t *ctx, char *at_cmd_buf)
Check the command parameters.
lteiot3_cfg_t::smi
pin_name_t smi
Definition: lteiot3.h:181
lteiot3_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: lteiot3.h:190
lteiot3_t::smi
digital_out_t smi
Definition: lteiot3.h:153
lteiot3_t::cts
digital_in_t cts
Definition: lteiot3.h:159
lteiot3_send_text_message
void lteiot3_send_text_message(lteiot3_t *ctx, char *phone_number, char *message_context)
LTE IoT 3 send text message.
lteiot3_send_cmd_check
void lteiot3_send_cmd_check(lteiot3_t *ctx, char *at_cmd_buf)
Check the sent command.
lteiot3_t
LTE IoT 3 Click context object.
Definition: lteiot3.h:151
lteiot3_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: lteiot3.h:192
lteiot3_generic_read
err_t lteiot3_generic_read(lteiot3_t *ctx, char *data_buf, uint16_t max_len)
LTE IoT 3 data reading function.
lteiot3_cfg_t::cs
pin_name_t cs
Definition: lteiot3.h:184
lteiot3_generic_write
err_t lteiot3_generic_write(lteiot3_t *ctx, char *data_buf, uint16_t len)
LTE IoT 3 data writing function.
lteiot3_t::on
digital_out_t on
Definition: lteiot3.h:154
lteiot3_default_cfg
err_t lteiot3_default_cfg(lteiot3_t *ctx)
LTE IoT 3 default configuration function.
lteiot3_return_value_t
lteiot3_return_value_t
LTE IoT 3 Click return value data.
Definition: lteiot3.h:201
lteiot3_send_cmd
void lteiot3_send_cmd(lteiot3_t *ctx, char *cmd)
Send command function.
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
LTE IoT 3 driver buffer size.
Definition: lteiot3.h:115
lteiot3_cfg_t::tx_pin
pin_name_t tx_pin
Definition: lteiot3.h:178
lteiot3_set_pin_on
void lteiot3_set_pin_on(lteiot3_t *ctx, uint8_t state)
Set ON pin state.
lteiot3_cfg_t
LTE IoT 3 Click configuration object.
Definition: lteiot3.h:175
LTEIOT3_ERROR_TIMEOUT
@ LTEIOT3_ERROR_TIMEOUT
Definition: lteiot3.h:205
LTEIOT3_ERROR_OVERFLOW
@ LTEIOT3_ERROR_OVERFLOW
Definition: lteiot3.h:204
lteiot3_t::uart
uart_t uart
Definition: lteiot3.h:162
lteiot3_cfg_t::rts
pin_name_t rts
Definition: lteiot3.h:185
lteiot3_cfg_t::on
pin_name_t on
Definition: lteiot3.h:182
lteiot3_cfg_t::cts
pin_name_t cts
Definition: lteiot3.h:183
lteiot3_t::cs
digital_out_t cs
Definition: lteiot3.h:155
lteiot3_cfg_t::rx_pin
pin_name_t rx_pin
Definition: lteiot3.h:177
lteiot3_cfg_setup
void lteiot3_cfg_setup(lteiot3_cfg_t *cfg)
LTE IoT 3 configuration object setup function.
lteiot3_set_sim_apn
void lteiot3_set_sim_apn(lteiot3_t *ctx, char *sim_apn)
Set sim card APN.
lteiot3_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: lteiot3.h:191
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: lteiot3.h:116
lteiot3_send_cmd_with_parameter
void lteiot3_send_cmd_with_parameter(lteiot3_t *ctx, char *at_cmd_buf, char *param_buf)
Send command function with parameter.
lteiot3_t::rts
digital_out_t rts
Definition: lteiot3.h:156
LTEIOT3_OK
@ LTEIOT3_OK
Definition: lteiot3.h:202
lteiot3_cfg_t::baud_rate
uint32_t baud_rate
Definition: lteiot3.h:188
lteiot3_cfg_t::uart_blocking
bool uart_blocking
Definition: lteiot3.h:189
lteiot3_init
err_t lteiot3_init(lteiot3_t *ctx, lteiot3_cfg_t *cfg)
LTE IoT 3 initialization function.
LTEIOT3_ERROR
@ LTEIOT3_ERROR
Definition: lteiot3.h:203