lteiot2 2.0.0.0
lteiot2.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef LTEIOT2_H
36#define LTEIOT2_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_uart.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
66#define LTEIOT2_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
68 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
69 cfg.sta = MIKROBUS( mikrobus, MIKROBUS_AN ); \
70 cfg.pwk = MIKROBUS( mikrobus, MIKROBUS_RST ); \
71 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
72 cfg.ri = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
73 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT )
80#define LTEIOT2_RETVAL uint8_t
87#define LTEIOT2_NMEA_GPGGA 1
88#define LTEIOT2_NMEA_GPGGA_NUM_ELEMENT 15
95#define LTEIOT2_GPGGA_TIME 1
96#define LTEIOT2_GPGGA_LATITUDE 2
97#define LTEIOT2_GPGGA_LATITUDE_SIDE 3
98#define LTEIOT2_GPGGA_LONGITUDE 4
99#define LTEIOT2_GPGGA_LONGITUDE_SIDE 5
100#define LTEIOT2_GPGGA_QUALITY_INDICATOR 6
101#define LTEIOT2_GPGGA_NUMBER_OF_SATELLITES 7
102#define LTEIOT2_GPGGA_H_DILUTION_OF_POS 8
103#define LTEIOT2_GPGGA_ALTITUDE 9
104#define LTEIOT2_GPGGA_ALTITUDE_UNIT 10
105#define LTEIOT2_GPGGA_GEOIDAL_SEPARATION 11
106#define LTEIOT2_GPGGA_GEOIDAL_SEPARATION_UNIT 12
107#define LTEIOT2_GPGGA_TIME_SINCE_LAST_DGPS 13
108#define LTEIOT2_GPGGA_DGPS_REFERENCE_STATION_ID 14
115#define LTEIOT2_ERROR_COMMAND_OR_ELEMENT 0xFF
116#define LTEIOT2_ERROR_START_OR_END_COMMAND 0x8F
117#define LTEIOT2_ERROR_NEXT_ELEMENT 0x4F
118#define LTEIOT2_ERROR_CURRENT_ELEMENT 0x2F
119#define LTEIOT2_NO_ERROR 0x00
126#define LTEIOT2_MODULE_POWER_ON 1
127#define LTEIOT2_MODULE_POWER_OFF 0
134#define LTEIOT2_CMD_AT "AT"
135#define LTEIOT2_CMD_ATI "ATI"
136#define LTEIOT2_CMD_CGMR "AT+CGMR"
137
138#define LTEIOT2_CMD_CFUN "AT+CFUN"
139#define LTEIOT2_CMD_CREG "AT+CREG"
140#define LTEIOT2_CMD_CGDCONT "AT+CGDCONT"
141#define LTEIOT2_CMD_CIMI "AT+CIMI"
142#define LTEIOT2_CMD_CGATT "AT+CGATT"
143#define LTEIOT2_CMD_CSQ "AT+CSQ"
144#define LTEIOT2_CMD_COPS "AT+COPS"
145#define LTEIOT2_CMD_CMGS "AT+CMGS"
146#define LTEIOT2_CMD_CMGF "AT+CMGF"
147#define LTEIOT2_CMD_QGPS "AT+QGPS"
148#define LTEIOT2_CMD_QGPSCFG "AT+QGPSCFG"
149#define LTEIOT2_CMD_QGPSGNMEA "AT+QGPSGNMEA"
150#define LTEIOT2_CMD_QGPSLOC "AT+QGPSLOC"
157#define DRV_RX_BUFFER_SIZE 256
158#define DRV_TX_BUFFER_SIZE 256
161 // End group macro
162// --------------------------------------------------------------- PUBLIC TYPES
170typedef struct
171{
172 // Output pins
173
174 digital_out_t pwk;
175 digital_out_t rts;
176
177
178 // Input pins
179
180 digital_in_t sta;
181 digital_in_t ri;
182 digital_in_t cts;
183
184 // Modules
185
186 uart_t uart;
187
188 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
189 char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
190
191} lteiot2_t;
192
196typedef struct
197{
198 // Communication gpio pins
199
200 pin_name_t rx_pin;
201 pin_name_t tx_pin;
202
203 // Additional gpio pins
204
205 pin_name_t sta;
206 pin_name_t pwk;
207 pin_name_t rts;
208 pin_name_t ri;
209 pin_name_t cts;
210
211 // static variable
212
213 uint32_t baud_rate; // Clock speed.
215 uart_data_bits_t data_bit; // Data bits.
216 uart_parity_t parity_bit; // Parity bit.
217 uart_stop_bits_t stop_bit; // Stop bits.
218
220
225typedef enum
226{
228 LTEIOT2_ERROR = -1
229
231
235typedef uint8_t lteiot2_error_t;
236
237 // End types group
238// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
239
245#ifdef __cplusplus
246extern "C"{
247#endif
248
258
268
274void lteiot2_module_power ( lteiot2_t *ctx, uint8_t state );
275
282void lteiot2_generic_write ( lteiot2_t *ctx, char *data_buf, uint16_t len );
283
291int32_t lteiot2_generic_read ( lteiot2_t *ctx, char *data_buf, uint16_t max_len );
292
301void lteiot2_set_rts ( lteiot2_t *ctx, uint8_t state );
302
311uint8_t lteiot2_get_cts ( lteiot2_t *ctx );
312
322void lteiot2_send_cmd ( lteiot2_t *ctx, char *cmd );
323
334void lteiot2_send_cmd_with_parameter ( lteiot2_t *ctx, char *at_cmd_buf, char *param_buf );
335
345void lteiot2_send_cmd_check ( lteiot2_t *ctx, char *at_cmd_buf );
346
356void lteiot2_send_cmd_parameter_check ( lteiot2_t *ctx, char *at_cmd_buf );
357
367void lteiot2_set_sim_apn ( lteiot2_t *ctx, char *sim_apn );
368
379void lteiot2_send_sms_text ( lteiot2_t *ctx, char *phone_number, char *sms_text );
380
394err_t lteiot2_send_sms_pdu ( lteiot2_t *ctx, char *service_center_number,
395 char *phone_number, char *sms_text );
396
406(
407 char *rsp, uint8_t command,
408 uint8_t element, char *parser_buf
409);
410
411#ifdef __cplusplus
412}
413#endif
414#endif // _LTEIOT2_H_
415
416 // End public_function group
418
419// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition lteiot2.h:157
#define LTEIOT2_RETVAL
Definition lteiot2.h:80
LTEIOT2_RETVAL lteiot2_init(lteiot2_t *ctx, lteiot2_cfg_t *cfg)
Initialization function.
err_t lteiot2_send_sms_pdu(lteiot2_t *ctx, char *service_center_number, char *phone_number, char *sms_text)
LTE IoT 2 send SMS in PDU mode.
int32_t lteiot2_generic_read(lteiot2_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
void lteiot2_module_power(lteiot2_t *ctx, uint8_t state)
Power ON/OFF the module.
void lteiot2_send_cmd_check(lteiot2_t *ctx, char *at_cmd_buf)
Check the sent command.
uint8_t lteiot2_get_cts(lteiot2_t *ctx)
CTS Pin Get function.
void lteiot2_set_rts(lteiot2_t *ctx, uint8_t state)
Sets state of the RTS pin.
void lteiot2_send_cmd_with_parameter(lteiot2_t *ctx, char *at_cmd_buf, char *param_buf)
Send command function with parameter.
void lteiot2_cfg_setup(lteiot2_cfg_t *cfg)
Config Object Initialization function.
void lteiot2_send_sms_text(lteiot2_t *ctx, char *phone_number, char *sms_text)
LTE IoT 2 send SMS in text mode.
void lteiot2_send_cmd(lteiot2_t *ctx, char *cmd)
Send command function.
lteiot2_error_t lteiot2_generic_parser(char *rsp, uint8_t command, uint8_t element, char *parser_buf)
Generic parser function.
void lteiot2_set_sim_apn(lteiot2_t *ctx, char *sim_apn)
Set sim card APN.
void lteiot2_send_cmd_parameter_check(lteiot2_t *ctx, char *at_cmd_buf)
Check the command parameters.
void lteiot2_generic_write(lteiot2_t *ctx, char *data_buf, uint16_t len)
Generic write function.
lteiot2_return_value_t
LTE IoT 2 Click return value data.
Definition lteiot2.h:226
uint8_t lteiot2_error_t
Error type.
Definition lteiot2.h:235
@ LTEIOT2_OK
Definition lteiot2.h:227
@ LTEIOT2_ERROR
Definition lteiot2.h:228
Click configuration structure definition.
Definition lteiot2.h:197
pin_name_t sta
Definition lteiot2.h:205
pin_name_t rts
Definition lteiot2.h:207
uint32_t baud_rate
Definition lteiot2.h:213
pin_name_t pwk
Definition lteiot2.h:206
pin_name_t cts
Definition lteiot2.h:209
bool uart_blocking
Definition lteiot2.h:214
pin_name_t ri
Definition lteiot2.h:208
uart_data_bits_t data_bit
Definition lteiot2.h:215
pin_name_t tx_pin
Definition lteiot2.h:201
pin_name_t rx_pin
Definition lteiot2.h:200
uart_stop_bits_t stop_bit
Definition lteiot2.h:217
uart_parity_t parity_bit
Definition lteiot2.h:216
Click ctx object definition.
Definition lteiot2.h:171
digital_in_t sta
Definition lteiot2.h:180
digital_out_t rts
Definition lteiot2.h:175
digital_in_t ri
Definition lteiot2.h:181
uart_t uart
Definition lteiot2.h:186
digital_in_t cts
Definition lteiot2.h:182
digital_out_t pwk
Definition lteiot2.h:174