mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-06-13 11:49:49 +08:00
update 电单车协议
This commit is contained in:
@@ -7,6 +7,7 @@ import lombok.Data;
|
|||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -26,21 +27,34 @@ public class ChargingPileMessage {
|
|||||||
// 从字节数组解析消息
|
// 从字节数组解析消息
|
||||||
public static ChargingPileMessage parseMessage(byte[] messageBytes) {
|
public static ChargingPileMessage parseMessage(byte[] messageBytes) {
|
||||||
log.info("parseMessage:{}", BytesUtil.binary(messageBytes, 16));
|
log.info("parseMessage:{}", BytesUtil.binary(messageBytes, 16));
|
||||||
String header = new String(Arrays.copyOfRange(messageBytes, 0, 3));
|
// 读取包头
|
||||||
|
byte[] headerBytes = Arrays.copyOfRange(messageBytes, 0, 3);
|
||||||
|
System.out.println(new String(headerBytes, StandardCharsets.UTF_8));
|
||||||
|
|
||||||
int length = ((messageBytes[3] & 0xFF) << 8) | (messageBytes[4] & 0xFF);
|
// 读取长度
|
||||||
|
byte[] lengthBytes = {messageBytes[3], messageBytes[4]};
|
||||||
|
System.out.println(BytesUtil.bcd2StrLittle(lengthBytes));
|
||||||
|
|
||||||
int physicalId = ((messageBytes[5] & 0xFF) << 24) | ((messageBytes[6] & 0xFF) << 16) |
|
// 读取物理ID
|
||||||
((messageBytes[7] & 0xFF) << 8) | (messageBytes[8] & 0xFF);
|
byte[] physicalIdBytes = Arrays.copyOfRange(messageBytes, 5, 9);
|
||||||
|
System.out.println(BytesUtil.bcd2StrLittle(physicalIdBytes));
|
||||||
|
|
||||||
int messageId = ((messageBytes[9] & 0xFF) << 8) | (messageBytes[10] & 0xFF);
|
// 读取消息ID
|
||||||
|
byte[] messageIdBytes = {messageBytes[9], messageBytes[10]};
|
||||||
|
System.out.println(BytesUtil.bcd2StrLittle(messageIdBytes));
|
||||||
|
|
||||||
|
// 读取命令
|
||||||
byte command = messageBytes[11];
|
byte command = messageBytes[11];
|
||||||
|
System.out.println(BytesUtil.bcd2StrLittle(new byte[] {command}));
|
||||||
|
|
||||||
|
// 读取数据
|
||||||
byte[] data = Arrays.copyOfRange(messageBytes, 12, messageBytes.length - 2);
|
byte[] data = Arrays.copyOfRange(messageBytes, 12, messageBytes.length - 2);
|
||||||
|
System.out.println(BytesUtil.bcd2StrLittle(data));
|
||||||
|
|
||||||
int checksum = ((messageBytes[messageBytes.length - 2] & 0xFF) << 8) | (messageBytes[messageBytes.length - 1] & 0xFF);
|
// 读取校验
|
||||||
|
byte[] checksumBytes = {messageBytes[messageBytes.length - 2], messageBytes[messageBytes.length - 1]};
|
||||||
|
System.out.println(BytesUtil.bcd2StrLittle(checksumBytes));
|
||||||
|
|
||||||
return new ChargingPileMessage(header, length, physicalId, messageId, command, data, checksum);
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user