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 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_uart.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define LTEIOT2_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
54  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
55  cfg.sta = MIKROBUS( mikrobus, MIKROBUS_AN ); \
56  cfg.pwk = MIKROBUS( mikrobus, MIKROBUS_RST ); \
57  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
58  cfg.ri = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
59  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT )
60 
66 #define LTEIOT2_RETVAL uint8_t
67 
73 #define LTEIOT2_NMEA_GPGGA 1
74 #define LTEIOT2_NMEA_GPGGA_NUM_ELEMENT 15
75 
81 #define LTEIOT2_GPGGA_TIME 1
82 #define LTEIOT2_GPGGA_LATITUDE 2
83 #define LTEIOT2_GPGGA_LATITUDE_SIDE 3
84 #define LTEIOT2_GPGGA_LONGITUDE 4
85 #define LTEIOT2_GPGGA_LONGITUDE_SIDE 5
86 #define LTEIOT2_GPGGA_QUALITY_INDICATOR 6
87 #define LTEIOT2_GPGGA_NUMBER_OF_SATELLITES 7
88 #define LTEIOT2_GPGGA_H_DILUTION_OF_POS 8
89 #define LTEIOT2_GPGGA_ALTITUDE 9
90 #define LTEIOT2_GPGGA_ALTITUDE_UNIT 10
91 #define LTEIOT2_GPGGA_GEOIDAL_SEPARATION 11
92 #define LTEIOT2_GPGGA_GEOIDAL_SEPARATION_UNIT 12
93 #define LTEIOT2_GPGGA_TIME_SINCE_LAST_DGPS 13
94 #define LTEIOT2_GPGGA_DGPS_REFERENCE_STATION_ID 14
95 
101 #define LTEIOT2_ERROR_COMMAND_OR_ELEMENT 0xFF
102 #define LTEIOT2_ERROR_START_OR_END_COMMAND 0x8F
103 #define LTEIOT2_ERROR_NEXT_ELEMENT 0x4F
104 #define LTEIOT2_ERROR_CURRENT_ELEMENT 0x2F
105 #define LTEIOT2_NO_ERROR 0x00
106 
112 #define LTEIOT2_MODULE_POWER_ON 1
113 #define LTEIOT2_MODULE_POWER_OFF 0
114 
120 #define LTEIOT2_CMD_AT "AT"
121 #define LTEIOT2_CMD_ATI "ATI"
122 #define LTEIOT2_CMD_CGMR "AT+CGMR"
123 
124 #define LTEIOT2_CMD_CFUN "AT+CFUN"
125 #define LTEIOT2_CMD_CREG "AT+CREG"
126 #define LTEIOT2_CMD_CGDCONT "AT+CGDCONT"
127 #define LTEIOT2_CMD_CIMI "AT+CIMI"
128 #define LTEIOT2_CMD_CGATT "AT+CGATT"
129 #define LTEIOT2_CMD_CSQ "AT+CSQ"
130 #define LTEIOT2_CMD_COPS "AT+COPS"
131 #define LTEIOT2_CMD_CMGS "AT+CMGS"
132 #define LTEIOT2_CMD_CMGF "AT+CMGF"
133 #define LTEIOT2_CMD_QGPS "AT+QGPS"
134 #define LTEIOT2_CMD_QGPSCFG "AT+QGPSCFG"
135 #define LTEIOT2_CMD_QGPSGNMEA "AT+QGPSGNMEA"
136 #define LTEIOT2_CMD_QGPSLOC "AT+QGPSLOC"
137 
143 #define DRV_RX_BUFFER_SIZE 256
144 #define DRV_TX_BUFFER_SIZE 256
145  // End group macro
148 // --------------------------------------------------------------- PUBLIC TYPES
156 typedef struct
157 {
158  // Output pins
159 
160  digital_out_t pwk;
161  digital_out_t rts;
162 
163 
164  // Input pins
165 
166  digital_in_t sta;
167  digital_in_t ri;
168  digital_in_t cts;
169 
170  // Modules
171 
172  uart_t uart;
173 
174  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
175  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
176 
177 } lteiot2_t;
178 
182 typedef struct
183 {
184  // Communication gpio pins
185 
186  pin_name_t rx_pin;
187  pin_name_t tx_pin;
188 
189  // Additional gpio pins
190 
191  pin_name_t sta;
192  pin_name_t pwk;
193  pin_name_t rts;
194  pin_name_t ri;
195  pin_name_t cts;
196 
197  // static variable
198 
199  uint32_t baud_rate; // Clock speed.
201  uart_data_bits_t data_bit; // Data bits.
202  uart_parity_t parity_bit; // Parity bit.
203  uart_stop_bits_t stop_bit; // Stop bits.
204 
205 } lteiot2_cfg_t;
206 
211 typedef enum
212 {
214  LTEIOT2_ERROR = -1
215 
217 
221 typedef uint8_t lteiot2_error_t;
222  // End types group
224 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
225 
231 #ifdef __cplusplus
232 extern "C"{
233 #endif
234 
244 
254 
260 void lteiot2_module_power ( lteiot2_t *ctx, uint8_t state );
261 
268 void lteiot2_generic_write ( lteiot2_t *ctx, char *data_buf, uint16_t len );
269 
277 int32_t lteiot2_generic_read ( lteiot2_t *ctx, char *data_buf, uint16_t max_len );
278 
287 void lteiot2_set_rts ( lteiot2_t *ctx, uint8_t state );
288 
297 uint8_t lteiot2_get_cts ( lteiot2_t *ctx );
298 
308 void lteiot2_send_cmd ( lteiot2_t *ctx, char *cmd );
309 
320 void lteiot2_send_cmd_with_parameter ( lteiot2_t *ctx, char *at_cmd_buf, char *param_buf );
321 
331 void lteiot2_send_cmd_check ( lteiot2_t *ctx, char *at_cmd_buf );
332 
342 void lteiot2_send_cmd_parameter_check ( lteiot2_t *ctx, char *at_cmd_buf );
343 
353 void lteiot2_set_sim_apn ( lteiot2_t *ctx, char *sim_apn );
354 
365 void lteiot2_send_sms_text ( lteiot2_t *ctx, char *phone_number, char *sms_text );
366 
380 err_t lteiot2_send_sms_pdu ( lteiot2_t *ctx, char *service_center_number,
381  char *phone_number, char *sms_text );
382 
392 (
393  char *rsp, uint8_t command,
394  uint8_t element, char *parser_buf
395 );
396 
397 #ifdef __cplusplus
398 }
399 #endif
400 #endif // _LTEIOT2_H_
401  // End public_function group
404 
405 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: lteiot2.h:143
lteiot2_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: lteiot2.h:201
lteiot2_t::uart
uart_t uart
Definition: lteiot2.h:172
lteiot2_t::pwk
digital_out_t pwk
Definition: lteiot2.h:160
lteiot2_send_cmd
void lteiot2_send_cmd(lteiot2_t *ctx, char *cmd)
Send command function.
lteiot2_cfg_t::cts
pin_name_t cts
Definition: lteiot2.h:195
lteiot2_get_cts
uint8_t lteiot2_get_cts(lteiot2_t *ctx)
CTS Pin Get function.
lteiot2_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: lteiot2.h:203
lteiot2_t
Click ctx object definition.
Definition: lteiot2.h:157
lteiot2_t::ri
digital_in_t ri
Definition: lteiot2.h:167
LTEIOT2_OK
@ LTEIOT2_OK
Definition: lteiot2.h:213
lteiot2_cfg_t::uart_blocking
bool uart_blocking
Definition: lteiot2.h:200
lteiot2_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: lteiot2.h:202
lteiot2_send_cmd_parameter_check
void lteiot2_send_cmd_parameter_check(lteiot2_t *ctx, char *at_cmd_buf)
Check the command parameters.
lteiot2_send_sms_pdu
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.
lteiot2_generic_read
int32_t lteiot2_generic_read(lteiot2_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
LTEIOT2_ERROR
@ LTEIOT2_ERROR
Definition: lteiot2.h:214
lteiot2_send_cmd_check
void lteiot2_send_cmd_check(lteiot2_t *ctx, char *at_cmd_buf)
Check the sent command.
LTEIOT2_RETVAL
#define LTEIOT2_RETVAL
Definition: lteiot2.h:66
lteiot2_t::cts
digital_in_t cts
Definition: lteiot2.h:168
lteiot2_cfg_setup
void lteiot2_cfg_setup(lteiot2_cfg_t *cfg)
Config Object Initialization function.
lteiot2_module_power
void lteiot2_module_power(lteiot2_t *ctx, uint8_t state)
Power ON/OFF the module.
lteiot2_cfg_t::baud_rate
uint32_t baud_rate
Definition: lteiot2.h:199
lteiot2_cfg_t
Click configuration structure definition.
Definition: lteiot2.h:183
lteiot2_t::sta
digital_in_t sta
Definition: lteiot2.h:166
lteiot2_cfg_t::ri
pin_name_t ri
Definition: lteiot2.h:194
lteiot2_cfg_t::sta
pin_name_t sta
Definition: lteiot2.h:191
lteiot2_generic_write
void lteiot2_generic_write(lteiot2_t *ctx, char *data_buf, uint16_t len)
Generic write function.
lteiot2_set_rts
void lteiot2_set_rts(lteiot2_t *ctx, uint8_t state)
Sets state of the RTS pin.
lteiot2_cfg_t::tx_pin
pin_name_t tx_pin
Definition: lteiot2.h:187
lteiot2_cfg_t::rx_pin
pin_name_t rx_pin
Definition: lteiot2.h:186
lteiot2_send_sms_text
void lteiot2_send_sms_text(lteiot2_t *ctx, char *phone_number, char *sms_text)
LTE IoT 2 send SMS in text mode.
lteiot2_set_sim_apn
void lteiot2_set_sim_apn(lteiot2_t *ctx, char *sim_apn)
Set sim card APN.
lteiot2_send_cmd_with_parameter
void lteiot2_send_cmd_with_parameter(lteiot2_t *ctx, char *at_cmd_buf, char *param_buf)
Send command function with parameter.
lteiot2_error_t
uint8_t lteiot2_error_t
Error type.
Definition: lteiot2.h:221
lteiot2_cfg_t::rts
pin_name_t rts
Definition: lteiot2.h:193
lteiot2_return_value_t
lteiot2_return_value_t
LTE IoT 2 Click return value data.
Definition: lteiot2.h:212
lteiot2_generic_parser
lteiot2_error_t lteiot2_generic_parser(char *rsp, uint8_t command, uint8_t element, char *parser_buf)
Generic parser function.
lteiot2_init
LTEIOT2_RETVAL lteiot2_init(lteiot2_t *ctx, lteiot2_cfg_t *cfg)
Initialization function.
lteiot2_cfg_t::pwk
pin_name_t pwk
Definition: lteiot2.h:192
lteiot2_t::rts
digital_out_t rts
Definition: lteiot2.h:161