From eab20dc122f41f7694ae96c2c020ec22b4e16ce4 Mon Sep 17 00:00:00 2001 From: xinfengkun Date: Wed, 13 Apr 2022 18:06:23 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=E5=8A=A0=E5=85=A5=E5=8E=9F=E5=A7=8B?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=A7=A3=E6=9E=90=E9=95=BF=E5=BA=A6=E5=88=A4?= =?UTF-8?q?=E6=96=AD=EF=BC=8C=E5=A2=9E=E5=BC=BA=E7=A8=8B=E5=BA=8F=E5=81=A5?= =?UTF-8?q?=E5=A3=AE=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../support/adas/high/protocol/RawUnpack.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/protocol/RawUnpack.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/protocol/RawUnpack.java index 70efe6ff9f..3f375ef424 100644 --- a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/protocol/RawUnpack.java +++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/protocol/RawUnpack.java @@ -35,17 +35,25 @@ public class RawUnpack { private synchronized void unpack(ByteString bytes, RawData raw) { // CupidLogUtils.w(TAG, "WS 原始数据=" + bytes.hex()); //读取magicCode - ByteString magicCode = bytes.substring(0, messageProtocol.getMagicCodeLength()); - raw.setMagicCode(magicCode.toByteArray()); + ByteString magicCode; + int magicCodeLength = messageProtocol.getMagicCodeLength(); + if (bytes.size() < magicCodeLength) { + magicCode = bytes; + } else { + magicCode = bytes.substring(0, magicCodeLength); + raw.setMagicCode(magicCode.toByteArray()); + } // CupidLogUtils.w(TAG, "WS MagicCode=" + magicCode.hex()); if (Arrays.equals(magicCode.toByteArray(), Constants.RAW_MG)) { + int offsetLength = messageProtocol.getOffsetLength(); + int outHeader = messageProtocol.getOutHeader(); //读取offset - ByteString offset = bytes.substring(messageProtocol.getMagicCodeLength(), messageProtocol.getMagicCodeLength() + messageProtocol.getOffsetLength()); + ByteString offset = bytes.substring(magicCodeLength, magicCodeLength + offsetLength); byte[] offsetB = offset.toByteArray(); raw.setOffset(offsetB, getOffsetValue(offsetB)); // CupidLogUtils.w(TAG, "WS 偏移量 bytes=" + offset.hex() + " 偏移量=" + raw.getOffsetValue()); //读取packageLength - ByteString packageLength = bytes.substring(messageProtocol.getMagicCodeLength() + messageProtocol.getOffsetLength(), messageProtocol.getOutHeader()); + ByteString packageLength = bytes.substring(magicCodeLength + offsetLength, outHeader); byte[] packageLengthB = packageLength.toByteArray(); raw.setPackageLength(packageLengthB, getPackageLengthValue(packageLengthB)); if (bytes.size() != raw.getPackageLengthValue()) { @@ -55,7 +63,7 @@ public class RawUnpack { } // CupidLogUtils.w(TAG, "WS 数据包从长度 bytes=" + packageLength.hex() + " 数据包从长度=" + raw.getPackageLengthValue()); //读取header - ByteString header = bytes.substring(messageProtocol.getOutHeader(), raw.getOffsetValue()); + ByteString header = bytes.substring(outHeader, raw.getOffsetValue()); raw.setHeader(header.toByteArray()); // CupidLogUtils.w(TAG, "WS Header=" + header.hex()); //读取payload