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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_uart.h"
38 
59 #define LTEIOT9_CMD_AT "AT"
60 #define LTEIOT9_CMD_ATI "ATI"
61 #define LTEIOT9_CMD_CGMR "AT+CGMR"
62 #define LTEIOT9_CMD_CFUN "AT+CFUN"
63 #define LTEIOT9_CMD_CREG "AT+CREG"
64 #define LTEIOT9_CMD_CEREG "AT+CEREG"
65 #define LTEIOT9_CMD_CGDCONT "AT+CGDCONT"
66 #define LTEIOT9_CMD_CIMI "AT+CIMI"
67 #define LTEIOT9_CMD_CGATT "AT+CGATT"
68 #define LTEIOT9_CMD_CSQ "AT+CSQ"
69 #define LTEIOT9_CMD_CESQ "AT+CESQ"
70 #define LTEIOT9_CMD_COPS "AT+COPS"
71 #define LTEIOT9_CMD_URAT "AT+URAT"
72 #define LTEIOT9_CMD_UBANDMASK "AT+UBANDMASK"
73 #define LTEIOT9_CMD_URATCONF "AT+URATCONF"
74 #define LTEIOT9_CMD_UAUTHREQ "AT+UAUTHREQ"
75 #define LTEIOT9_CMD_UUICC "AT+UUICC"
76 #define LTEIOT9_CMD_UCGED "AT+UCGED"
77 #define LTEIOT9_CMD_UCELLINFO "AT+UCELLINFO"
78 #define LTEIOT9_CMD_UANTR "AT+UANTR"
79 #define LTEIOT9_CMD_CMGF "AT+CMGF"
80 
81  // lteiot9_reg
83 
98 #define LTEIOT9_GNSS_GPGGA "GPGGA"
99 #define LTEIOT9_GNSS_START '$'
100 #define LTEIOT9_GNSS_SEPARATOR ','
101 
106 #define LTEIOT9_GPGGA_LATITUDE 2
107 #define LTEIOT9_GPGGA_LONGITUDE 4
108 #define LTEIOT9_GPGGA_ALTITUDE 9
109 
114 #define LTEIOT9_SYSSTART "^SYSSTART"
115 
120 #define LTEIOT9_RSP_OK "OK"
121 #define LTEIOT9_RSP_ERROR "ERROR"
122 
128 #define DRV_TX_BUFFER_SIZE 200
129 #define DRV_RX_BUFFER_SIZE 500
130  // lteiot9_set
132 
147 #define LTEIOT9_MAP_MIKROBUS( cfg, mikrobus ) \
148  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
149  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
150  cfg.smi = MIKROBUS( mikrobus, MIKROBUS_AN ); \
151  cfg.on = MIKROBUS( mikrobus, MIKROBUS_RST ); \
152  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
153  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT );
154  // lteiot9_map // lteiot9
157 
162 typedef struct
163 {
164  // Output pins
165  digital_out_t smi;
166  digital_out_t on;
167  digital_out_t rts;
169  // Input pins
170  digital_in_t cts;
172  // Modules
173  uart_t uart;
175  // Buffers
176  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
177  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
179 } lteiot9_t;
180 
185 typedef struct
186 {
187  // Communication gpio pins
188  pin_name_t rx_pin;
189  pin_name_t tx_pin;
191  // Additional gpio pins
192  pin_name_t smi;
193  pin_name_t on;
194  pin_name_t cts;
195  pin_name_t rts;
197  // Static variable
198  uint32_t baud_rate;
200  uart_data_bits_t data_bit;
201  uart_parity_t parity_bit;
202  uart_stop_bits_t stop_bit;
204 } lteiot9_cfg_t;
205 
210 typedef enum
211 {
216 
218 
235 
250 err_t lteiot9_init ( lteiot9_t *ctx, lteiot9_cfg_t *cfg );
251 
266 
280 err_t lteiot9_generic_write ( lteiot9_t *ctx, char *data_buf, uint16_t len );
281 
295 err_t lteiot9_generic_read ( lteiot9_t *ctx, char *data_buf, uint16_t max_len );
296 
306 void lteiot9_set_pin_on ( lteiot9_t *ctx, uint8_t state );
307 
317 void lteiot9_send_cmd ( lteiot9_t *ctx, char *cmd );
318 
329 void lteiot9_send_cmd_with_parameter ( lteiot9_t *ctx, char *at_cmd_buf, char *param_buf );
330 
340 void lteiot9_send_cmd_check ( lteiot9_t *ctx, char *at_cmd_buf );
341 
351 void lteiot9_send_cmd_parameter_check ( lteiot9_t *ctx, char *at_cmd_buf );
352 
362 void lteiot9_set_sim_apn ( lteiot9_t *ctx, char *sim_apn );
363 
374 void lteiot9_send_text_message ( lteiot9_t *ctx, char *phone_number, char *message_context );
375 
376 
377 #ifdef __cplusplus
378 }
379 #endif
380 #endif // LTEIOT9_H
381  // lteiot9
383 
384 // ------------------------------------------------------------------------ END
lteiot9_cfg_t::on
pin_name_t on
Definition: lteiot9.h:193
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:194
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
LTE IoT 9 driver buffer size.
Definition: lteiot9.h:128
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:192
lteiot9_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: lteiot9.h:200
lteiot9_cfg_t::baud_rate
uint32_t baud_rate
Definition: lteiot9.h:198
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:163
lteiot9_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: lteiot9.h:202
lteiot9_t::uart
uart_t uart
Definition: lteiot9.h:173
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:211
LTEIOT9_ERROR_TIMEOUT
@ LTEIOT9_ERROR_TIMEOUT
Definition: lteiot9.h:215
LTEIOT9_OK
@ LTEIOT9_OK
Definition: lteiot9.h:212
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:188
lteiot9_cfg_t
LTE IoT 9 Click configuration object.
Definition: lteiot9.h:186
LTEIOT9_ERROR_OVERFLOW
@ LTEIOT9_ERROR_OVERFLOW
Definition: lteiot9.h:214
lteiot9_t::rts
digital_out_t rts
Definition: lteiot9.h:167
lteiot9_cfg_t::tx_pin
pin_name_t tx_pin
Definition: lteiot9.h:189
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:201
lteiot9_t::smi
digital_out_t smi
Definition: lteiot9.h:165
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: lteiot9.h:129
lteiot9_t::cts
digital_in_t cts
Definition: lteiot9.h:170
lteiot9_cfg_t::uart_blocking
bool uart_blocking
Definition: lteiot9.h:199
lteiot9_cfg_t::rts
pin_name_t rts
Definition: lteiot9.h:195
lteiot9_t::on
digital_out_t on
Definition: lteiot9.h:166
LTEIOT9_ERROR
@ LTEIOT9_ERROR
Definition: lteiot9.h:213
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.