| | |
| | | package com.fzzy.protocol.zldz.analysis; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.fzzy.api.data.GatewayDeviceType; |
| | | import com.fzzy.api.utils.BytesUtil; |
| | | import com.fzzy.api.utils.ContextUtil; |
| | | import com.fzzy.api.utils.NumberUtil; |
| | | import com.fzzy.gateway.GatewayUtils; |
| | | import com.fzzy.gateway.api.GatewayDeviceReportService; |
| | | import com.fzzy.gateway.api.GatewayRemoteManager; |
| | | import com.fzzy.gateway.data.BaseReqData; |
| | | import com.fzzy.gateway.data.WeatherWebDto; |
| | | import com.fzzy.gateway.entity.GatewayDevice; |
| | | import com.fzzy.gateway.hx2023.ScConstant; |
| | | import com.fzzy.gateway.hx2023.data.*; |
| | | import com.fzzy.io.request.BaseRequest; |
| | | import com.fzzy.protocol.ProtocolUtils; |
| | | import com.fzzy.protocol.bhzn.v0.cmd.ReMessageBuilder; |
| | | import com.fzzy.protocol.data.THDto; |
| | | import com.fzzy.protocol.zldz.data.ReMessage; |
| | | import com.fzzy.protocol.zldz.service.ZldzGatewayGrainService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | |
| | | @Resource |
| | | private ZldzGatewayGrainService zldzGatewayGrainService; |
| | | |
| | | @Resource |
| | | private GatewayRemoteManager gatewayRemoteManager; |
| | | |
| | | |
| | | public static Map<String, Map<String, String>> contextMap = new HashMap<>(); |
| | | |
| | |
| | | // 备用值 |
| | | if (tempValue == ERROR_CHECK_TAG) { |
| | | tempValue = ProtocolUtils.ERROR_TEMP; |
| | | |
| | | |
| | | //验证是不是锥形仓补偿值 |
| | | curLay = (i % layMax) + 1; |
| | | curRoot = (i / layMax) + 1; |
| | |
| | | * @param packetMap |
| | | * @param sumPackets |
| | | */ |
| | | private void analysisStep1(ReMessage msg, |
| | | GatewayDevice device, BaseReqData reqData, |
| | | Map<String, String> packetMap, int sumPackets) { |
| | | private void analysisStep1(ReMessage msg, GatewayDevice device, BaseReqData reqData, Map<String, String> packetMap, int sumPackets) { |
| | | // 获取完整的粮情包信息 |
| | | String strPoints = ""; |
| | | for (int i = 1; i <= sumPackets; i++) { |
| | |
| | | |
| | | |
| | | // 将集合解析成坐标数据 |
| | | addPoint1(temps, msg, device, reqData); |
| | | addPoint1(temps, device, reqData, cableX, cableY, cableZ); |
| | | } |
| | | |
| | | private String buildCurKey(ReMessage msg, int curPacket) { |
| | |
| | | * @param temps |
| | | * @throws Exception |
| | | */ |
| | | private void addPoint1(List<Double> temps, ReMessage msg, |
| | | GatewayDevice device, BaseReqData reqData) { |
| | | //TODO |
| | | private void addPoint1(List<Double> temps, GatewayDevice device, BaseReqData reqData, int cableX, int cableY, int cableZ) { |
| | | |
| | | //数据封装 |
| | | GrainData grain = new GrainData(); |
| | | grain.setMessageId(ScConstant.getMessageId()); |
| | | grain.setDeviceId(device.getDeviceId()); |
| | | grain.setTimestamp(System.currentTimeMillis() + ""); |
| | | |
| | | ClientHeaders headers = new ClientHeaders(); |
| | | headers.setDeviceName(device.getDeviceName()); |
| | | headers.setProductId(device.getProductId()); |
| | | headers.setOrgId(device.getOrgId()); |
| | | headers.setMsgId(reqData.getMessageId()); |
| | | grain.setHeaders(headers); |
| | | |
| | | |
| | | GrainOutPut outPut = new GrainOutPut(); |
| | | |
| | | |
| | | double max = ReMessageBuilder.MAX_TEMP, min = ReMessageBuilder.MIN_TEMP, sumT = 0.0, sumNum = cableX * cableY * cableZ; |
| | | |
| | | List<GrainTemp> temperature = new ArrayList<>(); |
| | | //根号 |
| | | int cableNum = 1, position = 0; |
| | | |
| | | double curTemp; |
| | | int x = 0, y = 0, z = 0; |
| | | for (int i = 0; i < temps.size(); i++) { |
| | | curTemp = temps.get(i); |
| | | position = i; |
| | | z = i % cableZ + 1; |
| | | x = i / (cableZ * cableY); |
| | | y = x * (cableZ * cableY); |
| | | y = (i - y) / cableZ; |
| | | //根号 |
| | | cableNum = (i / cableZ) + 1; |
| | | |
| | | temperature.add(new GrainTemp(cableNum + "", z + "", curTemp + "", position + "")); |
| | | |
| | | //求最大最小值 |
| | | if (curTemp < -900) { |
| | | sumNum--; |
| | | } else { |
| | | sumT += curTemp; |
| | | if (curTemp > max) { |
| | | max = curTemp; |
| | | } |
| | | if (curTemp < min) { |
| | | min = curTemp; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (sumNum == 0) { |
| | | sumNum = 1; |
| | | log.warn("---当前粮情采集异常--"); |
| | | } |
| | | //过滤比较用的最大最小值 |
| | | if (max == ReMessageBuilder.MAX_TEMP) { |
| | | max = 0.0; |
| | | } |
| | | if (min == ReMessageBuilder.MIN_TEMP) { |
| | | min = 0.0; |
| | | } |
| | | |
| | | outPut.setTemperature(temperature); |
| | | outPut.setAvgTemperature(NumberUtil.keepPrecision((sumT / sumNum), 1) + ""); |
| | | outPut.setMinTemperature(min + ""); |
| | | outPut.setMaxTemperature(min + ""); |
| | | List<GrainTH> ths = new ArrayList<>(); |
| | | |
| | | |
| | | THDto thDto = ProtocolUtils.getCacheTh(device.getDeviceId()); |
| | | if (null == thDto) thDto = new THDto(); |
| | | |
| | | 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()); |
| | | |
| | | //系统气象站信息 |
| | | WeatherWebDto weather = WeatherWebDto.contextMap.get("default"); |
| | | |
| | | //气象信息 |
| | | GrainWeather weatherStation = new GrainWeather(); |
| | | weatherStation.setMessageId(ScConstant.getMessageId()); |
| | | weatherStation.setMessgeId(weatherStation.getMessageId()); |
| | | |
| | | if (null != gatewayDeviceWeather) { |
| | | weatherStation.setId(gatewayDeviceWeather.getDeviceId()); |
| | | } else { |
| | | weatherStation.setId(device.getDeviceId()); |
| | | } |
| | | weatherStation.setAirPressure(weather.getPressure()); |
| | | weatherStation.setHumidity(weather.getHumidity()); |
| | | weatherStation.setPm(weather.getAir_pm25()); |
| | | weatherStation.setRadiation("0"); |
| | | weatherStation.setRainfallAmount(weather.getWea()); |
| | | weatherStation.setTemperature(weather.getTem()); |
| | | weatherStation.setWindDirection(weather.getWin()); |
| | | weatherStation.setWindPower(weather.getWin_meter()); |
| | | weatherStation.setWindSpeed(weather.getWin_speed()); |
| | | |
| | | grain.setWeatherStation(JSONObject.toJSONString(weatherStation)); |
| | | |
| | | //封装好的数据 |
| | | log.info("---粮情机械封装完成----开始执行推送"); |
| | | |
| | | reqData.setData(JSONObject.toJSONString(grain)); |
| | | |
| | | doPushGrain(reqData); |
| | | } |
| | | |
| | | private void doPushGrain(BaseReqData reqData) { |
| | | |
| | | GatewayDeviceReportService reportService = gatewayRemoteManager.getDeviceReportService(reqData.getDevice().getPushProtocol()); |
| | | if (null == reportService) { |
| | | log.error("------------粮情推送失败,系统不存在当前协议执行类----{}", reqData.getDevice().getDeviceName()); |
| | | return; |
| | | } |
| | | reportService.reportGrainData(reqData); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 圆筒仓解析步骤 |
| | | * |