mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-21 19:45:09 +08:00
update 电单车协议
This commit is contained in:
@@ -101,4 +101,43 @@ public abstract class AbsEBikeMessage {
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String s = "44 4e 59 00 0d 3b 37 ab 04 b9 00 22 ee 32 cc 66 04 14".replace(" ", "");
|
||||
byte[] messageBytes = BytesUtil.hexStringToByteArray(s);
|
||||
// 读取包头
|
||||
byte[] headerBytes = Arrays.copyOfRange(messageBytes, 0, 3);
|
||||
String header = new String(headerBytes, StandardCharsets.UTF_8);
|
||||
System.out.println("header: " + header);
|
||||
|
||||
// 读取长度
|
||||
byte[] lengthBytes = Arrays.copyOfRange(messageBytes, 3, 5);
|
||||
int length = BytesUtil.bytesToIntLittle(lengthBytes);
|
||||
System.out.println("length: " + length);
|
||||
|
||||
// 读取物理ID
|
||||
byte[] physicalIdBytes = Arrays.copyOfRange(messageBytes, 5, 9);
|
||||
int physicalId = BytesUtil.bytesToIntLittle(physicalIdBytes);
|
||||
System.out.println("physicalId: " + physicalId);
|
||||
|
||||
// 读取消息ID
|
||||
byte[] messageIdBytes = Arrays.copyOfRange(messageBytes, 9, 11);
|
||||
int messageId = BytesUtil.bytesToIntLittle(messageIdBytes);
|
||||
System.out.println("messageId: " + messageId);
|
||||
|
||||
// 读取命令
|
||||
byte commandByte = messageBytes[11];
|
||||
String command = BytesUtil.bcd2StrLittle(new byte[]{commandByte});
|
||||
System.out.println("command: " + command);
|
||||
|
||||
// 读取数据
|
||||
byte[] dataBytes = Arrays.copyOfRange(messageBytes, 12, messageBytes.length - 2);
|
||||
String data = BytesUtil.bytesToIntLittle(dataBytes) + "";
|
||||
System.out.println("data: " + data);
|
||||
|
||||
// 读取校验
|
||||
byte[] checksumBytes = Arrays.copyOfRange(messageBytes, messageBytes.length - 2, messageBytes.length);
|
||||
int checksum = BytesUtil.bytesToIntLittle(checksumBytes);
|
||||
System.out.println("checksum: " + checksum);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ public class EBikeMessageCmd21 extends AbsEBikeMessage {
|
||||
public static class DeviceHeartbeat {
|
||||
/**
|
||||
* 电压:设备的当前电压(打包发送心跳包指令时的当前时间点的实时电压)
|
||||
* 2024年8月26日15点02分 已经转为标准单位V
|
||||
*/
|
||||
private String voltage;
|
||||
|
||||
@@ -68,10 +69,10 @@ public class EBikeMessageCmd21 extends AbsEBikeMessage {
|
||||
|
||||
|
||||
public DeviceHeartbeat(byte[] dataBytes) {
|
||||
this.voltage = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, 0, 2)) + "";
|
||||
this.voltage = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, 0, 2)) * 0.1 + "";
|
||||
this.portNumber = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, 2, 3));
|
||||
|
||||
byte[] statusBytes = Arrays.copyOfRange(dataBytes, 3, this.portNumber);
|
||||
byte[] statusBytes = BytesUtil.copyBytes(dataBytes, 3, this.portNumber);
|
||||
List<String> statusList = Lists.newArrayList();
|
||||
for (byte statusByte : statusBytes) {
|
||||
int status = BytesUtil.bytesToIntLittle(new byte[]{statusByte});
|
||||
|
||||
Reference in New Issue
Block a user