update 电单车

This commit is contained in:
Guoqs
2024-09-13 15:09:41 +08:00
parent 5cdc814496
commit f8d83b0f2c
2 changed files with 16 additions and 41 deletions

View File

@@ -1,5 +1,6 @@
package com.jsowell.pile.domain.ebike;
import com.alibaba.fastjson2.JSON;
import com.jsowell.common.YouDianUtils;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.pile.domain.ebike.deviceupload.*;
@@ -102,44 +103,12 @@ public class AbsEBikeMessage {
};
public static void main(String[] args) {
String s = "444e593200198bca077c000601010a0000000100000000000000001327388102240913141915803959463300000000750800005e00fe06";
String s = "444e593200198bca0782000600018e030700015a0b6b0b190b480b1327388101240913141035606593918397006e0b73083f055f002d0b";
String msg82 = "44 4E 59 26 00 3B 37 AB 04 02 00 82 00 64 01 00 00 01 01 00 00 12 34 56 78 12 34 56 78 12 34 56 78 12 34 56 78 80 70 88 13 F8 08";
s = s.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);
AbsEBikeMessage absEBikeMessage = parseMessage(messageBytes);
System.out.println(JSON.toJSONString(absEBikeMessage));
}

View File

@@ -6,7 +6,7 @@ import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
import lombok.Getter;
import lombok.Setter;
import java.util.Arrays;
import java.math.BigDecimal;
/**
* 端口充电时功率心跳包06指令
@@ -95,7 +95,7 @@ public class EBikeMessageCmd06 extends AbsEBikeMessage {
/**
* 该时间段内消耗电量此数据需除以4800后才是真实的电量该字段属于调试使用服务器无需关心此字段
*/
// private String timePeriodElectricity;
private String timePeriodElectricity;
/**
* 峰值功率:整个充电过程中出现过的最大功率,有些版本无此字段
@@ -136,8 +136,8 @@ public class EBikeMessageCmd06 extends AbsEBikeMessage {
public PowerHeartbeat(byte[] dataBytes) {
int startIndex = 0;
int length = 1;
int i = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length));
this.port = i + YouDianUtils.convertPortNumberToString(i);
int i = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(dataBytes, startIndex, length));
this.port = YouDianUtils.convertPortNumberToString(i);
startIndex += length;
length = 1;
@@ -176,17 +176,23 @@ public class EBikeMessageCmd06 extends AbsEBikeMessage {
length = 16;
this.orderCode = BytesUtil.bcd2Str(BytesUtil.copyBytes(dataBytes, startIndex, length));
startIndex += length;
length = 2;
this.timePeriodElectricity = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(dataBytes, startIndex, length)) + "";
startIndex += length;
length = 2;
this.peakPower = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(dataBytes, startIndex, length)) + "";
startIndex += length;
length = 2;
this.voltage = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(dataBytes, startIndex, length)) * 0.1 + "";
this.voltage = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(dataBytes, startIndex, length)))
.multiply(new BigDecimal("0.1")).toString();
startIndex += length;
length = 2;
this.current = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(dataBytes, startIndex, length)) * 0.0001 + "";
this.current = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(dataBytes, startIndex, length)))
.multiply(new BigDecimal("0.001")).toString();
startIndex += length;
length = 1;