作者fake01 (code)
看板AndroidDev
标题[问题] 蓝芽接值 掉值问题
时间Thu Jan 31 02:58:52 2013
使用手机蓝芽接值,而接的值是由硬体端不断丢值,
通常一秒丢一串字串 例如 123$456# or 455$123$
但是蓝芽这边接一次有时候会漏掉值 123456# 或 123$56,
但有时候又会正常接,是无法判断硬体这边丢一次的字串是甚麽,
请问该如何解决呢
case MESSAGE_READ:
byte[] readBuf = (byte[]) msg.obj;
// construct a string from the valid bytes in the buffer
String readMessage = null;
try {
readMessage = new String(readBuf, 0,msg.arg1,"GBK");
}
catch (UnsupportedEncodingException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
// 以上就是蓝芽抓值的code,麻烦各位了
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.58.82.128
1F:→ fireslayer:你可能要查查错误检查码 或是TCP的传输机制模仿看看 01/31 11:06
2F:→ fake01:F大什麽意思搞不太懂? 线再的问题是蓝芽传过的封包 有时候 01/31 17:53
3F:→ fake01:会有遗失的问题,想要正确的一次抓取正确的值 01/31 17:54
4F:→ fireslayer:你查error detection code我论蓝芽传输没有检查漏封包 01/31 21:15
5F:→ fireslayer:所以你要自己检查 01/31 21:15
6F:→ fireslayer:TCP三次握手机制也可以模仿 01/31 21:15
7F:→ fireslayer:以上是我的猜测 你可以试试看 01/31 21:16
8F:推 sdyy:好诡异 之前做蓝芽都没遇过这种情况 倒是会有丢两次值被合成 01/31 22:36
9F:→ sdyy:一次 01/31 22:36
10F:→ ChonPiggy:应该贴 socket 那边的 code 吧.. 01/31 23:21