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