package com.sandu.ximon.admin.entity;
|
|
import lombok.Data;
|
|
@Data
|
public class DataTransportMainResponse {
|
// 功能码(1)
|
private String functionCode;
|
// 命令类型(1)
|
private String orderType;
|
// 负荷长度(2)
|
private String payloadLength;
|
// 响应payload
|
private String payload;
|
// 校验码(4)
|
private String crc32;
|
// 是否通过校验
|
private boolean isValidate;
|
|
public String getDefaultConnectCodePayload() {
|
return payload.substring(2);
|
}
|
|
/**
|
* 转为响应帧
|
* @param hex 十六进制
|
* @return
|
*/
|
public DataTransportMainResponse convertInstance(String hex) {
|
if(hex.length()<16){
|
return null;
|
}
|
// 将十六进制数转为大写
|
hex = hex.toUpperCase();
|
// 功能码(1)
|
this.functionCode = hex.substring(0, 2);
|
// 命令类型(1)
|
this.orderType = hex.substring(2, 4);
|
// 负荷长度(2)
|
this.payloadLength = hex.substring(4, 8);
|
// 响应payload
|
this.payload = hex.substring(8, hex.length()-8);
|
// 校验码(4)
|
this.crc32 = hex.substring(hex.length()-8);
|
// 判断校验是否通过
|
String frame = hex.substring(0, hex.length()-8);
|
this.setValidate(CRC32Utils.validateFrame(frame, this.crc32));
|
|
return this;
|
}
|
|
}
|