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 "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_uart.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define LTEIOT2_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
64  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
65  cfg.sta = MIKROBUS( mikrobus, MIKROBUS_AN ); \
66  cfg.pwk = MIKROBUS( mikrobus, MIKROBUS_RST ); \
67  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
68  cfg.ri = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
69  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT )
70 
76 #define LTEIOT2_RETVAL uint8_t
77 
83 #define LTEIOT2_NMEA_GPGGA 1
84 #define LTEIOT2_NMEA_GPGGA_NUM_ELEMENT 15
85 
91 #define LTEIOT2_GPGGA_TIME 1
92 #define LTEIOT2_GPGGA_LATITUDE 2
93 #define LTEIOT2_GPGGA_LATITUDE_SIDE 3
94 #define LTEIOT2_GPGGA_LONGITUDE 4
95 #define LTEIOT2_GPGGA_LONGITUDE_SIDE 5
96 #define LTEIOT2_GPGGA_QUALITY_INDICATOR 6
97 #define LTEIOT2_GPGGA_NUMBER_OF_SATELLITES 7
98 #define LTEIOT2_GPGGA_H_DILUTION_OF_POS 8
99 #define LTEIOT2_GPGGA_ALTITUDE 9
100 #define LTEIOT2_GPGGA_ALTITUDE_UNIT 10
101 #define LTEIOT2_GPGGA_GEOIDAL_SEPARATION 11
102 #define LTEIOT2_GPGGA_GEOIDAL_SEPARATION_UNIT 12
103 #define LTEIOT2_GPGGA_TIME_SINCE_LAST_DGPS 13
104 #define LTEIOT2_GPGGA_DGPS_REFERENCE_STATION_ID 14
105 
111 #define LTEIOT2_ERROR_COMMAND_OR_ELEMENT 0xFF
112 #define LTEIOT2_ERROR_START_OR_END_COMMAND 0x8F
113 #define LTEIOT2_ERROR_NEXT_ELEMENT 0x4F
114 #define LTEIOT2_ERROR_CURRENT_ELEMENT 0x2F
115 #define LTEIOT2_NO_ERROR 0x00
116 
122 #define LTEIOT2_MODULE_POWER_ON 1
123 #define LTEIOT2_MODULE_POWER_OFF 0
124 
130 #define LTEIOT2_CMD_AT "AT"
131 #define LTEIOT2_CMD_ATI "ATI"
132 #define LTEIOT2_CMD_CGMR "AT+CGMR"
133 
134 #define LTEIOT2_CMD_CFUN "AT+CFUN"
135 #define LTEIOT2_CMD_CREG "AT+CREG"
136 #define LTEIOT2_CMD_CGDCONT "AT+CGDCONT"
137 #define LTEIOT2_CMD_CIMI "AT+CIMI"
138 #define LTEIOT2_CMD_CGATT "AT+CGATT"
139 #define LTEIOT2_CMD_CSQ "AT+CSQ"
140 #define LTEIOT2_CMD_COPS "AT+COPS"
141 #define LTEIOT2_CMD_CMGS "AT+CMGS"
142 #define LTEIOT2_CMD_CMGF "AT+CMGF"
143 #define LTEIOT2_CMD_QGPS "AT+QGPS"
144 #define LTEIOT2_CMD_QGPSCFG "AT+QGPSCFG"
145 #define LTEIOT2_CMD_QGPSGNMEA "AT+QGPSGNMEA"
146 #define LTEIOT2_CMD_QGPSLOC "AT+QGPSLOC"
147 
153 #define DRV_RX_BUFFER_SIZE 256
154 #define DRV_TX_BUFFER_SIZE 256
155  // End group macro
158 // --------------------------------------------------------------- PUBLIC TYPES
166 typedef struct
167 {
168  // Output pins
169 
170  digital_out_t pwk;
171  digital_out_t rts;
172 
173 
174  // Input pins
175 
176  digital_in_t sta;
177  digital_in_t ri;
178  digital_in_t cts;
179 
180  // Modules
181 
182  uart_t uart;
183 
184  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
185  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
186 
187 } lteiot2_t;
188 
192 typedef struct
193 {
194  // Communication gpio pins
195 
196  pin_name_t rx_pin;
197  pin_name_t tx_pin;
198 
199  // Additional gpio pins
200 
201  pin_name_t sta;
202  pin_name_t pwk;
203  pin_name_t rts;
204  pin_name_t ri;
205  pin_name_t cts;
206 
207  // static variable
208 
209  uint32_t baud_rate; // Clock speed.
211  uart_data_bits_t data_bit; // Data bits.
212  uart_parity_t parity_bit; // Parity bit.
213  uart_stop_bits_t stop_bit; // Stop bits.
214 
215 } lteiot2_cfg_t;
216 
221 typedef enum
222 {
224  LTEIOT2_ERROR = -1
225 
227 
231 typedef uint8_t lteiot2_error_t;
232  // End types group
234 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
235 
241 #ifdef __cplusplus
242 extern "C"{
243 #endif
244 
254 
264 
270 void lteiot2_module_power ( lteiot2_t *ctx, uint8_t state );
271 
278 void lteiot2_generic_write ( lteiot2_t *ctx, char *data_buf, uint16_t len );
279 
287 int32_t lteiot2_generic_read ( lteiot2_t *ctx, char *data_buf, uint16_t max_len );
288 
297 void lteiot2_set_rts ( lteiot2_t *ctx, uint8_t state );
298 
307 uint8_t lteiot2_get_cts ( lteiot2_t *ctx );
308 
318 void lteiot2_send_cmd ( lteiot2_t *ctx, char *cmd );
319 
330 void lteiot2_send_cmd_with_parameter ( lteiot2_t *ctx, char *at_cmd_buf, char *param_buf );
331 
341 void lteiot2_send_cmd_check ( lteiot2_t *ctx, char *at_cmd_buf );
342 
352 void lteiot2_send_cmd_parameter_check ( lteiot2_t *ctx, char *at_cmd_buf );
353 
363 void lteiot2_set_sim_apn ( lteiot2_t *ctx, char *sim_apn );
364 
375 void lteiot2_send_sms_text ( lteiot2_t *ctx, char *phone_number, char *sms_text );
376 
390 err_t lteiot2_send_sms_pdu ( lteiot2_t *ctx, char *service_center_number,
391  char *phone_number, char *sms_text );
392 
402 (
403  char *rsp, uint8_t command,
404  uint8_t element, char *parser_buf
405 );
406 
407 #ifdef __cplusplus
408 }
409 #endif
410 #endif // _LTEIOT2_H_
411  // End public_function group
414 
415 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: lteiot2.h:153
lteiot2_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: lteiot2.h:211
lteiot2_t::uart
uart_t uart
Definition: lteiot2.h:182
lteiot2_t::pwk
digital_out_t pwk
Definition: lteiot2.h:170
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:205
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:213
lteiot2_t
Click ctx object definition.
Definition: lteiot2.h:167
lteiot2_t::ri
digital_in_t ri
Definition: lteiot2.h:177
LTEIOT2_OK
@ LTEIOT2_OK
Definition: lteiot2.h:223
lteiot2_cfg_t::uart_blocking
bool uart_blocking
Definition: lteiot2.h:210
lteiot2_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: lteiot2.h:212
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:224
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:76
lteiot2_t::cts
digital_in_t cts
Definition: lteiot2.h:178
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:209
lteiot2_cfg_t
Click configuration structure definition.
Definition: lteiot2.h:193
lteiot2_t::sta
digital_in_t sta
Definition: lteiot2.h:176
lteiot2_cfg_t::ri
pin_name_t ri
Definition: lteiot2.h:204
lteiot2_cfg_t::sta
pin_name_t sta
Definition: lteiot2.h:201
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:197
lteiot2_cfg_t::rx_pin
pin_name_t rx_pin
Definition: lteiot2.h:196
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:231
lteiot2_cfg_t::rts
pin_name_t rts
Definition: lteiot2.h:203
lteiot2_return_value_t
lteiot2_return_value_t
LTE IoT 2 Click return value data.
Definition: lteiot2.h:222
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:202
lteiot2_t::rts
digital_out_t rts
Definition: lteiot2.h:171