缓冲区改位5k

This commit is contained in:
peng 2025-07-15 12:01:52 +08:00
parent ab3f86d9d9
commit b731771a83
2 changed files with 10 additions and 4 deletions

View File

@ -222,6 +222,7 @@ public class ASR5515Protocol {
} }
if (startIndex == -1 || startIndex + 7 >= data.length) { if (startIndex == -1 || startIndex + 7 >= data.length) {
//LogManager.e(TAG, "startIndex" + startIndex);
return null; return null;
} }
@ -240,11 +241,13 @@ public class ASR5515Protocol {
// 检查是否有足够的数据 // 检查是否有足够的数据
if (startIndex + totalFrameLength > data.length) { if (startIndex + totalFrameLength > data.length) {
//LogManager.e(TAG, "数据长度不够"+ " startIndex:" + startIndex + " totalFrameLength:" + totalFrameLength + " data len :" + data.length);
return null; return null;
} }
// 检查帧结束符 // 检查帧结束符
if (data[startIndex + totalFrameLength - 1] != FRAME_END) { if (data[startIndex + totalFrameLength - 1] != FRAME_END) {
//LogManager.e(TAG, "没有找到数据尾");
return null; return null;
} }
@ -253,7 +256,7 @@ public class ASR5515Protocol {
if (len > 0) { if (len > 0) {
frameData = new byte[len]; frameData = new byte[len];
System.arraycopy(data, startIndex + 7, frameData, 0, len); System.arraycopy(data, startIndex + 7, frameData, 0, len);
//LogManager.d(TAG,"data: "+ bytesToHexString(frameData)); LogManager.d(TAG,"5515->ASR DATA"+ bytesToHexString(data));
} else { } else {
frameData = new byte[0]; frameData = new byte[0];
} }

View File

@ -1,6 +1,7 @@
package com.ismart.ib86.feature.serial.SerialPort; package com.ismart.ib86.feature.serial.SerialPort;
import android.serialport.SerialPort; import android.serialport.SerialPort;
import android.util.Log;
import com.ismart.ib86.common.utils.LogManager; import com.ismart.ib86.common.utils.LogManager;
@ -44,7 +45,7 @@ public class SerialPortHelper {
private boolean isSimulationMode = false; private boolean isSimulationMode = false;
private Boolean lastWearStatus = null; private Boolean lastWearStatus = null;
// 增加帧缓冲区大小以处理大型心电图数据 // 增加帧缓冲区大小以处理大型心电图数据
private final ByteBuffer frameBuffer = ByteBuffer.allocate(4096); // 4KB private final ByteBuffer frameBuffer = ByteBuffer.allocate(5120); // 4KB
public interface SendCallback { public interface SendCallback {
void onSendSuccess(byte[] data); void onSendSuccess(byte[] data);
@ -497,7 +498,7 @@ public class SerialPortHelper {
if (receiveThread == null) { if (receiveThread == null) {
receiveThread = new Thread(() -> { receiveThread = new Thread(() -> {
// 增加接收缓冲区大小以处理大型心电图数据 // 增加接收缓冲区大小以处理大型心电图数据
byte[] buffer = new byte[4096]; // 4KB byte[] buffer = new byte[5120]; // 4KB
while (isRunning) { while (isRunning) {
if (mSerialPort != null) { if (mSerialPort != null) {
try { try {
@ -505,7 +506,7 @@ public class SerialPortHelper {
if (bytesRead > 0) { if (bytesRead > 0) {
byte[] receivedData = Arrays.copyOf(buffer, bytesRead); byte[] receivedData = Arrays.copyOf(buffer, bytesRead);
//LogManager.d(TAG, "5515->ASR DATA: " + Arrays.toString(receivedData)); //LogManager.d(TAG, "5515->ASR DATA: " + Arrays.toString(receivedData));
LogManager.d(TAG, "5515->ASR DATA: " + bytesToHexString(receivedData)); //LogManager.d(TAG, "5515->ASR DATA[" + bytesRead + "]" + bytesToHexString(receivedData));
receiveQueue.put(receivedData); receiveQueue.put(receivedData);
} }
} catch (IOException e) { } catch (IOException e) {
@ -617,6 +618,7 @@ public class SerialPortHelper {
ASR5515Protocol.Frame frame = ASR5515Protocol.parseFrame(bufferArray); ASR5515Protocol.Frame frame = ASR5515Protocol.parseFrame(bufferArray);
if (frame == null) { if (frame == null) {
// 解析失败可能是数据不完整保留数据等待下次处理 // 解析失败可能是数据不完整保留数据等待下次处理
LogManager.d(TAG, "数据不完整,保留等待下次");
frameBuffer.put(bufferArray); frameBuffer.put(bufferArray);
break; break;
} }
@ -626,6 +628,7 @@ public class SerialPortHelper {
// 如果还有剩余数据放回缓冲区 // 如果还有剩余数据放回缓冲区
if (frame.remainingData != null && frame.remainingData.length > 0) { if (frame.remainingData != null && frame.remainingData.length > 0) {
LogManager.e(TAG, "发现剩余数据");
frameBuffer.put(frame.remainingData); frameBuffer.put(frame.remainingData);
} }
} }