bur*_*rsk 13 android bluetooth
我使用蓝牙聊天示例作为实现从手机到嵌入式设备的BT连接的起点.我能够成功连接到设备但是一旦建立连接,logcat就会因大量的日志记录而被覆盖.我第一次做BT聊天应用手机打电话时没有看到这种类型的日志记录.
这是一遍又一遍的重复.它基本上使logcat无法使用.到目前为止,我还没有找到一种方法来配置日志记录或为什么它记录这么多.任何见解将不胜感激.
03-08 14:29:04.941: DEBUG/BluetoothSocket.cpp(11422): availableNative
03-08 14:29:04.957: DEBUG/BluetoothSocket(11422): available
03-08 14:29:04.957: DEBUG/BluetoothSocket.cpp(11422): availableNative
03-08 14:29:04.971: DEBUG/BluetoothSocket(11422): available
03-08 14:29:04.976: DEBUG/BluetoothSocket.cpp(11422): availableNative
03-08 14:29:04.989: DEBUG/BluetoothSocket(11422): available
03-08 14:29:04.991: DEBUG/BluetoothSocket.cpp(11422): availableNative
03-08 14:29:05.016: DEBUG/BluetoothSocket(11422): available
03-08 14:29:05.016: DEBUG/BluetoothSocket.cpp(11422): availableNative
03-08 14:29:05.034: DEBUG/BluetoothSocket(11422): available
03-08 14:29:05.036: DEBUG/BluetoothSocket.cpp(11422): availableNative
03-08 14:29:05.050: DEBUG/BluetoothSocket(11422): available
03-08 14:29:05.051: DEBUG/BluetoothSocket.cpp(11422): availableNative
03-08 14:29:05.066: DEBUG/BluetoothSocket(11422): available
03-08 14:29:05.066: DEBUG/BluetoothSocket.cpp(11422): availableNative
03-08 14:29:05.081: DEBUG/BluetoothSocket(11422): available
03-08 14:29:05.081: DEBUG/BluetoothSocket.cpp(11422): availableNative
03-08 14:29:05.086: DEBUG/(2419): jw_if_rfcomm_cl_cback: jw_if_rfcomm_cl_cback event=BTA_JV_RFCOMM_READ_EVT
03-08 14:29:05.086: DEBUG/(2419): jv_forward_data_to_jni: BTA_JV_RFCOMM_DATA_IND_EVT bta hdl 2
03-08 14:29:05.086: DEBUG/(2419): bts_log_tstamps_us: [update stats] ts 1263504, bta hdl 2, diff 01263504, tx_q 1 (1), rx_q 0 (0)
03-08 14:29:05.086: DEBUG/BLZ20_WRAPPER(11422): blz20_wrp_poll: transp poll : (fd 41) returned r_ev [POLLIN ] (0x1)
03-08 14:29:05.086: DEBUG/BLZ20_WRAPPER(11422): blz20_wrp_poll: return 1
03-08 14:29:05.086: DEBUG/BLZ20_WRAPPER(11422): blz20_wrp_read: read 122 bytes out of 1024 on fd 41
03-08 14:29:05.101: DEBUG/BluetoothSocket(11422): read
03-08 14:29:05.101: DEBUG/BluetoothSocket.cpp(11422): readNative
03-08 14:29:05.101: DEBUG/ASOCKWRP(11422): asocket_read
03-08 14:29:05.106: INFO/BLZ20_WRAPPER(11422): blz20_wrp_poll: nfds 2, timeout -1 ms
03-08 14:29:05.117: DEBUG/BluetoothSocket(11422): available
03-08 14:29:05.121: DEBUG/BluetoothSocket.cpp(11422): availableNative
Run Code Online (Sandbox Code Playgroud)
在使用我的 Arduino 板 + 蓝牙适配器后,我尝试实现MATT BELL'S BLOG中的蓝牙代码。问题是以下代码:
//final Handler handler = new Handler();
workerThread = new Thread(new Runnable()
{
public void run()
{
while(!Thread.currentThread().isInterrupted() && !stopWorker)
{
try {
int bytesAvailable = mmInputStream.available();
if(bytesAvailable > 0)
{
//Log.d(TAG,"bytesAvailable: "+bytesAvailable + " readBufferPosition: "+readBufferPosition);
byte[] packetBytes = new byte[bytesAvailable];
mmInputStream.read(packetBytes);
for(int i=0;i<bytesAvailable;i++)
{
byte delimiter = 0x0A; // /n bzw. LF
byte b = packetBytes[i];
if(b == delimiter)
{
byte[] encodedBytes = new byte[readBufferPosition];
System.arraycopy(readBuffer, 0, encodedBytes, 0, encodedBytes.length);
final String data = new String(encodedBytes, "US-ASCII");
//final String data = new String(readBuffer);
readBufferPosition = 0;
Log.d(TAG,""+data);
// //The variable data now contains our full command
// handler.post(new Runnable()
// {
// public void run()
// {
// //myLabel.setText(data);
// Log.d(TAG,""+data);
// }
// });
}
else
{
readBuffer[readBufferPosition++] = b;
}
}
}
} catch (Exception e) {
Log.d(TAG,"Exeption 2: "+e.getMessage());
stopWorker = true;
}
}
}
});
workerThread.start();
Run Code Online (Sandbox Code Playgroud)
调用以下函数会导致logCat 中出现大量Spam
int bytesAvailable = mmInputStream.available();
Run Code Online (Sandbox Code Playgroud)
日志猫:
PS:时间戳实际上是固定版本的。不使用修复程序将导致每5 毫秒发送一次垃圾邮件,从而有效地阻止我的整个日志
03-17 18:43:06.615: VERBOSE/BluetoothSocket.cpp(8871): availableNative
03-17 18:43:06.715: VERBOSE/BluetoothSocket.cpp(8871): availableNative
03-17 18:43:06.820: VERBOSE/BluetoothSocket.cpp(8871): availableNative
03-17 18:43:06.920: VERBOSE/BluetoothSocket.cpp(8871): availableNative
03-17 18:43:07.020: VERBOSE/BluetoothSocket.cpp(8871): availableNative
03-17 18:43:07.120: VERBOSE/BluetoothSocket.cpp(8871): availableNative
03-17 18:43:07.220: VERBOSE/BluetoothSocket.cpp(8871): availableNative
03-17 18:43:07.320: VERBOSE/BluetoothSocket.cpp(8871): availableNative
03-17 18:43:07.420: VERBOSE/BluetoothSocket.cpp(8871): availableNative
03-17 18:43:07.520: VERBOSE/BluetoothSocket.cpp(8871): availableNative
03-17 18:43:07.620: VERBOSE/BluetoothSocket.cpp(8871): availableNative
03-17 18:43:07.725: VERBOSE/BluetoothSocket.cpp(8871): availableNative
03-17 18:43:07.825: VERBOSE/BluetoothSocket.cpp(8871): availableNative
03-17 18:43:07.925: VERBOSE/BluetoothSocket.cpp(8871): availableNative
03-17 18:43:08.025: VERBOSE/BluetoothSocket.cpp(8871): availableNative
Run Code Online (Sandbox Code Playgroud)
我当前的修复方法是在while循环末尾添加以下代码,从而减少垃圾邮件。
try {
Thread.sleep(100);
} catch (Exception e) {
Log.d(TAG,"Exception Thread.sleep()");
}
Run Code Online (Sandbox Code Playgroud)
我希望这能帮助一些有类似问题的人。
编辑:目前我不得不将睡眠计时器减少到 10 毫秒 bam .. SPAM
03-18 15:50:18.470: VERBOSE/BluetoothSocket.cpp(3482): availableNative
03-18 15:50:18.470: VERBOSE/BluetoothSocket.cpp(3482): availableNative
03-18 15:50:18.470: VERBOSE/BluetoothSocket.cpp(3482): availableNative
03-18 15:50:18.470: VERBOSE/BluetoothSocket.cpp(3482): availableNative
03-18 15:50:18.470: VERBOSE/BluetoothSocket.cpp(3482): availableNative
03-18 15:50:18.470: VERBOSE/BluetoothSocket.cpp(3482): availableNative
03-18 15:50:18.470: VERBOSE/BluetoothSocket.cpp(3482): availableNative
03-18 15:50:18.470: VERBOSE/BluetoothSocket.cpp(3482): availableNative
03-18 15:50:18.470: VERBOSE/BluetoothSocket.cpp(3482): availableNative
03-18 15:50:18.470: VERBOSE/BluetoothSocket.cpp(3482): availableNative
Run Code Online (Sandbox Code Playgroud)
Rob*_*ond -1
在 DDMS 中,您可以使用调试、信息、错误、警告按钮来过滤掉内容,您还可以创建一个特殊的过滤器来仅显示您感兴趣的内容。不要认为有任何蓝牙设置可以关闭该日志记录你可以使用。
归档时间: |
|
查看次数: |
5848 次 |
最近记录: |