蓝牙的Andr​​oid RFCOMM / SPP错误处理的建议 [英] Bluetooth Android RFCOMM / SPP error handling suggestions

查看:211
本文介绍了蓝牙的Andr​​oid RFCOMM / SPP错误处理的建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我计划的通信协议的Andr​​oid设备,而且将使用商业蓝牙模块自定义传感器之间使用。我会使用SPP轮廓即所述提供一个简单可靠的数据流提供给用户,类似TCP。

I am planning a communication protocol to be used between an Android device and a custom sensor that would use a commercial Bluetooth module. I would use the SPP profile that is said to "provide a simple reliable data stream to the user, similar to TCP."

我不太熟悉的蓝牙技术,并有关于设计这样一个协议的一些问题。

I am not so familiar with the Bluetooth technology and have some questions about designing such a protocol.

首先,目前尚不清楚对我来说,如果我有担心损坏的数据传送与否。将底层protocoll栈保证我说的字节我从的InputStream Android的阅读给人都是一样的UART接收传感器上的一面呢?我一定要定义与CRC或东西保护自己的数据包,或会是矫枉过正?

First of all it is not clear to me if I have to worry corrupted data being transferred or not. Will the underlying protocoll stack guarantee me that the bytes I read from the InputStream Android gives are the same that the UART receives on the sensor side? Do I have to define my own data packages protected with CRC or stuff or would it be overkill?

这是我不清楚从Android蓝牙文件在我的应用程序会发生什么,如果信号弱,失去了一段时间。我会收到 IOException异常一次或平台提供我一些隐藏的错误处理和恢复,将我做出如此短的停机看不见?

It is not clear to me from the Android Bluetooth documentation what happens in my application if the signal is weak and is lost for a while. Do I get IOException at once or the platform provides me some hidden error handling and recovery that would make such short outages invisible to me?

感谢您的任何建议。

推荐答案

您不必担心数据损坏过SPP,蓝牙提供了2级的CRC,一个在基带,然后一个在L2CAP水平, 两者都具有重传机制,检测到任何损坏 - 因此,应用程序只能拿到不错的数据包

You need not worry about data corruption over SPP , Bluetooth provides 2 levels of CRC , one at the baseband and then one at the L2CAP level, Both have retransmission mechanism for any detected corruptions - thus applications will receive only good packets.

关于第二个问题 - 是的socket流是否已连接上,您将收到的IOExceptions如果底层的蓝牙连接断开连接,Android无法处理自动恢复 - 典型的应用需要检测的原因断开,并尝试重新连接如适用。 所以,如果你想继续从上次点你的数据交换成功接收/发送,然后为它的应用程序应该保持某种形式的序列号和轻型协议,实现了简历。 另一种选择是从数据交换的beaning后重新连接(因此它取决于你的用例)

About the second question - Yes on the Socket streams that you are connected on you will receive IOExceptions if the underlying Bluetooth connections get disconnected, Android cannot handle automatic restore - typically applications need to detect the reason for disconnection and try re-connect as applicable. So if you want to continue your data exchange from the point you last successfully received / sent then for it your application should maintain some sort of sequence number and light protocol to achieve a resume. The other option is to simply start from the beaning of data exchange upon a re-connect (So it depends on your usecase)

这篇关于蓝牙的Andr​​oid RFCOMM / SPP错误处理的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆