trying to send bytes from peripheral to central (DA14580 to smartphone)

⚠️
Hi there.. thanks for coming to the forums. Exciting news! we’re now in the process of moving to our new forum platform that will offer better functionality and is contained within the main Dialog website. All posts and accounts have been migrated. We’re now accepting traffic on the new forum only - please POST any new threads at//www.wsdof.com/support. We’ll be fixing bugs / optimising the searching and tagging over the coming days.
6 posts / 0 new
Last post
mahaju
Offline
Last seen:2 years 1 month ago
加入:2018-01-29 01:08
trying to send bytes from peripheral to central (DA14580 to smartphone)

I am trying to send a n array of bytes from the BLE chip to the smartphone, AFTER I receive an array of bytes in the BLE chip from the smartphone, that is, my intended order of operation is as follows:

Smartphone --BLE--> DA14580 chip --BLE--> smartphone

我已经设法做了第一部分(智能手机 - > DA14580芯片),但我无法理解如何做第二部分

I am modifying the ble_app_peripheral sample program

I took the code inside void app_adcval1_timer_cb_handler() in user_custs1_impl.c, and tried to modify it, but it doesn't work (that is, my bustom BLE receive app on my smartphone does not detect anything)
(我也确定它不是智能手机应用程序的问题,因为它可以从我拥有的另一个自定义BLE模块中检测到传入的BLE数据,以及我的目标创建我自己的此自定义模块的版本)

Here is my code:

void user_server_rx_data_ind_handler(ke_msg_id_t const msgid,
struct custs1_val_write_ind const *param,
ke_task_id_t const dest_id,
ke_task_id_t const src_id)
{
arch_printf("in function %s\n\r", __func__ );
//执行操作:只需显示数据即可
for(int i=0; ilength; i++){
arch_printf("\tparam->value[%d] = %d (0x%x)\n\r", i, param->value[i], param->value[i] );
}

//2018-02-12: I2C send byte to external dev
//send the data part of the received byte array to I2C slave address
ARCH_PRINTF(“写入I2C:添加:%D值:%d \ n \ r”,i2c_slave_address,param->值[(param-> length) - 1]);
i2c_write_mine(I2C_SLAVE_ADDRESS, param->value[(param->length) - 1]);

//2018-02-20: from forum post (https://support.dialog-semicondiondiond.com/ble-transmission.)
//*************************************Custom value 1*********************************//
struct musts1_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(“INSION%S \ n \ r \ tcusts1_val_ntf_req =%d \ n \ r \ ttask_custs1 =%d \ n \ r \ ttask_app =%d \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ 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);
static uint16_t sample[20];
for(int i = 0; i <20; i ++)
{
sample[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->值,&sample,def_cust1_adc_val_1_char_len);// 2018-02-20:orig
memcpy(req->value, &sample, DEF_USER_SERVER_TX_DATA_CHAR_LEN);

KE_MSG_SEND(REQ);

ARCH_PRINTF(“I2C数据发送完成\ n \ r”);
}

user_server_rx_data_ind_handler() is the custom function that gets called when DA14580 receives bytes from BLE (this function is called inside user_catch_rest_hndl() in user_peripheral.c, inside one of the switch()...case blocks

user_idx_server_tx_data_val在user_custs1_def.h中定义,沿着side cust1_idx_adc_val_1_val in枚举。此枚举条目是在BLE_PERITELAL_APP的教程中创建的。与此同时创建的其他枚举是:

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,
基本上,我试图使其与cust1_idx_adc_val_1_ *相同

def_user_server_tx_data_char_len在user_custs1_def.h中定义为
#define DEF_USER_SERVER_TX_DATA_CHAR_LEN 20

BLE_PERITALAL_APP教程我遵循是
training_03_custom_profile_gatt_cmd_example_v1 0.pdf.

我想我在这里缺少非常基本的东西。如何从BLE芯片向智能手机发送单个数据字节?

--- EDIT ---
这会导致UART终端上的以下输出:

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 data sending completed

It also causes a call to the user_catch_rest_hndl () function in user_peripheral.c

输入user_catch_rest_hndl:
msgd = 0xD805.
CUSTS1_VAL_NTF_CFM detected : msg_param->handle = 27

---编辑2 ---
The following entries were also added to the user_custs1_def.c file's struct attm_desc_128 custs1_att_db[CUST1_IDX_NB] = structure definition:

//user Server TX data Characteristic Declaration
[user_idx_server_tx_data_char] = {(uint8_t *)和att_decl_char,att_uuid_16_len,perm(rd,启用),
sizeof(user_server_tx_data_char),sizeof(user_server_tx_data_char),(uint8_t *)和user_server_tx_data_char},

//user Server TX data Characteristic Value
//might have to enable NTF permission here; come back to this point if needed later
[user_idx_server_tx_data_val] = {user_server_tx_data_uuuid_128,att_uuid_128_len,perm(rd,启用)|perm(ntf,启用),
def_user_server_tx_data_char_len,0,null},

//用户服务器TX数据特征配置描述符
[user_idx_server_tx_data_ntf_cfg] = {(uint8_t *)和att_decl_cfg,att_uuid_16_len,perm(rd,启用)|perm(wr,启用),
sizeof(uint16_t),0,null},

//user Server TX data Characteristic User Description
[user_idx_server_tx_data_user_desc] = {(uint8_t *)&att_decl_user_desc,att_uuid_16_len,perm(rd,启用),
sizeof(user_server_tx_data_user_desc) - 1,sizeof(user_server_tx_data_user_desc) - 1,user_server_tx_data_user_desc},

设备:
PM_Dialog
Offline
Last seen:10小时59分钟前
工作人员
加入:2018-02-08 11:03
嗨马哈茹,

嗨马哈茹,

BLE_APP_PERITWAL包含可写特性,如控制点和可读 - 可读取的特性,如ADC VAL 1.中央可以从设备写入特性,并且设备可以通知来自中央的特性。

In your application, when you send a message from your smartphone to the DA14580 SoC over BLE, this is a writable characteristic. On the other side, when you send a message from DA14580 SoC to your smartphone, this is a notifiable characteristic and you must have the notifications activated.

Please, check if the notifications are activated.

谢谢pm_dialog.

mahaju
Offline
Last seen:2 years 1 month ago
加入:2018-01-29 01:08
嗨,我启用了通知

嗨,我启用了通知the Dialog chip code as shown below:

struct custs1_val_set_req* msg_en_notf = KE_MSG_ALLOC_DYN(CUSTS1_VAL_SET_REQ,
TASK_CUSTS1,
TASK_APP,
custs1_val_set_req,
0x2);
static uint16_t enable_notif;
enable_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;//使用与上面的ke_msg_alloc_dyn()的参数相同的值
memcpy(msg_en_notf->value, &enable_notif, 0x2);

ke_msg_send(msg_en_notf);

每次需要将某些东西从BLE芯片发送到智能手机时,我都会调用此代码块,并且我能够在智能手机应用程序中查看从BLE芯片发送的数据

这是正确的方法吗?我尝试在User_PeripherAl.cn中的user_app_init()中调用一次,但它不起作用。

PM_Dialog
Offline
Last seen:10小时59分钟前
工作人员
加入:2018-02-08 11:03
嗨马哈茹,

嗨马哈茹,

No, this isn’t a correct approach. The correct approach is that the master should enable the indication/notification characteristic. In your implementation you have done the opposite, you write the notification attribute from your code. According to BLE specifications, the master enable the notification attribute, so you must enable the notifications from your smartphone application.
Its’s expected that it didn’t work when you call your block of code in the user_app_init() function. First the user_app_init() is called and then the BLE stack is reset. After the reset, you will lose all your data and the BLE stack get discharged.

谢谢pm_dialog.

mahaju
Offline
Last seen:2 years 1 month ago
加入:2018-01-29 01:08
Hi sorry for following up to

嗨抱歉跟进这么晚,但我有另一个问题

如果我正确地理解这一点,只需使用智能手机中的Android函数即可启用通知

这样对吗?是否需要在对话程序程序中添加一些额外的代码以接受和处理来自智能手机的“通知启用”命令?

PM_Dialog
Offline
Last seen:10小时59分钟前
工作人员
加入:2018-02-08 11:03
嗨马哈茹,

嗨马哈茹,

对,那是正确的。您应该通过使用移动BLE应用程序启用通知,但您应该通知您的特征,否您在代码中不应添加任何额外的内容,配置文件将管理此内容。我建议您检查SDK的BLE_APP_PERITELAL示例。此示例包含通知特性(ADC Val 1特征)的实现。

谢谢pm_dialog.