From c8ff96af8647474b1d03f5f374bb18eb59f65987 Mon Sep 17 00:00:00 2001 From: jiazx0107@163.com <jiazx0107@163.com> Date: 星期日, 24 十二月 2023 12:30:09 +0800 Subject: [PATCH] 游仙协议解析-2 --- src/main/java/com/fzzy/protocol/bhzn/analysis/AnalysisService.java | 32 +++++++++++++++++--------------- 1 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/fzzy/protocol/bhzn/analysis/AnalysisService.java b/src/main/java/com/fzzy/protocol/bhzn/analysis/AnalysisService.java index 7aca558..f44c036 100644 --- a/src/main/java/com/fzzy/protocol/bhzn/analysis/AnalysisService.java +++ b/src/main/java/com/fzzy/protocol/bhzn/analysis/AnalysisService.java @@ -14,14 +14,13 @@ import com.fzzy.gateway.entity.GatewayDevice; import com.fzzy.gateway.hx2023.ScConstant; import com.fzzy.gateway.hx2023.data.*; -import com.fzzy.protocol.ConstantProtocol; +import com.fzzy.protocol.ProtocolUtils; import com.fzzy.protocol.bhzn.cmd.CommandBuild; import com.fzzy.protocol.bhzn.cmd.ReMessageBuilder; import com.fzzy.protocol.bhzn.data.IoMessage; -import com.fzzy.protocol.bhzn.data.THDto; +import com.fzzy.protocol.data.THDto; import com.fzzy.protocol.bhzn.server.BhznGrainV2ServerEngine; import com.fzzy.protocol.bhzn.server.BhznGrainV2ServerUtils; -import com.fzzy.protocol.fzzy.server.ServerUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @@ -99,24 +98,25 @@ private void analysisGrain(IoMessage message) { try { + //鏍规嵁鍒嗘満SN鑾峰彇璁惧閰嶇疆淇℃伅 + GatewayDevice gatewayDevice = GatewayUtils.getCacheByDeviceSn(message.getAddr()); + if (null == gatewayDevice) { + replayGrain(message); + log.error("涓绘満-------->>骞冲彴锛岃В鏋愮伯鎯呭け璐ワ紝鏈幏鍙栧埌绯荤粺璁惧閰嶇疆淇℃伅锛�" + message.getAddr()); + return; + } //鏍规嵁鍒嗘満鍦板潃鑾峰彇鍒嗘満淇℃伅 - ApiCommonDevice commonDevice = Constant.getCommonDeviceCache(message.getAddr()); + ApiCommonDevice commonDevice = Constant.getCommonDeviceCache(message.getIp()); if (commonDevice == null) { replayGrain(message); log.error("涓绘満-------->>骞冲彴锛岃В鏋愮伯鎯呭け璐ワ紝鏈幏鍙栧埌绯荤粺绮儏涓绘満閰嶇疆锛�" + message.getAddr()); return; } - //鏍规嵁鍒嗘満SN鑾峰彇璁惧閰嶇疆淇℃伅 - GatewayDevice gatewayDevice = GatewayUtils.getCacheByDeviceSn(commonDevice.getSn()); - if (null == gatewayDevice) { - replayGrain(message); - log.error("涓绘満-------->>骞冲彴锛岃В鏋愮伯鎯呭け璐ワ紝鏈幏鍙栧埌绯荤粺璁惧閰嶇疆淇℃伅锛�" + message.getAddr()); - return; - } + //鑾峰彇璇锋眰淇℃伅 - BaseReqData reqData = BhznGrainV2ServerUtils.getSyncReq(gatewayDevice.getDepotIdSys()); + BaseReqData reqData = ProtocolUtils.getSyncReq(gatewayDevice.getDepotIdSys()); if (null == reqData) { replayGrain(message); log.error("涓绘満-------->>骞冲彴锛岃В鏋愮伯鎯呭け璐ワ紝鏈幏鍙栧埌绮儏璇锋眰淇℃伅锛�" + message.getAddr()); @@ -190,7 +190,6 @@ } private void analysisGrain2(IoMessage message, BaseReqData reqData, String grainStr) { - GatewayDevice device = reqData.getDevice(); // 鑾峰彇瀹屾暣鐨勭伯鎯呭寘淇℃伅 String[] attCable = device.getCableRule().split("-"); @@ -216,13 +215,13 @@ temp = "0000"; } if (ReMessageBuilder.ERROR_TAG.equals(temp)) { - tempValue = ConstantProtocol.ERROR_TEMP; + tempValue = ProtocolUtils.ERROR_TEMP; } else { tempValue = BytesUtil.hexToInt(BytesUtil.tran_LH(temp)) / 10.0; } // 鏁呴殰鍊煎鐞� if (tempValue >= ReMessageBuilder.FAULT_CHECK_TAG) { - tempValue = ConstantProtocol.FAULT_TEMP; + tempValue = ProtocolUtils.FAULT_TEMP; } temps.add(tempValue); } @@ -324,7 +323,10 @@ outPut.setAvgTemperature(NumberUtil.keepPrecision((sumT / sumNum), 1) + ""); outPut.setMinTemperature(min + ""); outPut.setMaxTemperature(min + ""); + List<GrainTH> ths = new ArrayList<>(); + ths.add(new GrainTH(thDto.getTempIn()!=null?thDto.getTempIn()+"":"",thDto.getHumidityIn()!=null?thDto.getHumidityIn()+"":"","1")); + outPut.setTemperatureAndhumidity(ths); grain.setOutput(JSONObject.toJSONString(outPut)); GatewayDevice gatewayDeviceWeather = GatewayUtils.getCacheByDeviceTypeOne(GatewayDeviceType.TYPE_09.getCode()); -- Gitblit v1.9.3