gpt4 book ai didi

Android 蓝牙日志记录填满 logcat

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:26:15 25 4
gpt4 key购买 nike

我以蓝牙聊天示例为起点,实现了从我的手机到嵌入式设备的 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

最佳答案

玩完我的 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();

调用以下函数会在 logCat 中产生大量垃圾邮件

int bytesAvailable = mmInputStream.available();

LogCat:

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

我目前的解决方法是在 while 循环的末尾添加以下代码,从而减少垃圾邮件。

try {
Thread.sleep(100);
} catch (Exception e) {
Log.d(TAG,"Exception Thread.sleep()");
}

我希望这能帮助一些有类似问题的人。

编辑:目前我不得不将 sleep 定时器减少到 10ms 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

关于Android 蓝牙日志记录填满 logcat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5237513/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com