android串口byte超过128,【基本解决】蓝牙数据传输数据单次超过990字节时被截断分段多次传输...

【背景】

Android中,用蓝牙发送数据,结果出现,超过990的字节的大批量的数据,就会被截断。

【解决过程】

1.google去搜:

Bluetooth 990 bytes

找到:

有人遇到,但是无解:

提到了“My android mobile bluetooth supporting maximum RFCOMM payload is 990 bytes”

不过好像其遇到的问题不一样:

发送了1K=2014=990+34,结果990丢失了,而不是截断的事情了。

说是:

RFCOMM中,就像串口,是没有Package包的概念的,只有字节流;

然后有时候多个小的数据包,又会被放在一起传输->一次性接收到的,是多个小的数据包。

而分段的大小,即一次性最大传输多少个,此处的990,是取决于每个蓝牙芯片内部的参数设置的。

->感觉说的也不一定对。。。

也有人遇到类似问题。

5.看到:

中关于蓝牙配置时,有个:# hciconfig

hci0: Type: BR/EDRBus: USB

BD Address: B4:B6:76:8D:AB:07ACL MTU: 310:10SCO MTU: 64:8

UP RUNNING

RX bytes:990 acl:0 sco:0 events:44 errors:0

TX bytes:738 acl:0 sco:0 commands:44 errors:0

其中的

RX bytes:990

感觉像是说:

一次性最多接受990个字节

如果是的话,那么:

TX bytes:738

或许就意味着:

一次性最多发送738个字节

6.再去搜:

Bluetooth RFCOMM max payload

找到:

都提到了:L2CAP’s functions include:Multiplexing data between different higher layer protocols.

Segmentation and reassembly of packets.

Providing one-way transmission management of multicast data to a group of other Bluetooth devices.

Quality of service (QoS) management for higher layer protocols.

L2CAP is used to communicate over the host ACL link. Its connection is established after the ACL link has been set up.

In basic mode, L2CAP provides packets with a payload configurable up to 64 kB, with 672 bytes as the default MTU, and 48 bytes as the minimum mandatory supported MTU.

根据:

Segmentation and reassembly of pack

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android 中进行串口传输,可能会出现数据被拆分成多个数据包的情况,这我们需要将这些数据包拼接起来才能正确处理数据。以下是一个示例代码,演示了如何将拆分的数据包拼接成完整的数据: ```java private StringBuilder stringBuilder = new StringBuilder(); // 用于拼接数据包的 StringBuilder // 接收到数据调用的方法 public void onDataReceived(byte[] buffer, int size) { String data = new String(buffer, 0, size); // 将 byte 数组转换为字符串 stringBuilder.append(data); // 将数据包拼接到 stringBuilder 中 // 判断是否已经接收到完整的数据 if (stringBuilder.toString().contains("END")) { // 以 "END" 结尾表示接收到完整的数据 String completeData = stringBuilder.toString().replace("END", ""); // 去掉 "END" 标记,得到完整的数据 // 在这里处理完整的数据 processData(completeData); stringBuilder.setLength(0); // 清空 stringBuilder,准备接收下一个数据包 } } ``` 以上代码中,我们使用 StringBuilder 对象来拼接数据包。在接收到数据,我们将其转换为字符串,并将其拼接到 stringBuilder 中。然后,我们判断 stringBuilder 中是否包含 "END" 标记,如果包含,就说明接收到了完整的数据。此,我们可以将 stringBuilder 中的数据去掉 "END" 标记,得到完整的数据。接下来,我们可以在 processData() 方法中处理完整的数据。最后,我们清空 stringBuilder,准备接收下一个数据包。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值