nbiot2 2.1.0.0
nbiot2.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 NBIOT2_H
29#define NBIOT2_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
35#include "drv_digital_out.h"
36#include "drv_digital_in.h"
37#include "drv_uart.h"
38
59#define NBIOT2_CMD_AT "AT"
60#define NBIOT2_CMD_ATI "ATI"
61#define NBIOT2_CMD_CGMR "AT+CGMR"
62#define NBIOT2_CMD_CFUN "AT+CFUN"
63#define NBIOT2_CMD_CREG "AT+CREG"
64#define NBIOT2_CMD_CEREG "AT+CEREG"
65#define NBIOT2_CMD_CGDCONT "AT+CGDCONT"
66#define NBIOT2_CMD_CIMI "AT+CIMI"
67#define NBIOT2_CMD_CGATT "AT+CGATT"
68#define NBIOT2_CMD_CSQ "AT+CSQ"
69#define NBIOT2_CMD_CESQ "AT+CESQ"
70#define NBIOT2_CMD_COPS "AT+COPS"
71#define NBIOT2_CMD_CSCON "AT+CSCON"
72#define NBIOT2_CMD_CMEE "AT+CMEE"
73#define NBIOT2_CMD_CMGS "AT+CMGS"
74#define NBIOT2_CMD_CGACT "AT+CGACT"
75#define NBIOT2_CMD_URAT "AT+URAT"
76#define NBIOT2_CMD_UBANDMASK "AT+UBANDMASK"
77#define NBIOT2_CMD_URATCONF "AT+URATCONF"
78#define NBIOT2_CMD_UAUTHREQ "AT+UAUTHREQ"
79#define NBIOT2_CMD_UUICC "AT+UUICC"
80#define NBIOT2_CMD_UCGED "AT+UCGED"
81#define NBIOT2_CMD_UCELLINFO "AT+UCELLINFO"
82#define NBIOT2_CMD_UANTR "AT+UANTR"
83#define NBIOT2_CMD_CMGF "AT+CMGF"
84#define NBIOT2_CMD_QSPCHSC "AT+QSPCHSC"
85#define NBIOT2_CMD_CPSMS "AT+CPSMS"
86#define NBIOT2_CMD_QRST "AT+QRST"
87#define NBIOT2_CMD_QBAND "AT+QBAND"
88#define NBIOT2_CMD_QNBIOTEVENT "AT+QNBIOTEVENT"
89#define NBIOT2_CMD_SM "AT+SM"
90#define NBIOT2_CMD_QSCLK "AT+QSCLK"
91#define NBIOT2_CMD_QIOPEN "AT+QIOPEN"
92#define NBIOT2_CMD_QISEND "AT+QISEND"
93#define NBIOT2_CMD_QIRD "AT+QIRD"
94#define NBIOT2_CMD_QICLOSE "AT+QICLOSE"
95
100#define NBIOT2_PIN_STATE_HIGH 0x01
101#define NBIOT2_PIN_STATE_LOW 0x00
102
107#define NBIOT2_RSP_OK "OK"
108#define NBIOT2_RSP_ERROR "ERROR"
109
115#define NBIOT2_TX_DRV_BUFFER_SIZE 100
116#define NBIOT2_RX_DRV_BUFFER_SIZE 300
117 // nbiot2_cmd
119
134#define NBIOT2_MAP_MIKROBUS( cfg, mikrobus ) \
135 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
136 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
137 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
138 cfg.wup = MIKROBUS( mikrobus, MIKROBUS_INT );
139 // nbiot2_map // nbiot2
142
147typedef struct
148{
149 // Output pins
150 digital_out_t rst;
151 digital_out_t wup;
153 // Modules
154 uart_t uart;
156 // Buffers
157 char uart_rx_buffer[ NBIOT2_RX_DRV_BUFFER_SIZE ];
158 char uart_tx_buffer[ NBIOT2_TX_DRV_BUFFER_SIZE ];
160} nbiot2_t;
161
166typedef struct
167{
168 // Communication gpio pins
169 pin_name_t rx_pin;
170 pin_name_t tx_pin;
172 // Additional gpio pins
173 pin_name_t rst;
174 pin_name_t wup;
176 // Static variable
177 uint32_t baud_rate;
179 uart_data_bits_t data_bit;
180 uart_parity_t parity_bit;
181 uart_stop_bits_t stop_bit;
184
189typedef enum
190{
195
197
214
228err_t nbiot2_init ( nbiot2_t *ctx, nbiot2_cfg_t *cfg );
229
242err_t nbiot2_generic_write ( nbiot2_t *ctx, char *data_in, uint16_t len );
243
256err_t nbiot2_generic_read ( nbiot2_t *ctx, char *data_out, uint16_t len );
257
267void nbiot2_set_rst_pin_state ( nbiot2_t *ctx, uint8_t state );
268
278void nbiot2_set_wup_pin_state ( nbiot2_t *ctx, uint8_t state );
279
289
299void nbiot2_send_cmd ( nbiot2_t *ctx, char *cmd );
300
311void nbiot2_send_cmd_with_parameter ( nbiot2_t *ctx, char *at_cmd_buf, char *param_buf );
312
322void nbiot2_send_cmd_check ( nbiot2_t *ctx, char *at_cmd_buf );
323
333void nbiot2_send_cmd_parameter_check ( nbiot2_t *ctx, char *at_cmd_buf );
334
344void nbiot2_set_apn( nbiot2_t *ctx, char *apn );
345
356void nbiot2_send_sms_text_mode ( nbiot2_t *ctx, char *phone_number, char *message_context );
357
371err_t nbiot2_send_sms_pdu ( nbiot2_t *ctx, char *service_center_number, char *phone_number, char *sms_text );
372
373#ifdef __cplusplus
374}
375#endif
376#endif // NBIOT2_H
377 // nbiot2
379
380// ------------------------------------------------------------------------ END
#define NBIOT2_RX_DRV_BUFFER_SIZE
Definition: nbiot2.h:116
#define NBIOT2_TX_DRV_BUFFER_SIZE
NB IoT 2 driver buffer size.
Definition: nbiot2.h:115
void nbiot2_send_cmd_check(nbiot2_t *ctx, char *at_cmd_buf)
NB IoT 2 check the sent command.
err_t nbiot2_send_sms_pdu(nbiot2_t *ctx, char *service_center_number, char *phone_number, char *sms_text)
NB IoT 2 send SMS in PDU mode.
void nbiot2_set_rst_pin_state(nbiot2_t *ctx, uint8_t state)
NB IoT 2 sets state of the RST pin.
void nbiot2_send_cmd(nbiot2_t *ctx, char *cmd)
NB IoT 2 send command function.
void nbiot2_hw_reset(nbiot2_t *ctx)
NB IoT 2 hardware reset function.
void nbiot2_send_cmd_with_parameter(nbiot2_t *ctx, char *at_cmd_buf, char *param_buf)
NB IoT 2 send command function with parameter.
void nbiot2_send_sms_text_mode(nbiot2_t *ctx, char *phone_number, char *message_context)
NB IoT 2 send SMS in text mode.
void nbiot2_cfg_setup(nbiot2_cfg_t *cfg)
NB IoT 2 configuration object setup function.
void nbiot2_set_wup_pin_state(nbiot2_t *ctx, uint8_t state)
NB IoT 2 sets state of the WUP pin.
void nbiot2_send_cmd_parameter_check(nbiot2_t *ctx, char *at_cmd_buf)
NB IoT 2 check the command parameters.
void nbiot2_set_apn(nbiot2_t *ctx, char *apn)
NB IoT 2 set sim card APN.
err_t nbiot2_generic_write(nbiot2_t *ctx, char *data_in, uint16_t len)
NB IoT 2 data writing function.
err_t nbiot2_generic_read(nbiot2_t *ctx, char *data_out, uint16_t len)
NB IoT 2 data reading function.
err_t nbiot2_init(nbiot2_t *ctx, nbiot2_cfg_t *cfg)
NB IoT 2 initialization function.
nbiot2_return_value_t
NB IoT 2 Click return value data.
Definition: nbiot2.h:190
@ NBIOT2_ERROR_OVERFLOW
Definition: nbiot2.h:193
@ NBIOT2_OK
Definition: nbiot2.h:191
@ NBIOT2_ERROR_TIMEOUT
Definition: nbiot2.h:194
@ NBIOT2_ERROR
Definition: nbiot2.h:192
NB IoT 2 Click configuration object.
Definition: nbiot2.h:167
uint32_t baud_rate
Definition: nbiot2.h:177
pin_name_t wup
Definition: nbiot2.h:174
bool uart_blocking
Definition: nbiot2.h:178
uart_data_bits_t data_bit
Definition: nbiot2.h:179
pin_name_t tx_pin
Definition: nbiot2.h:170
pin_name_t rx_pin
Definition: nbiot2.h:169
uart_stop_bits_t stop_bit
Definition: nbiot2.h:181
uart_parity_t parity_bit
Definition: nbiot2.h:180
pin_name_t rst
Definition: nbiot2.h:173
NB IoT 2 Click context object.
Definition: nbiot2.h:148
uart_t uart
Definition: nbiot2.h:154
digital_out_t wup
Definition: nbiot2.h:151
digital_out_t rst
Definition: nbiot2.h:150