lteiot12 2.1.0.0
lteiot12.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 LTEIOT12_H
29#define LTEIOT12_H
30
31#ifdef __cplusplus
32extern "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 LTEIOT12_CMD_AT "AT"
70#define LTEIOT12_CMD_ATI "ATI"
71#define LTEIOT12_CMD_CGMR "AT+CGMR"
72#define LTEIOT12_CMD_CFUN "AT+CFUN"
73#define LTEIOT12_CMD_CREG "AT+CREG"
74#define LTEIOT12_CMD_CEREG "AT+CEREG"
75#define LTEIOT12_CMD_CGREG "AT+CGREG"
76#define LTEIOT12_CMD_CGDCONT "AT+CGDCONT"
77#define LTEIOT12_CMD_CMGF "AT+CMGF"
78#define LTEIOT12_CMD_CGDCONT "AT+CGDCONT"
79#define LTEIOT12_CMD_CIMI "AT+CIMI"
80#define LTEIOT12_CMD_CGATT "AT+CGATT"
81#define LTEIOT12_CMD_CSQ "AT+CSQ"
82#define LTEIOT12_CMD_CESQ "AT+CESQ"
83#define LTEIOT12_CMD_COPS "AT+COPS"
84#define LTEIOT12_CMD_CSCON "AT+CSCON"
85#define LTEIOT12_CMD_CMEE "AT+CMEE"
86#define LTEIOT12_CMD_CMGS "AT+CMGS"
87#define LTEIOT12_CMD_CGACT "AT+CGACT"
88#define LTEIOT12_CMD_CSCS "AT+CSCS"
89#define LTEIOT12_CMD_CMGF "AT+CMGF"
90#define LTEIOT12_CMD_CPSMS "AT+CPSMS"
91#define LTEIOT12_CMD_SM "AT+SM"
92#define LTEIOT12_CMD_QSCLK "AT+QSCLK"
93#define LTEIOT12_CMD_QIOPEN "AT+QIOPEN"
94#define LTEIOT12_CMD_QISEND "AT+QISEND"
95#define LTEIOT12_CMD_QIRD "AT+QIRD"
96#define LTEIOT12_CMD_QICLOSE "AT+QICLOSE"
97#define LTEIOT12_CMD_QCSCON "AT+QCSCON"
98#define LTEIOT12_CMD_QGPS "AT+QGPS"
99#define LTEIOT12_CMD_QGPSCFG "AT+QGPSCFG"
100#define LTEIOT12_CMD_QGPSGNMEA "AT+QGPSGNMEA"
101#define LTEIOT12_CMD_QGPSLOC "AT+QGPSLOC"
102
107#define LTEIOT12_RSP_OK "OK"
108#define LTEIOT12_RSP_RDY "RDY"
109#define LTEIOT12_RSP_APPRDY "APP RDY"
110#define LTEIOT12_RSP_ERROR "ERROR"
111#define LTEIOT12_RSP_START "$"
112#define LTEIOT12_RSP_DELIMITER ","
113#define LTEIOT12_RSP_GPGGA "GPGGA"
114
119#define LTEIOT12_NMEA_GNGGA 1
120#define LTEIOT12_NMEA_GPGLL 3
121#define LTEIOT12_NMEA_GNGGA_NUM_ELEMENT 15
122#define LTEIOT12_NMEA_GPGLL_NUM_ELEMENT 5
123
128#define LTEIOT12_GNGGA_TIME 1
129#define LTEIOT12_GNGGA_LATITUDE 2
130#define LTEIOT12_GNGGA_LATITUDE_SIDE 3
131#define LTEIOT12_GNGGA_LONGITUDE 4
132#define LTEIOT12_GNGGA_LONGITUDE_SIDE 5
133#define LTEIOT12_GNGGA_QUALITY_INDICATOR 6
134#define LTEIOT12_GNGGA_NUMBER_OF_SATELLITES 7
135#define LTEIOT12_GNGGA_H_DILUTION_OF_POS 8
136#define LTEIOT12_GNGGA_ALTITUDE 9
137#define LTEIOT12_GNGGA_ALTITUDE_UNIT 10
138#define LTEIOT12_GNGGA_GEOIDAL_SEPARATION 11
139#define LTEIOT12_GNGGA_GEOIDAL_SEPARATION_UNIT 12
140#define LTEIOT12_GNGGA_TIME_SINCE_LAST_DGPS 13
141#define LTEIOT12_GNGGA_DGPS_REFERENCE_STATION_ID 14
142
147#define LTEIOT12_PIN_STATE_HIGH 0x01
148#define LTEIOT12_PIN_STATE_LOW 0x00
149
155#define LTEIOT12_TX_DRV_BUFFER_SIZE 300
156#define LTEIOT12_RX_DRV_BUFFER_SIZE 300
157 // lteiot12_cmd
159
174#define LTEIOT12_MAP_MIKROBUS( cfg, mikrobus ) \
175 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
176 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
177 cfg.sta = MIKROBUS( mikrobus, MIKROBUS_AN ); \
178 cfg.pwr = MIKROBUS( mikrobus, MIKROBUS_RST ); \
179 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
180 cfg.ri = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
181 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT );
182 // lteiot12_map // lteiot12
185
190typedef struct
191{
192 // Output pins
193 digital_out_t pwr;
194 digital_out_t rts;
196 // Input pins
197 digital_in_t sta;
198 digital_in_t ri;
199 digital_in_t cts;
201 // Modules
202 uart_t uart;
204 // Buffers
205 uint8_t uart_rx_buffer[ LTEIOT12_RX_DRV_BUFFER_SIZE ];
206 uint8_t uart_tx_buffer[ LTEIOT12_TX_DRV_BUFFER_SIZE ];
208} lteiot12_t;
209
214typedef struct
215{
216 // Communication gpio pins
217 pin_name_t rx_pin;
218 pin_name_t tx_pin;
220 // Additional gpio pins
221 pin_name_t sta;
222 pin_name_t pwr;
223 pin_name_t rts;
224 pin_name_t ri;
225 pin_name_t cts;
227 // Static variable
228 uint32_t baud_rate;
230 uart_data_bits_t data_bit;
231 uart_parity_t parity_bit;
232 uart_stop_bits_t stop_bit;
235
240typedef enum
241{
246
248
265
280
293err_t lteiot12_generic_write ( lteiot12_t *ctx, uint8_t *data_in, uint16_t len );
294
307err_t lteiot12_generic_read ( lteiot12_t *ctx, uint8_t *data_out, uint16_t len );
308
318void lteiot12_set_pwr_pin ( lteiot12_t *ctx, uint8_t pin_state );
319
329void lteiot12_set_rts_pin ( lteiot12_t *ctx, uint8_t pin_state );
330
340
350
360void lteiot12_send_cmd ( lteiot12_t *ctx, uint8_t *cmd );
361
372void lteiot12_send_cmd_with_params ( lteiot12_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf );
373
383void lteiot12_send_cmd_check ( lteiot12_t *ctx, uint8_t *at_cmd_buf );
384
394void lteiot12_send_cmd_params_check ( lteiot12_t *ctx, uint8_t *at_cmd_buf );
395
405void lteiot12_set_sim_apn ( lteiot12_t *ctx, uint8_t *sim_apn );
406
417void lteiot12_send_sms_text_mode ( lteiot12_t *ctx, uint8_t *phone_number, uint8_t *sms_text );
418
432err_t lteiot12_send_sms_pdu ( lteiot12_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text );
433
445err_t lteiot12_parse_gngga ( uint8_t *rsp_buf, uint8_t gngga_element, uint8_t *element_data );
446
447#ifdef __cplusplus
448}
449#endif
450#endif // LTEIOT12_H
451 // lteiot12
453
454// ------------------------------------------------------------------------ END
#define LTEIOT12_RX_DRV_BUFFER_SIZE
Definition: lteiot12.h:156
#define LTEIOT12_TX_DRV_BUFFER_SIZE
LTE IoT 12 driver buffer size.
Definition: lteiot12.h:155
void lteiot12_cfg_setup(lteiot12_cfg_t *cfg)
LTE IoT 12 configuration object setup function.
err_t lteiot12_send_sms_pdu(lteiot12_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text)
LTE IoT 12 send SMS in PDU mode.
void lteiot12_send_cmd_check(lteiot12_t *ctx, uint8_t *at_cmd_buf)
LTE IoT 12 check the sent command.
err_t lteiot12_parse_gngga(uint8_t *rsp_buf, uint8_t gngga_element, uint8_t *element_data)
LTE IoT 12 parse GNGGA function.
void lteiot12_set_rts_pin(lteiot12_t *ctx, uint8_t pin_state)
LTE IoT 12 set RTS pin function.
void lteiot12_hw_reset(lteiot12_t *ctx)
LTE IoT 12 hardware reset function.
void lteiot12_send_cmd(lteiot12_t *ctx, uint8_t *cmd)
LTE IoT 12 send command function.
void lteiot12_send_sms_text_mode(lteiot12_t *ctx, uint8_t *phone_number, uint8_t *sms_text)
LTE IoT 12 send SMS in text mode.
void lteiot12_set_sim_apn(lteiot12_t *ctx, uint8_t *sim_apn)
LTE IoT 12 set sim card APN.
err_t lteiot12_generic_write(lteiot12_t *ctx, uint8_t *data_in, uint16_t len)
LTE IoT 12 data writing function.
void lteiot12_send_cmd_with_params(lteiot12_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf)
LTE IoT 12 send command function with parameter.
uint8_t lteiot12_get_cts_pin(lteiot12_t *ctx)
LTE IoT 12 get cts pin function.
err_t lteiot12_init(lteiot12_t *ctx, lteiot12_cfg_t *cfg)
LTE IoT 12 initialization function.
void lteiot12_set_pwr_pin(lteiot12_t *ctx, uint8_t pin_state)
LTE IoT 12 set PWR pin function.
void lteiot12_send_cmd_params_check(lteiot12_t *ctx, uint8_t *at_cmd_buf)
LTE IoT 12 check the command parameters.
err_t lteiot12_generic_read(lteiot12_t *ctx, uint8_t *data_out, uint16_t len)
LTE IoT 12 data reading function.
lteiot12_return_value_t
LTE IoT 12 Click return value data.
Definition: lteiot12.h:241
@ LTEIOT12_OK
Definition: lteiot12.h:242
@ LTEIOT12_ERROR
Definition: lteiot12.h:243
@ LTEIOT12_TIMEOUT
Definition: lteiot12.h:245
@ LTEIOT12_OWERFLOW
Definition: lteiot12.h:244
LTE IoT 12 Click configuration object.
Definition: lteiot12.h:215
pin_name_t sta
Definition: lteiot12.h:221
pin_name_t rts
Definition: lteiot12.h:223
uint32_t baud_rate
Definition: lteiot12.h:228
pin_name_t cts
Definition: lteiot12.h:225
bool uart_blocking
Definition: lteiot12.h:229
pin_name_t ri
Definition: lteiot12.h:224
uart_data_bits_t data_bit
Definition: lteiot12.h:230
pin_name_t tx_pin
Definition: lteiot12.h:218
pin_name_t pwr
Definition: lteiot12.h:222
pin_name_t rx_pin
Definition: lteiot12.h:217
uart_stop_bits_t stop_bit
Definition: lteiot12.h:232
uart_parity_t parity_bit
Definition: lteiot12.h:231
LTE IoT 12 Click context object.
Definition: lteiot12.h:191
digital_in_t sta
Definition: lteiot12.h:197
digital_out_t pwr
Definition: lteiot12.h:193
digital_out_t rts
Definition: lteiot12.h:194
digital_in_t ri
Definition: lteiot12.h:198
uart_t uart
Definition: lteiot12.h:202
digital_in_t cts
Definition: lteiot12.h:199