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 )
64#define NBIOT_RETVAL uint8_t
65
66#define NBIOT_OK 0x00
67#define NBIOT_INIT_ERROR 0xFF
74#define NBIOT_CMD_AT "AT"
75#define NBIOT_CMD_ATI "ATI"
76#define NBIOT_CMD_CGMR "AT+CGMR"
77
78#define NBIOT_CMD_CFUN "AT+CFUN"
79#define NBIOT_CMD_CEREG "AT+CEREG"
80#define NBIOT_CMD_CGDCONT "AT+CGDCONT"
81#define NBIOT_CMD_CIMI "AT+CIMI"
82#define NBIOT_CMD_CGATT "AT+CGATT"
83#define NBIOT_CMD_CSQ "AT+CSQ"
84#define NBIOT_CMD_CESQ "AT+CESQ"
85#define NBIOT_CMD_COPS "AT+COPS"
92#define DRV_RX_BUFFER_SIZE 500
93#define DRV_TX_BUFFER_SIZE 100 // End group macro
97// --------------------------------------------------------------- PUBLIC TYPES
105typedef struct
106{
107 // Output pins
108
109 digital_out_t rst;
110
111 // Input pins
112
113 digital_in_t stat;
114
115 // Modules
116
117 uart_t uart;
118
119 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
120 char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
121
122} nbiot_t;
123
127typedef struct
128{
129 // Communication gpio pins
130
131 pin_name_t rx_pin;
132 pin_name_t tx_pin;
133
134 // Additional gpio pins
135
136 pin_name_t stat;
137 pin_name_t rst;
138
139 // static variable
140
141 uint32_t baud_rate; // Clock speed.
143 uart_data_bits_t data_bit; // Data bits.
144 uart_parity_t parity_bit; // Parity bit.
145 uart_stop_bits_t stop_bit; // Stop bits.
146
148
152// Actuator switch type
153typedef uint8_t nbiot_actuator_sw_t;
154
155// Actuator counter type
156typedef int16_t nbiot_actuator_cnt_t;
157
158// Actuator string type
160
161// Parser error type
162typedef uint8_t nbiot_error_t;
163 // End types group
165// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
166
172#ifdef __cplusplus
173extern "C"{
174#endif
175
186
201err_t nbiot_init ( nbiot_t *ctx, nbiot_cfg_t *cfg );
202
216err_t nbiot_generic_write ( nbiot_t *ctx, char *data_buf, uint16_t len );
217
231err_t nbiot_generic_read ( nbiot_t *ctx, char *data_buf, uint16_t max_len );
232
241
250void nbiot_set_rst ( nbiot_t *ctx, uint8_t state );
251
260uint8_t nbiot_get_stat ( nbiot_t *ctx );
261
271void nbiot_send_cmd ( nbiot_t *ctx, char *cmd );
272
283void nbiot_send_cmd_with_parameter ( nbiot_t *ctx, char *at_cmd_buf, char *param_buf );
284
294void nbiot_send_cmd_check ( nbiot_t *ctx, char *at_cmd_buf );
295
305void nbiot_send_cmd_parameter_check ( nbiot_t *ctx, char *at_cmd_buf );
306
316void nbiot_set_sim_apn ( nbiot_t *ctx, char *sim_apn );
317
318#ifdef __cplusplus
319}
320#endif
321#endif // _NBIOT_H_
322 // End public_function group
325
326// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition: nbiot.h:92
#define DRV_TX_BUFFER_SIZE
Definition: nbiot.h:93
void nbiot_power_on(nbiot_t *ctx)
NB IoT module power on.
err_t nbiot_init(nbiot_t *ctx, nbiot_cfg_t *cfg)
NB IoT initialization function.
void nbiot_send_cmd_check(nbiot_t *ctx, char *at_cmd_buf)
Check the sent command.
void nbiot_set_rst(nbiot_t *ctx, uint8_t state)
Sets state of the RST pin.
void nbiot_send_cmd_with_parameter(nbiot_t *ctx, char *at_cmd_buf, char *param_buf)
Send command function with parameter.
void nbiot_cfg_setup(nbiot_cfg_t *cfg)
NB IoT configuration object setup function.
uint8_t nbiot_get_stat(nbiot_t *ctx)
STAT Pin Get function.
err_t nbiot_generic_read(nbiot_t *ctx, char *data_buf, uint16_t max_len)
NB IoT data reading function.
void nbiot_set_sim_apn(nbiot_t *ctx, char *sim_apn)
Set sim card APN.
err_t nbiot_generic_write(nbiot_t *ctx, char *data_buf, uint16_t len)
NB IoT data writing function.
void nbiot_send_cmd_parameter_check(nbiot_t *ctx, char *at_cmd_buf)
Check the command parameters.
void nbiot_send_cmd(nbiot_t *ctx, char *cmd)
Send command function.
char nbiot_actuator_str_t
Definition: nbiot.h:159
uint8_t nbiot_error_t
Definition: nbiot.h:162
int16_t nbiot_actuator_cnt_t
Definition: nbiot.h:156
uint8_t nbiot_actuator_sw_t
Error type.
Definition: nbiot.h:153
Click configuration structure definition.
Definition: nbiot.h:128
uint32_t baud_rate
Definition: nbiot.h:141
bool uart_blocking
Definition: nbiot.h:142
uart_data_bits_t data_bit
Definition: nbiot.h:143
pin_name_t tx_pin
Definition: nbiot.h:132
pin_name_t rx_pin
Definition: nbiot.h:131
uart_stop_bits_t stop_bit
Definition: nbiot.h:145
uart_parity_t parity_bit
Definition: nbiot.h:144
pin_name_t stat
Definition: nbiot.h:136
pin_name_t rst
Definition: nbiot.h:137
Click ctx object definition.
Definition: nbiot.h:106
digital_in_t stat
Definition: nbiot.h:113
uart_t uart
Definition: nbiot.h:117
digital_out_t rst
Definition: nbiot.h:109