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_ACTIVATE_PDP_CONTEXT "AT+CGACT"
85 #define LTEIOT17_CMD_SHOW_PDP_ADDRESS "AT+CGPADDR"
86 #define LTEIOT17_CMD_APP_NETWORK_ACTIVE "AT+CNACT"
87 #define LTEIOT17_CMD_SET_TCP_UDP_ID "AT+CACID"
88 #define LTEIOT17_CMD_OPEN_TCP_UDP_CONNECTION "AT+CAOPEN"
89 #define LTEIOT17_CMD_SEND_DATA_VIA_CONNECTION "AT+CASEND"
90 #define LTEIOT17_CMD_RECEIVE_DATA_VIA_CONNECTION "AT+CARECV"
91 #define LTEIOT17_CMD_CLOSE_TCP_UDP_CONNECTION "AT+CACLOSE"
92 
97 #define LTEIOT17_RSP_OK "OK"
98 #define LTEIOT17_RSP_ERROR "ERROR"
99 
104 #define LTEIOT17_URC_RECEIVED_DATA "+CADATAIND:"
105 #define LTEIOT17_URC_CONNECTION_OPEN "+CAOPEN:"
106 
111 #define LTEIOT17_POWER_STATE_OFF 0
112 #define LTEIOT17_POWER_STATE_ON 1
113 #define LTEIOT17_POWER_STATE_RESET 2
114 
120 #define LTEIOT17_TX_DRV_BUFFER_SIZE 256
121 #define LTEIOT17_RX_DRV_BUFFER_SIZE 256
122  // lteiot17_cmd
124 
139 #define LTEIOT17_MAP_MIKROBUS( cfg, mikrobus ) \
140  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
141  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
142  cfg.pwr = MIKROBUS( mikrobus, MIKROBUS_AN ); \
143  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
144  cfg.ring = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
145  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT );
146  // lteiot17_map // lteiot17
149 
154 typedef struct
155 {
156  // Output pins
157  digital_out_t pwr;
158  digital_out_t rts;
160  // Input pins
161  digital_in_t ring;
162  digital_in_t cts;
164  // Modules
165  uart_t uart;
167  // Buffers
168  uint8_t uart_rx_buffer[ LTEIOT17_RX_DRV_BUFFER_SIZE ];
169  uint8_t uart_tx_buffer[ LTEIOT17_TX_DRV_BUFFER_SIZE ];
170  uint8_t cmd_buffer[ LTEIOT17_TX_DRV_BUFFER_SIZE ];
172 } lteiot17_t;
173 
178 typedef struct
179 {
180  // Communication gpio pins
181  pin_name_t rx_pin;
182  pin_name_t tx_pin;
184  // Additional gpio pins
185  pin_name_t pwr;
186  pin_name_t rts;
187  pin_name_t ring;
188  pin_name_t cts;
190  // Static variable
191  uint32_t baud_rate;
193  uart_data_bits_t data_bit;
194  uart_parity_t parity_bit;
195  uart_stop_bits_t stop_bit;
198 
203 typedef enum
204 {
210 
212 
229 
244 
257 err_t lteiot17_generic_write ( lteiot17_t *ctx, uint8_t *data_in, uint16_t len );
258 
271 err_t lteiot17_generic_read ( lteiot17_t *ctx, uint8_t *data_out, uint16_t len );
272 
282 void lteiot17_set_pwr_pin ( lteiot17_t *ctx, uint8_t state );
283 
293 void lteiot17_set_rts_pin ( lteiot17_t *ctx, uint8_t state );
294 
304 
314 
326 void lteiot17_set_power_state ( lteiot17_t *ctx, uint8_t state );
327 
337 void lteiot17_send_cmd ( lteiot17_t *ctx, uint8_t *cmd );
338 
349 void lteiot17_send_cmd_par ( lteiot17_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf );
350 
360 void lteiot17_send_cmd_check ( lteiot17_t *ctx, uint8_t *at_cmd_buf );
361 
371 void lteiot17_set_sim_apn ( lteiot17_t *ctx, uint8_t *sim_apn );
372 
383 void lteiot17_send_sms_text ( lteiot17_t *ctx, uint8_t *phone_number, uint8_t *sms_text );
384 
398 err_t lteiot17_send_sms_pdu ( lteiot17_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text );
399 
400 #ifdef __cplusplus
401 }
402 #endif
403 #endif // LTEIOT17_H
404  // lteiot17
406 
407 // ------------------------------------------------------------------------ END
lteiot17_cfg_t::baud_rate
uint32_t baud_rate
Definition: lteiot17.h:191
LTEIOT17_ERROR_UNKNOWN
@ LTEIOT17_ERROR_UNKNOWN
Definition: lteiot17.h:209
lteiot17_return_value_t
lteiot17_return_value_t
LTE IoT 17 Click return value data.
Definition: lteiot17.h:204
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:207
lteiot17_cfg_t::rx_pin
pin_name_t rx_pin
Definition: lteiot17.h:181
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:155
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:162
lteiot17_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: lteiot17.h:194
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:208
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:157
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:161
LTEIOT17_ERROR
@ LTEIOT17_ERROR
Definition: lteiot17.h:206
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:195
lteiot17_cfg_t::rts
pin_name_t rts
Definition: lteiot17.h:186
lteiot17_cfg_t::cts
pin_name_t cts
Definition: lteiot17.h:188
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:205
lteiot17_t::uart
uart_t uart
Definition: lteiot17.h:165
lteiot17_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: lteiot17.h:193
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:187
lteiot17_t::rts
digital_out_t rts
Definition: lteiot17.h:158
lteiot17_cfg_t
LTE IoT 17 Click configuration object.
Definition: lteiot17.h:179
LTEIOT17_TX_DRV_BUFFER_SIZE
#define LTEIOT17_TX_DRV_BUFFER_SIZE
LTE IoT 17 driver buffer size.
Definition: lteiot17.h:120
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:182
lteiot17_cfg_t::uart_blocking
bool uart_blocking
Definition: lteiot17.h:192
lteiot17_cfg_t::pwr
pin_name_t pwr
Definition: lteiot17.h:185
LTEIOT17_RX_DRV_BUFFER_SIZE
#define LTEIOT17_RX_DRV_BUFFER_SIZE
Definition: lteiot17.h:121