mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-05-17 00:08:35 +08:00
update 电单车协议
This commit is contained in:
@@ -2,6 +2,7 @@ package com.jsowell.common.util;
|
|||||||
|
|
||||||
import com.google.common.primitives.Bytes;
|
import com.google.common.primitives.Bytes;
|
||||||
import com.jsowell.common.constant.Constants;
|
import com.jsowell.common.constant.Constants;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import javax.xml.bind.DatatypeConverter;
|
import javax.xml.bind.DatatypeConverter;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
@@ -11,6 +12,7 @@ import java.time.LocalDateTime;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
public class BytesUtil {
|
public class BytesUtil {
|
||||||
|
|
||||||
static final long fx = 0xffl;
|
static final long fx = 0xffl;
|
||||||
@@ -234,6 +236,35 @@ public class BytesUtil {
|
|||||||
return new String(temp);
|
return new String(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将byte数组转换为物理ID
|
||||||
|
* @param bytes 输入的byte数组
|
||||||
|
* @return 物理ID对象,包含设备识别码和二维码下方的编号
|
||||||
|
*/
|
||||||
|
public static int convertToPhysicalId(byte[] bytes) {
|
||||||
|
// 检查输入是否合法
|
||||||
|
if (bytes == null || bytes.length != 4) {
|
||||||
|
throw new IllegalArgumentException("Input byte array must be of length 4.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 小端模式转大端模式
|
||||||
|
byte[] bigEndianBytes = new byte[4];
|
||||||
|
bigEndianBytes[0] = bytes[3];
|
||||||
|
bigEndianBytes[1] = bytes[2];
|
||||||
|
bigEndianBytes[2] = bytes[1];
|
||||||
|
bigEndianBytes[3] = bytes[0];
|
||||||
|
|
||||||
|
// 提取设备识别码
|
||||||
|
byte deviceId = bigEndianBytes[0];
|
||||||
|
|
||||||
|
// 剩余的三个字节转换为十进制
|
||||||
|
int deviceNumber = ((bigEndianBytes[1] & 0xFF) << 16) |
|
||||||
|
((bigEndianBytes[2] & 0xFF) << 8) |
|
||||||
|
(bigEndianBytes[3] & 0xFF);
|
||||||
|
log.info("设备识别码:{}, 桩编号:{}", deviceId, deviceNumber);
|
||||||
|
return deviceNumber;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @函数功能: BCD码转为10进制串(阿拉伯数据) 小端模式
|
* @函数功能: BCD码转为10进制串(阿拉伯数据) 小端模式
|
||||||
* @输入参数: BCD码
|
* @输入参数: BCD码
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ public abstract class AbsEBikeMessage {
|
|||||||
|
|
||||||
// 读取物理ID
|
// 读取物理ID
|
||||||
byte[] physicalIdBytes = Arrays.copyOfRange(messageBytes, 5, 9);
|
byte[] physicalIdBytes = Arrays.copyOfRange(messageBytes, 5, 9);
|
||||||
int physicalId = BytesUtil.bytesToIntLittle(physicalIdBytes);
|
int physicalId = BytesUtil.convertToPhysicalId(physicalIdBytes);
|
||||||
|
|
||||||
// 读取消息ID
|
// 读取消息ID
|
||||||
byte[] messageIdBytes = Arrays.copyOfRange(messageBytes, 9, 11);
|
byte[] messageIdBytes = Arrays.copyOfRange(messageBytes, 9, 11);
|
||||||
|
|||||||
@@ -84,8 +84,13 @@ public class EBikeMessageCmd21 extends AbsEBikeMessage {
|
|||||||
statusList.add(PortStatusEnum.getDescriptionByValue(status));
|
statusList.add(PortStatusEnum.getDescriptionByValue(status));
|
||||||
}
|
}
|
||||||
this.portStatus = statusList;
|
this.portStatus = statusList;
|
||||||
this.rssi = BytesUtil.bcd2StrLittle(Arrays.copyOfRange(dataBytes, dataBytes.length - 2, dataBytes.length - 1));
|
this.rssi = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, dataBytes.length - 2, dataBytes.length - 1)) + "";
|
||||||
this.temperature = BytesUtil.bcd2StrLittle(Arrays.copyOfRange(dataBytes, dataBytes.length - 1, dataBytes.length));
|
//
|
||||||
|
int i = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, dataBytes.length - 1, dataBytes.length));
|
||||||
|
if (i > 65) {
|
||||||
|
i = i - 65;
|
||||||
|
}
|
||||||
|
this.temperature = i + "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user