lteiot17  2.1.0.0
lteiot17.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 LTEIOT17_H
29 #define LTEIOT17_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 LTEIOT17_CMD_AT "AT"
74 #define LTEIOT17_CMD_GET_MODEL_ID "AT+CGMM"
75 #define LTEIOT17_CMD_GET_SW_VERSION "AT+CGMR"
76 #define LTEIOT17_CMD_GET_SERIAL_NUM "AT+CGSN"
77 #define LTEIOT17_CMD_SET_PHONE_FUNCTIONALITY "AT+CFUN"
78 #define LTEIOT17_CMD_NETWORK_REGISTRATION "AT+CREG"
79 #define LTEIOT17_CMD_SIGNAL_QUALITY_REPORT "AT+CSQ"
80 #define LTEIOT17_CMD_OPERATOR_SELECTION "AT+COPS"
81 #define LTEIOT17_CMD_SEND_SMS "AT+CMGS"
82 #define LTEIOT17_CMD_SELECT_SMS_FORMAT "AT+CMGF"
83 #define LTEIOT17_CMD_DEFINE_PDP_CONTEXT "AT+CGDCONT"
84 #define LTEIOT17_CMD_APP_NETWORK_CONFIG "AT+CNCFG"
85 #define LTEIOT17_CMD_APP_NETWORK_ACTIVE "AT+CNACT"
86 #define LTEIOT17_CMD_SET_TCP_UDP_ID "AT+CACID"
87 #define LTEIOT17_CMD_OPEN_TCP_UDP_CONNECTION "AT+CAOPEN"
88 #define LTEIOT17_CMD_SEND_DATA_VIA_CONNECTION "AT+CASEND"
89 #define LTEIOT17_CMD_RECEIVE_DATA_VIA_CONNECTION "AT+CARECV"
90 #define LTEIOT17_CMD_CLOSE_TCP_UDP_CONNECTION "AT+CACLOSE"
91 
96 #define LTEIOT17_RSP_OK "OK"
97 #define LTEIOT17_RSP_ERROR "ERROR"
98 
103 #define LTEIOT17_URC_RECEIVED_DATA "+CADATAIND:"
104 #define LTEIOT17_URC_CONNECTION_OPEN "+CAOPEN:"
105 
110 #define LTEIOT17_POWER_STATE_OFF 0
111 #define LTEIOT17_POWER_STATE_ON 1
112 #define LTEIOT17_POWER_STATE_RESET 2
113 
119 #define LTEIOT17_TX_DRV_BUFFER_SIZE 256
120 #define LTEIOT17_RX_DRV_BUFFER_SIZE 256
121  // lteiot17_cmd
123 
138 #define LTEIOT17_MAP_MIKROBUS( cfg, mikrobus ) \
139  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
140  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
141  cfg.pwr = MIKROBUS( mikrobus, MIKROBUS_AN ); \
142  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
143  cfg.ring = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
144  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT );
145  // lteiot17_map // lteiot17
148 
153 typedef struct
154 {
155  // Output pins
156  digital_out_t pwr;
157  digital_out_t rts;
159  // Input pins
160  digital_in_t ring;
161  digital_in_t cts;
163  // Modules
164  uart_t uart;
166  // Buffers
167  uint8_t uart_rx_buffer[ LTEIOT17_RX_DRV_BUFFER_SIZE ];
168  uint8_t uart_tx_buffer[ LTEIOT17_TX_DRV_BUFFER_SIZE ];
169  uint8_t cmd_buffer[ LTEIOT17_TX_DRV_BUFFER_SIZE ];
171 } lteiot17_t;
172 
177 typedef struct
178 {
179  // Communication gpio pins
180  pin_name_t rx_pin;
181  pin_name_t tx_pin;
183  // Additional gpio pins
184  pin_name_t pwr;
185  pin_name_t rts;
186  pin_name_t ring;
187  pin_name_t cts;
189  // Static variable
190  uint32_t baud_rate;
192  uart_data_bits_t data_bit;
193  uart_parity_t parity_bit;
194  uart_stop_bits_t stop_bit;
197 
202 typedef enum
203 {
209 
211 
228 
243 
256 err_t lteiot17_generic_write ( lteiot17_t *ctx, uint8_t *data_in, uint16_t len );
257 
270 err_t lteiot17_generic_read ( lteiot17_t *ctx, uint8_t *data_out, uint16_t len );
271 
281 void lteiot17_set_pwr_pin ( lteiot17_t *ctx, uint8_t state );
282 
292 void lteiot17_set_rts_pin ( lteiot17_t *ctx, uint8_t state );
293 
303 
313 
325 void lteiot17_set_power_state ( lteiot17_t *ctx, uint8_t state );
326 
336 void lteiot17_send_cmd ( lteiot17_t *ctx, uint8_t *cmd );
337 
348 void lteiot17_send_cmd_par ( lteiot17_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf );
349 
359 void lteiot17_send_cmd_check ( lteiot17_t *ctx, uint8_t *at_cmd_buf );
360 
370 void lteiot17_set_sim_apn ( lteiot17_t *ctx, uint8_t *sim_apn );
371 
382 void lteiot17_send_sms_text ( lteiot17_t *ctx, uint8_t *phone_number, uint8_t *sms_text );
383 
397 err_t lteiot17_send_sms_pdu ( lteiot17_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text );
398 
399 #ifdef __cplusplus
400 }
401 #endif
402 #endif // LTEIOT17_H
403  // lteiot17
405 
406 // ------------------------------------------------------------------------ END
lteiot17_cfg_t::baud_rate
uint32_t baud_rate
Definition: lteiot17.h:190
LTEIOT17_ERROR_UNKNOWN
@ LTEIOT17_ERROR_UNKNOWN
Definition: lteiot17.h:208
lteiot17_return_value_t
lteiot17_return_value_t
LTE IoT 17 Click return value data.
Definition: lteiot17.h:203
lteiot17_send_sms_text
void lteiot17_send_sms_text(lteiot17_t *ctx, uint8_t *phone_number, uint8_t *sms_text)
LTE IoT 17 send SMS in text mode.
LTEIOT17_ERROR_TIMEOUT
@ LTEIOT17_ERROR_TIMEOUT
Definition: lteiot17.h:206
lteiot17_cfg_t::rx_pin
pin_name_t rx_pin
Definition: lteiot17.h:180
lteiot17_init
err_t lteiot17_init(lteiot17_t *ctx, lteiot17_cfg_t *cfg)
LTE IoT 17 initialization function.
lteiot17_send_sms_pdu
err_t lteiot17_send_sms_pdu(lteiot17_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text)
LTE IoT 17 send SMS in PDU mode.
lteiot17_send_cmd_par
void lteiot17_send_cmd_par(lteiot17_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf)
Send command function with parameter.
lteiot17_t
LTE IoT 17 Click context object.
Definition: lteiot17.h:154
lteiot17_set_pwr_pin
void lteiot17_set_pwr_pin(lteiot17_t *ctx, uint8_t state)
LTE IoT 17 set PWR pin function.
lteiot17_t::cts
digital_in_t cts
Definition: lteiot17.h:161
lteiot17_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: lteiot17.h:193
lteiot17_set_rts_pin
void lteiot17_set_rts_pin(lteiot17_t *ctx, uint8_t state)
LTE IoT 17 set RTS pin function.
LTEIOT17_ERROR_CMD
@ LTEIOT17_ERROR_CMD
Definition: lteiot17.h:207
lteiot17_set_power_state
void lteiot17_set_power_state(lteiot17_t *ctx, uint8_t state)
LTE IoT 17 set power state function.
lteiot17_generic_read
err_t lteiot17_generic_read(lteiot17_t *ctx, uint8_t *data_out, uint16_t len)
LTE IoT 17 data reading function.
lteiot17_generic_write
err_t lteiot17_generic_write(lteiot17_t *ctx, uint8_t *data_in, uint16_t len)
LTE IoT 17 data writing function.
lteiot17_t::pwr
digital_out_t pwr
Definition: lteiot17.h:156
lteiot17_get_cts_pin
uint8_t lteiot17_get_cts_pin(lteiot17_t *ctx)
LTE IoT 17 get CTS pin function.
lteiot17_t::ring
digital_in_t ring
Definition: lteiot17.h:160
LTEIOT17_ERROR
@ LTEIOT17_ERROR
Definition: lteiot17.h:205
lteiot17_send_cmd
void lteiot17_send_cmd(lteiot17_t *ctx, uint8_t *cmd)
Send command function.
lteiot17_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: lteiot17.h:194
lteiot17_cfg_t::rts
pin_name_t rts
Definition: lteiot17.h:185
lteiot17_cfg_t::cts
pin_name_t cts
Definition: lteiot17.h:187
lteiot17_set_sim_apn
void lteiot17_set_sim_apn(lteiot17_t *ctx, uint8_t *sim_apn)
Set sim card APN.
lteiot17_send_cmd_check
void lteiot17_send_cmd_check(lteiot17_t *ctx, uint8_t *at_cmd_buf)
Check the sent command.
LTEIOT17_OK
@ LTEIOT17_OK
Definition: lteiot17.h:204
lteiot17_t::uart
uart_t uart
Definition: lteiot17.h:164
lteiot17_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: lteiot17.h:192
lteiot17_cfg_setup
void lteiot17_cfg_setup(lteiot17_cfg_t *cfg)
LTE IoT 17 configuration object setup function.
lteiot17_cfg_t::ring
pin_name_t ring
Definition: lteiot17.h:186
lteiot17_t::rts
digital_out_t rts
Definition: lteiot17.h:157
lteiot17_cfg_t
LTE IoT 17 Click configuration object.
Definition: lteiot17.h:178
LTEIOT17_TX_DRV_BUFFER_SIZE
#define LTEIOT17_TX_DRV_BUFFER_SIZE
LTE IoT 17 driver buffer size.
Definition: lteiot17.h:119
lteiot17_get_ring_pin
uint8_t lteiot17_get_ring_pin(lteiot17_t *ctx)
LTE IoT 17 get RING pin function.
lteiot17_cfg_t::tx_pin
pin_name_t tx_pin
Definition: lteiot17.h:181
lteiot17_cfg_t::uart_blocking
bool uart_blocking
Definition: lteiot17.h:191
lteiot17_cfg_t::pwr
pin_name_t pwr
Definition: lteiot17.h:184
LTEIOT17_RX_DRV_BUFFER_SIZE
#define LTEIOT17_RX_DRV_BUFFER_SIZE
Definition: lteiot17.h:120