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
32extern "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 LTEIOT3_CMD_AT "AT"
74#define LTEIOT3_CMD_ATI "ATI"
75#define LTEIOT3_CMD_CFUN "AT+CFUN"
76#define LTEIOT3_CMD_CREG "AT+CREG"
77#define LTEIOT3_CMD_CGDCONT "AT+CGDCONT"
78#define LTEIOT3_CMD_CESQ "AT+CESQ"
79#define LTEIOT3_CMD_COPS "AT+COPS"
80#define LTEIOT3_CMD_CMGS "AT+CMGS"
81#define LTEIOT3_CMD_CMGF "AT+CMGF"
82#define LTEIOT3_CMD_CGPADDR "AT+CGPADDR"
83#define LTEIOT3_CMD_SICA "AT^SICA"
84#define LTEIOT3_CMD_SISS "AT^SISS"
85#define LTEIOT3_CMD_SISO "AT^SISO"
86#define LTEIOT3_CMD_SISW "AT^SISW"
87#define LTEIOT3_CMD_SISR "AT^SISR"
88#define LTEIOT3_CMD_SISC "AT^SISC"
89#define LTEIOT3_CMD_SGPSC "AT^SGPSC"
90
95#define LTEIOT3_RSP_OK "OK"
96#define LTEIOT3_RSP_ERROR "ERROR"
97#define LTEIOT3_RSP_SYSSTART "^SYSSTART"
98
103#define LTEIOT3_POWER_STATE_SWITCH 0
104#define LTEIOT3_POWER_STATE_ON 1
105#define LTEIOT3_POWER_STATE_REBOOT 2
106
111#define LTEIOT3_RSP_START "$"
112#define LTEIOT3_RSP_DELIMITER ","
113#define LTEIOT3_RSP_END "\r\n"
114#define LTEIOT3_RSP_GGA "GGA"
115
120#define LTEIOT3_GGA_ELEMENT_SIZE 15
121#define LTEIOT3_GGA_TIME 1
122#define LTEIOT3_GGA_LATITUDE 2
123#define LTEIOT3_GGA_LATITUDE_SIDE 3
124#define LTEIOT3_GGA_LONGITUDE 4
125#define LTEIOT3_GGA_LONGITUDE_SIDE 5
126#define LTEIOT3_GGA_QUALITY_INDICATOR 6
127#define LTEIOT3_GGA_NUMBER_OF_SATELLITES 7
128#define LTEIOT3_GGA_H_DILUTION_OF_POS 8
129#define LTEIOT3_GGA_ALTITUDE 9
130#define LTEIOT3_GGA_ALTITUDE_UNIT 10
131#define LTEIOT3_GGA_GEOIDAL_SEPARATION 11
132#define LTEIOT3_GGA_GEOIDAL_SEPARATION_UNIT 12
133#define LTEIOT3_GGA_TIME_SINCE_LAST_DGPS 13
134#define LTEIOT3_GGA_DGPS_REFERENCE_STATION_ID 14
135
141#define LTEIOT3_RX_DRV_BUFFER_SIZE 256
142#define LTEIOT3_TX_DRV_BUFFER_SIZE 256
143
144 // lteiot3_cmd
145
160#define LTEIOT3_MAP_MIKROBUS( cfg, mikrobus ) \
161 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
162 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
163 cfg.smi = MIKROBUS( mikrobus, MIKROBUS_AN ); \
164 cfg.on = MIKROBUS( mikrobus, MIKROBUS_RST ); \
165 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
166 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
167 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT );
168
169 // lteiot3_map
170 // lteiot3
171
176typedef struct
177{
178 // Output pins
179 digital_out_t on;
180 digital_out_t cs;
181 digital_out_t rts;
183 // Input pins
184 digital_in_t smi;
185 digital_in_t cts;
187 // Modules
188 uart_t uart;
190 // Buffers
191 uint8_t uart_rx_buffer[ LTEIOT3_RX_DRV_BUFFER_SIZE ];
192 uint8_t uart_tx_buffer[ LTEIOT3_TX_DRV_BUFFER_SIZE ];
194} lteiot3_t;
195
200typedef struct
201{
202 // Communication gpio pins
203 pin_name_t rx_pin;
204 pin_name_t tx_pin;
206 // Additional gpio pins
207 pin_name_t on;
208 pin_name_t cs;
209 pin_name_t cts;
210 pin_name_t smi;
211 pin_name_t rts;
213 // Static variable
214 uint32_t baud_rate;
216 uart_data_bits_t data_bit;
217 uart_parity_t parity_bit;
218 uart_stop_bits_t stop_bit;
221
235
252
267
280err_t lteiot3_generic_write ( lteiot3_t *ctx, uint8_t *data_in, uint16_t len );
281
294err_t lteiot3_generic_read ( lteiot3_t *ctx, uint8_t *data_out, uint16_t len );
295
305void lteiot3_set_on_pin ( lteiot3_t *ctx, uint8_t state );
306
316void lteiot3_set_rts_pin ( lteiot3_t *ctx, uint8_t state );
317
327void lteiot3_set_cs_pin ( lteiot3_t *ctx, uint8_t state );
328
338
348
358void lteiot3_send_cmd ( lteiot3_t *ctx, uint8_t *cmd );
359
370void lteiot3_send_cmd_with_parameter ( lteiot3_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf );
371
381void lteiot3_send_cmd_check ( lteiot3_t *ctx, uint8_t *at_cmd_buf );
382
392void lteiot3_send_cmd_parameter_check ( lteiot3_t *ctx, uint8_t *at_cmd_buf );
393
403void lteiot3_set_sim_apn ( lteiot3_t *ctx, uint8_t *sim_apn );
404
415void lteiot3_send_sms_text ( lteiot3_t *ctx, uint8_t *phone_number, uint8_t *sms_text );
416
430err_t lteiot3_send_sms_pdu ( lteiot3_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text );
431
443err_t lteiot3_parse_gga ( uint8_t *rsp_buf, uint8_t gga_element, uint8_t *element_data );
444
445#ifdef __cplusplus
446}
447#endif
448#endif // LTEIOT3_H
449
450 // lteiot3
451
452// ------------------------------------------------------------------------ END
#define LTEIOT3_TX_DRV_BUFFER_SIZE
Definition lteiot3.h:142
#define LTEIOT3_RX_DRV_BUFFER_SIZE
LTE IoT 3 driver buffer size.
Definition lteiot3.h:141
err_t lteiot3_generic_read(lteiot3_t *ctx, uint8_t *data_out, uint16_t len)
LTE IoT 3 data reading function.
err_t lteiot3_init(lteiot3_t *ctx, lteiot3_cfg_t *cfg)
LTE IoT 3 initialization function.
void lteiot3_set_sim_apn(lteiot3_t *ctx, uint8_t *sim_apn)
Set sim card APN.
void lteiot3_send_sms_text(lteiot3_t *ctx, uint8_t *phone_number, uint8_t *sms_text)
LTE IoT 3 send SMS in text mode.
void lteiot3_send_cmd_parameter_check(lteiot3_t *ctx, uint8_t *at_cmd_buf)
Check the command parameters.
void lteiot3_cfg_setup(lteiot3_cfg_t *cfg)
LTE IoT 3 configuration object setup function.
uint8_t lteiot3_get_smi_pin(lteiot3_t *ctx)
LTE IoT 3 get smi pin function.
err_t lteiot3_parse_gga(uint8_t *rsp_buf, uint8_t gga_element, uint8_t *element_data)
LTE IoT 3 parse GGA function.
void lteiot3_set_on_pin(lteiot3_t *ctx, uint8_t state)
LTE IoT 3 set on pin function.
void lteiot3_send_cmd(lteiot3_t *ctx, uint8_t *cmd)
Send command function.
uint8_t lteiot3_get_cts_pin(lteiot3_t *ctx)
LTE IoT 3 get cts pin function.
void lteiot3_send_cmd_with_parameter(lteiot3_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf)
Send command function with parameter.
void lteiot3_set_cs_pin(lteiot3_t *ctx, uint8_t state)
LTE IoT 3 set cs pin function.
err_t lteiot3_generic_write(lteiot3_t *ctx, uint8_t *data_in, uint16_t len)
LTE IoT 3 data writing function.
void lteiot3_send_cmd_check(lteiot3_t *ctx, uint8_t *at_cmd_buf)
Check the sent command.
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.
void lteiot3_set_rts_pin(lteiot3_t *ctx, uint8_t state)
LTE IoT 3 set rts pin function.
lteiot3_return_value_t
LTE IoT 3 Click return value data.
Definition lteiot3.h:227
@ LTEIOT3_ERROR_CMD
Definition lteiot3.h:231
@ LTEIOT3_ERROR_UNKNOWN
Definition lteiot3.h:232
@ LTEIOT3_OK
Definition lteiot3.h:228
@ LTEIOT3_ERROR
Definition lteiot3.h:229
@ LTEIOT3_ERROR_TIMEOUT
Definition lteiot3.h:230
LTE IoT 3 Click configuration object.
Definition lteiot3.h:201
pin_name_t rts
Definition lteiot3.h:211
uint32_t baud_rate
Definition lteiot3.h:214
pin_name_t cts
Definition lteiot3.h:209
bool uart_blocking
Definition lteiot3.h:215
pin_name_t smi
Definition lteiot3.h:210
uart_data_bits_t data_bit
Definition lteiot3.h:216
pin_name_t on
Definition lteiot3.h:207
pin_name_t tx_pin
Definition lteiot3.h:204
pin_name_t rx_pin
Definition lteiot3.h:203
uart_stop_bits_t stop_bit
Definition lteiot3.h:218
uart_parity_t parity_bit
Definition lteiot3.h:217
pin_name_t cs
Definition lteiot3.h:208
LTE IoT 3 Click context object.
Definition lteiot3.h:177
digital_out_t cs
Definition lteiot3.h:180
digital_out_t on
Definition lteiot3.h:179
digital_out_t rts
Definition lteiot3.h:181
uart_t uart
Definition lteiot3.h:188
digital_in_t smi
Definition lteiot3.h:184
digital_in_t cts
Definition lteiot3.h:185