nbiot4  2.0.0.0
nbiot4.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 NBIOT4_H
29 #define NBIOT4_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_uart.h"
38 
59 #define NBIOT4_CMD_AT "AT"
60 #define NBIOT4_CMD_ATE1 "ATE1"
61 #define NBIOT4_CMD_CFUN "AT+CFUN"
62 #define NBIOT4_CMD_CREG "AT+CREG"
63 #define NBIOT4_CMD_CEREG "AT+CEREG"
64 #define NBIOT4_CMD_CGDCONT "AT+CGDCONT"
65 #define NBIOT4_CMD_CSQ "AT+CSQ"
66 #define NBIOT4_CMD_COPS "AT+COPS"
67 #define NBIOT4_CMD_CMGS "AT+CMGS"
68 #define NBIOT4_CMD_CMGF "AT+CMGF"
69 #define NBIOT4_CMD_SIMSWAP "AT^SIMSWAP"
70 #define NBIOT4_CMD_TRB "AT+TRB"
71 #define NBIOT4_CMD_CIPMUX "AT+CIPMUX"
72 #define NBIOT4_CMD_CIPSTART "AT+CIPSTART"
73 #define NBIOT4_CMD_CIPCLOSE "AT+CIPCLOSE"
74 #define NBIOT4_CMD_CIPSEND "AT+CIPSEND"
75 #define NBIOT4_CMD_CIPHEAD "AT+CIPHEAD"
76 
81 #define NBIOT4_RSP_OK "OK"
82 #define NBIOT4_RSP_ERROR "ERROR"
83 #define NBIOT4_RSP_REBOOTING "REBOOTING"
84 
90 #define NBIOT4_RX_DRV_BUFFER_SIZE 256
91 #define NBIOT4_TX_DRV_BUFFER_SIZE 256
92  // nbiot4_set
94 
109 #define NBIOT4_MAP_MIKROBUS( cfg, mikrobus ) \
110  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
111  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
112  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
113  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
114  cfg.ring = MIKROBUS( mikrobus, MIKROBUS_INT )
115  // nbiot4_map // nbiot4
118 
123 typedef struct
124 {
125  // Output pins
126  digital_out_t rst;
127  digital_out_t cs;
129  // Input pins
130  digital_in_t ring;
132  // Modules
133  uart_t uart;
135  // Buffers
136  uint8_t uart_rx_buffer[ NBIOT4_RX_DRV_BUFFER_SIZE ];
137  uint8_t uart_tx_buffer[ NBIOT4_TX_DRV_BUFFER_SIZE ];
139 } nbiot4_t;
140 
145 typedef struct
146 {
147  // Communication gpio pins
148  pin_name_t rx_pin;
149  pin_name_t tx_pin;
151  // Additional gpio pins
152  pin_name_t rst;
153  pin_name_t cs;
154  pin_name_t ring;
156  // Static variable
157  uint32_t baud_rate;
159  uart_data_bits_t data_bit;
160  uart_parity_t parity_bit;
161  uart_stop_bits_t stop_bit;
163 } nbiot4_cfg_t;
164 
169 typedef enum
170 {
176 
178 
195 
209 err_t nbiot4_init ( nbiot4_t *ctx, nbiot4_cfg_t *cfg );
210 
223 err_t nbiot4_generic_write ( nbiot4_t *ctx, uint8_t *data_in, uint16_t len );
224 
237 err_t nbiot4_generic_read ( nbiot4_t *ctx, uint8_t *data_out, uint16_t len );
238 
248 void nbiot4_set_rst_pin ( nbiot4_t *ctx, uint8_t state );
249 
259 void nbiot4_set_cs_pin ( nbiot4_t *ctx, uint8_t state );
260 
269 uint8_t nbiot4_get_ring_pin ( nbiot4_t *ctx );
270 
280 void nbiot4_send_cmd ( nbiot4_t *ctx, uint8_t *cmd );
281 
292 void nbiot4_send_cmd_with_par ( nbiot4_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf );
293 
303 void nbiot4_send_cmd_check ( nbiot4_t *ctx, uint8_t *at_cmd_buf );
304 
314 void nbiot4_send_cmd_par_check ( nbiot4_t *ctx, uint8_t *at_cmd_buf );
315 
325 void nbiot4_set_sim_apn ( nbiot4_t *ctx, uint8_t *sim_apn );
326 
337 void nbiot4_send_sms_text ( nbiot4_t *ctx, uint8_t *phone_number, uint8_t *sms_text );
338 
352 err_t nbiot4_send_sms_pdu ( nbiot4_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text );
353 
354 #ifdef __cplusplus
355 }
356 #endif
357 #endif // NBIOT4_H
358  // nbiot4
360 
361 // ------------------------------------------------------------------------ END
nbiot4_send_cmd
void nbiot4_send_cmd(nbiot4_t *ctx, uint8_t *cmd)
Send command function.
nbiot4_set_rst_pin
void nbiot4_set_rst_pin(nbiot4_t *ctx, uint8_t state)
NB IoT 4 set rst pin function.
nbiot4_init
err_t nbiot4_init(nbiot4_t *ctx, nbiot4_cfg_t *cfg)
NB IoT 4 initialization function.
nbiot4_cfg_setup
void nbiot4_cfg_setup(nbiot4_cfg_t *cfg)
NB IoT 4 configuration object setup function.
nbiot4_cfg_t::rst
pin_name_t rst
Definition: nbiot4.h:152
nbiot4_t::cs
digital_out_t cs
Definition: nbiot4.h:127
nbiot4_send_cmd_par_check
void nbiot4_send_cmd_par_check(nbiot4_t *ctx, uint8_t *at_cmd_buf)
Check the command parameters.
nbiot4_generic_read
err_t nbiot4_generic_read(nbiot4_t *ctx, uint8_t *data_out, uint16_t len)
NB IoT 4 data reading function.
nbiot4_send_cmd_check
void nbiot4_send_cmd_check(nbiot4_t *ctx, uint8_t *at_cmd_buf)
Check the sent command.
NBIOT4_OK
@ NBIOT4_OK
Definition: nbiot4.h:171
nbiot4_t::rst
digital_out_t rst
Definition: nbiot4.h:126
nbiot4_return_value_t
nbiot4_return_value_t
NB IoT 4 Click return value data.
Definition: nbiot4.h:170
nbiot4_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: nbiot4.h:159
NBIOT4_ERROR
@ NBIOT4_ERROR
Definition: nbiot4.h:172
nbiot4_cfg_t::tx_pin
pin_name_t tx_pin
Definition: nbiot4.h:149
nbiot4_cfg_t
NB IoT 4 Click configuration object.
Definition: nbiot4.h:146
nbiot4_t::uart
uart_t uart
Definition: nbiot4.h:133
nbiot4_t::ring
digital_in_t ring
Definition: nbiot4.h:130
nbiot4_cfg_t::baud_rate
uint32_t baud_rate
Definition: nbiot4.h:157
nbiot4_t
NB IoT 4 Click context object.
Definition: nbiot4.h:124
nbiot4_set_cs_pin
void nbiot4_set_cs_pin(nbiot4_t *ctx, uint8_t state)
NB IoT 4 set cs pin function.
nbiot4_cfg_t::rx_pin
pin_name_t rx_pin
Definition: nbiot4.h:148
NBIOT4_ERROR_UNKNOWN
@ NBIOT4_ERROR_UNKNOWN
Definition: nbiot4.h:175
nbiot4_set_sim_apn
void nbiot4_set_sim_apn(nbiot4_t *ctx, uint8_t *sim_apn)
Set sim card APN.
nbiot4_send_cmd_with_par
void nbiot4_send_cmd_with_par(nbiot4_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf)
Send command function with parameter.
nbiot4_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: nbiot4.h:161
nbiot4_get_ring_pin
uint8_t nbiot4_get_ring_pin(nbiot4_t *ctx)
NB IoT 4 get ring pin function.
nbiot4_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: nbiot4.h:160
nbiot4_cfg_t::ring
pin_name_t ring
Definition: nbiot4.h:154
nbiot4_send_sms_pdu
err_t nbiot4_send_sms_pdu(nbiot4_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text)
NB IoT 4 send SMS in PDU mode.
nbiot4_send_sms_text
void nbiot4_send_sms_text(nbiot4_t *ctx, uint8_t *phone_number, uint8_t *sms_text)
NB IoT 4 send SMS in text mode.
nbiot4_cfg_t::cs
pin_name_t cs
Definition: nbiot4.h:153
NBIOT4_ERROR_CMD
@ NBIOT4_ERROR_CMD
Definition: nbiot4.h:174
nbiot4_cfg_t::uart_blocking
bool uart_blocking
Definition: nbiot4.h:158
NBIOT4_RX_DRV_BUFFER_SIZE
#define NBIOT4_RX_DRV_BUFFER_SIZE
NB IoT 4 driver buffer size.
Definition: nbiot4.h:90
nbiot4_generic_write
err_t nbiot4_generic_write(nbiot4_t *ctx, uint8_t *data_in, uint16_t len)
NB IoT 4 data writing function.
NBIOT4_TX_DRV_BUFFER_SIZE
#define NBIOT4_TX_DRV_BUFFER_SIZE
Definition: nbiot4.h:91
NBIOT4_ERROR_TIMEOUT
@ NBIOT4_ERROR_TIMEOUT
Definition: nbiot4.h:173