lteiot14  2.1.0.0
lteiot14.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 LTEIOT14_H
29 #define LTEIOT14_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_uart.h"
52 
73 #define LTEIOT14_CMD_AT "AT"
74 #define LTEIOT14_CMD_GET_MODEL_ID "AT+CGMM"
75 #define LTEIOT14_CMD_GET_SW_VERSION "AT+CGMR"
76 #define LTEIOT14_CMD_GET_SERIAL_NUM "AT+CGSN"
77 #define LTEIOT14_CMD_SET_PHONE_FUNCTIONALITY "AT+CFUN"
78 #define LTEIOT14_CMD_NETWORK_REGISTRATION "AT+CREG"
79 #define LTEIOT14_CMD_SIGNAL_QUALITY_REPORT "AT+CSQ"
80 #define LTEIOT14_CMD_OPERATOR_SELECTION "AT+COPS"
81 #define LTEIOT14_CMD_SEND_SMS "AT+CMGS"
82 #define LTEIOT14_CMD_SELECT_SMS_FORMAT "AT+CMGF"
83 #define LTEIOT14_CMD_DEFINE_PDP_CONTEXT "AT+CGDCONT"
84 #define LTEIOT14_CMD_ACTIVATE_PDP_CONTEXT "AT+CGACT"
85 #define LTEIOT14_CMD_SHOW_PDP_ADDRESS "AT+CGPADDR"
86 #define LTEIOT14_CMD_APP_NETWORK_ACTIVE "AT+CNACT"
87 #define LTEIOT14_CMD_SET_TCP_UDP_ID "AT+CACID"
88 #define LTEIOT14_CMD_OPEN_TCP_UDP_CONNECTION "AT+CAOPEN"
89 #define LTEIOT14_CMD_SEND_DATA_VIA_CONNECTION "AT+CASEND"
90 #define LTEIOT14_CMD_RECEIVE_DATA_VIA_CONNECTION "AT+CARECV"
91 #define LTEIOT14_CMD_CLOSE_TCP_UDP_CONNECTION "AT+CACLOSE"
92 #define LTEIOT14_CMD_GNSS_POWER_CONTROL "AT+CGNSPWR"
93 #define LTEIOT14_CMD_GET_GNSS_INFO "AT+CGNSINF"
94 
99 #define LTEIOT14_RSP_OK "OK"
100 #define LTEIOT14_RSP_ERROR "ERROR"
101 
106 #define LTEIOT14_URC_RECEIVED_DATA "+CADATAIND:"
107 #define LTEIOT14_URC_GNSS_INFO "+CGNSINF:"
108 
113 #define LTEIOT14_POWER_STATE_OFF 0
114 #define LTEIOT14_POWER_STATE_ON 1
115 #define LTEIOT14_POWER_STATE_RESET 2
116 
122 #define LTEIOT14_TX_DRV_BUFFER_SIZE 256
123 #define LTEIOT14_RX_DRV_BUFFER_SIZE 256
124  // lteiot14_cmd
126 
141 #define LTEIOT14_MAP_MIKROBUS( cfg, mikrobus ) \
142  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
143  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
144  cfg.pwr = MIKROBUS( mikrobus, MIKROBUS_AN ); \
145  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
146  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
147  cfg.ring = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
148  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT );
149  // lteiot14_map // lteiot14
152 
157 typedef struct
158 {
159  // Output pins
160  digital_out_t pwr;
161  digital_out_t rst;
162  digital_out_t rts;
164  // Input pins
165  digital_in_t ring;
166  digital_in_t cts;
168  // Modules
169  uart_t uart;
171  // Buffers
172  uint8_t uart_rx_buffer[ LTEIOT14_RX_DRV_BUFFER_SIZE ];
173  uint8_t uart_tx_buffer[ LTEIOT14_TX_DRV_BUFFER_SIZE ];
174  uint8_t cmd_buffer[ LTEIOT14_TX_DRV_BUFFER_SIZE ];
176 } lteiot14_t;
177 
182 typedef struct
183 {
184  // Communication gpio pins
185  pin_name_t rx_pin;
186  pin_name_t tx_pin;
188  // Additional gpio pins
189  pin_name_t pwr;
190  pin_name_t rst;
191  pin_name_t rts;
192  pin_name_t ring;
193  pin_name_t cts;
195  // Static variable
196  uint32_t baud_rate;
198  uart_data_bits_t data_bit;
199  uart_parity_t parity_bit;
200  uart_stop_bits_t stop_bit;
203 
208 typedef enum
209 {
215 
217 
234 
249 
262 err_t lteiot14_generic_write ( lteiot14_t *ctx, uint8_t *data_in, uint16_t len );
263 
276 err_t lteiot14_generic_read ( lteiot14_t *ctx, uint8_t *data_out, uint16_t len );
277 
287 void lteiot14_set_pwr_pin ( lteiot14_t *ctx, uint8_t state );
288 
298 void lteiot14_set_rst_pin ( lteiot14_t *ctx, uint8_t state );
299 
309 void lteiot14_set_rts_pin ( lteiot14_t *ctx, uint8_t state );
310 
320 
330 
342 void lteiot14_set_power_state ( lteiot14_t *ctx, uint8_t state );
343 
353 void lteiot14_send_cmd ( lteiot14_t *ctx, uint8_t *cmd );
354 
365 void lteiot14_send_cmd_par ( lteiot14_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf );
366 
376 void lteiot14_send_cmd_check ( lteiot14_t *ctx, uint8_t *at_cmd_buf );
377 
387 void lteiot14_set_sim_apn ( lteiot14_t *ctx, uint8_t *sim_apn );
388 
399 void lteiot14_send_sms_text ( lteiot14_t *ctx, uint8_t *phone_number, uint8_t *sms_text );
400 
414 err_t lteiot14_send_sms_pdu ( lteiot14_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text );
415 
416 #ifdef __cplusplus
417 }
418 #endif
419 #endif // LTEIOT14_H
420  // lteiot14
422 
423 // ------------------------------------------------------------------------ END
lteiot14_cfg_t::rts
pin_name_t rts
Definition: lteiot14.h:191
lteiot14_t::ring
digital_in_t ring
Definition: lteiot14.h:165
lteiot14_cfg_t::pwr
pin_name_t pwr
Definition: lteiot14.h:189
lteiot14_get_ring_pin
uint8_t lteiot14_get_ring_pin(lteiot14_t *ctx)
LTE IoT 14 get RING pin function.
lteiot14_send_cmd_par
void lteiot14_send_cmd_par(lteiot14_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf)
Send command function with parameter.
lteiot14_send_cmd
void lteiot14_send_cmd(lteiot14_t *ctx, uint8_t *cmd)
Send command function.
lteiot14_cfg_t::uart_blocking
bool uart_blocking
Definition: lteiot14.h:197
lteiot14_init
err_t lteiot14_init(lteiot14_t *ctx, lteiot14_cfg_t *cfg)
LTE IoT 14 initialization function.
LTEIOT14_ERROR_TIMEOUT
@ LTEIOT14_ERROR_TIMEOUT
Definition: lteiot14.h:212
LTEIOT14_RX_DRV_BUFFER_SIZE
#define LTEIOT14_RX_DRV_BUFFER_SIZE
Definition: lteiot14.h:123
lteiot14_cfg_t::tx_pin
pin_name_t tx_pin
Definition: lteiot14.h:186
lteiot14_t
LTE IoT 14 Click context object.
Definition: lteiot14.h:158
lteiot14_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: lteiot14.h:200
lteiot14_set_pwr_pin
void lteiot14_set_pwr_pin(lteiot14_t *ctx, uint8_t state)
LTE IoT 14 set PWR pin function.
LTEIOT14_ERROR_CMD
@ LTEIOT14_ERROR_CMD
Definition: lteiot14.h:213
lteiot14_t::uart
uart_t uart
Definition: lteiot14.h:169
lteiot14_t::rts
digital_out_t rts
Definition: lteiot14.h:162
lteiot14_return_value_t
lteiot14_return_value_t
LTE IoT 14 Click return value data.
Definition: lteiot14.h:209
lteiot14_generic_write
err_t lteiot14_generic_write(lteiot14_t *ctx, uint8_t *data_in, uint16_t len)
LTE IoT 14 data writing function.
lteiot14_set_sim_apn
void lteiot14_set_sim_apn(lteiot14_t *ctx, uint8_t *sim_apn)
Set sim card APN.
lteiot14_generic_read
err_t lteiot14_generic_read(lteiot14_t *ctx, uint8_t *data_out, uint16_t len)
LTE IoT 14 data reading function.
lteiot14_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: lteiot14.h:198
lteiot14_set_power_state
void lteiot14_set_power_state(lteiot14_t *ctx, uint8_t state)
LTE IoT 14 set power state function.
lteiot14_get_cts_pin
uint8_t lteiot14_get_cts_pin(lteiot14_t *ctx)
LTE IoT 14 get CTS pin function.
LTEIOT14_OK
@ LTEIOT14_OK
Definition: lteiot14.h:210
LTEIOT14_ERROR_UNKNOWN
@ LTEIOT14_ERROR_UNKNOWN
Definition: lteiot14.h:214
lteiot14_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: lteiot14.h:199
lteiot14_send_sms_pdu
err_t lteiot14_send_sms_pdu(lteiot14_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text)
LTE IoT 14 send SMS in PDU mode.
lteiot14_send_sms_text
void lteiot14_send_sms_text(lteiot14_t *ctx, uint8_t *phone_number, uint8_t *sms_text)
LTE IoT 14 send SMS in text mode.
LTEIOT14_TX_DRV_BUFFER_SIZE
#define LTEIOT14_TX_DRV_BUFFER_SIZE
LTE IoT 14 driver buffer size.
Definition: lteiot14.h:122
lteiot14_set_rts_pin
void lteiot14_set_rts_pin(lteiot14_t *ctx, uint8_t state)
LTE IoT 14 set RTS pin function.
lteiot14_cfg_t::rx_pin
pin_name_t rx_pin
Definition: lteiot14.h:185
lteiot14_t::rst
digital_out_t rst
Definition: lteiot14.h:161
lteiot14_cfg_t::baud_rate
uint32_t baud_rate
Definition: lteiot14.h:196
lteiot14_t::cts
digital_in_t cts
Definition: lteiot14.h:166
lteiot14_cfg_t
LTE IoT 14 Click configuration object.
Definition: lteiot14.h:183
lteiot14_set_rst_pin
void lteiot14_set_rst_pin(lteiot14_t *ctx, uint8_t state)
LTE IoT 14 set RST pin function.
lteiot14_cfg_t::rst
pin_name_t rst
Definition: lteiot14.h:190
lteiot14_cfg_t::cts
pin_name_t cts
Definition: lteiot14.h:193
LTEIOT14_ERROR
@ LTEIOT14_ERROR
Definition: lteiot14.h:211
lteiot14_send_cmd_check
void lteiot14_send_cmd_check(lteiot14_t *ctx, uint8_t *at_cmd_buf)
Check the sent command.
lteiot14_cfg_setup
void lteiot14_cfg_setup(lteiot14_cfg_t *cfg)
LTE IoT 14 configuration object setup function.
lteiot14_t::pwr
digital_out_t pwr
Definition: lteiot14.h:160
lteiot14_cfg_t::ring
pin_name_t ring
Definition: lteiot14.h:192