当前位置:网站首页>nus_ data_ Handler source code interprets data types such as structure
nus_ data_ Handler source code interprets data types such as structure
2022-06-12 05:46:00 【m0_ seven thousand seven hundred and eighty-eight】
c++ Object programming thinking is embodied in struct.
Structs are convenient for defining data types ,struct Describe data objects that require different types of data .
enumeration (Enum) type , Be able to list all possible values , And give them a name .
nodic Official website uart Introduce
## ***services_init register NUS,nus_init.data_handler = nus_data_handler;***
static void nus_data_handler(ble_nus_evt_t *p_evt)
{
if (p_evt->type == BLE_NUS_EVT_RX_DATA)
{
uint32_t err_code;
NRF_LOG_DEBUG("nus_data_handler:Received data from BLE NUS. Writing data on UART.");
NRF_LOG_HEXDUMP_DEBUG(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length);
for (uint32_t i = 0; i < p_evt->params.rx_data.length; i++)
{
do
{
err_code = app_uart_put(p_evt->params.rx_data.p_data[i]);
if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY))
{
NRF_LOG_ERROR("Failed receiving NUS message. Error 0x%x. ", err_code);
APP_ERROR_CHECK(err_code);
}
} while (err_code == NRF_ERROR_BUSY);
}
if (p_evt->params.rx_data.p_data[p_evt->params.rx_data.length - 1] == '\r')
{
while (app_uart_put('\n') == NRF_ERROR_BUSY);
}
}
}
## ***ble_nus.h***
//p_evt->type(ble_nus_evt_type_t) == BLE_NUS_EVT_RX_DATA
//p_evt->params.rx_data.p_data
typedef struct
{
ble_nus_evt_type_t type; /**< Event type. */
ble_nus_t * p_nus; /**< A pointer to the instance. */
uint16_t conn_handle; /**< Connection handle. */
ble_nus_client_context_t * p_link_ctx; /**< A pointer to the link context. */
union
{
ble_nus_evt_rx_data_t rx_data; /**< @ref BLE_NUS_EVT_RX_DATA event data. */
ble_nus_evt_rx_data_t led_data;// preservation led data
} params;
} ble_nus_evt_t;
//evt_type
typedef enum
{
BLE_NUS_EVT_RX_DATA, /**< Data received. */
BLE_NUS_EVT_TX_RDY, /**< Service is ready to accept new data to be transmitted. */
BLE_NUS_EVT_LED_OPT, // add to led Event type
BLE_NUS_EVT_COMM_STARTED, /**< Notification has been enabled. */
BLE_NUS_EVT_COMM_STOPPED, /**< Notification has been disabled. */
} ble_nus_evt_type_t;
//the buffer with received data
typedef struct
{
uint8_t const * p_data; /**< A pointer to the buffer with received data. */
uint16_t length; /**< Length of received data. */
} ble_nus_evt_rx_data_t;
边栏推荐
- Introduction to redis high availability
- Wireshark filter rule
- Available RTMP and RTSP test addresses of the public network (updated in March, 2021)
- RTMP streaming +rtmp playback low delay solution in unity environment
- 深入理解异步编程
- Market trend report, technical innovation and market forecast of Chinese stump crusher
- March 22, 2021
- Laravel8 authentication login
- Why can't NAND flash be used as RAM while nor flash can
- Deep understanding of asynchronous programming
猜你喜欢
随机推荐
Stack and queue classic interview questions
Conversion of Halcon 3D depth map to 3D image
Market trend report, technical innovation and market forecast of Chinese stump crusher
Tkinter uses webview2 web component (sequel)
16. sum of the nearest three numbers
数据库实验二:数据更新
Analysis of pointer
Date ()
Individual application for ov type SSL certificate
yolov5
Rtmp/rtsp/hls public network real available test address
Introduction to sringmvc
[go] Viper reads the configuration file in the go project
Redis transaction
CODIS stress test (PHP)
[daily question on niuke.com] two point search
March 23, 2021
China's alternative sports equipment market trend report, technology dynamic innovation and market forecast
Halcon 3D 1 读取3d数据
[Speech] 如何根据不同国家客制化ring back tone
![【长时间序列预测】Aotoformer 代码详解之[4]自相关机制](/img/12/27531fc791b3f49306385831309c5e.png)
![[gin] gin framework for golang web development](/img/15/68c4fd217555f940b3cd3d10fcd54f.jpg)






