nbiot  2.0.0.0
nbiot.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef NBIOT_H
36 #define NBIOT_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_uart.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define NBIOT_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
55  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
56  cfg.stat = MIKROBUS( mikrobus, MIKROBUS_AN ); \
57  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
58 
64 #define NBIOT_RETVAL uint8_t
65 
66 #define NBIOT_OK 0x00
67 #define NBIOT_INIT_ERROR 0xFF
68 
74 #define NBIOT_PARSER_NO_ERROR 0x00
75 #define NBIOT_PARSER_ERROR_REF 0x01
76 #define NBIOT_PARSER_ERROR_CMD 0x02
77 #define NBIOT_PARSER_ERROR_DATA 0x04
78 
84 #define NBIOT_STATUS_DEVICE_READY 1
85 #define NBIOT_STATUS_ACT_NETWORK_AND_BROKER 4
86 #define NBIOT_STATUS_ACT_NETWORK 2
87 #define NBIOT_STATUS_ACT_BROKER 3
88 #define NBIOT_STATUS_DEVICE_BUSY 0
89 
95 #define NBIOT_MODULE_POWER_ON 1
96 #define NBIOT_MODULE_POWER_OFF 0
97 
103 #define NBIOT_SINGLE_CMD_AT "AT"
104 #define NBIOT_SINGLE_CMD_ATI "ATI"
105 #define NBIOT_SINGLE_CMD_AT_W "AT+W"
106 #define NBIOT_SINGLE_CMD_AT_R "AT+R"
107 #define NBIOT_SINGLE_CMD_ATE0 "ATE0"
108 #define NBIOT_SINGLE_CMD_ATE1 "ATE1"
109 #define NBIOT_SINGLE_CMD_AT_RST "AT+RST"
110 #define NBIOT_SINGLE_CMD_AT_CRST "AT+CRST"
111 #define NBIOT_SINGLE_CMD_AT_GMR "AT+GMR"
112 #define NBIOT_SINGLE_CMD_AT_GMSTA "AT+GMSTA"
113 #define NBIOT_SINGLE_CMD_AT_PUB "AT+PUB"
114 #define NBIOT_SINGLE_CMD_AT_CIMI "AT+CIMI"
115 
116 #define NBIOT_SINGLE_CMD_SET_AT_LRSP_1 "AT+LRSP=1"
117 #define NBIOT_SINGLE_CMD_SET_AT_LRSP_0 "AT+LRSP=0"
118 #define NBIOT_SINGLE_CMD_SET_AT_CEN_1 "AT+CEN=1"
119 #define NBIOT_SINGLE_CMD_SET_AT_CEN_0 "AT+CEN=0"
120 #define NBIOT_SINGLE_CMD_SET_AT_NWC_1 "AT+NWC=1"
121 #define NBIOT_SINGLE_CMD_SET_AT_NWC_0 "AT+NWC=0"
122 #define NBIOT_SINGLE_CMD_SET_AT_BRC_1 "AT+BRC=1"
123 #define NBIOT_SINGLE_CMD_SET_AT_BRC_0 "AT+BRC=0"
124 #define NBIOT_SINGLE_CMD_SET_AT_GPEN_0 "AT+GPEN=0"
125 #define NBIOT_SINGLE_CMD_SET_AT_GPEN_1 "AT+GPEN=1"
126 #define NBIOT_SINGLE_CMD_SET_AT_CFUN "AT+CFUN=1"
127 
128 #define NBIOT_SINGLE_CMD_GET_AT_LRSP "AT+LRSP?"
129 #define NBIOT_SINGLE_CMD_GET_AT_CEN "AT+CEN?"
130 #define NBIOT_SINGLE_CMD_GET_AT_NWC "AT+NWC?"
131 #define NBIOT_SINGLE_CMD_GET_AT_BRC "AT+BRC?"
132 #define NBIOT_SINGLE_CMD_GET_AT_GPEN "AT+GPEN?"
133 #define NBIOT_SINGLE_CMD_GET_AT_NWCR "AT+NWCR?"
134 #define NBIOT_SINGLE_CMD_GET_AT_BRCR "AT+BRCR?"
135 #define NBIOT_SINGLE_CMD_GET_AT_DSET "AT+DSET?"
136 
137 #define NBIOT_SINGLE_CMD_TEST_AT_LRSP "AT+LRSP=?"
138 #define NBIOT_SINGLE_CMD_TEST_AT_CEN "AT+CEN=?"
139 #define NBIOT_SINGLE_CMD_TEST_AT_NWC "AT+NWC=?"
140 #define NBIOT_SINGLE_CMD_TEST_AT_BRC "AT+BRC=?"
141 #define NBIOT_SINGLE_CMD_TEST_AT_GPEN "AT+GPEN=?"
142 #define NBIOT_SINGLE_CMD_TEST_AT_NWCR "AT+NWCR=?"
143 #define NBIOT_SINGLE_CMD_TEST_AT_BRCR "AT+BRCR=?"
144 #define NBIOT_SINGLE_CMD_TEST_AT_DSET "AT+DSET=?"
145 #define NBIOT_SINGLE_CMD_TEST_ATAT_CGDCONT "AT+CGDCONT?"
146 #define C5GNBIOT_SINGLE_CMD_GET_AT_CGATT "AT+CGATT?"
147 
148 #define NBIOT_MULTI_CMD_AT_DSET "AT+DSET"
149 #define NBIOT_MULTI_CMD_AT_BRCR "AT+BRCR"
150 #define NBIOT_MULTI_CMD_AT_NWCR "AT+NWCR"
151 
152 #define C5GNBIOT_SINGLE_CMD_SET_AT_CGDCONT_1 "AT+CGDCONT=1,\"IP\",\"vip.iot\""
153 #define NBIOT_CMD_AT_NCONFIG "AT+NCONFIG=CR_0354_0338_SCRAMBLING,TRUE"
154 #define NBIOT_CMD_AT_NCONFIG1 "AT+NCONFIG=CR_0859_SI_AVOID,TRUE"
155 #define NBIOT_CMD_AT_NCONFIG2 "AT+NCONFIG=AUTOCONNECT,FALSE"
156 #define NBIOT_CMD_AT_NBAND "AT+NBAND=8"
157 #define NBIOT_CMD_AT_CEREG "AT+CEREG=2"
158 #define NBIOT_CMD_AT_COPS "AT+COPS=1,2,\"12345\""
159 #define NBIOT_CMD_AT_NSOCR "AT+NSOCR= DGRAM,17,16666,1"
160 #define NBIOT_CMD_AT_NSOST "AT+NSOST=0,83.58.228.64,16666,2,ABCD"
161 #define NBIOT_CMD_AT_NSOCL "AT+NSOCL=0"
162 
169 #define DRV_RX_BUFFER_SIZE 500
170  // End group macro
173 // --------------------------------------------------------------- PUBLIC TYPES
181 typedef struct
182 {
183  // Output pins
184 
185  digital_out_t rst;
186 
187  // Input pins
188 
189  digital_in_t stat;
190 
191  // Modules
192 
193  uart_t uart;
194 
195  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
196  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
197 
198 } nbiot_t;
199 
203 typedef struct
204 {
205  // Communication gpio pins
206 
207  pin_name_t rx_pin;
208  pin_name_t tx_pin;
209 
210  // Additional gpio pins
211 
212  pin_name_t stat;
213  pin_name_t rst;
214 
215  // static variable
216 
217  uint32_t baud_rate; // Clock speed.
219  uart_data_bits_t data_bit; // Data bits.
220  uart_parity_t parity_bit; // Parity bit.
221  uart_stop_bits_t stop_bit; // Stop bits.
222 
223 } nbiot_cfg_t;
224 
228 // Actuator switch type
229 typedef uint8_t nbiot_actuator_sw_t;
230 
231 // Actuator counter type
232 typedef int16_t nbiot_actuator_cnt_t;
233 
234 // Actuator string type
235 typedef char nbiot_actuator_str_t;
236 
237 // Parser error type
238 typedef uint8_t nbiot_error_t;
239  // End types group
241 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
242 
248 #ifdef __cplusplus
249 extern "C"{
250 #endif
251 
260 void nbiot_cfg_setup ( nbiot_cfg_t *cfg );
261 
270 
275 void nbiot_module_power ( nbiot_t *ctx );
276 
281 void nbiot_reset ( nbiot_t *ctx );
282 
289 void nbiot_generic_write ( nbiot_t *ctx, char *data_buf, uint16_t len );
290 
298 int32_t nbiot_generic_read ( nbiot_t *ctx, char *data_buf, uint16_t max_len );
299 
306 void nbiot_send_command ( nbiot_t *ctx, char *command );
307 
308 #ifdef __cplusplus
309 }
310 #endif
311 #endif // _NBIOT_H_
312  // End public_function group
315 
316 // ------------------------------------------------------------------------- END
uart_stop_bits_t stop_bit
Definition: nbiot.h:221
void nbiot_send_command(nbiot_t *ctx, char *command)
Send Command function.
uint8_t nbiot_actuator_sw_t
Error type.
Definition: nbiot.h:229
NBIOT_RETVAL nbiot_init(nbiot_t *ctx, nbiot_cfg_t *cfg)
Initialization function.
int32_t nbiot_generic_read(nbiot_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
uart_t uart
Definition: nbiot.h:193
void nbiot_module_power(nbiot_t *ctx)
Power up modules.
Click ctx object definition.
Definition: nbiot.h:181
digital_out_t rst
Definition: nbiot.h:185
#define NBIOT_RETVAL
Definition: nbiot.h:64
uint32_t baud_rate
Definition: nbiot.h:217
#define DRV_RX_BUFFER_SIZE
Definition: nbiot.h:169
Click configuration structure definition.
Definition: nbiot.h:203
pin_name_t rst
Definition: nbiot.h:213
digital_in_t stat
Definition: nbiot.h:189
pin_name_t rx_pin
Definition: nbiot.h:207
void nbiot_generic_write(nbiot_t *ctx, char *data_buf, uint16_t len)
Generic write function.
uint8_t nbiot_error_t
Definition: nbiot.h:238
void nbiot_reset(nbiot_t *ctx)
Reset module.
uart_data_bits_t data_bit
Definition: nbiot.h:219
uart_parity_t parity_bit
Definition: nbiot.h:220
char nbiot_actuator_str_t
Definition: nbiot.h:235
pin_name_t stat
Definition: nbiot.h:212
bool uart_blocking
Definition: nbiot.h:218
void nbiot_cfg_setup(nbiot_cfg_t *cfg)
Config Object Initialization function.
int16_t nbiot_actuator_cnt_t
Definition: nbiot.h:232
pin_name_t tx_pin
Definition: nbiot.h:208