update 电单车协议

This commit is contained in:
Guoqs
2024-08-27 08:48:05 +08:00
parent 613c6a74d8
commit 39fcfbb4e2
3 changed files with 4 additions and 7 deletions

View File

@@ -38,21 +38,17 @@ public abstract class AbstractEBikeHandler implements InitializingBean {
protected byte[] getResult(EBikeDataProtocol dataProtocol, byte[] messageBody) {
// 起始标志
byte[] head = dataProtocol.getHead();
// 长度 = 物理ID(4) + 消息ID(2) + 命令(1) + 数据(n) + 校验(2)每包最多256字节
byte[] length = BytesUtil.intToBytesLittle(9 + messageBody.length);
// 物理id
byte[] physicalId = dataProtocol.getPhysicalId();
// 加密标志
byte[] messageId = dataProtocol.getMessageId();
// 请求帧类型
byte[] command = dataProtocol.getCommand();
// 整个数据包中的每个字节(不包括校验字段本身)
byte[] dataFields = Bytes.concat(head, length, physicalId, messageId, command, messageBody);
byte[] checkFieldBytes = YouDianUtils.getCheckFieldBytes(dataFields);
return Bytes.concat(dataFields, checkFieldBytes);
}

View File

@@ -1,6 +1,7 @@
package com.jsowell.netty.handler.electricbicycles;
import com.alibaba.fastjson2.JSON;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.domain.ebike.EBikeDataProtocol;
import com.jsowell.netty.factory.EBikeOperateFactory;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
@@ -36,6 +37,6 @@ public class RegistrationHandler extends AbstractEBikeHandler {
EBikeMessageCmd20 message = (EBikeMessageCmd20) AbsEBikeMessage.parseMessage(dataProtocol.getBytes());
EBikeMessageCmd20.DeviceRegister deviceRegister = message.getDeviceRegister();
log.info("设备注册包:{}", JSON.toJSONString(message));
return new byte[0];
return getResult(dataProtocol, Constants.zeroByteArray);
}
}