lteiot11  2.1.0.0
lteiot11.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 LTEIOT11_H
29 #define LTEIOT11_H
30 
31 #ifdef __cplusplus
32 extern "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 LTEIOT11_CMD_AT "AT"
70 #define LTEIOT11_CMD_ATI "ATI"
71 #define LTEIOT11_CMD_CFUN "AT+CFUN"
72 #define LTEIOT11_CMD_CREG "AT+CREG"
73 #define LTEIOT11_CMD_CGDCONT "AT+CGDCONT"
74 #define LTEIOT11_CMD_CESQ "AT+CESQ"
75 #define LTEIOT11_CMD_COPS "AT+COPS"
76 #define LTEIOT11_CMD_CMGS "AT+CMGS"
77 #define LTEIOT11_CMD_CMGF "AT+CMGF"
78 #define LTEIOT11_CMD_CGPADDR "AT+CGPADDR"
79 #define LTEIOT11_CMD_SICA "AT^SICA"
80 #define LTEIOT11_CMD_SISS "AT^SISS"
81 #define LTEIOT11_CMD_SISO "AT^SISO"
82 #define LTEIOT11_CMD_SISW "AT^SISW"
83 #define LTEIOT11_CMD_SISR "AT^SISR"
84 #define LTEIOT11_CMD_SISC "AT^SISC"
85 #define LTEIOT11_CMD_SGPSC "AT^SGPSC"
86 
91 #define LTEIOT11_RSP_OK "OK"
92 #define LTEIOT11_RSP_ERROR "ERROR"
93 #define LTEIOT11_RSP_SYSSTART "^SYSSTART"
94 
99 #define LTEIOT11_RSP_START "$"
100 #define LTEIOT11_RSP_DELIMITER ","
101 #define LTEIOT11_RSP_END "\r\n"
102 #define LTEIOT11_RSP_GGA "GGA"
103 
108 #define LTEIOT11_GGA_ELEMENT_SIZE 15
109 #define LTEIOT11_GGA_TIME 1
110 #define LTEIOT11_GGA_LATITUDE 2
111 #define LTEIOT11_GGA_LATITUDE_SIDE 3
112 #define LTEIOT11_GGA_LONGITUDE 4
113 #define LTEIOT11_GGA_LONGITUDE_SIDE 5
114 #define LTEIOT11_GGA_QUALITY_INDICATOR 6
115 #define LTEIOT11_GGA_NUMBER_OF_SATELLITES 7
116 #define LTEIOT11_GGA_H_DILUTION_OF_POS 8
117 #define LTEIOT11_GGA_ALTITUDE 9
118 #define LTEIOT11_GGA_ALTITUDE_UNIT 10
119 #define LTEIOT11_GGA_GEOIDAL_SEPARATION 11
120 #define LTEIOT11_GGA_GEOIDAL_SEPARATION_UNIT 12
121 #define LTEIOT11_GGA_TIME_SINCE_LAST_DGPS 13
122 #define LTEIOT11_GGA_DGPS_REFERENCE_STATION_ID 14
123 
129 #define LTEIOT11_RX_DRV_BUFFER_SIZE 256
130 #define LTEIOT11_TX_DRV_BUFFER_SIZE 256
131  // lteiot11_cmd
133 
148 #define LTEIOT11_MAP_MIKROBUS( cfg, mikrobus ) \
149  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
150  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
151  cfg.smi = MIKROBUS( mikrobus, MIKROBUS_AN ); \
152  cfg.on = MIKROBUS( mikrobus, MIKROBUS_RST ); \
153  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
154  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
155  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT );
156  // lteiot11_map // lteiot11
159 
164 typedef struct
165 {
166  // Output pins
167  digital_out_t on;
168  digital_out_t cs;
169  digital_out_t rts;
171  // Input pins
172  digital_in_t smi;
173  digital_in_t cts;
175  // Modules
176  uart_t uart;
178  // Buffers
179  uint8_t uart_rx_buffer[ LTEIOT11_RX_DRV_BUFFER_SIZE ];
180  uint8_t uart_tx_buffer[ LTEIOT11_TX_DRV_BUFFER_SIZE ];
182 } lteiot11_t;
183 
188 typedef struct
189 {
190  // Communication gpio pins
191  pin_name_t rx_pin;
192  pin_name_t tx_pin;
194  // Additional gpio pins
195  pin_name_t on;
196  pin_name_t cs;
197  pin_name_t cts;
198  pin_name_t smi;
199  pin_name_t rts;
201  // Static variable
202  uint32_t baud_rate;
204  uart_data_bits_t data_bit;
205  uart_parity_t parity_bit;
206  uart_stop_bits_t stop_bit;
209 
214 typedef enum
215 {
221 
223 
240 
255 
268 err_t lteiot11_generic_write ( lteiot11_t *ctx, uint8_t *data_in, uint16_t len );
269 
282 err_t lteiot11_generic_read ( lteiot11_t *ctx, uint8_t *data_out, uint16_t len );
283 
293 void lteiot11_set_on_pin ( lteiot11_t *ctx, uint8_t state );
294 
304 void lteiot11_set_rts_pin ( lteiot11_t *ctx, uint8_t state );
305 
315 void lteiot11_set_cs_pin ( lteiot11_t *ctx, uint8_t state );
316 
326 
336 
346 void lteiot11_send_cmd ( lteiot11_t *ctx, uint8_t *cmd );
347 
358 void lteiot11_send_cmd_with_par ( lteiot11_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf );
359 
369 void lteiot11_send_cmd_check ( lteiot11_t *ctx, uint8_t *at_cmd_buf );
370 
380 void lteiot11_send_cmd_par_check ( lteiot11_t *ctx, uint8_t *at_cmd_buf );
381 
391 void lteiot11_set_sim_apn ( lteiot11_t *ctx, uint8_t *sim_apn );
392 
403 void lteiot11_send_sms_text ( lteiot11_t *ctx, uint8_t *phone_number, uint8_t *sms_text );
404 
418 err_t lteiot11_send_sms_pdu ( lteiot11_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text );
419 
431 err_t lteiot11_parse_gga ( uint8_t *rsp_buf, uint8_t gga_element, uint8_t *element_data );
432 
433 #ifdef __cplusplus
434 }
435 #endif
436 #endif // LTEIOT11_H
437  // lteiot11
439 
440 // ------------------------------------------------------------------------ END
LTEIOT11_ERROR_CMD
@ LTEIOT11_ERROR_CMD
Definition: lteiot11.h:219
LTEIOT11_ERROR
@ LTEIOT11_ERROR
Definition: lteiot11.h:217
LTEIOT11_ERROR_TIMEOUT
@ LTEIOT11_ERROR_TIMEOUT
Definition: lteiot11.h:218
lteiot11_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: lteiot11.h:206
lteiot11_cfg_t::cs
pin_name_t cs
Definition: lteiot11.h:196
lteiot11_t::rts
digital_out_t rts
Definition: lteiot11.h:169
lteiot11_t::smi
digital_in_t smi
Definition: lteiot11.h:172
lteiot11_cfg_t::cts
pin_name_t cts
Definition: lteiot11.h:197
LTEIOT11_TX_DRV_BUFFER_SIZE
#define LTEIOT11_TX_DRV_BUFFER_SIZE
Definition: lteiot11.h:130
lteiot11_get_smi_pin
uint8_t lteiot11_get_smi_pin(lteiot11_t *ctx)
LTE IoT 11 get smi pin function.
lteiot11_set_sim_apn
void lteiot11_set_sim_apn(lteiot11_t *ctx, uint8_t *sim_apn)
Set sim card APN.
lteiot11_generic_write
err_t lteiot11_generic_write(lteiot11_t *ctx, uint8_t *data_in, uint16_t len)
LTE IoT 11 data writing function.
lteiot11_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: lteiot11.h:204
lteiot11_send_sms_text
void lteiot11_send_sms_text(lteiot11_t *ctx, uint8_t *phone_number, uint8_t *sms_text)
LTE IoT 11 send SMS in text mode.
lteiot11_send_cmd_with_par
void lteiot11_send_cmd_with_par(lteiot11_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf)
Send command function with parameter.
lteiot11_t
LTE IoT 11 Click context object.
Definition: lteiot11.h:165
lteiot11_cfg_t::rts
pin_name_t rts
Definition: lteiot11.h:199
lteiot11_t::cts
digital_in_t cts
Definition: lteiot11.h:173
lteiot11_cfg_setup
void lteiot11_cfg_setup(lteiot11_cfg_t *cfg)
LTE IoT 11 configuration object setup function.
lteiot11_cfg_t::uart_blocking
bool uart_blocking
Definition: lteiot11.h:203
lteiot11_send_cmd
void lteiot11_send_cmd(lteiot11_t *ctx, uint8_t *cmd)
Send command function.
lteiot11_cfg_t::tx_pin
pin_name_t tx_pin
Definition: lteiot11.h:192
lteiot11_parse_gga
err_t lteiot11_parse_gga(uint8_t *rsp_buf, uint8_t gga_element, uint8_t *element_data)
LTE IoT 11 parse GGA function.
lteiot11_cfg_t::rx_pin
pin_name_t rx_pin
Definition: lteiot11.h:191
lteiot11_get_cts_pin
uint8_t lteiot11_get_cts_pin(lteiot11_t *ctx)
LTE IoT 11 get cts pin function.
lteiot11_cfg_t::on
pin_name_t on
Definition: lteiot11.h:195
lteiot11_send_cmd_check
void lteiot11_send_cmd_check(lteiot11_t *ctx, uint8_t *at_cmd_buf)
Check the sent command.
lteiot11_return_value_t
lteiot11_return_value_t
LTE IoT 11 Click return value data.
Definition: lteiot11.h:215
lteiot11_cfg_t::baud_rate
uint32_t baud_rate
Definition: lteiot11.h:202
lteiot11_generic_read
err_t lteiot11_generic_read(lteiot11_t *ctx, uint8_t *data_out, uint16_t len)
LTE IoT 11 data reading function.
lteiot11_cfg_t::smi
pin_name_t smi
Definition: lteiot11.h:198
lteiot11_init
err_t lteiot11_init(lteiot11_t *ctx, lteiot11_cfg_t *cfg)
LTE IoT 11 initialization function.
lteiot11_t::uart
uart_t uart
Definition: lteiot11.h:176
lteiot11_t::cs
digital_out_t cs
Definition: lteiot11.h:168
lteiot11_set_cs_pin
void lteiot11_set_cs_pin(lteiot11_t *ctx, uint8_t state)
LTE IoT 11 set cs pin function.
lteiot11_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: lteiot11.h:205
lteiot11_cfg_t
LTE IoT 11 Click configuration object.
Definition: lteiot11.h:189
lteiot11_t::on
digital_out_t on
Definition: lteiot11.h:167
LTEIOT11_OK
@ LTEIOT11_OK
Definition: lteiot11.h:216
lteiot11_set_rts_pin
void lteiot11_set_rts_pin(lteiot11_t *ctx, uint8_t state)
LTE IoT 11 set rts pin function.
lteiot11_send_sms_pdu
err_t lteiot11_send_sms_pdu(lteiot11_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text)
LTE IoT 11 send SMS in PDU mode.
LTEIOT11_RX_DRV_BUFFER_SIZE
#define LTEIOT11_RX_DRV_BUFFER_SIZE
LTE IoT 11 driver buffer size.
Definition: lteiot11.h:129
LTEIOT11_ERROR_UNKNOWN
@ LTEIOT11_ERROR_UNKNOWN
Definition: lteiot11.h:220
lteiot11_send_cmd_par_check
void lteiot11_send_cmd_par_check(lteiot11_t *ctx, uint8_t *at_cmd_buf)
Check the command parameters.
lteiot11_set_on_pin
void lteiot11_set_on_pin(lteiot11_t *ctx, uint8_t state)
LTE IoT 11 set on pin function.