From b731771a83d4ef8cb6d2768f901a5d583e697dd9 Mon Sep 17 00:00:00 2001 From: peng <704047449@qq.com> Date: Tue, 15 Jul 2025 12:01:52 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=93=E5=86=B2=E5=8C=BA=E6=94=B9=E4=BD=8D5k?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ib86/feature/serial/SerialPort/ASR5515Protocol.java | 5 ++++- .../ib86/feature/serial/SerialPort/SerialPortHelper.java | 9 ++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/ismart/ib86/feature/serial/SerialPort/ASR5515Protocol.java b/app/src/main/java/com/ismart/ib86/feature/serial/SerialPort/ASR5515Protocol.java index 2ee02d4..29e4d0f 100644 --- a/app/src/main/java/com/ismart/ib86/feature/serial/SerialPort/ASR5515Protocol.java +++ b/app/src/main/java/com/ismart/ib86/feature/serial/SerialPort/ASR5515Protocol.java @@ -222,6 +222,7 @@ public class ASR5515Protocol { } if (startIndex == -1 || startIndex + 7 >= data.length) { + //LogManager.e(TAG, "startIndex:" + startIndex); return null; } @@ -240,11 +241,13 @@ public class ASR5515Protocol { // 检查是否有足够的数据 if (startIndex + totalFrameLength > data.length) { + //LogManager.e(TAG, "数据长度不够"+ " startIndex:" + startIndex + " totalFrameLength:" + totalFrameLength + " data len :" + data.length); return null; } // 检查帧结束符 if (data[startIndex + totalFrameLength - 1] != FRAME_END) { + //LogManager.e(TAG, "没有找到数据尾"); return null; } @@ -253,7 +256,7 @@ public class ASR5515Protocol { if (len > 0) { frameData = new byte[len]; System.arraycopy(data, startIndex + 7, frameData, 0, len); - //LogManager.d(TAG,"data: "+ bytesToHexString(frameData)); + LogManager.d(TAG,"5515->ASR DATA"+ bytesToHexString(data)); } else { frameData = new byte[0]; } diff --git a/app/src/main/java/com/ismart/ib86/feature/serial/SerialPort/SerialPortHelper.java b/app/src/main/java/com/ismart/ib86/feature/serial/SerialPort/SerialPortHelper.java index 13a258d..a1bd8dc 100644 --- a/app/src/main/java/com/ismart/ib86/feature/serial/SerialPort/SerialPortHelper.java +++ b/app/src/main/java/com/ismart/ib86/feature/serial/SerialPort/SerialPortHelper.java @@ -1,6 +1,7 @@ package com.ismart.ib86.feature.serial.SerialPort; import android.serialport.SerialPort; +import android.util.Log; import com.ismart.ib86.common.utils.LogManager; @@ -44,7 +45,7 @@ public class SerialPortHelper { private boolean isSimulationMode = false; private Boolean lastWearStatus = null; // 增加帧缓冲区大小,以处理大型心电图数据 - private final ByteBuffer frameBuffer = ByteBuffer.allocate(4096); // 4KB + private final ByteBuffer frameBuffer = ByteBuffer.allocate(5120); // 4KB public interface SendCallback { void onSendSuccess(byte[] data); @@ -497,7 +498,7 @@ public class SerialPortHelper { if (receiveThread == null) { receiveThread = new Thread(() -> { // 增加接收缓冲区大小,以处理大型心电图数据 - byte[] buffer = new byte[4096]; // 4KB + byte[] buffer = new byte[5120]; // 4KB while (isRunning) { if (mSerialPort != null) { try { @@ -505,7 +506,7 @@ public class SerialPortHelper { if (bytesRead > 0) { byte[] receivedData = Arrays.copyOf(buffer, bytesRead); //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); } } catch (IOException e) { @@ -617,6 +618,7 @@ public class SerialPortHelper { ASR5515Protocol.Frame frame = ASR5515Protocol.parseFrame(bufferArray); if (frame == null) { // 解析失败,可能是数据不完整,保留数据等待下次处理 + LogManager.d(TAG, "数据不完整,保留等待下次"); frameBuffer.put(bufferArray); break; } @@ -626,6 +628,7 @@ public class SerialPortHelper { // 如果还有剩余数据,放回缓冲区 if (frame.remainingData != null && frame.remainingData.length > 0) { + LogManager.e(TAG, "发现剩余数据"); frameBuffer.put(frame.remainingData); } }