diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/domain/ebike/AbsEBikeMessage2.java b/jsowell-pile/src/main/java/com/jsowell/pile/domain/ebike/AbsEBikeMessage2.java index d8289c0cb..220528e2a 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/domain/ebike/AbsEBikeMessage2.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/domain/ebike/AbsEBikeMessage2.java @@ -12,16 +12,17 @@ import java.util.Arrays; @NoArgsConstructor @AllArgsConstructor @Builder +@ToString public class AbsEBikeMessage2 { protected String header; // 包头 (3字节) protected int msgLength; // 长度 (2字节) protected int physicalId; // 物理ID (4字节) protected int messageId; // 消息ID (2字节) protected String command; // 命令 (1字节) - protected Object payload; // 数据 (n字节) + // protected Object payload; // 数据 (n字节) protected int checksum; // 校验 (2字节) - protected void parseMessage(byte[] messageBytes) { + public AbsEBikeMessage2(byte[] messageBytes) { if (messageBytes == null || messageBytes.length < 14 || messageBytes.length > 256) { throw new IllegalArgumentException("Invalid message bytes"); } @@ -67,6 +68,5 @@ public class AbsEBikeMessage2 { // 读取校验 byte[] checksumBytes = Arrays.copyOfRange(messageBytes, messageBytes.length - 2, messageBytes.length); this.checksum = BytesUtil.bytesToIntLittle(checksumBytes); - } } diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/domain/ebike/deviceupload/ChargingOperationResponse.java b/jsowell-pile/src/main/java/com/jsowell/pile/domain/ebike/deviceupload/ChargingOperationResponse.java index fb4ffefdc..a41ccb4ad 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/domain/ebike/deviceupload/ChargingOperationResponse.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/domain/ebike/deviceupload/ChargingOperationResponse.java @@ -1,15 +1,18 @@ package com.jsowell.pile.domain.ebike.deviceupload; -import com.alibaba.fastjson2.JSON; import com.jsowell.common.YouDianUtils; import com.jsowell.common.util.BytesUtil; import com.jsowell.pile.domain.ebike.AbsEBikeMessage2; -import lombok.Data; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; /** * 启动充电回复 */ -@Data +@Getter +@Setter +@ToString(callSuper = true) public class ChargingOperationResponse extends AbsEBikeMessage2 { /** * 应答:执行开始充电命令,=0执行成功(启动或停止充电), @@ -39,7 +42,10 @@ public class ChargingOperationResponse extends AbsEBikeMessage2 { private String waitPortNumber; public ChargingOperationResponse(byte[] dataBytes) { - int startIndex = 0; + super(dataBytes); + + // 读取结果 + int startIndex = 12; int length = 1; this.result = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(dataBytes, startIndex, length)); @@ -56,20 +62,11 @@ public class ChargingOperationResponse extends AbsEBikeMessage2 { // this.waitPortNumber = YouDianUtils.convertPortNumberToString(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(dataBytes, startIndex, length))); } - @Override - protected void parseMessage(byte[] messageBytes) { - super.parseMessage(messageBytes); - // 截取数据 - byte[] bytes = BytesUtil.copyBytes(messageBytes, 12, this.msgLength); - ChargingOperationResponse response = new ChargingOperationResponse(bytes); - System.out.println(JSON.toJSONString(response)); - } public static void main(String[] args) { String s = "444e591d00198bca07da0c8200132738810124091416463569289954500000007907"; byte[] messageBytes = BytesUtil.hexStringToByteArray(s); ChargingOperationResponse response = new ChargingOperationResponse(messageBytes); - response.parseMessage(messageBytes); - // System.out.println(response); + System.out.println(response); } }