update 电单车协议

This commit is contained in:
Guoqs
2024-08-26 14:45:19 +08:00
parent f27773ba05
commit c091b6dea7
10 changed files with 144 additions and 83 deletions

View File

@@ -0,0 +1,73 @@
package com.jsowell.common.core.domain.ebike;
import com.google.common.primitives.Bytes;
import com.jsowell.common.util.BytesUtil;
import lombok.Data;
/**
* 云快充数据模板
*/
@Data
public class EBikeDataProtocol {
/**
* 包头 3字节
*/
private byte[] head;
/**
* 数据长度 2字节
*/
private byte[] length;
/**
* 物理id 4字节
*/
private byte[] physicalId;
/**
* 消息id 2字节
*/
private byte[] messageId;
/**
* 命令 1字节
*/
private byte[] command;
/**
* 消息体 N字节
*/
private byte[] msgBody;
/**
* 帧校验域 2字节
*/
private byte[] checksum;
public EBikeDataProtocol(byte[] msg) {
// 起始标志
this.head = BytesUtil.copyBytes(msg, 0, 3);
// 数据长度
this.length = BytesUtil.copyBytes(msg, 3, 2);
// 物理id
this.physicalId = BytesUtil.copyBytes(msg, 5, 4);
// 消息id
this.messageId = BytesUtil.copyBytes(msg, 9, 2);
// 命令
this.command = BytesUtil.copyBytes(msg, 11, 1);
// 消息体
this.msgBody = BytesUtil.copyBytes(msg, 12, msg.length - 14);
// 帧校验域
this.checksum = new byte[]{msg[msg.length - 2], msg[msg.length - 1]};
}
/**
* 转换为十六进制字符串
*
* @return 报文
*/
public String getHEXString() {
byte[] bytes = Bytes.concat(this.head, this.length, this.physicalId, this.messageId, this.command, this.msgBody, this.checksum);
return BytesUtil.binary(bytes, 16);
}
}