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 )
74 
80 #define LTEIOT2_RETVAL uint8_t
81 
87 #define LTEIOT2_NMEA_GPGGA 1
88 #define LTEIOT2_NMEA_GPGGA_NUM_ELEMENT 15
89 
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
109 
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
120 
126 #define LTEIOT2_MODULE_POWER_ON 1
127 #define LTEIOT2_MODULE_POWER_OFF 0
128 
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"
151 
157 #define DRV_RX_BUFFER_SIZE 256
158 #define DRV_TX_BUFFER_SIZE 256
159  // End group macro
162 // --------------------------------------------------------------- PUBLIC TYPES
170 typedef 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 
196 typedef 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 
219 } lteiot2_cfg_t;
220 
225 typedef enum
226 {
228  LTEIOT2_ERROR = -1
229 
231 
235 typedef uint8_t lteiot2_error_t;
236  // End types group
238 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
239 
245 #ifdef __cplusplus
246 extern "C"{
247 #endif
248 
258 
268 
274 void lteiot2_module_power ( lteiot2_t *ctx, uint8_t state );
275 
282 void lteiot2_generic_write ( lteiot2_t *ctx, char *data_buf, uint16_t len );
283 
291 int32_t lteiot2_generic_read ( lteiot2_t *ctx, char *data_buf, uint16_t max_len );
292 
301 void lteiot2_set_rts ( lteiot2_t *ctx, uint8_t state );
302 
311 uint8_t lteiot2_get_cts ( lteiot2_t *ctx );
312 
322 void lteiot2_send_cmd ( lteiot2_t *ctx, char *cmd );
323 
334 void lteiot2_send_cmd_with_parameter ( lteiot2_t *ctx, char *at_cmd_buf, char *param_buf );
335 
345 void lteiot2_send_cmd_check ( lteiot2_t *ctx, char *at_cmd_buf );
346 
356 void lteiot2_send_cmd_parameter_check ( lteiot2_t *ctx, char *at_cmd_buf );
357 
367 void lteiot2_set_sim_apn ( lteiot2_t *ctx, char *sim_apn );
368 
379 void lteiot2_send_sms_text ( lteiot2_t *ctx, char *phone_number, char *sms_text );
380 
394 err_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  // End public_function group
418 
419 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: lteiot2.h:157
lteiot2_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: lteiot2.h:215
lteiot2_t::uart
uart_t uart
Definition: lteiot2.h:186
lteiot2_t::pwk
digital_out_t pwk
Definition: lteiot2.h:174
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:209
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:217
lteiot2_t
Click ctx object definition.
Definition: lteiot2.h:171
lteiot2_t::ri
digital_in_t ri
Definition: lteiot2.h:181
LTEIOT2_OK
@ LTEIOT2_OK
Definition: lteiot2.h:227
lteiot2_cfg_t::uart_blocking
bool uart_blocking
Definition: lteiot2.h:214
lteiot2_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: lteiot2.h:216
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:228
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:80
lteiot2_t::cts
digital_in_t cts
Definition: lteiot2.h:182
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:213
lteiot2_cfg_t
Click configuration structure definition.
Definition: lteiot2.h:197
lteiot2_t::sta
digital_in_t sta
Definition: lteiot2.h:180
lteiot2_cfg_t::ri
pin_name_t ri
Definition: lteiot2.h:208
lteiot2_cfg_t::sta
pin_name_t sta
Definition: lteiot2.h:205
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:201
lteiot2_cfg_t::rx_pin
pin_name_t rx_pin
Definition: lteiot2.h:200
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:235
lteiot2_cfg_t::rts
pin_name_t rts
Definition: lteiot2.h:207
lteiot2_return_value_t
lteiot2_return_value_t
LTE IoT 2 Click return value data.
Definition: lteiot2.h:226
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:206
lteiot2_t::rts
digital_out_t rts
Definition: lteiot2.h:175