mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-05-05 02:20:12 +08:00
update 电单车协议
This commit is contained in:
@@ -38,21 +38,17 @@ public abstract class AbstractEBikeHandler implements InitializingBean {
|
|||||||
protected byte[] getResult(EBikeDataProtocol dataProtocol, byte[] messageBody) {
|
protected byte[] getResult(EBikeDataProtocol dataProtocol, byte[] messageBody) {
|
||||||
// 起始标志
|
// 起始标志
|
||||||
byte[] head = dataProtocol.getHead();
|
byte[] head = dataProtocol.getHead();
|
||||||
|
|
||||||
// 长度 = 物理ID(4) + 消息ID(2) + 命令(1) + 数据(n) + 校验(2),每包最多256字节
|
// 长度 = 物理ID(4) + 消息ID(2) + 命令(1) + 数据(n) + 校验(2),每包最多256字节
|
||||||
byte[] length = BytesUtil.intToBytesLittle(9 + messageBody.length);
|
byte[] length = BytesUtil.intToBytesLittle(9 + messageBody.length);
|
||||||
|
|
||||||
// 物理id
|
// 物理id
|
||||||
byte[] physicalId = dataProtocol.getPhysicalId();
|
byte[] physicalId = dataProtocol.getPhysicalId();
|
||||||
// 加密标志
|
// 加密标志
|
||||||
byte[] messageId = dataProtocol.getMessageId();
|
byte[] messageId = dataProtocol.getMessageId();
|
||||||
// 请求帧类型
|
// 请求帧类型
|
||||||
byte[] command = dataProtocol.getCommand();
|
byte[] command = dataProtocol.getCommand();
|
||||||
|
|
||||||
// 整个数据包中的每个字节(不包括校验字段本身)
|
// 整个数据包中的每个字节(不包括校验字段本身)
|
||||||
byte[] dataFields = Bytes.concat(head, length, physicalId, messageId, command, messageBody);
|
byte[] dataFields = Bytes.concat(head, length, physicalId, messageId, command, messageBody);
|
||||||
byte[] checkFieldBytes = YouDianUtils.getCheckFieldBytes(dataFields);
|
byte[] checkFieldBytes = YouDianUtils.getCheckFieldBytes(dataFields);
|
||||||
|
|
||||||
return Bytes.concat(dataFields, checkFieldBytes);
|
return Bytes.concat(dataFields, checkFieldBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.jsowell.netty.handler.electricbicycles;
|
package com.jsowell.netty.handler.electricbicycles;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSON;
|
import com.alibaba.fastjson2.JSON;
|
||||||
|
import com.jsowell.common.constant.Constants;
|
||||||
import com.jsowell.common.core.domain.ebike.EBikeDataProtocol;
|
import com.jsowell.common.core.domain.ebike.EBikeDataProtocol;
|
||||||
import com.jsowell.netty.factory.EBikeOperateFactory;
|
import com.jsowell.netty.factory.EBikeOperateFactory;
|
||||||
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
|
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
|
||||||
@@ -36,6 +37,6 @@ public class RegistrationHandler extends AbstractEBikeHandler {
|
|||||||
EBikeMessageCmd20 message = (EBikeMessageCmd20) AbsEBikeMessage.parseMessage(dataProtocol.getBytes());
|
EBikeMessageCmd20 message = (EBikeMessageCmd20) AbsEBikeMessage.parseMessage(dataProtocol.getBytes());
|
||||||
EBikeMessageCmd20.DeviceRegister deviceRegister = message.getDeviceRegister();
|
EBikeMessageCmd20.DeviceRegister deviceRegister = message.getDeviceRegister();
|
||||||
log.info("设备注册包:{}", JSON.toJSONString(message));
|
log.info("设备注册包:{}", JSON.toJSONString(message));
|
||||||
return new byte[0];
|
return getResult(dataProtocol, Constants.zeroByteArray);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,10 +60,10 @@ public class EBikeMessageCmd20 extends AbsEBikeMessage {
|
|||||||
private String powerBoardVersion;
|
private String powerBoardVersion;
|
||||||
|
|
||||||
public DeviceRegister(byte[] dataBytes) {
|
public DeviceRegister(byte[] dataBytes) {
|
||||||
this.firmwareVersion = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, 0, 2)) + "";
|
this.firmwareVersion = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, 0, 2)) * 0.01 + "";
|
||||||
this.portNumber = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, 2, 3)) + "";
|
this.portNumber = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, 2, 3)) + "";
|
||||||
this.virtualId = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, 3, 4)) + "";
|
this.virtualId = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, 3, 4)) + "";
|
||||||
this.deviceType = BytesUtil.bcd2StrLittle(Arrays.copyOfRange(dataBytes, 4, 5));
|
this.deviceType = BytesUtil.printHexBinary(Arrays.copyOfRange(dataBytes, 4, 5));
|
||||||
this.workMode = BytesUtil.bcd2StrLittle(Arrays.copyOfRange(dataBytes, 5, 6));
|
this.workMode = BytesUtil.bcd2StrLittle(Arrays.copyOfRange(dataBytes, 5, 6));
|
||||||
this.powerBoardVersion = BytesUtil.bcd2StrLittle(Arrays.copyOfRange(dataBytes, 6, 8));
|
this.powerBoardVersion = BytesUtil.bcd2StrLittle(Arrays.copyOfRange(dataBytes, 6, 8));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user