ltecat16  2.1.0.0
ltecat16.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 LTECAT16_H
29 #define LTECAT16_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_uart.h"
52 
73 #define LTECAT16_CMD_AT "AT"
74 #define LTECAT16_CMD_GET_MODEL_ID "AT+CGMM"
75 #define LTECAT16_CMD_GET_SW_VERSION "AT+CGMR"
76 #define LTECAT16_CMD_GET_SERIAL_NUM "AT+CGSN"
77 #define LTECAT16_CMD_FACTORY_RESET "AT&F"
78 #define LTECAT16_CMD_SET_PHONE_FUNCTIONALITY "AT+CFUN"
79 #define LTECAT16_CMD_NETWORK_REGISTRATION "AT+CREG"
80 #define LTECAT16_CMD_SIGNAL_QUALITY_REPORT "AT+CSQ"
81 #define LTECAT16_CMD_OPERATOR_SELECTION "AT+COPS"
82 #define LTECAT16_CMD_SEND_SMS "AT+CMGS"
83 #define LTECAT16_CMD_SELECT_SMS_FORMAT "AT+CMGF"
84 #define LTECAT16_CMD_DEFINE_PDP_CONTEXT "AT+CGDCONT"
85 #define LTECAT16_CMD_ACTIVATE_PDP_CONTEXT "AT+CGACT"
86 #define LTECAT16_CMD_SHOW_PDP_ADDRESS "AT+CGPADDR"
87 #define LTECAT16_CMD_START_TCPIP_SERVICE "AT+NETOPEN"
88 #define LTECAT16_CMD_OPEN_TCP_UDP_CONNECTION "AT+CIPOPEN"
89 #define LTECAT16_CMD_SEND_DATA_VIA_CONNECTION "AT+CIPSEND"
90 #define LTECAT16_CMD_RECEIVE_DATA_VIA_CONNECTION "AT+CIPRXGET"
91 #define LTECAT16_CMD_CLOSE_TCP_UDP_CONNECTION "AT+CIPCLOSE"
92 
97 #define LTECAT16_RSP_OK "OK"
98 #define LTECAT16_RSP_ERROR "ERROR"
99 
104 #define LTECAT16_URC_RECEIVED_DATA "+CIPRXGET:"
105 
110 #define LTECAT16_POWER_STATE_OFF 0
111 #define LTECAT16_POWER_STATE_ON 1
112 
118 #define LTECAT16_TX_DRV_BUFFER_SIZE 256
119 #define LTECAT16_RX_DRV_BUFFER_SIZE 256
120  // ltecat16_cmd
122 
137 #define LTECAT16_MAP_MIKROBUS( cfg, mikrobus ) \
138  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
139  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
140  cfg.pwr = MIKROBUS( mikrobus, MIKROBUS_AN ); \
141  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
142  cfg.ring = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
143  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT );
144  // ltecat16_map // ltecat16
147 
152 typedef struct
153 {
154  // Output pins
155  digital_out_t pwr;
156  digital_out_t rts;
158  // Input pins
159  digital_in_t ring;
160  digital_in_t cts;
162  // Modules
163  uart_t uart;
165  // Buffers
166  uint8_t uart_rx_buffer[ LTECAT16_RX_DRV_BUFFER_SIZE ];
167  uint8_t uart_tx_buffer[ LTECAT16_TX_DRV_BUFFER_SIZE ];
168  uint8_t cmd_buffer[ LTECAT16_TX_DRV_BUFFER_SIZE ];
170 } ltecat16_t;
171 
176 typedef struct
177 {
178  // Communication gpio pins
179  pin_name_t rx_pin;
180  pin_name_t tx_pin;
182  // Additional gpio pins
183  pin_name_t pwr;
184  pin_name_t rts;
185  pin_name_t ring;
186  pin_name_t cts;
188  // Static variable
189  uint32_t baud_rate;
191  uart_data_bits_t data_bit;
192  uart_parity_t parity_bit;
193  uart_stop_bits_t stop_bit;
196 
201 typedef enum
202 {
208 
210 
227 
242 
255 err_t ltecat16_generic_write ( ltecat16_t *ctx, uint8_t *data_in, uint16_t len );
256 
269 err_t ltecat16_generic_read ( ltecat16_t *ctx, uint8_t *data_out, uint16_t len );
270 
280 void ltecat16_set_pwr_pin ( ltecat16_t *ctx, uint8_t state );
281 
291 void ltecat16_set_rts_pin ( ltecat16_t *ctx, uint8_t state );
292 
302 
312 
323 void ltecat16_set_power_state ( ltecat16_t *ctx, uint8_t state );
324 
334 void ltecat16_send_cmd ( ltecat16_t *ctx, uint8_t *cmd );
335 
346 void ltecat16_send_cmd_par ( ltecat16_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf );
347 
357 void ltecat16_send_cmd_check ( ltecat16_t *ctx, uint8_t *at_cmd_buf );
358 
368 void ltecat16_set_sim_apn ( ltecat16_t *ctx, uint8_t *sim_apn );
369 
380 void ltecat16_send_sms_text ( ltecat16_t *ctx, uint8_t *phone_number, uint8_t *sms_text );
381 
395 err_t ltecat16_send_sms_pdu ( ltecat16_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text );
396 
397 #ifdef __cplusplus
398 }
399 #endif
400 #endif // LTECAT16_H
401  // ltecat16
403 
404 // ------------------------------------------------------------------------ END
LTECAT16_TX_DRV_BUFFER_SIZE
#define LTECAT16_TX_DRV_BUFFER_SIZE
LTE Cat.1 6 driver buffer size.
Definition: ltecat16.h:118
ltecat16_cfg_setup
void ltecat16_cfg_setup(ltecat16_cfg_t *cfg)
LTE Cat.1 6 configuration object setup function.
LTECAT16_ERROR_CMD
@ LTECAT16_ERROR_CMD
Definition: ltecat16.h:206
ltecat16_set_power_state
void ltecat16_set_power_state(ltecat16_t *ctx, uint8_t state)
LTE Cat.1 6 set power state function.
LTECAT16_RX_DRV_BUFFER_SIZE
#define LTECAT16_RX_DRV_BUFFER_SIZE
Definition: ltecat16.h:119
ltecat16_generic_read
err_t ltecat16_generic_read(ltecat16_t *ctx, uint8_t *data_out, uint16_t len)
LTE Cat.1 6 data reading function.
ltecat16_send_sms_pdu
err_t ltecat16_send_sms_pdu(ltecat16_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text)
LTE Cat.1 6 send SMS in PDU mode.
ltecat16_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: ltecat16.h:192
ltecat16_cfg_t::tx_pin
pin_name_t tx_pin
Definition: ltecat16.h:180
ltecat16_cfg_t::baud_rate
uint32_t baud_rate
Definition: ltecat16.h:189
ltecat16_t::ring
digital_in_t ring
Definition: ltecat16.h:159
ltecat16_set_pwr_pin
void ltecat16_set_pwr_pin(ltecat16_t *ctx, uint8_t state)
LTE Cat.1 6 set PWR pin function.
ltecat16_set_sim_apn
void ltecat16_set_sim_apn(ltecat16_t *ctx, uint8_t *sim_apn)
Set sim card APN.
ltecat16_t::rts
digital_out_t rts
Definition: ltecat16.h:156
ltecat16_send_sms_text
void ltecat16_send_sms_text(ltecat16_t *ctx, uint8_t *phone_number, uint8_t *sms_text)
LTE Cat.1 6 send SMS in text mode.
LTECAT16_OK
@ LTECAT16_OK
Definition: ltecat16.h:203
ltecat16_get_ring_pin
uint8_t ltecat16_get_ring_pin(ltecat16_t *ctx)
LTE Cat.1 6 get RING pin function.
ltecat16_cfg_t::pwr
pin_name_t pwr
Definition: ltecat16.h:183
ltecat16_cfg_t::uart_blocking
bool uart_blocking
Definition: ltecat16.h:190
ltecat16_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: ltecat16.h:191
ltecat16_cfg_t::rts
pin_name_t rts
Definition: ltecat16.h:184
ltecat16_get_cts_pin
uint8_t ltecat16_get_cts_pin(ltecat16_t *ctx)
LTE Cat.1 6 get CTS pin function.
ltecat16_set_rts_pin
void ltecat16_set_rts_pin(ltecat16_t *ctx, uint8_t state)
LTE Cat.1 6 set RTS pin function.
ltecat16_t::uart
uart_t uart
Definition: ltecat16.h:163
ltecat16_t
LTE Cat.1 6 Click context object.
Definition: ltecat16.h:153
LTECAT16_ERROR_TIMEOUT
@ LTECAT16_ERROR_TIMEOUT
Definition: ltecat16.h:205
ltecat16_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: ltecat16.h:193
ltecat16_generic_write
err_t ltecat16_generic_write(ltecat16_t *ctx, uint8_t *data_in, uint16_t len)
LTE Cat.1 6 data writing function.
ltecat16_t::pwr
digital_out_t pwr
Definition: ltecat16.h:155
ltecat16_cfg_t::ring
pin_name_t ring
Definition: ltecat16.h:185
ltecat16_cfg_t::cts
pin_name_t cts
Definition: ltecat16.h:186
ltecat16_send_cmd
void ltecat16_send_cmd(ltecat16_t *ctx, uint8_t *cmd)
Send command function.
ltecat16_send_cmd_check
void ltecat16_send_cmd_check(ltecat16_t *ctx, uint8_t *at_cmd_buf)
Check the sent command.
ltecat16_cfg_t
LTE Cat.1 6 Click configuration object.
Definition: ltecat16.h:177
ltecat16_send_cmd_par
void ltecat16_send_cmd_par(ltecat16_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf)
Send command function with parameter.
ltecat16_init
err_t ltecat16_init(ltecat16_t *ctx, ltecat16_cfg_t *cfg)
LTE Cat.1 6 initialization function.
ltecat16_return_value_t
ltecat16_return_value_t
LTE Cat.1 6 Click return value data.
Definition: ltecat16.h:202
ltecat16_t::cts
digital_in_t cts
Definition: ltecat16.h:160
LTECAT16_ERROR
@ LTECAT16_ERROR
Definition: ltecat16.h:204
ltecat16_cfg_t::rx_pin
pin_name_t rx_pin
Definition: ltecat16.h:179
LTECAT16_ERROR_UNKNOWN
@ LTECAT16_ERROR_UNKNOWN
Definition: ltecat16.h:207