Cypress技术william hill官网
直播中

刘倩

7年用户 191经验值
私信 关注
[问答]

怎么将数据分成多个通知

亲爱的各位,
我正在建造一个定制的BLE服务,我无意中发现了这个问题:
因为我需要使用一个AtTytMut-3大小,所以我只能在每个通知中发送20字节的数据。但是我必须发送一个更长的通知(例如36字节),所有这些字节需要存储在相同的特性中。现在我想知道是否有办法把这个数据分成2个通知。
我现在的部分将发送20字节数据的通知,我可以在客户端接收它。当我在客户端使用读函数时,我得到了36个字节的数据。每当我将长度从20更改为更大的通知时,该通知将不被发送,我知道这与AtTytMTU大小有关。(我不想增加ATTHMTU的大小!)!)
无效更新(无效)
{
如果(CyByLyGestStand())!= CyBySt-状态连接
{
返回;
}
CyBLY-GATSH-HANDLY ValueEntfft瞬变;
ToPHANDEL.AtHuffRe= CyByLyPrimultHub句柄;
TyPHANDEL.ValueVal=(Uti8*)和MyDATA;
TyPHANDEL.Value.Le= siZeof(MyDATA);
CybLyggTraceWrrestAtvestValue:(0;and CysLyCon句柄,0);
如果(CyBygGATGETBUSTSTATUS()= = CyByth-StaskStaseEnFiel&App.;通知)
{
BelysEngEngress(CysLyPrimultRoad,(UTIN 8*)和GaIDATA,20);
}
}
虚空BelsSeNeNebug(CysLyggdBdAtdulAddiLext特性,UTI8*数据,UIT16长度)
{
CyBLY-GATSH-HANDLYVALIONEVITY NTFIFT通知;
Valtual.Value.Val=数据;
长度=长度;
特征句柄=特征;
如果(CyBLY-GATS通知)(CyByLyCon句柄,和通知)!CyelyyeloRosiok
{
dggpPrimTf(“错误发送通知 rn”);
}
其他的
{
dggPrimtf(“发送通知 rn”);
}
}

以上来自于百度翻译


     以下为原文
  Dear all,

I'm building a custom BLE-Service and i've stumbled on the folowing problem:

Since I am required to use a ATT_MTU-3 Size i can only send 20 bytes of data in each notification. But I have to send a notification which is longer (e.g. 36 bytes) and all these bytes need to be stored in the same characteristic. Now I am wondering if there is a way to split this data into 2 notifications.

The part i have now will send a notification of 20 bytes of data and i can receive it on the client side. When i use the READ function on the client side i get the full 36 bytes of data. Whenever i change the length from 20 to anything larger the notification will not be send, I am aware that this has to do with the ATT_MTU size. (I do not want to increase the ATT_MTU size!!)

void UpdateGaid(void)
{
    if(CyBle_GetState() != CYBLE_STATE_CONNECTED)
    {
        return;
    }
   
    CYBLE_GATTS_HANDLE_VALUE_NTF_T tempHandle;
   
   
    tempHandle.attrHandle = CYBLE_CHARACTER_HANDLE;
    tempHandle.value.val = (uint8 *)&MyData;
    tempHandle.value.len = sizeof(MyData);
    CyBle_GattsWriteAttributeValue(&tempHandle, 0, &cyBle_connHandle, 0);
   
    if(CyBle_GattGetBusStatus() == CYBLE_STACK_STATE_FREE && Notify)
    {
        ble_SendNotification(CYBLE_CHARACTER_HANDLE, (uint8 *)&GaiData, 20);
    }
}

void ble_SendNotification(CYBLE_GATT_DB_ATTR_HANDLE_T characteristic, uint8* data, uint16 length)
{
    CYBLE_GATTS_HANDLE_VALUE_NTF_T notification;
    notification.value.val  = data;
    notification.value.len  = length;
    notification.attrHandle = characteristic;
    if (CyBle_GattsNotification(cyBle_connHandle, ¬ification) != CYBLE_ERROR_OK)
    {
        DBG_PRINTF("ERROR sending notificationrn");
    }   
    else
    {
        DBG_PRINTF("sending notificationrn");
    }
}

回帖(3)

黎歆俭

2018-11-28 16:42:43
如果你想把一个特性分成两个单独的通知,我怀疑是否有办法做到这一点。
但是,如果你只是想让你的数据分离通知包,那么你可以设置你的发送服务器来发送两个不同的通知(比如NTF1和NTF2),每个通知都包含一部分数据。然后,您只发送NTF1一半的通知,然后发送NTF2一半,在接收侧重建原始特征/数据。不幸的是,这将需要两个单独的特性,但这将允许您区分数据的第一和第二部分。
另一种选择是将两个通知发送到同一个特性上,然后接收和存储通知数据到重新组装的包中。然而,这可能会覆盖你原来的特性。

以上来自于百度翻译


     以下为原文
  If you are wanting to split a single characteristic into two separate notifications, I would be doubtful there is a way to do that
But, if you just want your data in to separate notification packets, then you could probably setup your sending-server to send two different notifications (say NTF1 and NTF2) that would each contain part of the data. Then, you merely send a notification with the NTF1 half, and send a NTF2 half afterwards, rebuilding the original characteristic/data on the receiving side. This would require two separate characteristics unfortunately, but would allow you to differentiate between the first and second half of the data.
The other option, is to send both notifications on the same characteristic you have right now, and then to receive and store the notification data into the reassembled packet. This might overwrite your original characteristic however.
举报

刘倩

2018-11-28 16:59:21
引用: yuhe82 发表于 2018-11-28 09:52
如果你想把一个特性分成两个单独的通知,我怀疑是否有办法做到这一点。
但是,如果你只是想让你的数据分离通知包,那么你可以设置你的发送服务器来发送两个不同的通知(比如NTF1和NTF2),每个通知都包含一部分数据。然后,您只发送NTF1一半的通知,然后发送NTF2一半,在接收侧重建原始特征/数据。不幸的是,这将需要两个单 ...

你好,你有什么关于如何建造这个的例子吗?但是,如果你只是想让你的数据分离通知包,那么你可以设置你的发送服务器来发送两个不同的通知(比如NTF1和NTF2),每个通知都包含一部分数据。然后,您只发送NTF1一半的通知,然后发送NTF2一半。

以上来自于百度翻译


     以下为原文
  e.pratt_1639216 Hello, do you have any example on how to build this?
"But, if you just want your data in to separate notification packets, then you could probably setup your sending-server to send two different notifications (say NTF1 and NTF2) that would each contain part of the data. Then, you merely send a notification with the NTF1 half, and send a NTF2 half afterwards"
 
举报

黎歆俭

2018-11-28 17:17:27
引用: hzy_jack 发表于 2018-11-28 10:09
你好,你有什么关于如何建造这个的例子吗?但是,如果你只是想让你的数据分离通知包,那么你可以设置你的发送服务器来发送两个不同的通知(比如NTF1和NTF2),每个通知都包含一部分数据。然后,您只发送NTF1一半的通知,然后发送NTF2一半。

以上来自于百度翻译

不幸的是,我没有一个例子,但这将是与处理IP碎片(IP碎片-维基百科)相同的理论/实践。
你基本上是在获取数据,而不是同时尝试发送所有数据,而是在每一个数据包中发送一部分数据,然后接收端对数据进行分类和重新组合以供使用。
例如:
要发送0xAA,0xbb的“长”数据,您将发送一个通知
0x01,0xAA表示第一段数据是0xAA(0x01是接收端重新排序数据包)
接下来,您将发送一个带有0x02、0xbb的数据包,表示第二部分的数据是0xbb(0x02是用于接收端重新排序数据包)。
接收方需要做大量的工作来处理丢失的数据包,并在使用之前验证所有数据是否存在。但是,在精确的顺序/数据格式上进行一点尝试和错误应该是可行的。
您可能需要某种方式来指示通知的重试、您期望的数据包/通知的数量以及接收到的所有数据的使用。

以上来自于百度翻译


     以下为原文
  Unfortunately, I don't have an example of this, but it would be the same theory/practice as dealing with IP Fragmentation (IP fragmentation - Wikipedia )
You essentially take your data, and instead of trying to send it all at the same time, you send part of it in each packet, and the receiving side then sorts and recombines the data for use.
For example:
To send the "long" data of 0xAA,0xBB, you would send a notification with
0x01, 0xAA to signify the first section of data is 0xAA (0x01 is for the receiving side to reorder the packets)
Next you would send a packet with 0x02, 0xBB to signify the second section of data is 0xBB (0x02 is for receiving side to reorder the packets)
The receiving side would need to do alot of work to deal with missing packets of data, and verifying all of the data is present before using it. But it should be feasible with a little bit of trial and error on the exact sequencing/data formats.
You will probably need to have some way to signal a retry of the notification, how many packets of data/notifications you expect, and all data received for use.
举报

更多回帖

发帖
×
20
完善资料,
赚取积分