当前位置:网站首页>nus_data_handler源码解读结构体等数据类型
nus_data_handler源码解读结构体等数据类型
2022-06-12 05:44:00 【m0_7788】
c++对象编程思维体现在struct。
结构体是方便定义数据类型,struct描述需要不同类型数据的数据对象。
枚举(Enum)类型,能够列出所有可能的取值,并给它们取一个名字。
## ***services_init注册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;//保存led数据
} 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, //添加led事件类型
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;
边栏推荐
- 按键精灵的简单入门
- The way to promote software test engineer
- beginning一款非常优秀的emlog主题v3.1,支持Emlog Pro
- Heap classical problem
- XML参数架构,同一MTK SW版本兼容两套不同的音频参数
- XML parameter schema, the same MTK SW version is compatible with two different sets of audio parameters
- How much Ma is the driving current of SIM card signal? Is it adjustable?
- Optipng can optimize the compressed PNG picture file format
- Introduction to Internet Protocol
- json-c常用API
猜你喜欢

Simple introduction to key Wizard

The application could not be installed: INSTALL_FAILED_TEST_ONLY

Performance test - GTI application service performance monitoring platform

38. 外观数列

分公司负责人需要承担的法律责任

Role and understanding of proc/cmdline

March 4, 2021
![[long time series prediction] the [4] autocorrelation mechanism of aotoformer code explanation](/img/12/27531fc791b3f49306385831309c5e.png)
[long time series prediction] the [4] autocorrelation mechanism of aotoformer code explanation

CCF noi2022 quota allocation scheme

Filter的注解配置
随机推荐
March 4, 2021
[machine learning] first day of introduction
16. sum of the nearest three numbers
Nature | make an account of the new crown casualties in the world
Halcon uses points to fit a plane
利用jieba库进行词频统计
Introduction to sringmvc
[gpio] how to modify / display GPIO status through ADB shell
Thesis reading_ Figure neural network gin
CCF noi2022 quota allocation scheme
C language - how to define arrays
Flutter monitors application lifecycle status
Introduction to Internet Protocol
登录验证过滤器
Research Report on market supply and demand and strategy of China's digital camera lens industry
IO stream introduction
Is the individual industrial and commercial door a legal person enterprise
深入理解异步编程
Halcon 3D 1 Reading 3D data
Automated test - dark horse headline test project