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
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 LTEIOT7_CMD_AT "AT"
70 #define LTEIOT7_CMD_ATI "ATI"
71 #define LTEIOT7_CMD_CGMR "AT+CGMR"
72 #define LTEIOT7_CMD_CFUN "AT+CFUN"
73 #define LTEIOT7_CMD_CREG "AT+CREG"
74 #define LTEIOT7_CMD_CGREG "AT+CGREG"
75 #define LTEIOT7_CMD_CGDCONT "AT+CGDCONT"
76 #define LTEIOT7_CMD_CIMI "AT+CIMI"
77 #define LTEIOT7_CMD_CMEE "AT+CMEE"
78 #define LTEIOT7_CMD_CGATT "AT+CGATT"
79 #define LTEIOT7_CMD_CSQ "AT+CSQ"
80 #define LTEIOT7_CMD_COPS "AT+COPS"
81 #define LTEIOT7_CMD_CMGS "AT+CMGS"
82 #define LTEIOT7_CMD_CMGF "AT+CMGF"
83 #define LTEIOT7_CMD_CGACT "AT+CGACT"
84 #define LTEIOT7_CMD_USOCR "AT+USOCR"
85 #define LTEIOT7_CMD_USOCO "AT+USOCO"
86 #define LTEIOT7_CMD_USOWR "AT+USOWR"
87 #define LTEIOT7_CMD_USORD "AT+USORD"
88 #define LTEIOT7_CMD_USORF "AT+USORF"
89 #define LTEIOT7_CMD_USOCL "AT+USOCL"
90 #define LTEIOT7_CMD_UGPS "AT+UGPS"
91 #define LTEIOT7_CMD_UGGGA "AT+UGGGA"
92 
97 #define LTEIOT7_RSP_OK "OK"
98 #define LTEIOT7_RSP_ERROR "ERROR"
99 
104 #define LTEIOT7_POWER_STATE_SWITCH 0
105 #define LTEIOT7_POWER_STATE_ON 1
106 #define LTEIOT7_POWER_STATE_REBOOT 2
107 
112 #define LTEIOT7_RSP_START "$"
113 #define LTEIOT7_RSP_DELIMITER ","
114 #define LTEIOT7_RSP_GPGGA "$GPGGA"
115 
120 #define LTEIOT7_GPGGA_ELEMENT_SIZE 15
121 #define LTEIOT7_GPGGA_TIME 1
122 #define LTEIOT7_GPGGA_LATITUDE 2
123 #define LTEIOT7_GPGGA_LATITUDE_SIDE 3
124 #define LTEIOT7_GPGGA_LONGITUDE 4
125 #define LTEIOT7_GPGGA_LONGITUDE_SIDE 5
126 #define LTEIOT7_GPGGA_QUALITY_INDICATOR 6
127 #define LTEIOT7_GPGGA_NUMBER_OF_SATELLITES 7
128 #define LTEIOT7_GPGGA_H_DILUTION_OF_POS 8
129 #define LTEIOT7_GPGGA_ALTITUDE 9
130 #define LTEIOT7_GPGGA_ALTITUDE_UNIT 10
131 #define LTEIOT7_GPGGA_GEOIDAL_SEPARATION 11
132 #define LTEIOT7_GPGGA_GEOIDAL_SEPARATION_UNIT 12
133 #define LTEIOT7_GPGGA_TIME_SINCE_LAST_DGPS 13
134 #define LTEIOT7_GPGGA_DGPS_REFERENCE_STATION_ID 14
135 
141 #define DRV_BUFFER_SIZE 256
142  // lteiot7_cmd
144 
159 #define LTEIOT7_MAP_MIKROBUS( cfg, mikrobus ) \
160  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
161  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
162  cfg.pwr = MIKROBUS( mikrobus, MIKROBUS_AN ); \
163  cfg.ein = MIKROBUS( mikrobus, MIKROBUS_RST ); \
164  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
165  cfg.ri = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
166  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT );
167  // lteiot7_map // lteiot7
170 
175 typedef struct
176 {
177  // Output pins
178  digital_out_t pwr;
179  digital_out_t ein;
180  digital_out_t rts;
182  // Input pins
183  digital_in_t ri;
184  digital_in_t cts;
186  // Modules
187  uart_t uart;
189  // Buffers
190  char uart_rx_buffer[ DRV_BUFFER_SIZE ];
191  char uart_tx_buffer[ DRV_BUFFER_SIZE ];
193 } lteiot7_t;
194 
199 typedef struct
200 {
201  // Communication gpio pins
202  pin_name_t rx_pin;
203  pin_name_t tx_pin;
205  // Additional gpio pins
206  pin_name_t pwr;
207  pin_name_t ein;
208  pin_name_t rts;
209  pin_name_t ri;
210  pin_name_t cts;
212  // Static variable
213  uint32_t baud_rate;
215  uart_data_bits_t data_bit;
216  uart_parity_t parity_bit;
217  uart_stop_bits_t stop_bit;
219 } lteiot7_cfg_t;
220 
225 typedef enum
226 {
232 
234 
251 
265 err_t lteiot7_init ( lteiot7_t *ctx, lteiot7_cfg_t *cfg );
266 
279 err_t lteiot7_generic_write ( lteiot7_t *ctx, char *data_in, uint16_t len );
280 
293 err_t lteiot7_generic_read ( lteiot7_t *ctx, char *data_out, uint16_t len );
294 
304 void lteiot7_set_pwr_pin ( lteiot7_t *ctx, uint8_t state );
305 
315 void lteiot7_set_ein_pin ( lteiot7_t *ctx, uint8_t state );
316 
326 void lteiot7_set_rts_pin ( lteiot7_t *ctx, uint8_t state );
327 
336 uint8_t lteiot7_get_ri_pin ( lteiot7_t *ctx );
337 
347 
359 void lteiot7_set_power_state ( lteiot7_t *ctx, uint8_t state );
360 
370 void lteiot7_send_cmd ( lteiot7_t *ctx, char *cmd );
371 
382 void lteiot7_send_cmd_with_parameter ( lteiot7_t *ctx, char *at_cmd_buf, char *param_buf );
383 
393 void lteiot7_send_cmd_check ( lteiot7_t *ctx, char *at_cmd_buf );
394 
404 void lteiot7_send_cmd_parameter_check ( lteiot7_t *ctx, char *at_cmd_buf );
405 
415 void lteiot7_set_sim_apn ( lteiot7_t *ctx, char *sim_apn );
416 
427 void lteiot7_send_sms_text ( lteiot7_t *ctx, char *phone_number, char *sms_text );
428 
442 err_t lteiot7_send_sms_pdu ( lteiot7_t *ctx, char *service_center_number, char *phone_number, char *sms_text );
443 
455 err_t lteiot7_parse_gpgga ( char *rsp_buf, uint8_t gpgga_element, char *element_data );
456 
457 #ifdef __cplusplus
458 }
459 #endif
460 #endif // LTEIOT7_H
461  // lteiot7
463 
464 // ------------------------------------------------------------------------ END
lteiot7_cfg_t::pwr
pin_name_t pwr
Definition: lteiot7.h:206
lteiot7_cfg_t::uart_blocking
bool uart_blocking
Definition: lteiot7.h:214
lteiot7_cfg_t::ein
pin_name_t ein
Definition: lteiot7.h:207
lteiot7_get_ri_pin
uint8_t lteiot7_get_ri_pin(lteiot7_t *ctx)
LTE IoT 7 get RI pin function.
LTEIOT7_ERROR
@ LTEIOT7_ERROR
Definition: lteiot7.h:228
lteiot7_get_cts_pin
uint8_t lteiot7_get_cts_pin(lteiot7_t *ctx)
LTE IoT 7 get CTS pin function.
lteiot7_cfg_setup
void lteiot7_cfg_setup(lteiot7_cfg_t *cfg)
LTE IoT 7 configuration object setup function.
LTEIOT7_ERROR_CMD
@ LTEIOT7_ERROR_CMD
Definition: lteiot7.h:230
lteiot7_parse_gpgga
err_t lteiot7_parse_gpgga(char *rsp_buf, uint8_t gpgga_element, char *element_data)
LTE IoT 7 parse GPGGA function.
lteiot7_t::ri
digital_in_t ri
Definition: lteiot7.h:183
lteiot7_set_rts_pin
void lteiot7_set_rts_pin(lteiot7_t *ctx, uint8_t state)
LTE IoT 7 set RTS pin function.
lteiot7_set_pwr_pin
void lteiot7_set_pwr_pin(lteiot7_t *ctx, uint8_t state)
LTE IoT 7 set PWR pin function.
LTEIOT7_ERROR_UNKNOWN
@ LTEIOT7_ERROR_UNKNOWN
Definition: lteiot7.h:231
lteiot7_cfg_t::tx_pin
pin_name_t tx_pin
Definition: lteiot7.h:203
lteiot7_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: lteiot7.h:215
LTEIOT7_ERROR_TIMEOUT
@ LTEIOT7_ERROR_TIMEOUT
Definition: lteiot7.h:229
lteiot7_send_cmd_parameter_check
void lteiot7_send_cmd_parameter_check(lteiot7_t *ctx, char *at_cmd_buf)
Check the command parameters.
lteiot7_set_sim_apn
void lteiot7_set_sim_apn(lteiot7_t *ctx, char *sim_apn)
Set sim card APN.
lteiot7_t
LTE IoT 7 Click context object.
Definition: lteiot7.h:176
lteiot7_t::cts
digital_in_t cts
Definition: lteiot7.h:184
lteiot7_cfg_t
LTE IoT 7 Click configuration object.
Definition: lteiot7.h:200
lteiot7_generic_write
err_t lteiot7_generic_write(lteiot7_t *ctx, char *data_in, uint16_t len)
LTE IoT 7 data writing function.
lteiot7_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: lteiot7.h:217
lteiot7_cfg_t::rts
pin_name_t rts
Definition: lteiot7.h:208
lteiot7_send_cmd
void lteiot7_send_cmd(lteiot7_t *ctx, char *cmd)
Send command function.
lteiot7_return_value_t
lteiot7_return_value_t
LTE IoT 7 Click return value data.
Definition: lteiot7.h:226
DRV_BUFFER_SIZE
#define DRV_BUFFER_SIZE
LTE IoT 7 driver buffer size.
Definition: lteiot7.h:141
lteiot7_send_sms_text
void lteiot7_send_sms_text(lteiot7_t *ctx, char *phone_number, char *sms_text)
LTE IoT 7 send SMS in text mode.
lteiot7_t::ein
digital_out_t ein
Definition: lteiot7.h:179
LTEIOT7_OK
@ LTEIOT7_OK
Definition: lteiot7.h:227
lteiot7_t::rts
digital_out_t rts
Definition: lteiot7.h:180
lteiot7_send_sms_pdu
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.
lteiot7_set_ein_pin
void lteiot7_set_ein_pin(lteiot7_t *ctx, uint8_t state)
LTE IoT 7 set EIN pin function.
lteiot7_send_cmd_check
void lteiot7_send_cmd_check(lteiot7_t *ctx, char *at_cmd_buf)
Check the sent command.
lteiot7_send_cmd_with_parameter
void lteiot7_send_cmd_with_parameter(lteiot7_t *ctx, char *at_cmd_buf, char *param_buf)
Send command function with parameter.
lteiot7_cfg_t::ri
pin_name_t ri
Definition: lteiot7.h:209
lteiot7_cfg_t::baud_rate
uint32_t baud_rate
Definition: lteiot7.h:213
lteiot7_generic_read
err_t lteiot7_generic_read(lteiot7_t *ctx, char *data_out, uint16_t len)
LTE IoT 7 data reading function.
lteiot7_t::uart
uart_t uart
Definition: lteiot7.h:187
lteiot7_cfg_t::cts
pin_name_t cts
Definition: lteiot7.h:210
lteiot7_set_power_state
void lteiot7_set_power_state(lteiot7_t *ctx, uint8_t state)
LTE IoT 7 set power state function.
lteiot7_cfg_t::rx_pin
pin_name_t rx_pin
Definition: lteiot7.h:202
lteiot7_init
err_t lteiot7_init(lteiot7_t *ctx, lteiot7_cfg_t *cfg)
LTE IoT 7 initialization function.
lteiot7_t::pwr
digital_out_t pwr
Definition: lteiot7.h:178
lteiot7_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: lteiot7.h:216