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_ATI "ATI"
61 #define NBIOT4_CMD_CGMR "AT+CGMR"
62 #define NBIOT4_CMD_CFUN "AT+CFUN"
63 #define NBIOT4_CMD_CREG "AT+CREG"
64 #define NBIOT4_CMD_CEREG "AT+CEREG"
65 #define NBIOT4_CMD_CGDCONT "AT+CGDCONT"
66 #define NBIOT4_CMD_CIMI "AT+CIMI"
67 #define NBIOT4_CMD_CGATT "AT+CGATT"
68 #define NBIOT4_CMD_CSQ "AT+CSQ"
69 #define NBIOT4_CMD_CESQ "AT+CESQ"
70 #define NBIOT4_CMD_COPS "AT+COPS"
71 #define NBIOT4_CMD_CMGF "AT+CMGF"
72 #define NBIOT4_CMD_CMGS "AT+CMGS"
73 #define NBIOT4_CMD_CSCA "AT+CSCA"
74 #define NBIOT4_CMD_SQNLED "AT+SQNLED"
75 #define NBIOT4_CMD_SIMSWAP "AT^SIMSWAP"
76 #define NBIOT4_CMD_RESTART "AT+TRB"
77  // nbiot4_reg
79 
94 #define NBIOT4_RSP_OK "OK"
95 #define NBIOT4_RSP_ERROR "ERROR"
96 #define NBIOT4_RSP_CMD_NO_RSP "COMMAND NO RESPONSE!"
97 #define NBIOT4_RSP_NO_RSP "NO RESPONSE!"
98 
104 #define DRV_TX_BUFFER_SIZE 150
105 #define DRV_RX_BUFFER_SIZE 600
106  // nbiot4_set
108 
123 #define NBIOT4_MAP_MIKROBUS( cfg, mikrobus ) \
124  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
125  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
126  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
127  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
128  cfg.ri = MIKROBUS( mikrobus, MIKROBUS_INT );
129  // nbiot4_map // nbiot4
132 
137 typedef struct
138 {
139  // Output pins
140  digital_out_t rst;
141  digital_out_t cs;
142  digital_out_t ri;
144  // Modules
145  uart_t uart;
147  // Buffers
148  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
149  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
151 } nbiot4_t;
152 
157 typedef struct
158 {
159  // Communication gpio pins
160  pin_name_t rx_pin;
161  pin_name_t tx_pin;
163  // Additional gpio pins
164  //pin_name_t an; /**< Description. */
165  pin_name_t rst;
166  pin_name_t cs;
167  pin_name_t ri;
169  // Static variable
170  uint32_t baud_rate;
171  bool uart_blocking;
172  uart_data_bits_t data_bit;
173  uart_parity_t parity_bit;
174  uart_stop_bits_t stop_bit;
176 } nbiot4_cfg_t;
177 
182 typedef enum
183 {
188 
190 
206 void nbiot4_cfg_setup ( nbiot4_cfg_t *cfg );
207 
222 err_t nbiot4_init ( nbiot4_t *ctx, nbiot4_cfg_t *cfg );
223 
237 err_t nbiot4_default_cfg ( nbiot4_t *ctx );
238 
252 err_t nbiot4_generic_write ( nbiot4_t *ctx, char *data_buf, uint16_t len );
253 
267 err_t nbiot4_generic_read ( nbiot4_t *ctx, char *data_buf, uint16_t max_len );
268 
278 void nbiot4_send_cmd ( nbiot4_t *ctx, char *cmd );
279 
291 void nbiot4_send_cmd_with_parameter ( nbiot4_t *ctx, char *at_cmd_buf, char *param_buf );
292 
302 void nbiot4_send_cmd_check ( nbiot4_t *ctx, char *at_cmd_buf );
303 
313 void nbiot4_send_cmd_syntax_check ( nbiot4_t *ctx, char *at_cmd_buf );
314 
324 void nbiot4_set_sim_apn ( nbiot4_t *ctx, char *sim_apn );
325 
338 void nbiot4_send_text_message ( nbiot4_t *ctx, char *phone_number, char *message_content );
339 
353 err_t nbiot4_send_sms_pdu ( nbiot4_t *ctx, char *service_center_number, char *phone_number, char *sms_text );
354 
364 void nbiot4_set_reset ( nbiot4_t *ctx, uint8_t state );
365 
375 void nbiot_set_ri ( nbiot4_t *ctx, uint8_t state );
376 
377 #ifdef __cplusplus
378 }
379 #endif
380 #endif // NBIOT4_H
381  // nbiot4
383 
384 // ------------------------------------------------------------------------ END
nbiot4_set_reset
void nbiot4_set_reset(nbiot4_t *ctx, uint8_t state)
Set reset pin state.
nbiot4_send_text_message
void nbiot4_send_text_message(nbiot4_t *ctx, char *phone_number, char *message_content)
Send SMS message to number in text mode.
nbiot4_set_sim_apn
void nbiot4_set_sim_apn(nbiot4_t *ctx, char *sim_apn)
Set SIM APN.
nbiot4_default_cfg
err_t nbiot4_default_cfg(nbiot4_t *ctx)
NB IoT 4 default configuration 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_generic_write
err_t nbiot4_generic_write(nbiot4_t *ctx, char *data_buf, uint16_t len)
NB IoT 4 data writing function.
NBIOT4_OK
Definition: nbiot4.h:183
nbiot4_return_value_t
nbiot4_return_value_t
NB IoT 4 Click return value data.
Definition: nbiot4.h:181
NBIOT4_ERROR
Definition: nbiot4.h:184
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
NB IoT 4 driver buffer size.
Definition: nbiot4.h:103
nbiot4_send_cmd
void nbiot4_send_cmd(nbiot4_t *ctx, char *cmd)
Send command function.
nbiot4_send_cmd_syntax_check
void nbiot4_send_cmd_syntax_check(nbiot4_t *ctx, char *at_cmd_buf)
Send command to check commands available parameters.
nbiot4_cfg_t
NB IoT 4 Click configuration object.
Definition: nbiot4.h:156
nbiot4_send_sms_pdu
err_t nbiot4_send_sms_pdu(nbiot4_t *ctx, char *service_center_number, char *phone_number, char *sms_text)
Send SMS message to number in pdu mode.
nbiot4_t
NB IoT 4 Click context object.
Definition: nbiot4.h:136
nbiot4_generic_read
err_t nbiot4_generic_read(nbiot4_t *ctx, char *data_buf, uint16_t max_len)
NB IoT 4 data reading function.
nbiot4_send_cmd_with_parameter
void nbiot4_send_cmd_with_parameter(nbiot4_t *ctx, char *at_cmd_buf, char *param_buf)
Send command with parameters.
NBIOT4_ERROR_UNKNOWN
Definition: nbiot4.h:186
nbiot4_send_cmd_check
void nbiot4_send_cmd_check(nbiot4_t *ctx, char *at_cmd_buf)
Send command to check commands current value.
NBIOT4_ERROR_CMD
Definition: nbiot4.h:185
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: nbiot4.h:104
nbiot_set_ri
void nbiot_set_ri(nbiot4_t *ctx, uint8_t state)
Set ri pin state.