lteiot3  2.1.0.0
lteiot3.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 LTEIOT3_H
29 #define LTEIOT3_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 LTEIOT3_CMD_AT "AT"
70 #define LTEIOT3_CMD_ATI "ATI"
71 #define LTEIOT3_CMD_CFUN "AT+CFUN"
72 #define LTEIOT3_CMD_CREG "AT+CREG"
73 #define LTEIOT3_CMD_CGDCONT "AT+CGDCONT"
74 #define LTEIOT3_CMD_CESQ "AT+CESQ"
75 #define LTEIOT3_CMD_COPS "AT+COPS"
76 #define LTEIOT3_CMD_CMGS "AT+CMGS"
77 #define LTEIOT3_CMD_CMGF "AT+CMGF"
78 #define LTEIOT3_CMD_CGPADDR "AT+CGPADDR"
79 #define LTEIOT3_CMD_SICA "AT^SICA"
80 #define LTEIOT3_CMD_SISS "AT^SISS"
81 #define LTEIOT3_CMD_SISO "AT^SISO"
82 #define LTEIOT3_CMD_SISW "AT^SISW"
83 #define LTEIOT3_CMD_SISR "AT^SISR"
84 #define LTEIOT3_CMD_SISC "AT^SISC"
85 #define LTEIOT3_CMD_SGPSC "AT^SGPSC"
86 
91 #define LTEIOT3_RSP_OK "OK"
92 #define LTEIOT3_RSP_ERROR "ERROR"
93 #define LTEIOT3_RSP_SYSSTART "^SYSSTART"
94 
99 #define LTEIOT3_POWER_STATE_SWITCH 0
100 #define LTEIOT3_POWER_STATE_ON 1
101 #define LTEIOT3_POWER_STATE_REBOOT 2
102 
107 #define LTEIOT3_RSP_START "$"
108 #define LTEIOT3_RSP_DELIMITER ","
109 #define LTEIOT3_RSP_END "\r\n"
110 #define LTEIOT3_RSP_GGA "GGA"
111 
116 #define LTEIOT3_GGA_ELEMENT_SIZE 15
117 #define LTEIOT3_GGA_TIME 1
118 #define LTEIOT3_GGA_LATITUDE 2
119 #define LTEIOT3_GGA_LATITUDE_SIDE 3
120 #define LTEIOT3_GGA_LONGITUDE 4
121 #define LTEIOT3_GGA_LONGITUDE_SIDE 5
122 #define LTEIOT3_GGA_QUALITY_INDICATOR 6
123 #define LTEIOT3_GGA_NUMBER_OF_SATELLITES 7
124 #define LTEIOT3_GGA_H_DILUTION_OF_POS 8
125 #define LTEIOT3_GGA_ALTITUDE 9
126 #define LTEIOT3_GGA_ALTITUDE_UNIT 10
127 #define LTEIOT3_GGA_GEOIDAL_SEPARATION 11
128 #define LTEIOT3_GGA_GEOIDAL_SEPARATION_UNIT 12
129 #define LTEIOT3_GGA_TIME_SINCE_LAST_DGPS 13
130 #define LTEIOT3_GGA_DGPS_REFERENCE_STATION_ID 14
131 
137 #define LTEIOT3_RX_DRV_BUFFER_SIZE 256
138 #define LTEIOT3_TX_DRV_BUFFER_SIZE 256
139  // lteiot3_cmd
141 
156 #define LTEIOT3_MAP_MIKROBUS( cfg, mikrobus ) \
157  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
158  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
159  cfg.smi = MIKROBUS( mikrobus, MIKROBUS_AN ); \
160  cfg.on = MIKROBUS( mikrobus, MIKROBUS_RST ); \
161  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
162  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
163  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT );
164  // lteiot3_map // lteiot3
167 
172 typedef struct
173 {
174  // Output pins
175  digital_out_t on;
176  digital_out_t cs;
177  digital_out_t rts;
179  // Input pins
180  digital_in_t smi;
181  digital_in_t cts;
183  // Modules
184  uart_t uart;
186  // Buffers
187  uint8_t uart_rx_buffer[ LTEIOT3_RX_DRV_BUFFER_SIZE ];
188  uint8_t uart_tx_buffer[ LTEIOT3_TX_DRV_BUFFER_SIZE ];
190 } lteiot3_t;
191 
196 typedef struct
197 {
198  // Communication gpio pins
199  pin_name_t rx_pin;
200  pin_name_t tx_pin;
202  // Additional gpio pins
203  pin_name_t on;
204  pin_name_t cs;
205  pin_name_t cts;
206  pin_name_t smi;
207  pin_name_t rts;
209  // Static variable
210  uint32_t baud_rate;
212  uart_data_bits_t data_bit;
213  uart_parity_t parity_bit;
214  uart_stop_bits_t stop_bit;
216 } lteiot3_cfg_t;
217 
222 typedef enum
223 {
229 
231 
248 
262 err_t lteiot3_init ( lteiot3_t *ctx, lteiot3_cfg_t *cfg );
263 
276 err_t lteiot3_generic_write ( lteiot3_t *ctx, uint8_t *data_in, uint16_t len );
277 
290 err_t lteiot3_generic_read ( lteiot3_t *ctx, uint8_t *data_out, uint16_t len );
291 
301 void lteiot3_set_on_pin ( lteiot3_t *ctx, uint8_t state );
302 
312 void lteiot3_set_rts_pin ( lteiot3_t *ctx, uint8_t state );
313 
323 void lteiot3_set_cs_pin ( lteiot3_t *ctx, uint8_t state );
324 
334 
344 
354 void lteiot3_send_cmd ( lteiot3_t *ctx, uint8_t *cmd );
355 
366 void lteiot3_send_cmd_with_parameter ( lteiot3_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf );
367 
377 void lteiot3_send_cmd_check ( lteiot3_t *ctx, uint8_t *at_cmd_buf );
378 
388 void lteiot3_send_cmd_parameter_check ( lteiot3_t *ctx, uint8_t *at_cmd_buf );
389 
399 void lteiot3_set_sim_apn ( lteiot3_t *ctx, uint8_t *sim_apn );
400 
411 void lteiot3_send_sms_text ( lteiot3_t *ctx, uint8_t *phone_number, uint8_t *sms_text );
412 
426 err_t lteiot3_send_sms_pdu ( lteiot3_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text );
427 
439 err_t lteiot3_parse_gga ( uint8_t *rsp_buf, uint8_t gga_element, uint8_t *element_data );
440 
441 #ifdef __cplusplus
442 }
443 #endif
444 #endif // LTEIOT3_H
445  // lteiot3
447 
448 // ------------------------------------------------------------------------ END
lteiot3_parse_gga
err_t lteiot3_parse_gga(uint8_t *rsp_buf, uint8_t gga_element, uint8_t *element_data)
LTE IoT 3 parse GGA function.
lteiot3_get_cts_pin
uint8_t lteiot3_get_cts_pin(lteiot3_t *ctx)
LTE IoT 3 get cts pin function.
lteiot3_set_on_pin
void lteiot3_set_on_pin(lteiot3_t *ctx, uint8_t state)
LTE IoT 3 set on pin function.
lteiot3_send_cmd_with_parameter
void lteiot3_send_cmd_with_parameter(lteiot3_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf)
Send command function with parameter.
lteiot3_cfg_t::smi
pin_name_t smi
Definition: lteiot3.h:206
lteiot3_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: lteiot3.h:212
LTEIOT3_TX_DRV_BUFFER_SIZE
#define LTEIOT3_TX_DRV_BUFFER_SIZE
Definition: lteiot3.h:138
lteiot3_t::smi
digital_in_t smi
Definition: lteiot3.h:180
lteiot3_t::cts
digital_in_t cts
Definition: lteiot3.h:181
lteiot3_send_cmd
void lteiot3_send_cmd(lteiot3_t *ctx, uint8_t *cmd)
Send command function.
lteiot3_generic_read
err_t lteiot3_generic_read(lteiot3_t *ctx, uint8_t *data_out, uint16_t len)
LTE IoT 3 data reading function.
lteiot3_send_cmd_check
void lteiot3_send_cmd_check(lteiot3_t *ctx, uint8_t *at_cmd_buf)
Check the sent command.
lteiot3_send_sms_text
void lteiot3_send_sms_text(lteiot3_t *ctx, uint8_t *phone_number, uint8_t *sms_text)
LTE IoT 3 send SMS in text mode.
lteiot3_t
LTE IoT 3 Click context object.
Definition: lteiot3.h:173
lteiot3_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: lteiot3.h:214
lteiot3_cfg_t::cs
pin_name_t cs
Definition: lteiot3.h:204
lteiot3_t::on
digital_out_t on
Definition: lteiot3.h:175
lteiot3_return_value_t
lteiot3_return_value_t
LTE IoT 3 Click return value data.
Definition: lteiot3.h:223
lteiot3_set_cs_pin
void lteiot3_set_cs_pin(lteiot3_t *ctx, uint8_t state)
LTE IoT 3 set cs pin function.
lteiot3_set_rts_pin
void lteiot3_set_rts_pin(lteiot3_t *ctx, uint8_t state)
LTE IoT 3 set rts pin function.
lteiot3_cfg_t::tx_pin
pin_name_t tx_pin
Definition: lteiot3.h:200
lteiot3_cfg_t
LTE IoT 3 Click configuration object.
Definition: lteiot3.h:197
LTEIOT3_ERROR_TIMEOUT
@ LTEIOT3_ERROR_TIMEOUT
Definition: lteiot3.h:226
lteiot3_generic_write
err_t lteiot3_generic_write(lteiot3_t *ctx, uint8_t *data_in, uint16_t len)
LTE IoT 3 data writing function.
lteiot3_t::uart
uart_t uart
Definition: lteiot3.h:184
LTEIOT3_ERROR_CMD
@ LTEIOT3_ERROR_CMD
Definition: lteiot3.h:227
lteiot3_cfg_t::rts
pin_name_t rts
Definition: lteiot3.h:207
LTEIOT3_ERROR_UNKNOWN
@ LTEIOT3_ERROR_UNKNOWN
Definition: lteiot3.h:228
lteiot3_cfg_t::on
pin_name_t on
Definition: lteiot3.h:203
lteiot3_cfg_t::cts
pin_name_t cts
Definition: lteiot3.h:205
lteiot3_get_smi_pin
uint8_t lteiot3_get_smi_pin(lteiot3_t *ctx)
LTE IoT 3 get smi pin function.
lteiot3_t::cs
digital_out_t cs
Definition: lteiot3.h:176
lteiot3_cfg_t::rx_pin
pin_name_t rx_pin
Definition: lteiot3.h:199
lteiot3_set_sim_apn
void lteiot3_set_sim_apn(lteiot3_t *ctx, uint8_t *sim_apn)
Set sim card APN.
lteiot3_cfg_setup
void lteiot3_cfg_setup(lteiot3_cfg_t *cfg)
LTE IoT 3 configuration object setup function.
lteiot3_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: lteiot3.h:213
lteiot3_send_cmd_parameter_check
void lteiot3_send_cmd_parameter_check(lteiot3_t *ctx, uint8_t *at_cmd_buf)
Check the command parameters.
lteiot3_t::rts
digital_out_t rts
Definition: lteiot3.h:177
lteiot3_send_sms_pdu
err_t lteiot3_send_sms_pdu(lteiot3_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text)
LTE IoT 3 send SMS in PDU mode.
LTEIOT3_OK
@ LTEIOT3_OK
Definition: lteiot3.h:224
LTEIOT3_RX_DRV_BUFFER_SIZE
#define LTEIOT3_RX_DRV_BUFFER_SIZE
LTE IoT 3 driver buffer size.
Definition: lteiot3.h:137
lteiot3_cfg_t::baud_rate
uint32_t baud_rate
Definition: lteiot3.h:210
lteiot3_cfg_t::uart_blocking
bool uart_blocking
Definition: lteiot3.h:211
lteiot3_init
err_t lteiot3_init(lteiot3_t *ctx, lteiot3_cfg_t *cfg)
LTE IoT 3 initialization function.
LTEIOT3_ERROR
@ LTEIOT3_ERROR
Definition: lteiot3.h:225