lteiot8  2.0.0.0
lteiot8.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 LTEIOT8_H
29 #define LTEIOT8_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 LTEIOT8_CMD_AT "AT"
70 #define LTEIOT8_CMD_ATI "ATI"
71 #define LTEIOT8_CMD_CGMR "AT+CGMR"
72 #define LTEIOT8_CMD_CFUN "AT+CFUN"
73 #define LTEIOT8_CMD_CREG "AT+CREG"
74 #define LTEIOT8_CMD_CEREG "AT+CEREG"
75 #define LTEIOT8_CMD_CGDCONT "AT+CGDCONT"
76 #define LTEIOT8_CMD_CIMI "AT+CIMI"
77 #define LTEIOT8_CMD_CGATT "AT+CGATT"
78 #define LTEIOT8_CMD_CSQ "AT+CSQ"
79 #define LTEIOT8_CMD_CESQ "AT+CESQ"
80 #define LTEIOT8_CMD_COPS "AT+COPS"
81 #define LTEIOT8_CMD_CMGF "AT+CMGF"
82 #define LTEIOT8_CMD_CMGS "AT+CMGS"
83 #define LTEIOT8_CMD_CSCA "AT+CSCA"
84 #define LTEIOT8_CMD_SQNLED "AT+SQNLED"
85  // lteiot8_cmd
87 
102 #define LTEIOT8_RSP_OK "OK"
103 #define LTEIOT8_RSP_ERROR "ERROR"
104 #define LTEIOT8_RSP_SYSTART "+SYSSTART"
105 
111 #define DRV_TX_BUFFER_SIZE 200
112 #define DRV_RX_BUFFER_SIZE 500
113  // lteiot8_set
115 
130 #define LTEIOT8_MAP_MIKROBUS( cfg, mikrobus ) \
131  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
132  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
133  cfg.rng = MIKROBUS( mikrobus, MIKROBUS_AN ); \
134  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
135  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
136  cfg.pst = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
137  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT );
138  // lteiot8_map // lteiot8
141 
146 typedef struct
147 {
148  // Output pins
149  digital_out_t rst;
150  digital_out_t cts;
152  // Input pins
153  digital_in_t rng;
154  digital_in_t pst;
155  digital_in_t rts;
157  // Modules
158  uart_t uart;
160  // Buffers
161  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
162  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
164 } lteiot8_t;
165 
170 typedef struct
171 {
172  // Communication gpio pins
173  pin_name_t rx_pin;
174  pin_name_t tx_pin;
176  // Additional gpio pins
177  pin_name_t rng;
178  pin_name_t rst;
179  pin_name_t cts;
180  pin_name_t pst;
181  pin_name_t rts;
183  // Static variable
184 
185  uint32_t baud_rate;
187  uart_data_bits_t data_bit;
188  uart_parity_t parity_bit;
189  uart_stop_bits_t stop_bit;
191 } lteiot8_cfg_t;
192 
197 typedef enum
198 {
204 
206 
223 
238 err_t lteiot8_init ( lteiot8_t *ctx, lteiot8_cfg_t *cfg );
239 
254 
268 err_t lteiot8_generic_write ( lteiot8_t *ctx, char *data_buf, uint16_t len );
269 
283 err_t lteiot8_generic_read ( lteiot8_t *ctx, char *data_buf, uint16_t max_len );
284 
294 void lteiot8_send_cmd ( lteiot8_t *ctx, char *cmd );
295 
307 void lteiot8_send_cmd_with_parameter ( lteiot8_t *ctx, char *at_cmd_buf, char *param_buf );
308 
318 void lteiot8_send_cmd_check ( lteiot8_t *ctx, char *at_cmd_buf );
319 
329 void lteiot8_send_cmd_syntax_check ( lteiot8_t *ctx, char *at_cmd_buf );
330 
340 void lteiot8_set_sim_apn ( lteiot8_t *ctx, char *sim_apn );
341 
354 void lteiot8_send_text_message ( lteiot8_t *ctx, char *phone_number, char *message_content );
355 
369 err_t lteiot8_send_sms_pdu ( lteiot8_t *ctx, char *service_center_number, char *phone_number, char *sms_text );
370 
371 #ifdef __cplusplus
372 }
373 #endif
374 #endif // LTEIOT8_H
375  // lteiot8
377 
378 // ------------------------------------------------------------------------ END
lteiot8_send_cmd_with_parameter
void lteiot8_send_cmd_with_parameter(lteiot8_t *ctx, char *at_cmd_buf, char *param_buf)
Send command with parameters.
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
LTE IoT 8 driver buffer size.
Definition: lteiot8.h:111
lteiot8_t::rst
digital_out_t rst
Definition: lteiot8.h:149
lteiot8_cfg_t::rst
pin_name_t rst
Definition: lteiot8.h:178
lteiot8_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: lteiot8.h:187
lteiot8_send_cmd
void lteiot8_send_cmd(lteiot8_t *ctx, char *cmd)
Send command function.
lteiot8_cfg_t::cts
pin_name_t cts
Definition: lteiot8.h:179
LTEIOT8_OK
@ LTEIOT8_OK
Definition: lteiot8.h:199
lteiot8_set_sim_apn
void lteiot8_set_sim_apn(lteiot8_t *ctx, char *sim_apn)
Set SIM APN.
lteiot8_t::rng
digital_in_t rng
Definition: lteiot8.h:153
lteiot8_send_text_message
void lteiot8_send_text_message(lteiot8_t *ctx, char *phone_number, char *message_content)
Send SMS message to number in text mode.
lteiot8_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: lteiot8.h:189
LTEIOT8_ERROR_TIMEOUT
@ LTEIOT8_ERROR_TIMEOUT
Definition: lteiot8.h:201
lteiot8_send_cmd_check
void lteiot8_send_cmd_check(lteiot8_t *ctx, char *at_cmd_buf)
Send command to check commands current value.
lteiot8_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: lteiot8.h:188
lteiot8_t::pst
digital_in_t pst
Definition: lteiot8.h:154
lteiot8_default_cfg
err_t lteiot8_default_cfg(lteiot8_t *ctx)
LTE IoT 8 default configuration function.
lteiot8_cfg_t::pst
pin_name_t pst
Definition: lteiot8.h:180
lteiot8_cfg_setup
void lteiot8_cfg_setup(lteiot8_cfg_t *cfg)
LTE IoT 8 configuration object setup function.
lteiot8_cfg_t::uart_blocking
bool uart_blocking
Definition: lteiot8.h:186
lteiot8_cfg_t::baud_rate
uint32_t baud_rate
Definition: lteiot8.h:185
LTEIOT8_ERROR_UNKNOWN
@ LTEIOT8_ERROR_UNKNOWN
Definition: lteiot8.h:203
lteiot8_generic_write
err_t lteiot8_generic_write(lteiot8_t *ctx, char *data_buf, uint16_t len)
LTE IoT 8 data writing function.
lteiot8_cfg_t
LTE IoT 8 Click configuration object.
Definition: lteiot8.h:171
LTEIOT8_ERROR
@ LTEIOT8_ERROR
Definition: lteiot8.h:200
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: lteiot8.h:112
lteiot8_t::rts
digital_in_t rts
Definition: lteiot8.h:155
lteiot8_t
LTE IoT 8 Click context object.
Definition: lteiot8.h:147
lteiot8_cfg_t::tx_pin
pin_name_t tx_pin
Definition: lteiot8.h:174
lteiot8_cfg_t::rx_pin
pin_name_t rx_pin
Definition: lteiot8.h:173
lteiot8_return_value_t
lteiot8_return_value_t
LTE IoT 8 Click return value data.
Definition: lteiot8.h:198
lteiot8_send_cmd_syntax_check
void lteiot8_send_cmd_syntax_check(lteiot8_t *ctx, char *at_cmd_buf)
Send command to check commands available parameters.
lteiot8_cfg_t::rng
pin_name_t rng
Definition: lteiot8.h:177
lteiot8_cfg_t::rts
pin_name_t rts
Definition: lteiot8.h:181
lteiot8_t::cts
digital_out_t cts
Definition: lteiot8.h:150
lteiot8_t::uart
uart_t uart
Definition: lteiot8.h:158
lteiot8_init
err_t lteiot8_init(lteiot8_t *ctx, lteiot8_cfg_t *cfg)
LTE IoT 8 initialization function.
lteiot8_send_sms_pdu
err_t lteiot8_send_sms_pdu(lteiot8_t *ctx, char *service_center_number, char *phone_number, char *sms_text)
Send SMS message to number in pdu mode.
lteiot8_generic_read
err_t lteiot8_generic_read(lteiot8_t *ctx, char *data_buf, uint16_t max_len)
LTE IoT 8 data reading function.
LTEIOT8_ERROR_CMD
@ LTEIOT8_ERROR_CMD
Definition: lteiot8.h:202