| ¶Ô±ÈÐÂÎļþ |
| | |
| | | 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); |
| | | } |
| | | } |