package com.sandu.ximon.admin.manager.iot.frame.inner.report;
|
|
import cn.hutool.core.util.StrUtil;
|
import com.sandu.common.execption.BusinessException;
|
import com.sandu.ximon.admin.manager.iot.frame.inner.BaseResponseInnerFrame;
|
import com.sandu.ximon.admin.manager.iot.rrpc.enums.C3ChargingEnum;
|
import com.sandu.ximon.admin.manager.iot.rrpc.util.CRC32Utils;
|
import lombok.Data;
|
import lombok.ToString;
|
|
import java.text.DecimalFormat;
|
|
/**
|
* @author ZZQ
|
* @date 2022/3/18 9:51
|
* C3充电桩查询指令响应帧
|
*/
|
@Data
|
@ToString(callSuper = true)
|
public class A5C3QueryReportInnerFrame extends BaseResponseInnerFrame<A5C3QueryReportInnerFrame> {
|
//MAC地址
|
private String mac;
|
//版本号
|
private String version;
|
//心跳包间隔时间
|
private String IntervalTime;
|
//查询电压/电流常数
|
private String constant;
|
//查询地址(暂时不用到)
|
private String address;
|
//故障码
|
private String faultCode;
|
|
@Override
|
public A5C3QueryReportInnerFrame transformFrame(String hex) {
|
if (StrUtil.isBlank(hex)) {
|
return null;
|
}
|
// MQTT通信方式(1)
|
setConnectType(hex.substring(0, 2));
|
// 功能码(1)
|
setFunctionCode(hex.substring(2, 4));
|
// 负荷长度(2)
|
setPayloadLength(hex.substring(4, 8));
|
//MAC地址
|
setMac(hex.substring(8, 16));
|
|
retuenInfomation(functionCode, hex.substring(16, hex.length() - 8));
|
|
setCrc32(hex.substring(hex.length() - 8));
|
// 校验CRC32
|
String frame = hex.substring(2, hex.length() - 8);
|
this.setValidate(CRC32Utils.validateFrame(frame, getCrc32()));
|
return this;
|
}
|
|
public void retuenInfomation(String functionCode, String hex) {
|
|
/**
|
* 查询版本号
|
*/
|
if (functionCode.equals(C3ChargingEnum.QueryVersion.getCode())) {
|
if (hex.length() != 8) {
|
throw new BusinessException("数据错误,请重新请求!");
|
}
|
DecimalFormat df = new DecimalFormat("00");
|
setVersion("硬件版本号:" + df.format(parseVal(hex, 0, 2)) + df.format(parseVal(hex, 2, 4))
|
+ "; " + "软件版本号:" + df.format(parseVal(hex, 4, 6)) + df.format(parseVal(hex, 6, 8)));
|
}
|
|
/**
|
* 查询心跳包间隔时间
|
*/
|
if (functionCode.equals(C3ChargingEnum.QueryIntervalTime.getCode())) {
|
if (hex.length() != 4) {
|
throw new BusinessException("数据错误,请重新请求!");
|
}
|
setIntervalTime("心跳包间隔时间(s):" + parseVal(hex, 0, 4));
|
}
|
|
/**
|
* 查询电压/电流常数
|
*/
|
if (functionCode.equals(C3ChargingEnum.QueryConstant.getCode())) {
|
if (hex.length() != 4) {
|
throw new BusinessException("数据错误,请重新请求!");
|
}
|
setConstant("电压常数:" + parseVal(hex, 0, 2) + " ;电流常数:" + parseVal(hex, 2, 4));
|
}
|
|
/**
|
* 查询地址(暂时不用到)
|
*/
|
if (functionCode.equals(C3ChargingEnum.QueryAddress.getCode())) {
|
if (hex.length() != 4) {
|
throw new BusinessException("数据错误,请重新请求!");
|
}
|
setAddress(hex);
|
}
|
|
/**
|
* 查询地址(暂时不用到)
|
*/
|
if (functionCode.equals(C3ChargingEnum.QueryFaultCode.getCode())) {
|
if (hex.length() != 4) {
|
throw new BusinessException("数据错误,请重新请求!");
|
}
|
setFaultCode(hex);
|
}
|
}
|
|
private Integer parseVal(String frame, int start, int end) {
|
return Integer.parseInt(frame.substring(start, end), 16);
|
}
|
}
|