我正在尝试从BLE芯片向智能手机向智能手机发送N个字节,在从智能手机中收到BLE芯片中的一组字节,即,我的预期操作顺序如下:
智能手机 - > DA14580芯片 - >智能手机
I have managed to do the first part (Smartphone --BLE--> DA14580 chip) but I am having trouble understanding how to do the second part
我正在修改ble_app_peripheral样本程序
我在user_custs1_impl.c中取消了void app_adcval1_timer_cb_handler()的代码,并尝试修改它,但它不起作用(即,我的智能手机上的Buttom BLE接收应用程序不会检测到任何东西)
(I am also sure it is not a problem with the smartphone app, as it can detect incoming BLE data from another custom BLE module that I have, and my goal to create my own version of this custom module)
这是我的代码:
void user_server_rx_data_ind_handler(ke_msg_id_t const msgid,
struct musts1_val_write_ind const * param,
ke_task_id_t const dest_id,
ke_task_id_t const src_id)
{
ARCH_PRINTF(“功能%s \ n \ r”,__func__);
// DO OPERATION: just display data for now
for(int i = 0; iLength; i ++){
ARCH_PRINTF(“\ TPARAM->值[%d] =%d(0x%x)\ n \ r”,i,param-> value [i],param-> value [i]);
}
// 2018-02-12:i2c将字节发送到外部开发
//将接收的字节数组的数据部分发送到I2C从地址
arch_printf("Writing to I2C: Add: %d value: %d\n\r", I2C_SLAVE_ADDRESS, param->value[(param->length) - 1] );
i2c_write_mine(i2c_slave_address,param-> value [(param-> length) - 1]);
// 2018-02-20:来自论坛帖子(https://support.dialog-semiconductor.com/ble-transmission)
// *************************************定制价值1 ********************************* //
struct custs1_val_ntf_req* req = KE_MSG_ALLOC_DYN(CUSTS1_VAL_NTF_REQ,
task_custs1,
task_app,
custs1_val_ntf_req,
def_user_server_tx_data_char_len);
arch_printf("Inside %s\n\r\tCUSTS1_VAL_NTF_REQ = %d\n\r\tTASK_CUSTS1 = %d\n\r\tTASK_APP = %d\n\r\tDEF_CUST1_ADC_VAL_1_CHAR_LEN = %d\n\r",__func__, CUSTS1_VAL_NTF_REQ, TASK_CUSTS1, TASK_APP, DEF_USER_SERVER_TX_DATA_CHAR_LEN);
静态UINT16_T样本[20];
for(int i=0; i< 20; i++)
{
样本[i] = 65 + i;
}
req->conhdl = app_env->conhdl;
// req-> handle = cust1_idx_adc_val_1_val;// 2018-02-20:orig
req->handle = USER_IDX_SERVER_TX_DATA_VAL;
// req->length = DEF_CUST1_ADC_VAL_1_CHAR_LEN; // 2018-02-20 : ORIG
req->length = DEF_USER_SERVER_TX_DATA_CHAR_LEN;
// memcpy(req->value, &sample, DEF_CUST1_ADC_VAL_1_CHAR_LEN); // 2018-02-20 : ORIG
memcpy(req->值,&sample,def_user_server_tx_data_char_len);
ke_msg_send(req);
arch_printf("I2C data sending completed\n\r");
}
user_server_rx_data_ind_handler()是当da14580从ble收到字节时调用的自定义函数(此函数在user_catch_rest_hndl()中调用user_peripheral.c中的一个,其中一个switch()...案例块
USER_IDX_SERVER_TX_DATA_VAL is defined in user_custs1_def.h, as an enum along side CUST1_IDX_ADC_VAL_1_VAL. This enum entry was created following the tutorial for the ble_peripheral_app. The other enums created alongside this are:
user_idx_server_tx_data_char,
USER_IDX_SERVER_TX_DATA_VAL,
user_idx_server_tx_data_ntf_cfg,
user_idx_server_tx_data_user_desc,
Basically I have tried to make this the same as CUST1_IDX_ADC_VAL_1_*
DEF_USER_SERVER_TX_DATA_CHAR_LEN is defined in user_custs1_def.h as
#define def_user_server_tx_data_char_len 20.
The ble_peripheral_app tutorial I followed is
Training_03_custom_profile_gatt_cmd_example_v1 0.pdf
I think I am missing something very basic here. How can I send a single byte of data from the BLE chip to the smartphone?
- - 编辑 - -
This causes the following outputs on the UART terminal:
Inside user_server_rx_data_ind_handler.
CUSTS1_VAL_NTF_REQ = 55300
TASK_CUSTS1 = 54
task_app = 50.
def_cust1_adc_val_1_char_len = 20.
I2C数据发送已完成
它还导致user_peripheral.c中的呼叫呼叫user_catch_rest_hndl()函数
Entered user_catch_rest_hndl :
msgid = 0xd805
检测到MSG_PARAM-> HARKE = 27)检测到CUSTS1_VAL_NTF_CFM
--- EDIT 2 ---
还将以下条目添加到user_custs1_def.c文件的struct attm_desc_128 custs1_att_db [cust1_idx_nb] =结构定义:
//用户服务器TX数据特征声明
[USER_IDX_SERVER_TX_DATA_CHAR] = {(uint8_t*)&att_decl_char, ATT_UUID_16_LEN, PERM(RD, ENABLE),
sizeof(user_server_tx_data_char), sizeof(user_server_tx_data_char), (uint8_t*)&user_server_tx_data_char},
//用户服务器TX数据特征值
//可能必须在此处启用NTF权限;如果需要稍后回到这一点
[USER_IDX_SERVER_TX_DATA_VAL] = {USER_SERVER_TX_DATA_UUID_128, ATT_UUID_128_LEN, PERM(RD, ENABLE) | PERM(NTF, ENABLE),
DEF_USER_SERVER_TX_DATA_CHAR_LEN, 0, NULL},
// user Server TX data Characteristic Configuration Descriptor
[USER_IDX_SERVER_TX_DATA_NTF_CFG] = {(uint8_t*)&att_decl_cfg, ATT_UUID_16_LEN, PERM(RD, ENABLE) | PERM(WR, ENABLE),
sizeof(uint16_t), 0, NULL},
//用户服务器TX数据特征用户描述
[USER_IDX_SERVER_TX_DATA_USER_DESC] = {(uint8_t*)&att_decl_user_desc, ATT_UUID_16_LEN, PERM(RD, ENABLE),
sizeof(USER_SERVER_TX_DATA_USER_DESC) - 1, sizeof(USER_SERVER_TX_DATA_USER_DESC) - 1, USER_SERVER_TX_DATA_USER_DESC},
Hi mahaju,
The ble_app_peripheral contains writable characteristics, like control point and readable – notifiable characteristics, like ADC VAL 1. The central can write a characteristic from a device, and the device can notify a characteristic from the central.
在您的应用程序中,当您通过BLE从智能手机发送消息到DA14580 SoC时,这是一个可写的特征。在另一方面,当您向智能手机发送DA14580 SoC的消息时,这是一个通知的特征,您必须启动通知。
请检查通知是否已激活。
Thanks PM_dialog
嗨I启用了对话框芯片代码中的通知,如下所示:
struct susts1_val_set_req * msg_en_notf = ke_msg_alloc_dyn(custs1_val_set_req,
task_custs1,
task_app,
custs1_val_set_req,
0x2);
静态uint16_t enable_notif;
启用_notif = 0x0001;
// enable_notif [0] = 0x01;
// enable_notif [2] = 0x00;
msg_en_notf->conhdl = app_env->conhdl;
msg_en_notf-> handle = user_idx_server_tx_data_ntf_cfg;
// msg_en_notf->handle = USER_IDX_SERVER_TX_DATA_VAL;
msg_en_notf->length = 0x2; // use the same value as the argument for KE_MSG_ALLOC_DYN() above
memcpy(msg_en_notf->值,&enable_notif,0x2);
ke_msg_send(msg_en_notf);
I call this block of code every time I need to send something from the BLE chip to smartphone, and I am able to view the data I sent from the BLE chip in my smartphone app
Is this the correct approach? I tried calling this just once in user_app_init() in user_peripheral.c, but it didn't work.
Hi mahaju,
不,这不是一个正确的方法。正确的方法是主站应启用指示/通知特性。在您的实现中,您已完成相反的操作,您将从代码中编写通知属性。根据BLE规范,主设备启用通知属性,因此您必须从智能手机应用程序启用通知。
当您在User_App_Init()函数中调用代码块时,它的预期它不起作用。首先调用user_app_init(),然后重置BLE堆栈。重置后,您将丢失所有数据,并且放电BLE堆栈。
Thanks PM_dialog
嗨抱歉以下this so late, but I have another question
If I understand this correctly, notifications should be enabled by just using the android functions in the smartphone
这是正确的吗?我需要添加一些额外的代码吗in the Dialog program to accept and process the "notification enable" command from the smartphone?
Hi mahaju,
Yes, that is correct. You should enable the notifications by using you mobile BLE application, but your characteristic should be notifiable, and no you should not add anything extra in your code, the profile will manage this. I suggest you to check the ble_app_peripheral example of the SDK. This example contains the implementation of a notifiable characteristic (ADC VAL 1 characteristic).
Thanks PM_dialog