mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 11:05:18 +08:00
update 电单车协议
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user