我下了一个BLE_BRIDGE 的代码,放到BLE目录里面
然后添加如下发送代码
uint16 sendToCentral(uint8* buff, uint16 len)
{
{
//ensure queue of notification is successful
bool send_error = FALSE;
//return value to update tail and send ack to msp
uint16 bytes_sent = 0;
attHandleValueNoti_t noti;
//dummy handle
bool send_error = FALSE;
//return value to update tail and send ack to msp
uint16 bytes_sent = 0;
attHandleValueNoti_t noti;
//dummy handle
noti.handle = 0x2E;
//counter
uint8 i;
while ((bytes_sent < len) && (send_error == FALSE))
{
noti.len = min(len - bytes_sent, 20);
noti.pValue = (uint8 *)GATT_bm_alloc( 0, ATT_HANDLE_VALUE_NOTI,
noti.len, &len );
if ( noti.pValue != NULL )
{
for (i = 0; i < noti.len; i++)
{
noti.pValue[i] = buff[bytes_sent + i];
}
//connection handle currently hardcoded
if (!(GATT_Notification(0, ¬i, FALSE))) //if sucessful
{
bytes_sent += noti.len;
}
else
{
send_error = TRUE;
GATT_bm_free( (gattMsg_t *)¬i, ATT_HANDLE_VALUE_NOTI );
}
}
}
return bytes_sent;
}
//counter
uint8 i;
while ((bytes_sent < len) && (send_error == FALSE))
{
noti.len = min(len - bytes_sent, 20);
noti.pValue = (uint8 *)GATT_bm_alloc( 0, ATT_HANDLE_VALUE_NOTI,
noti.len, &len );
if ( noti.pValue != NULL )
{
for (i = 0; i < noti.len; i++)
{
noti.pValue[i] = buff[bytes_sent + i];
}
//connection handle currently hardcoded
if (!(GATT_Notification(0, ¬i, FALSE))) //if sucessful
{
bytes_sent += noti.len;
}
else
{
send_error = TRUE;
GATT_bm_free( (gattMsg_t *)¬i, ATT_HANDLE_VALUE_NOTI );
}
}
}
return bytes_sent;
}
然后用手机连接测试, 无法收到notification, 但是一台Android 5.1的平板和BTool可以收到notification, 不知道什么原因,有人遇到过么
这个是BTool 收到的,可是手机怎么也收不到
