lteiot9  2.0.0.0
lteiot9.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 LTEIOT9_H
29 #define LTEIOT9_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 LTEIOT9_CMD_AT "AT"
70 #define LTEIOT9_CMD_ATI "ATI"
71 #define LTEIOT9_CMD_CGMR "AT+CGMR"
72 #define LTEIOT9_CMD_CFUN "AT+CFUN"
73 #define LTEIOT9_CMD_CREG "AT+CREG"
74 #define LTEIOT9_CMD_CEREG "AT+CEREG"
75 #define LTEIOT9_CMD_CGDCONT "AT+CGDCONT"
76 #define LTEIOT9_CMD_CIMI "AT+CIMI"
77 #define LTEIOT9_CMD_CGATT "AT+CGATT"
78 #define LTEIOT9_CMD_CSQ "AT+CSQ"
79 #define LTEIOT9_CMD_CESQ "AT+CESQ"
80 #define LTEIOT9_CMD_COPS "AT+COPS"
81 #define LTEIOT9_CMD_URAT "AT+URAT"
82 #define LTEIOT9_CMD_UBANDMASK "AT+UBANDMASK"
83 #define LTEIOT9_CMD_URATCONF "AT+URATCONF"
84 #define LTEIOT9_CMD_UAUTHREQ "AT+UAUTHREQ"
85 #define LTEIOT9_CMD_UUICC "AT+UUICC"
86 #define LTEIOT9_CMD_UCGED "AT+UCGED"
87 #define LTEIOT9_CMD_UCELLINFO "AT+UCELLINFO"
88 #define LTEIOT9_CMD_UANTR "AT+UANTR"
89 #define LTEIOT9_CMD_CMGF "AT+CMGF"
90 
91  // lteiot9_reg
93 
108 #define LTEIOT9_GNSS_GPGGA "GPGGA"
109 #define LTEIOT9_GNSS_START '$'
110 #define LTEIOT9_GNSS_SEPARATOR ','
111 
116 #define LTEIOT9_GPGGA_LATITUDE 2
117 #define LTEIOT9_GPGGA_LONGITUDE 4
118 #define LTEIOT9_GPGGA_ALTITUDE 9
119 
124 #define LTEIOT9_SYSSTART "^SYSSTART"
125 
130 #define LTEIOT9_RSP_OK "OK"
131 #define LTEIOT9_RSP_ERROR "ERROR"
132 
138 #define DRV_TX_BUFFER_SIZE 200
139 #define DRV_RX_BUFFER_SIZE 500
140  // lteiot9_set
142 
157 #define LTEIOT9_MAP_MIKROBUS( cfg, mikrobus ) \
158  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
159  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
160  cfg.smi = MIKROBUS( mikrobus, MIKROBUS_AN ); \
161  cfg.on = MIKROBUS( mikrobus, MIKROBUS_RST ); \
162  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
163  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT );
164  // lteiot9_map // lteiot9
167 
172 typedef struct
173 {
174  // Output pins
175  digital_out_t smi;
176  digital_out_t on;
177  digital_out_t rts;
179  // Input pins
180  digital_in_t cts;
182  // Modules
183  uart_t uart;
185  // Buffers
186  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
187  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
189 } lteiot9_t;
190 
195 typedef struct
196 {
197  // Communication gpio pins
198  pin_name_t rx_pin;
199  pin_name_t tx_pin;
201  // Additional gpio pins
202  pin_name_t smi;
203  pin_name_t on;
204  pin_name_t cts;
205  pin_name_t rts;
207  // Static variable
208  uint32_t baud_rate;
210  uart_data_bits_t data_bit;
211  uart_parity_t parity_bit;
212  uart_stop_bits_t stop_bit;
214 } lteiot9_cfg_t;
215 
220 typedef enum
221 {
226 
228 
245 
260 err_t lteiot9_init ( lteiot9_t *ctx, lteiot9_cfg_t *cfg );
261 
276 
290 err_t lteiot9_generic_write ( lteiot9_t *ctx, char *data_buf, uint16_t len );
291 
305 err_t lteiot9_generic_read ( lteiot9_t *ctx, char *data_buf, uint16_t max_len );
306 
316 void lteiot9_set_pin_on ( lteiot9_t *ctx, uint8_t state );
317 
327 void lteiot9_send_cmd ( lteiot9_t *ctx, char *cmd );
328 
339 void lteiot9_send_cmd_with_parameter ( lteiot9_t *ctx, char *at_cmd_buf, char *param_buf );
340 
350 void lteiot9_send_cmd_check ( lteiot9_t *ctx, char *at_cmd_buf );
351 
361 void lteiot9_send_cmd_parameter_check ( lteiot9_t *ctx, char *at_cmd_buf );
362 
372 void lteiot9_set_sim_apn ( lteiot9_t *ctx, char *sim_apn );
373 
384 void lteiot9_send_text_message ( lteiot9_t *ctx, char *phone_number, char *message_context );
385 
386 
387 #ifdef __cplusplus
388 }
389 #endif
390 #endif // LTEIOT9_H
391  // lteiot9
393 
394 // ------------------------------------------------------------------------ END
lteiot9_cfg_t::on
pin_name_t on
Definition: lteiot9.h:203
lteiot9_set_sim_apn
void lteiot9_set_sim_apn(lteiot9_t *ctx, char *sim_apn)
Set sim card APN.
lteiot9_cfg_t::cts
pin_name_t cts
Definition: lteiot9.h:204
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
LTE IoT 9 driver buffer size.
Definition: lteiot9.h:138
lteiot9_send_cmd_parameter_check
void lteiot9_send_cmd_parameter_check(lteiot9_t *ctx, char *at_cmd_buf)
Check the command parameters.
lteiot9_cfg_t::smi
pin_name_t smi
Definition: lteiot9.h:202
lteiot9_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: lteiot9.h:210
lteiot9_cfg_t::baud_rate
uint32_t baud_rate
Definition: lteiot9.h:208
lteiot9_generic_read
err_t lteiot9_generic_read(lteiot9_t *ctx, char *data_buf, uint16_t max_len)
LTE IoT 9 data reading function.
lteiot9_send_cmd_with_parameter
void lteiot9_send_cmd_with_parameter(lteiot9_t *ctx, char *at_cmd_buf, char *param_buf)
Send command function with parameter.
lteiot9_t
LTE IoT 9 Click context object.
Definition: lteiot9.h:173
lteiot9_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: lteiot9.h:212
lteiot9_t::uart
uart_t uart
Definition: lteiot9.h:183
lteiot9_send_cmd_check
void lteiot9_send_cmd_check(lteiot9_t *ctx, char *at_cmd_buf)
Check the sent command.
lteiot9_return_value_t
lteiot9_return_value_t
LTE IoT 9 Click return value data.
Definition: lteiot9.h:221
LTEIOT9_ERROR_TIMEOUT
@ LTEIOT9_ERROR_TIMEOUT
Definition: lteiot9.h:225
LTEIOT9_OK
@ LTEIOT9_OK
Definition: lteiot9.h:222
lteiot9_set_pin_on
void lteiot9_set_pin_on(lteiot9_t *ctx, uint8_t state)
Set ON pin state.
lteiot9_generic_write
err_t lteiot9_generic_write(lteiot9_t *ctx, char *data_buf, uint16_t len)
LTE IoT 9 data writing function.
lteiot9_init
err_t lteiot9_init(lteiot9_t *ctx, lteiot9_cfg_t *cfg)
LTE IoT 9 initialization function.
lteiot9_send_text_message
void lteiot9_send_text_message(lteiot9_t *ctx, char *phone_number, char *message_context)
LTE IoT 9 send text message.
lteiot9_cfg_t::rx_pin
pin_name_t rx_pin
Definition: lteiot9.h:198
lteiot9_cfg_t
LTE IoT 9 Click configuration object.
Definition: lteiot9.h:196
LTEIOT9_ERROR_OVERFLOW
@ LTEIOT9_ERROR_OVERFLOW
Definition: lteiot9.h:224
lteiot9_t::rts
digital_out_t rts
Definition: lteiot9.h:177
lteiot9_cfg_t::tx_pin
pin_name_t tx_pin
Definition: lteiot9.h:199
lteiot9_cfg_setup
void lteiot9_cfg_setup(lteiot9_cfg_t *cfg)
LTE IoT 9 configuration object setup function.
lteiot9_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: lteiot9.h:211
lteiot9_t::smi
digital_out_t smi
Definition: lteiot9.h:175
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: lteiot9.h:139
lteiot9_t::cts
digital_in_t cts
Definition: lteiot9.h:180
lteiot9_cfg_t::uart_blocking
bool uart_blocking
Definition: lteiot9.h:209
lteiot9_cfg_t::rts
pin_name_t rts
Definition: lteiot9.h:205
lteiot9_t::on
digital_out_t on
Definition: lteiot9.h:176
LTEIOT9_ERROR
@ LTEIOT9_ERROR
Definition: lteiot9.h:223
lteiot9_send_cmd
void lteiot9_send_cmd(lteiot9_t *ctx, char *cmd)
Send command function.
lteiot9_default_cfg
err_t lteiot9_default_cfg(lteiot9_t *ctx)
LTE IoT 9 default configuration function.