lteiot7 2.1.0.0
lteiot7.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 LTEIOT7_H
29#define LTEIOT7_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 LTEIOT7_CMD_AT "AT"
74#define LTEIOT7_CMD_ATI "ATI"
75#define LTEIOT7_CMD_CGMR "AT+CGMR"
76#define LTEIOT7_CMD_CFUN "AT+CFUN"
77#define LTEIOT7_CMD_CREG "AT+CREG"
78#define LTEIOT7_CMD_CGREG "AT+CGREG"
79#define LTEIOT7_CMD_CGDCONT "AT+CGDCONT"
80#define LTEIOT7_CMD_CIMI "AT+CIMI"
81#define LTEIOT7_CMD_CMEE "AT+CMEE"
82#define LTEIOT7_CMD_CGATT "AT+CGATT"
83#define LTEIOT7_CMD_CSQ "AT+CSQ"
84#define LTEIOT7_CMD_COPS "AT+COPS"
85#define LTEIOT7_CMD_CMGS "AT+CMGS"
86#define LTEIOT7_CMD_CMGF "AT+CMGF"
87#define LTEIOT7_CMD_CGACT "AT+CGACT"
88#define LTEIOT7_CMD_USOCR "AT+USOCR"
89#define LTEIOT7_CMD_USOCO "AT+USOCO"
90#define LTEIOT7_CMD_USOWR "AT+USOWR"
91#define LTEIOT7_CMD_USORD "AT+USORD"
92#define LTEIOT7_CMD_USORF "AT+USORF"
93#define LTEIOT7_CMD_USOCL "AT+USOCL"
94#define LTEIOT7_CMD_UGPS "AT+UGPS"
95#define LTEIOT7_CMD_UGGGA "AT+UGGGA"
96
101#define LTEIOT7_RSP_OK "OK"
102#define LTEIOT7_RSP_ERROR "ERROR"
103
108#define LTEIOT7_POWER_STATE_SWITCH 0
109#define LTEIOT7_POWER_STATE_ON 1
110#define LTEIOT7_POWER_STATE_REBOOT 2
111
116#define LTEIOT7_RSP_START "$"
117#define LTEIOT7_RSP_DELIMITER ","
118#define LTEIOT7_RSP_GPGGA "$GPGGA"
119
124#define LTEIOT7_GPGGA_ELEMENT_SIZE 15
125#define LTEIOT7_GPGGA_TIME 1
126#define LTEIOT7_GPGGA_LATITUDE 2
127#define LTEIOT7_GPGGA_LATITUDE_SIDE 3
128#define LTEIOT7_GPGGA_LONGITUDE 4
129#define LTEIOT7_GPGGA_LONGITUDE_SIDE 5
130#define LTEIOT7_GPGGA_QUALITY_INDICATOR 6
131#define LTEIOT7_GPGGA_NUMBER_OF_SATELLITES 7
132#define LTEIOT7_GPGGA_H_DILUTION_OF_POS 8
133#define LTEIOT7_GPGGA_ALTITUDE 9
134#define LTEIOT7_GPGGA_ALTITUDE_UNIT 10
135#define LTEIOT7_GPGGA_GEOIDAL_SEPARATION 11
136#define LTEIOT7_GPGGA_GEOIDAL_SEPARATION_UNIT 12
137#define LTEIOT7_GPGGA_TIME_SINCE_LAST_DGPS 13
138#define LTEIOT7_GPGGA_DGPS_REFERENCE_STATION_ID 14
139
145#define DRV_BUFFER_SIZE 256
146
147 // lteiot7_cmd
148
163#define LTEIOT7_MAP_MIKROBUS( cfg, mikrobus ) \
164 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
165 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
166 cfg.pwr = MIKROBUS( mikrobus, MIKROBUS_AN ); \
167 cfg.ein = MIKROBUS( mikrobus, MIKROBUS_RST ); \
168 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
169 cfg.ri = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
170 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT );
171
172 // lteiot7_map
173 // lteiot7
174
179typedef struct
180{
181 // Output pins
182 digital_out_t pwr;
183 digital_out_t ein;
184 digital_out_t rts;
186 // Input pins
187 digital_in_t ri;
188 digital_in_t cts;
190 // Modules
191 uart_t uart;
193 // Buffers
194 char uart_rx_buffer[ DRV_BUFFER_SIZE ];
195 char uart_tx_buffer[ DRV_BUFFER_SIZE ];
197} lteiot7_t;
198
203typedef struct
204{
205 // Communication gpio pins
206 pin_name_t rx_pin;
207 pin_name_t tx_pin;
209 // Additional gpio pins
210 pin_name_t pwr;
211 pin_name_t ein;
212 pin_name_t rts;
213 pin_name_t ri;
214 pin_name_t cts;
216 // Static variable
217 uint32_t baud_rate;
219 uart_data_bits_t data_bit;
220 uart_parity_t parity_bit;
221 uart_stop_bits_t stop_bit;
224
238
255
270
283err_t lteiot7_generic_write ( lteiot7_t *ctx, char *data_in, uint16_t len );
284
297err_t lteiot7_generic_read ( lteiot7_t *ctx, char *data_out, uint16_t len );
298
308void lteiot7_set_pwr_pin ( lteiot7_t *ctx, uint8_t state );
309
319void lteiot7_set_ein_pin ( lteiot7_t *ctx, uint8_t state );
320
330void lteiot7_set_rts_pin ( lteiot7_t *ctx, uint8_t state );
331
341
351
363void lteiot7_set_power_state ( lteiot7_t *ctx, uint8_t state );
364
374void lteiot7_send_cmd ( lteiot7_t *ctx, char *cmd );
375
386void lteiot7_send_cmd_with_parameter ( lteiot7_t *ctx, char *at_cmd_buf, char *param_buf );
387
397void lteiot7_send_cmd_check ( lteiot7_t *ctx, char *at_cmd_buf );
398
408void lteiot7_send_cmd_parameter_check ( lteiot7_t *ctx, char *at_cmd_buf );
409
419void lteiot7_set_sim_apn ( lteiot7_t *ctx, char *sim_apn );
420
431void lteiot7_send_sms_text ( lteiot7_t *ctx, char *phone_number, char *sms_text );
432
446err_t lteiot7_send_sms_pdu ( lteiot7_t *ctx, char *service_center_number, char *phone_number, char *sms_text );
447
459err_t lteiot7_parse_gpgga ( char *rsp_buf, uint8_t gpgga_element, char *element_data );
460
461#ifdef __cplusplus
462}
463#endif
464#endif // LTEIOT7_H
465
466 // lteiot7
467
468// ------------------------------------------------------------------------ END
#define DRV_BUFFER_SIZE
LTE IoT 7 driver buffer size.
Definition lteiot7.h:145
err_t lteiot7_send_sms_pdu(lteiot7_t *ctx, char *service_center_number, char *phone_number, char *sms_text)
LTE IoT 7 send SMS in PDU mode.
void lteiot7_send_cmd_check(lteiot7_t *ctx, char *at_cmd_buf)
Check the sent command.
uint8_t lteiot7_get_cts_pin(lteiot7_t *ctx)
LTE IoT 7 get CTS pin function.
err_t lteiot7_generic_write(lteiot7_t *ctx, char *data_in, uint16_t len)
LTE IoT 7 data writing function.
void lteiot7_send_cmd_with_parameter(lteiot7_t *ctx, char *at_cmd_buf, char *param_buf)
Send command function with parameter.
void lteiot7_set_rts_pin(lteiot7_t *ctx, uint8_t state)
LTE IoT 7 set RTS pin function.
void lteiot7_set_pwr_pin(lteiot7_t *ctx, uint8_t state)
LTE IoT 7 set PWR pin function.
err_t lteiot7_generic_read(lteiot7_t *ctx, char *data_out, uint16_t len)
LTE IoT 7 data reading function.
void lteiot7_cfg_setup(lteiot7_cfg_t *cfg)
LTE IoT 7 configuration object setup function.
void lteiot7_set_ein_pin(lteiot7_t *ctx, uint8_t state)
LTE IoT 7 set EIN pin function.
err_t lteiot7_parse_gpgga(char *rsp_buf, uint8_t gpgga_element, char *element_data)
LTE IoT 7 parse GPGGA function.
void lteiot7_set_sim_apn(lteiot7_t *ctx, char *sim_apn)
Set sim card APN.
uint8_t lteiot7_get_ri_pin(lteiot7_t *ctx)
LTE IoT 7 get RI pin function.
err_t lteiot7_init(lteiot7_t *ctx, lteiot7_cfg_t *cfg)
LTE IoT 7 initialization function.
void lteiot7_send_sms_text(lteiot7_t *ctx, char *phone_number, char *sms_text)
LTE IoT 7 send SMS in text mode.
void lteiot7_send_cmd(lteiot7_t *ctx, char *cmd)
Send command function.
void lteiot7_send_cmd_parameter_check(lteiot7_t *ctx, char *at_cmd_buf)
Check the command parameters.
void lteiot7_set_power_state(lteiot7_t *ctx, uint8_t state)
LTE IoT 7 set power state function.
lteiot7_return_value_t
LTE IoT 7 Click return value data.
Definition lteiot7.h:230
@ LTEIOT7_ERROR_CMD
Definition lteiot7.h:234
@ LTEIOT7_ERROR_UNKNOWN
Definition lteiot7.h:235
@ LTEIOT7_ERROR_TIMEOUT
Definition lteiot7.h:233
@ LTEIOT7_OK
Definition lteiot7.h:231
@ LTEIOT7_ERROR
Definition lteiot7.h:232
LTE IoT 7 Click configuration object.
Definition lteiot7.h:204
pin_name_t rts
Definition lteiot7.h:212
uint32_t baud_rate
Definition lteiot7.h:217
pin_name_t ein
Definition lteiot7.h:211
pin_name_t cts
Definition lteiot7.h:214
bool uart_blocking
Definition lteiot7.h:218
pin_name_t ri
Definition lteiot7.h:213
uart_data_bits_t data_bit
Definition lteiot7.h:219
pin_name_t tx_pin
Definition lteiot7.h:207
pin_name_t pwr
Definition lteiot7.h:210
pin_name_t rx_pin
Definition lteiot7.h:206
uart_stop_bits_t stop_bit
Definition lteiot7.h:221
uart_parity_t parity_bit
Definition lteiot7.h:220
LTE IoT 7 Click context object.
Definition lteiot7.h:180
digital_out_t pwr
Definition lteiot7.h:182
digital_out_t rts
Definition lteiot7.h:184
digital_in_t ri
Definition lteiot7.h:187
uart_t uart
Definition lteiot7.h:191
digital_out_t ein
Definition lteiot7.h:183
digital_in_t cts
Definition lteiot7.h:188