src/main/java/com/fzzy/api/data/GatewayDeviceProtocol.java
@@ -14,7 +14,8 @@ TCP_FZZY_V3("TCP_FZZY_V3", "ç²®æ -飿£è´è¿æ§å¶æåè®®V3"), GRAIN_FZZY_IGDS_V40("GRAIN_FZZY_IGDS_V40", "ç²®æ -飿£è´è¿ç³»ç»V40"), GRAIN_FZZY_BHZN_WEB("GRAIN_FZZY_BHZN_WEB", "ç²®æ -FZZY-BHZNç½å£åè®®"), GRAIN_BHZN_V0_WEB("GRAIN_BHZN_V0_WEB", "ç²®æ -BHZN-V0ç½å£åè®®"), GRAIN_BHZN_V0_WEB("GRAIN_BHZN_V0_WEB", "ç²®æ -BHZN-V0æ 线åè®®"), GRAIN_BHZN_V01_WEB("GRAIN_BHZN_V01_WEB", "ç²®æ -BHZN-V01æ 线å议带å¼å¤´ç»å°¾ç¬¦å·"), GRAIN_FZZY_ZLDZ_WEB("GRAIN_FZZY_ZLDZ_WEB", "ç²®æ -FZZY-ZLDZç½å£åè®®"), GRAIN_YOUXIAN0_2023("GRAIN_YOUXIAN0_2023", "ç²®æ -游ä»ä¸»åºåè®®"), GRAIN_YOUXIAN1_2023("GRAIN_YOUXIAN1_2023", "ç²®æ -游ä»ååºåè®®"), @@ -36,6 +37,7 @@ list.add(new ApiTrigger(TCP_FZZY_V3.getCode(), TCP_FZZY_V3.getName())); list.add(new ApiTrigger(GRAIN_FZZY_IGDS_V40.getCode(), GRAIN_FZZY_IGDS_V40.getName())); list.add(new ApiTrigger(GRAIN_BHZN_V0_WEB.getCode(), GRAIN_BHZN_V0_WEB.getName())); list.add(new ApiTrigger(GRAIN_BHZN_V01_WEB.getCode(), GRAIN_BHZN_V01_WEB.getName())); list.add(new ApiTrigger(GRAIN_FZZY_BHZN_WEB.getCode(), GRAIN_FZZY_BHZN_WEB.getName())); list.add(new ApiTrigger(GRAIN_FZZY_ZLDZ_WEB.getCode(), GRAIN_FZZY_ZLDZ_WEB.getName())); list.add(new ApiTrigger(GRAIN_YOUXIAN0_2023.getCode(), GRAIN_YOUXIAN0_2023.getName())); src/main/java/com/fzzy/gateway/GatewayTimerScheduled.java
@@ -105,8 +105,10 @@ /** * <p> * ç²®æ æ¯å¤©8ç¹ééç²®æ * */ @Scheduled(cron = "0 32 7 ? * *") // @Scheduled(cron = "0 32 11 ? * *") @Scheduled(cron = "0 32 11 ? * 2,5 *") public void scheduledGrain2() { //è·å设å¤é ç½®ï¼åªé对粮æ 设å¤è¿è¡æ§è¡ log.info("宿¶ç²®æ éékafkaæ¨é"); @@ -132,6 +134,7 @@ GatewaySyncGranService syncGrainService = gatewayRemoteManager.getSyncGrainService(device.getSyncProtocol()); resp = syncGrainService.syncGrain(reqData); log.info("å½ä»¤åéç»æï¼"+resp.toString()); Thread.sleep(30000); }catch (Exception e){ log.error(e.getMessage(),e); } src/main/java/com/fzzy/protocol/ProtocolRunner.java
@@ -2,6 +2,7 @@ import com.fzzy.protocol.bhzn.server.BhznGrainV2ServerEngine; import com.fzzy.protocol.bhzn.v0.server.BhznGrainV0ServerEngine; import com.fzzy.protocol.bhzn.v01.server.BhznGrainV01ServerEngine; import com.fzzy.protocol.fzzy.server.FzzyServerEngine; import com.fzzy.protocol.weightyh.YhScaleServerEngine; import com.fzzy.protocol.zldz.server.ZldzServerEngine; @@ -36,7 +37,9 @@ //馿µ·æºè½çº¯ç½å£è®¾å¤åè®® BhznGrainV2ServerEngine.start(null); //馿µ·æºè½æ 线主æºè®¾å¤åè®® BhznGrainV0ServerEngine.start(null); //BhznGrainV0ServerEngine.start(null); //馿µ·æºè½æ 线主æºè®¾å¤åè®® BhznGrainV01ServerEngine.start(null); } } src/main/java/com/fzzy/protocol/bhzn/analysis/AnalysisService.java
@@ -346,7 +346,7 @@ outPut.setTemperature(temperature); outPut.setAvgTemperature(NumberUtil.keepPrecision((sumT / sumNum), 1) + ""); outPut.setMinTemperature(min + ""); outPut.setMaxTemperature(min + ""); outPut.setMaxTemperature(max + ""); JSONObject properties = new JSONObject(); src/main/java/com/fzzy/protocol/bhzn/v0/analysis/AnalysisService.java
@@ -465,7 +465,7 @@ outPut.setTemperature(temperature); outPut.setAvgTemperature(NumberUtil.keepPrecision((sumT / sumNum), 1) + ""); outPut.setMinTemperature(min + ""); outPut.setMaxTemperature(min + ""); outPut.setMaxTemperature(max + ""); List<GrainTH> ths = new ArrayList<>(); ths.add(new GrainTH(thDto.getTempIn() != null ? thDto.getTempIn() + "" : "", thDto.getHumidityIn() != null ? thDto.getHumidityIn() + "" : "", "1")); src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0ServerEngine.java
@@ -44,10 +44,10 @@ //确认ç»å°¾æ å¿ //ioServerOption.setDelimiter(BhznGrainV2ServerUtils.MSG_END.getBytes()); // ioServerOption.setSplitDecoderType(SplitByteDecoderType.NO_LIMIT); ioServerOption.setSplitDecoderType(SplitByteDecoderType.NO_LIMIT); ioServerOption.setDelimiter(BhznGrainV2ServerUtils.MSG_END.getBytes()); ioServerOption.setSplitDecoderType(SplitByteDecoderType.DELIMITER_SYMBOL); // ioServerOption.setDelimiter(BhznGrainV2ServerUtils.MSG_END.getBytes()); // ioServerOption.setSplitDecoderType(SplitByteDecoderType.DELIMITER_SYMBOL); // é 置系ç»å¿è·³é´é ioServerOption.setReaderIdleTime(5 * 60); src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0ServerUtils.java
@@ -26,10 +26,10 @@ public static int HEART_BEAT_TIME = 30;//å¿è·³é´éæ¶é´ public static String MSG_START = "3C42485A4E3E";//<BHZN> public static String MSG_START = "";//<BHZN> 3C42485A4E3E public static String MSG_START2 = "AA"; public static String MSG_END = "<END>";//<END> public static String MSG_END_16 = "3C454E443E";//<END>3C454E443E public static String MSG_END_16 = "";//<END>3C454E443E public static final String CHARSET = "UTF-8"; src/main/java/com/fzzy/protocol/bhzn/v0/²»´ø¿ªÍ·½áβµÄ°æ±¾
src/main/java/com/fzzy/protocol/bhzn/v01/analysis/AnalysisService.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,577 @@ package com.fzzy.protocol.bhzn.v01.analysis; import com.alibaba.fastjson.JSONObject; import com.fzzy.api.data.DepotType; import com.fzzy.api.data.GatewayDeviceType; import com.fzzy.api.utils.BytesUtil; import com.fzzy.api.utils.NumberUtil; import com.fzzy.api.utils.RedisConst; import com.fzzy.api.utils.RedisUtil; import com.fzzy.data.ConfigData; 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.GrainCableData; 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.protocol.ProtocolUtils; import com.fzzy.protocol.bhzn.v01.cmd.CommandBuild; import com.fzzy.protocol.bhzn.v01.cmd.ReMessageBuilder; import com.fzzy.protocol.bhzn.v01.data.IoMessage; import com.fzzy.protocol.bhzn.v01.server.BhznGrainV01ServerEngine; import com.fzzy.protocol.bhzn.v01.server.BhznGrainV01ServerUtils; import com.fzzy.protocol.data.THDto; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * å议解æ */ @Slf4j @Component(AnalysisService.BEAN_ID) public class AnalysisService { public static final String BEAN_ID = "bhzn01.analysisService"; @Resource private GatewayRemoteManager gatewayRemoteManager; @Resource private ConfigData configData; @Resource private RedisUtil redisUtil; /** * é对åå ç²®æ æ¥æè¿è¡å°è£ */ public static Map<String, String> contextMapGrain = new HashMap<>(); /** * ç¨äºåæ¾è¿åç仿¸©ä»æ¹¿ä¿¡æ¯ */ public static Map<String, THDto> contextMapTH = new HashMap<>(); /** * @param sessionKey ip:port */ public void analysis(String sessionKey, IoMessage message) throws Exception { //注å if (BhznGrainV01ServerUtils.FUNCTION_ID_F1.equals(message.getFunctionId())) { log.info("主æº------->>å¹³å°ï¼æ³¨åä¿¡æ¯æ¥æ={}", message); //DO NOTHING return; } //å¿è·³ if (BhznGrainV01ServerUtils.FUNCTION_ID_F2.equals(message.getFunctionId())) { //DO NOTHING return; } // 93 è§£æä»æ¸©ä»æ¹¿ï¼å¹¶è¿åæ¶å°æ¥æ if (BhznGrainV01ServerUtils.FUNCTION_ID_93.equals(message.getFunctionId())) { log.info("主æº------->>å¹³å°ï¼æ¸©æ¹¿åº¦ä¿¡æ¯æ¥æ={}", message); analysisTh(message); return; } // 92 è§£æç²®æ¸©ï¼å¹¶è¿åæ¶å°æ¥æ if (BhznGrainV01ServerUtils.FUNCTION_ID_92.equals(message.getFunctionId())) { log.info("主æº------->>å¹³å°ï¼ç²®æ ä¿¡æ¯æ¥æ={}", message); analysisGrain(message); } } /** * ææ¶ä¸æ¯æä¹åæºå¤ä»æ¨¡å¼ï¼--å¹³æ¿ä» * * @param message */ private void analysisGrain(IoMessage message) { try { //æ ¹æ®åæºSNè·å设å¤é ç½®ä¿¡æ¯ GatewayDevice gatewayDevice = BhznGrainV01ServerUtils.contextOrder; if (null == gatewayDevice) { replayGrain(message); log.error("主æº-------->>å¹³å°ï¼è§£æç²®æ å¤±è´¥ï¼æªè·åå°ç³»ç»è®¾å¤é 置信æ¯ï¼" + message.getAddr()); return; } //æ ¹æ®åæºå°åè·ååæºä¿¡æ¯ // ApiCommonDevice commonDevice = Constant.getCommonDeviceCache(message.getIp()); // if (commonDevice == null) { // replayGrain(message); // log.error("主æº-------->>å¹³å°ï¼è§£æç²®æ å¤±è´¥ï¼æªè·åå°ç³»ç»ç²®æ 主æºé ç½®ï¼" + message.getAddr()); // return; // } //è·å请æ±ä¿¡æ¯ BaseReqData reqData = ProtocolUtils.getSyncReq(gatewayDevice.getDepotIdSys()); if (null == reqData) { replayGrain(message); log.error("主æº-------->>å¹³å°ï¼è§£æç²®æ å¤±è´¥ï¼æªè·åå°ç²®æ 请æ±ä¿¡æ¯ï¼" + message.getAddr()); return; } // å¤ææ°æ®ææ²¡ææ¶å宿´ GrainCableData cableData = GatewayUtils.getCableData(gatewayDevice); //è·åå½åç²®æ æ¸©åº¦æ¥æ String grainHex = message.getContent().substring(16); //å½åæ¥ææ¸©åº¦ç¹æ° int curPoint = BytesUtil.hexToInt(BytesUtil.tran_LH(message.getContent().substring(4, 8))); //妿å½åå çæ°æ®ä¸ªæ°å¤§äºçäºå½åä»åºçé ç½®ç¹ä½å表示åå è¿å if (curPoint >= cableData.getSumNum()) { log.info("åæº------>>>å¹³å°ï¼ç²®æ æ°æ®åå =" + grainHex); //è¿åç²®æ æ¥æ¶ä¿¡æ¯ replayGrain(message); analysisGrain2(message, reqData, grainHex, cableData); return; } //表示åå ä¼ é String key = "GRAIN_" + message.getAddr(); String oldGrainHex = contextMapGrain.get(key) == null ? "" : contextMapGrain.get(key); //è·åå½åå èµ·å§ç¹çå±è¡å int hang = BytesUtil.hexToInt(BytesUtil.tran_LH(message.getContent().substring(8, 10))); int lie = BytesUtil.hexToInt(BytesUtil.tran_LH(message.getContent().substring(10, 12))); int ceng = BytesUtil.hexToInt(BytesUtil.tran_LH(message.getContent().substring(12, 14))); if (hang > 0 || lie > 0 || ceng > 0) { //说æé第ä¸å æ°æ® grainHex = oldGrainHex + grainHex; } if (grainHex.length() >= cableData.getSumNum() * 4) { //è¿åç²®æ æ¥æ¶ä¿¡æ¯ replayGrain(message); log.info("åæº------>>>å¹³å°ï¼ç²®æ æ°æ®å¤å ï¼å®æ´æ°æ®=" + grainHex); analysisGrain2(message, reqData, grainHex, cableData); return; } else { log.info("åæº------>>>å¹³å°ï¼å°ç¬¬ä¸å æ°æ®åå ¥å å=" + grainHex); contextMapGrain.put(key, grainHex); replayGrain(message); } } catch (Exception e) { log.error(e.getMessage(), e); } } /** * è¿åç²®æ æ¶å°æ¥æä¿¡æ¯ï¼éè¦æ³¨æï¼å¦æåå¨åå æ åµä¸ï¼éè¦çææå æ¶å°åè¿å * * @param message */ private void replayGrain(IoMessage message) throws InterruptedException { Thread.sleep(50); String hexStr = CommandBuild.getMsgGrainReply(message.getAddr()); log.info("å¹³å°--------->>>主æºï¼è¿åç²®æ æ¥ææ¶å°ä¿¡æ¯ï¼æ¥æ={}", hexStr); BhznGrainV01ServerEngine.pushByMin(hexStr); } /** * è·åå°ææçç²®æ æ°æ®ï¼å¼å§è§£æ * * @param message * @param reqData * @param grainStr */ private void analysisGrain2(IoMessage message, BaseReqData reqData, String grainStr, GrainCableData cableData) { GatewayDevice device = reqData.getDevice(); // æ ¹æ®å±è¡åè·åæå®é¿åº¦ int start = 0; int len = 4 * cableData.getSumNum(); log.info("åæº------>>>å¹³å°ï¼è¿åç²®æ 宿´ä¿¡æ¯ï¼åæº={}", device.getDeviceName()); String strPoints = grainStr.substring(start, start + len); // å°ç²®æ è§£æææ°ç» List<Double> temps = new ArrayList<>(); double tempValue; String temp; for (int i = 0; i < strPoints.length() / 4; i++) { temp = strPoints.substring(i * 4, i * 4 + 4); if (temp == null) { temp = "0000"; } if (ReMessageBuilder.ERROR_TAG.equals(temp)) { tempValue = ProtocolUtils.ERROR_TEMP; } else { tempValue = BytesUtil.hexToInt(BytesUtil.tran_LH(temp)) / 10.0; } // æ éå¼å¤ç if (tempValue >= ReMessageBuilder.FAULT_CHECK_TAG) { tempValue = ProtocolUtils.FAULT_TEMP; } temps.add(tempValue); } THDto thDto = this.getTH(message); if (null != thDto) { log.info("-------THDto--={}", thDto); } //æ¸ ç©º String key = "GRAIN_" + message.getAddr(); contextMapGrain.put(key, null); if(DepotType.TYPE_03.getCode().equals(device.getDepotType())){ //çä» analysisAndPush3(temps, reqData, thDto, cableData); }else if(DepotType.TYPE_02.getCode().equals(device.getDepotType())){ analysisAndPush2(temps, reqData, thDto, cableData); }else if(DepotType.TYPE_04.getCode().equals(device.getDepotType())){ analysisAndPush2(temps, reqData, thDto, cableData); }else { //å¹³æ¿ä» analysisAndPush1(temps, reqData, thDto, cableData); } } /** * çä»ï¼è§£æç¬¬äºæ¥ï¼è§£æå°åæ æ°æ® * @param temps * @param reqData * @param thDto * @param cableData */ private void analysisAndPush2(List<Double> temps, BaseReqData reqData, THDto thDto, GrainCableData cableData) { //TODO log.info("-------------------------ææªå®ç°----------------"); } /** * æ²¹ç½ä»ï¼è§£æç¬¬äºæ¥ï¼è§£æå°åæ æ°æ® * * @param temps * @throws Exception */ private void analysisAndPush3(List<Double> temps, BaseReqData reqData, THDto thDto, GrainCableData cableData) { GatewayDevice device = reqData.getDevice(); int cableZ = cableData.getCableZ(); int cableY = cableData.getCableY(); int cableX = cableData.getCableX(); int sumNum = temps.size(); //æ°æ®å°è£ 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; List<GrainTemp> temperature = new ArrayList<>(); //æ ¹å· int cableNum = 1, position = 0; double curTemp; int x = 0, y = 0, z = 0; for (int i = 0; i < sumNum; 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 + ""); JSONObject properties = new JSONObject(); properties.put("data", outPut); properties.put("timestamp", grain.getTimestamp()); String height = this.getCacheHeight(device); if (StringUtils.isEmpty(height)) height = "0.0"; properties.put("liquidHeight", height); grain.setProperties(properties); //å°è£ å¥½çæ°æ® log.info("---æµ åä»å°è£ 宿----å¼å§æ§è¡æ¨é"); reqData.setData(JSONObject.toJSONString(grain)); doPushGrain(reqData,grain); } /** * ä»REDISä¸è·åæ¶²ä½é«åº¦ä¿¡æ¯ * * @param device * @return */ private String getCacheHeight(GatewayDevice device) { //ç»å ¶ä»è½¯ä½¿ç¨ String key = RedisConst.KEY_DEPOT_HEIGHT + ":" + configData.getCompanyId() + "_" + device.getDepotIdSys(); return (String) redisUtil.get(key); } /** * å¹³æ¿ä»ï¼è§£æç¬¬äºæ¥ï¼è§£æå°åæ æ°æ® * * @param temps * @throws Exception */ private void analysisAndPush1(List<Double> temps, BaseReqData reqData, THDto thDto, GrainCableData cableData) { GatewayDevice device = reqData.getDevice(); int cableZ = cableData.getCableZ(); int cableY = cableData.getCableY(); int cableX = cableData.getCableX(); //æ°æ®å°è£ 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 = cableData.getSumNum(); 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(max + ""); 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()); //ç³»ç»æ°è±¡ç«ä¿¡æ¯ 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,grain); } private void doPushGrain(BaseReqData reqData,GrainData grainData) { GatewayDeviceReportService reportService = gatewayRemoteManager.getDeviceReportService(reqData.getDevice().getPushProtocol()); if (null == reportService) { log.error("------------ç²®æ æ¨é失败ï¼ç³»ç»ä¸åå¨å½ååè®®æ§è¡ç±»----{}", reqData.getDevice().getDeviceName()); return; } reportService.reportGrainData(reqData); reqData.setData(reportService.grainData2GatewayApiInfoKafka(grainData,reqData.getDevice()).getData()); reportService.reportGrainDataByKafka(reqData); } private void analysisTh(IoMessage message) { try { THDto th = new THDto(); String data = message.getContent(); String houseNo = data.substring(0, 2); int depotId = BytesUtil.hexToInt(houseNo); String t = data.substring(4, 8); String h = data.substring(8, 12); double humy; String temp; int symbol = 0; //符å·ä½ double tempValue; if (ReMessageBuilder.ERROR_TAG.equals(t)) { temp = "0000"; } else { temp = BytesUtil.tran_LH(t); } temp = BytesUtil.hexString2binaryString(temp, 16); //符å·ä½ symbol = Integer.valueOf(temp.substring(0, 1)); //è·åæ¸©åº¦å¼ tempValue = BytesUtil.biannary2Decimal(temp.substring(6)) / 10; //è¥ä¸ºè´ï¼åè¡¥ç ï¼ååå 1 if (symbol == 1) { tempValue = 0.0 - BytesUtil.twoToString(temp) / 10; } th.setTempIn(tempValue); if (ReMessageBuilder.ERROR_TAG.equals(h)) { humy = 0.0; } else { humy = (double) BytesUtil.hexToBigInt(BytesUtil.tran_LH(h)) / 10; } th.setHumidityIn(humy); log.info("主æº--------->>>å¹³å°ï¼è§£æä»æ¸©ä»æ¹¿ä¿¡æ¯ï¼ä»åº={},ç»æ={}", depotId, th.toString()); String key = "TH_" + depotId; contextMapTH.put(key, th); } catch (Exception e) { log.error(e.getMessage(), e); } finally { String hexStr = CommandBuild.getMsgTHReply(message.getAddr()); log.info("å¹³å°--------->>>主æºï¼è¿å仿¸©ä»æ¹¿æ¶å°ä¿¡æ¯ï¼æ¥æ={}", hexStr); BhznGrainV01ServerEngine.pushByMin(hexStr); } } private THDto getTH(IoMessage message) { String data = message.getContent(); String houseNo = data.substring(0, 2); Integer depotId = BytesUtil.hexToInt(houseNo); String key = "TH_" + depotId; return contextMapTH.get(key); } } src/main/java/com/fzzy/protocol/bhzn/v01/cmd/CommandBuild.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,179 @@ package com.fzzy.protocol.bhzn.v01.cmd; import com.fzzy.api.utils.BytesUtil; import com.fzzy.protocol.bhzn.v01.server.BhznGrainV01ServerUtils; /** * å½ä»¤çæ * * @author vince */ public class CommandBuild { private final static CommandBuild instance = new CommandBuild(); private CommandBuild() { } public static CommandBuild getInstance() { return instance; } /** * PCåå¤ å¿è·³å æ¶å°ä¿¡æ¯ * * @param grainAddr * @return */ public static String getMsgHeartReply(String grainAddr) { StringBuffer sb = new StringBuffer(); //å¼å§ç¬¦å· sb.append(BhznGrainV01ServerUtils.MSG_START); sb.append(BhznGrainV01ServerUtils.MSG_START2); //åæºå°å int i = Integer.parseInt(grainAddr); sb.append(BytesUtil.tran_LH(BytesUtil.intToHexStr(i))); //åéæ¹å°å sb.append("0001"); //å½ä»¤ID sb.append(BhznGrainV01ServerUtils.FUNCTION_ID_F2); //æ°æ®é¿åº¦-01 sb.append("01"); //æ°æ®åº--ä»»æå¼ sb.append("01"); //è·åæ ¡éªç sb.append(BhznGrainV01ServerUtils.getCheck(sb.toString())); //ç»å°¾ç¬¦ sb.append(BhznGrainV01ServerUtils.MSG_END_16); return sb.toString(); } /** * ç²®æ ééå½ä»¤ * * @param grainAddr ç²®æ åæºå°å * @param deptId ä»åºç¼å·å°å * @return */ public static String getMsgCheck(String grainAddr, String deptId) { StringBuffer sb = new StringBuffer(); //å¼å§ç¬¦å· sb.append(BhznGrainV01ServerUtils.MSG_START); sb.append(BhznGrainV01ServerUtils.MSG_START2); //åæºå°å int i = Integer.parseInt(grainAddr); sb.append(BytesUtil.tran_LH(BytesUtil.intToHexStr(i))); //åéæ¹å°å sb.append("0001"); //å½ä»¤ID sb.append(BhznGrainV01ServerUtils.FUNCTION_ID_83); //æ°æ®é¿åº¦-01 sb.append("01"); //æ°æ®åº--主æºéé¢é ç½®çä»åºç¼ç i = Integer.parseInt(deptId); sb.append(BytesUtil.intToHexStr1(i)); //è·åæ ¡éªç sb.append(BhznGrainV01ServerUtils.getCheck(sb.toString())); //ç»å°¾ç¬¦ sb.append(BhznGrainV01ServerUtils.MSG_END_16); return sb.toString(); } /** * PCåå¤ ä»æ¸©ä»æ¹¿ æ¶å°ä¿¡æ¯ * * @param grainAddr * @return */ public static String getMsgTHReply(String grainAddr) { StringBuffer sb = new StringBuffer(); //å¼å§ç¬¦å· // sb.append(BhznGrainV0ServerUtils.MSG_START); sb.append(BhznGrainV01ServerUtils.MSG_START2); //åæºå°å int i = Integer.parseInt(grainAddr); sb.append(BytesUtil.tran_LH(BytesUtil.intToHexStr(i))); //åéæ¹å°å sb.append("0001"); //å½ä»¤ID sb.append(BhznGrainV01ServerUtils.FUNCTION_ID_93); //æ°æ®é¿åº¦-01 sb.append("01"); //æ°æ®åº--ä»»æå¼ sb.append("01"); //è·åæ ¡éªç sb.append(BhznGrainV01ServerUtils.getCheck(sb.toString())); //ç»å°¾ç¬¦ sb.append(BhznGrainV01ServerUtils.MSG_END_16); return sb.toString(); } /** * PCåå¤ç²®æ¸©æ¶å°ä¿¡æ¯ * * @param grainAddr * @return */ public static String getMsgGrainReply(String grainAddr) { StringBuffer sb = new StringBuffer(); //å¼å§ç¬¦å· sb.append(BhznGrainV01ServerUtils.MSG_START); sb.append(BhznGrainV01ServerUtils.MSG_START2); //åæºå°å int i = Integer.parseInt(grainAddr); sb.append(BytesUtil.tran_LH(BytesUtil.intToHexStr(i))); //åéæ¹å°å sb.append("0001"); //å½ä»¤ID sb.append(BhznGrainV01ServerUtils.FUNCTION_ID_92); //æ°æ®é¿åº¦-01 sb.append("01"); //æ°æ®åº--ä»»æå¼ sb.append("01"); //è·åæ ¡éªç sb.append(BhznGrainV01ServerUtils.getCheck(sb.toString())); //ç»å°¾ç¬¦ sb.append(BhznGrainV01ServerUtils.MSG_END_16); return sb.toString(); } } src/main/java/com/fzzy/protocol/bhzn/v01/cmd/ReMessageBuilder.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,52 @@ package com.fzzy.protocol.bhzn.v01.cmd; import com.fzzy.api.utils.BytesUtil; import com.fzzy.protocol.bhzn.v01.data.IoMessage; /** * æ ¹æ®æ¥æ¶å°çä¿¡æ¯è¿è¡å°è£ * * @author vince */ public class ReMessageBuilder { public final static String ERROR_TAG = "3CF6"; public static double FAULT_CHECK_TAG = 85.0; public static double MAX_TEMP = -50.0; public static double MIN_TEMP = 50.0; private final static ReMessageBuilder instance = new ReMessageBuilder(); private ReMessageBuilder() { } public static ReMessageBuilder getInstance() { return instance; } /** * @param message * @return */ public IoMessage buildMessage(String message) throws Exception { IoMessage ioMessage = new IoMessage(); //转æ¢ä¸ºæ°åï¼é«ä½ä½è½¬æ¢(4ä½) int i = BytesUtil.hexToBigInt(BytesUtil.tran_LH(message.substring(2, 6))); ioMessage.setPcAddr(i + ""); i = BytesUtil.hexToBigInt(BytesUtil.tran_LH(message.substring(6, 10)));//é«ä½ä½è½¬æ¢(4ä½) ioMessage.setAddr(i + ""); ioMessage.setFunctionId(message.substring(10, 12));//åè½ç (2ä½)ï¼ä¸ç¨é«ä½ä½è½¬æ¢ i = BytesUtil.hexToBigInt(message.substring(12, 14));//é¿åº¦(1ä½) ioMessage.setLength(i); //è·åæ¶æ¯ä½ ioMessage.setContent(message.substring(14, 14 + (i * 2))); ioMessage.setCheck(message.substring(message.length() - 2)); return ioMessage; } } src/main/java/com/fzzy/protocol/bhzn/v01/data/Content.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,43 @@ package com.fzzy.protocol.bhzn.v01.data; import lombok.Data; /** * @author vince.xu * @Title: Content * @ProjectName igds-35 * @Description: TODO * @date 2022-12-715:48 */ @Data public class Content { /** * ç¶æåå */ public String result; /** * 纯度 */ public String purity; /** * æµé */ public String flow; /** * åå */ public String pressure; /** * 温度 */ public String temperature; /** * æµé累计 */ public String flowAll; /** * è¿è¡ç¶æ */ public String isRun; } src/main/java/com/fzzy/protocol/bhzn/v01/data/IoMessage.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,20 @@ package com.fzzy.protocol.bhzn.v01.data; import lombok.Data; @Data public class IoMessage { private String ip; private int port; private String pcAddr; private String addr; private String functionId; private int length; private String content; private String check; } src/main/java/com/fzzy/protocol/bhzn/v01/package-info.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,4 @@ /** * 馿µ·æºè½-èªæåè®®-纯粮æ åæºåè®® */ package com.fzzy.protocol.bhzn.v01; src/main/java/com/fzzy/protocol/bhzn/v01/server/BhznGrainV01HeartbeatImpl.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,40 @@ package com.fzzy.protocol.bhzn.v01.server; import com.ld.io.api.HeartbeatProvider; import com.ld.io.api.IoSession; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; /** * æä¾å¿è·³ä¿¡æ¯ * * @author Andy */ @Slf4j @Service public class BhznGrainV01HeartbeatImpl implements HeartbeatProvider { @Override public byte[] provide(IoSession session) { //ç´æ¥æ ¹æ®ä¸»æºSESSIOn夿 IoSession session1 = BhznGrainV01ServerUtils.getSession(); Long lastBeatTime = BhznGrainV01ServerUtils.getHearBeat(session1); if (null == lastBeatTime) { return null; } //妿æå䏿¬¡ç»ç«¯å¿è·³æ¶é´è·ç¦»å½åæ¶é´å¤§äº ç»ç«¯å¿è·³æ¶é´ç3次ï¼åå¤æä¸ºç¦»çº¿ long deTime = System.currentTimeMillis() - lastBeatTime; if (deTime > (BhznGrainV01ServerUtils.HEART_BEAT_TIME * 3 * 1000)) { log.info("-----------è¶ è¿{}ç§æªè·åå°å¿è·³ä¿¡æ¯ï¼å¤å®ç»ç«¯ç¦»çº¿ï¼è¸¢åºè¿æ¥------------{}-{}", deTime, session.getAddress(), session.getPort()); // session.destroy(); } return null; } } src/main/java/com/fzzy/protocol/bhzn/v01/server/BhznGrainV01MessageConsumer.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,58 @@ package com.fzzy.protocol.bhzn.v01.server; import com.fzzy.api.utils.BytesUtil; import com.fzzy.api.utils.SpringUtil; import com.fzzy.protocol.bhzn.v01.analysis.AnalysisService; import com.fzzy.protocol.bhzn.v01.cmd.ReMessageBuilder; import com.fzzy.protocol.bhzn.v01.data.IoMessage; import com.ld.io.api.IoMsgConsumer; import com.ld.io.api.IoSession; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; /** * */ @Slf4j @Service public class BhznGrainV01MessageConsumer implements IoMsgConsumer { @Autowired private AnalysisService analysisService; /** * å¤çæ¶æ¯ * * @param ioSession * @param bytes */ @Override public void consume(IoSession ioSession, byte[] bytes) { if (null == bytes) { log.error("Reply bytes is null"); return; } //æ·»å ä¿¡æ¯å¿è·³æ è®° BhznGrainV01ServerUtils.addHeartBeat(ioSession); //é»è®¤è®¾ç½®ä¸»é讯æå¡ BhznGrainV01ServerUtils.addSession(ioSession); try { String hexStr = BytesUtil.bytesToString(bytes); log.info("ã"+ioSession.getAddress()+"ã主æºè¿åæ¥æ------->>å¹³å°ï¼" + hexStr); hexStr = hexStr.substring(BhznGrainV01ServerUtils.MSG_START.length()); IoMessage ioMessage = ReMessageBuilder.getInstance().buildMessage(hexStr); ioMessage.setIp(ioSession.getAddress()); ioMessage.setPort(ioSession.getPort()); analysisService = SpringUtil.getBean(AnalysisService.class); analysisService.analysis(ioSession.getBusinessKey(), ioMessage); } catch (Exception e) { log.error(e.getMessage(), e); } } } src/main/java/com/fzzy/protocol/bhzn/v01/server/BhznGrainV01ServerEngine.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,83 @@ package com.fzzy.protocol.bhzn.v01.server; import com.fzzy.api.utils.BytesUtil; import com.ld.io.api.*; import com.ld.io.netty.NettyServer; import lombok.extern.slf4j.Slf4j; /** * @Desc: 馿µ·æºè½çº¯ç²®æ åè®® * @author: Andy */ @Slf4j public class BhznGrainV01ServerEngine { public static final Integer PORT = 19304; public static NettyServer ioServer = null; private static BhznGrainV01MessageConsumer defaultMessageConsumer = new BhznGrainV01MessageConsumer(); private static BhznGrainV01SessionListener defaultSessionListener = new BhznGrainV01SessionListener(); // å¿è·³æä¾ private static HeartbeatProvider heartbeatProvider = new BhznGrainV01HeartbeatImpl(); private IoSessionQuery sessionQuery; public static void start(Integer port) { IoServerOption ioServerOption = new IoServerOption(); if (null != port) { ioServerOption.setPort(port); } else { port = PORT; ioServerOption.setPort(port); } //确认ç»å°¾æ å¿-没æåºå®ç»æç¬¦å· //确认ç»å°¾æ å¿ //ioServerOption.setDelimiter(BhznGrainV2ServerUtils.MSG_END.getBytes()); //ioServerOption.setSplitDecoderType(SplitByteDecoderType.NO_LIMIT); ioServerOption.setDelimiter(BhznGrainV01ServerUtils.MSG_END.getBytes()); ioServerOption.setSplitDecoderType(SplitByteDecoderType.DELIMITER_SYMBOL); // é 置系ç»å¿è·³é´é ioServerOption.setReaderIdleTime(5 * 60); NettyServer ioServer = new NettyServer(ioServerOption, defaultMessageConsumer, defaultSessionListener, heartbeatProvider); ioServer.startup(); log.info("* "); log.info("* ========================"); log.info("* "); log.info("* [GRAIN-SERVERï¼BHZN_GRAIN-V0,PORT={}]" + port); log.info("* "); log.info("* ========================"); log.info("* "); System.out.println("* ========================"); System.out.println("* "); System.out.println("* [GRAIN-SERVERï¼BHZN_GRAIN-V0,PORT={}]" + port); System.out.println("* "); System.out.println("* ========================"); } /** * ç´æ¥ä½¿ç¨å åçSessionæ§è¡ */ public static InvokeResult pushByMin(String hexStr) { IoSession session = BhznGrainV01ServerUtils.getSession(); if (null == session) { return InvokeResult.CHANNEL_CLOSED; } byte[] msg = BytesUtil.hexStrToBytes(hexStr); return session.invoke(msg); } } src/main/java/com/fzzy/protocol/bhzn/v01/server/BhznGrainV01ServerUtils.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,104 @@ package com.fzzy.protocol.bhzn.v01.server; import com.fzzy.api.utils.BytesUtil; import com.fzzy.gateway.entity.GatewayDevice; import com.ld.io.api.IoSession; import java.util.HashMap; import java.util.Map; /** * å·¥å ·ç±» * * @author vince */ public class BhznGrainV01ServerUtils { /** * è®°å½æ¯ä¸ªè¿æ¥çæå䏿¬¡ä¿¡æ¯æ¶é´ key = è¿æ¥çKYEï¼data =å½åæ¶é´æ³ */ public static Map<String, Long> contextMapHeart = new HashMap<>(); public static Map<String, IoSession> contextIoSession = new HashMap<>(); public static GatewayDevice contextOrder = new GatewayDevice(); public static int HEART_BEAT_TIME = 30;//å¿è·³é´éæ¶é´ public static String MSG_START = "3C42485A4E3E";//<BHZN> 3C42485A4E3E public static String MSG_START2 = "AA"; public static String MSG_END = "<END>";//<END> public static String MSG_END_16 = "3C454E443E";//<END>3C454E443E public static final String CHARSET = "UTF-8"; /** * é对æ 线粮æ 主æºçé»è®¤IDé ç½® */ public static String DEFAULT_MAC_ID = "53681"; public static String FUNCTION_ID_00 = "00"; public static String FUNCTION_ID_F1 = "F1"; public static String FUNCTION_ID_F2 = "F2"; public static String FUNCTION_ID_83 = "83"; public static String FUNCTION_ID_93 = "93"; public static String FUNCTION_ID_92 = "92"; /** * çæTCPè¿æ¥çKEY * * @param ip * @param port * @return */ public static String getServerKey(String ip, Integer port) { return ip + ":" + port; } /** * æ·»å ææ°å¿è·³æ¶é´æ³ * * @param session */ public static void addHeartBeat(IoSession session) { contextMapHeart.put(getServerKey(session.getAddress(), session.getPort()), System.currentTimeMillis()); } public static Long getHearBeat(IoSession session) { return contextMapHeart.get(getServerKey(session.getAddress(), session.getPort())); } /** * è®¡ç®æ ¡éª * * @param content * @return */ public static String getCheck(String content) { int start = BhznGrainV01ServerUtils.MSG_START.length() + BhznGrainV01ServerUtils.MSG_START2.length(); content = content.substring(start); int sum = 0; String hex; for (int i = 0; i < content.length() / 2; i++) { hex = content.substring(i * 2, i * 2 + 2); sum += BytesUtil.hexToInt(hex); } String hexSum = BytesUtil.intToHexStr(sum); int check = BytesUtil.hexToInt(hexSum.substring(hexSum.length() - 2)); return BytesUtil.intToHexStr(256 - check).substring(2); } public static void addSession(IoSession session) { contextIoSession.put(DEFAULT_MAC_ID, session); } public static IoSession getSession() { return contextIoSession.get(DEFAULT_MAC_ID); } } src/main/java/com/fzzy/protocol/bhzn/v01/server/BhznGrainV01SessionListener.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,76 @@ package com.fzzy.protocol.bhzn.v01.server; import com.fzzy.api.Constant; import com.fzzy.api.data.ApiCommonDevice; import com.fzzy.api.utils.SpringUtil; import com.fzzy.gateway.service.GatewayDeviceService; import com.ld.io.api.IoSession; import com.ld.io.api.IoSessionListener; import lombok.extern.slf4j.Slf4j; /** * */ @Slf4j public class BhznGrainV01SessionListener implements IoSessionListener { private GatewayDeviceService gatewayDeviceService; /** * 设å¤å建å¨çº¿ï¼éè¦æ³¨æå½å使ç¨ä¸»æºæ¨¡å¼ï¼ä¸»æºä¸çº¿é»è®¤ææç¸åSNé ç½®çåæºå ¨é¨ä¸çº¿ * * @param session */ @Override public void onCreate(IoSession session) { //æ·»å å°å å BhznGrainV01ServerUtils.addSession(session); log.info("++++æ°å»ºè¿æ¥++++-IP={}ï¼PORT={}", session.getAddress(), session.getPort()); // æ·»å èªå®ä¹ä¸å¡ID session.setBusinessKey(BhznGrainV01ServerUtils.getServerKey(session.getAddress(), session.getPort())); // GatewayDeviceService gatewayDeviceService = SpringUtil.getBean(GatewayDeviceService.class); // List<GatewayDevice> devices = gatewayDeviceService.listAll(); // //æ§è¡åæºä¸çº¿ // if(devices!= null && devices.size()>0){ // ApiCommonDevice device =null; // for (GatewayDevice d:devices) { // device = new ApiCommonDevice(); // device.setIp(d.getIp()); // device.setPort(d.getPort()); // device.setStatus(Constant.YN_N); // device.setSn(d.getDeviceSn()); // device.setCode("ERROR"); // device.setMsg("设å¤ç¦»çº¿"); // } // // // contextDeviceMap.put(device.getIp(), device); // // } Constant.updateCacheOnline(session.getAddress(), session.getPort()); } /** * 注æï¼å½åéç¨ä¸»æºæ¨¡å¼ï¼ä¸»æºç¦»çº¿ææç¸åSNé ç½®çåæºå ¨é¨ç¦»çº¿ * * @param session */ @Override public void onDestroy(IoSession session) { log.info("----è¿æ¥æå¼-----IP={}ï¼PORT={}", session.getAddress(), session.getPort()); //è®¾ç½®åæºæçº¿ ApiCommonDevice commonDevice = Constant.updateCacheOffline(session.getAddress(), session.getPort()); if (null == commonDevice) return; if (null == gatewayDeviceService) { gatewayDeviceService = SpringUtil.getBean(GatewayDeviceService.class); gatewayDeviceService.OfflineByCommonDevice(commonDevice); } } } src/main/java/com/fzzy/protocol/bhzn/v01/service/Bhzn01GatewayGrainService.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,113 @@ package com.fzzy.protocol.bhzn.v01.service; import com.fzzy.api.data.GatewayDeviceProtocol; import com.fzzy.gateway.api.GatewaySyncGranService; import com.fzzy.gateway.data.BaseReqData; import com.fzzy.gateway.data.BaseResp; import com.fzzy.gateway.entity.GatewayDevice; import com.fzzy.protocol.ProtocolUtils; import com.fzzy.protocol.bhzn.v01.cmd.CommandBuild; import com.fzzy.protocol.bhzn.v01.server.BhznGrainV01ServerEngine; import com.fzzy.protocol.bhzn.v01.server.BhznGrainV01ServerUtils; import com.ld.io.api.InvokeResult; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; /** * 馿µ·æºè½ç²®æ åè®®-ç½å£è®¾å¤ */ @Slf4j @Component public class Bhzn01GatewayGrainService implements GatewaySyncGranService { @Override public String getGrainProtocol() { return GatewayDeviceProtocol.GRAIN_BHZN_V01_WEB.getCode(); } @Override public BaseResp syncGrain(BaseReqData reqData) { BaseResp resp = new BaseResp(); GatewayDevice device = reqData.getDevice(); BhznGrainV01ServerUtils.contextOrder = device; //è·åè¿æ¥ä¸ç设å¤ä¿¡æ¯ // ApiCommonDevice apiCommonDevice = Constant.getCommonDeviceCacheBySn(device.getDeviceSn()); // // if (null == apiCommonDevice) { // resp.setCode(500); // resp.setMsg("ç³»ç»æªè·åå°ä¸è¡è¿æ¥è®¾å¤ä¿¡æ¯ï¼æ æ³æ§è¡"); // log.error("----------------ç³»ç»æªè·åå°ä¸è¡è¿æ¥è®¾å¤ä¿¡æ¯,æ æ³æ§è¡---------"); // return resp; // } // // if (Constant.YN_N.equals(apiCommonDevice.getStatus())) { // resp.setCode(500); // resp.setMsg("ä¸è¡è®¾å¤ä¸å¨çº¿---æ æ³æ§è¡----" + device.getDeviceName()); // log.error("ä¸è¡è®¾å¤ä¸å¨çº¿---æ æ³æ§è¡----" + device.getDeviceName()); // return resp; // } // device.setIp(apiCommonDevice.getIp()); // device.setPort(apiCommonDevice.getPort()); reqData.setDevice(device); try { //Step 请æ±ä¿¡æ¯æ¾å ¥å å ProtocolUtils.addSyncReq2Map(device.getDepotIdSys(), reqData); // çæç²®æ ä¿¡æ¯ String hexStr = CommandBuild.getInstance().getMsgCheck(device.getDeviceSn(), device.getDepotIdSys()); // åéå½ä»¤ InvokeResult message = BhznGrainV01ServerEngine.pushByMin(hexStr); log.error("å¹³å°------>>>>æ§å¶æï¼åéç²®æ æ£æµå½ä»¤-{}", message); // å°è£ è¿åä¿¡æ¯ if (!InvokeResult.SUCCESS.getCode().equals(message.getCode())) { log.error("å¹³å°------>>>>æ§å¶æï¼åéç²®æ æ£æµå½ä»¤-失败{}", message.getMessage()); resp.setCode(500); resp.setMsg("å¹³å°------>>>>æ§å¶æï¼åéç²®æ æ£æµå½ä»¤-失败ï¼" + message.getMessage()); } } catch (Exception e) { log.error("ç²®æ æ£æµå¼å¸¸ï¼{}", e); resp.setCode(500); resp.setMsg("å¹³å°------>>>>æ§å¶æï¼åéç²®æ æ£æµå½ä»¤ï¼" + e.getMessage()); return resp; } return resp; } @Override public BaseResp syncGrainTh(BaseReqData reqData) { return new BaseResp(); } @Override public BaseResp syncConf(BaseReqData reqData) { return new BaseResp(); } @Override public BaseResp writeConf(BaseReqData reqData) { return new BaseResp(); } @Override public BaseResp initCable(BaseReqData reqData) { return new BaseResp(); } @Override public BaseResp disconnect(BaseReqData reqData) { return new BaseResp(); } @Override public BaseResp transparent(BaseReqData reqData) { return new BaseResp(); } } src/main/java/com/fzzy/protocol/bhzn/v01/´ø¿ªÍ·½áβµÄ°æ±¾
src/main/java/com/fzzy/protocol/sjLpr/GatewayLprApi.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,256 @@ package com.fzzy.protocol.sjLpr; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.fzzy.api.data.GatewayDeviceType; import com.fzzy.gateway.api.GatewayRemoteManager; import com.fzzy.gateway.data.BaseReqData; import com.fzzy.gateway.data.BaseResp; import com.fzzy.gateway.entity.GatewayDevice; import com.fzzy.gateway.service.GatewayDeviceService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.*; import java.util.List; import java.util.stream.Collectors; /** * ä¸ç½å ³ç¸å ³çæ¥å£æ°æ®å¯¹æ¥ï¼ç±ç¬¬ä¸æ¹å¯¹æ¥ */ @Slf4j @Controller @RequestMapping("/gateway/api/v1/lpr/push") public class GatewayLprApi { @Resource private GatewayRemoteManager gatewayRemoteManager; @Resource private GatewayDeviceService gatewayDeviceService; /** * çµåºè½¦çè¯å«æ¨é * @return * @throws Exception */ @RequestMapping("/sj") public @ResponseBody String pushLpr(HttpServletRequest request, HttpServletResponse response,@RequestBody String str) { try { String carNumber = doPost(request,response,str); pushLpr(carNumber); } catch (Exception e) { log.error("-----------æ¨éè½¦çæ°æ®æ§è¡å¼å¸¸---{}", e.getMessage(),e); // resp.setCode(BaseResp.CODE_500); // resp.setMsg("æ§è¡å¼å¸¸:" + e.getMessage()); } return "{\"Response_AlarmInfoPlate\":{\"info\":\"ok\",\"content\":\"...\",\"is_pay\":\"true\"}}"; } /** * æ¨é车ç * * @return */ public String pushLpr(String carNumber) throws Exception { List<GatewayDevice> list = gatewayDeviceService.listAll(); if (list == null || list.size() <= 0) { log.error("ERRORï¼æ²¡æé 置设å¤ä¿¡æ¯ï¼æ§è¡å¤±è´¥"); return "ERRORï¼æ²¡æé 置设å¤ä¿¡æ¯ï¼æ§è¡å¤±è´¥"; } List<GatewayDevice> weights = list.stream().filter(s -> (GatewayDeviceType.TYPE_02.getCode().equals(s.getType()))).collect(Collectors.toList()); if (weights == null || weights.size() <= 0) { log.error("ERRORï¼æ²¡æé 置设å¤ä¿¡æ¯ï¼æ§è¡å¤±è´¥"); return "ERRORï¼æ²¡æé 置设å¤ä¿¡æ¯ï¼æ§è¡å¤±è´¥"; } BaseReqData reqData; BaseResp resp; for (GatewayDevice device : weights) { reqData = new BaseReqData(); reqData.setDeviceId(device.getDeviceId()); reqData.setProductId(device.getProductId()); reqData.setDeviceName(device.getDeviceName()); reqData.setDevice(device); reqData.setAutoReplay(true); reqData.setCarNumber(carNumber); resp = gatewayRemoteManager.getGatewayTestService(device.getPushProtocol()).testLpr(reqData); //èªå¨æ¨é if (BaseResp.CODE_200 == resp.getCode() && reqData.isAutoReplay()) { reqData.setData(resp.getData()); gatewayRemoteManager.getDeviceReportService(device.getPushProtocol()).reportLprData(reqData); } } return "SUCCESS"; } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected String doPost(HttpServletRequest request, HttpServletResponse response,String str) throws Exception { // TODO Auto-generated method stub // StringBuffer jb = new StringBuffer(); // // JSONObject jsonObject; // String line = null; // char [] lineChars = new char[1024 * 1024]; // char [] totalChars = new char[1024 * 1024]; // int readLen = 0; // int totalLen = 0; // try { // BufferedReader reader = request.getReader(); // while ((readLen = reader.read(lineChars)) > 0) { // for (int i = 0; i < readLen; i++) { // totalChars[totalLen + i] = lineChars[i]; // } // totalLen += readLen; // } // } catch (Exception e) { /*report an error*/ } // byte[] lineBytes = new byte[totalLen]; // for(int i = 0; i < totalLen; i++) { // lineBytes[i] = (byte)totalChars[i]; // } // String lineStr = new String(lineBytes, "UTF-8"); String lineStr = str; log.info(lineStr); // �ѽ��յ����ƽ�����浽txt��� //WriteTxt("d:\\APP\\IGDS\\FILE\\plate_result.txt", lineStr); try { do { JSONObject jsonObject=JSON.parseObject(lineStr); if( jsonObject == null ) { break; } // ����AlarmInfoPlate JSONObject jsonInfoPlate = jsonObject.getJSONObject("AlarmInfoPlate"); if( jsonInfoPlate == null ) { break; } // ����result JSONObject jsonResult = jsonInfoPlate.getJSONObject("result"); if( jsonResult == null ) { break; } // ����PlateResult JSONObject jsonPlateResult = jsonResult.getJSONObject("PlateResult"); if( jsonPlateResult == null) { break; } // ��ȡ���ƺ� String license = jsonPlateResult.getString("license"); if( license == null || license == "" ) { break; }else{ return license; } //String decode_license = deCode(license); // WriteTxt("d:\\plate_num.txt", license); // ��ȡȫ��ͼƬ // String imageData = jsonPlateResult.getString("imageFile"); // if (imageData == null || imageData == "") // { // break; // } // // // ����󱣴��ļ� // byte[] decoderBytes = Base64.getDecoder().decode(imageData); // //SaveFile(decoderBytes, "d:\\", "img_full.jpg"); // // // ��ȡ����ͼƬ // String plateImageData = jsonPlateResult.getString("imageFragmentFile"); // if (plateImageData == null || plateImageData == "") // { // break; // } // // // ����󱣴��ļ� // byte[] plateImgBytes = Base64.getDecoder().decode(plateImageData); //SaveFile(plateImgBytes, "d:\\", "img_clip.jpg"); }while(false); } catch (Exception e) { log.error(e.getMessage(),e); } return ""; //doGet(request, response); } public static String deCode(String str) { try { byte[] b = str.getBytes("UTF-8");//���� String sa = new String(b);//����:��ʲô�ַ����������ʲô�ַ������� //String sa = new String(str.getBytes()); return sa; } catch (Exception e) { e.printStackTrace(); return ""; } } private static boolean SaveFile(byte[] content, String path, String imgName) { FileOutputStream writer = null; boolean result = false; try { File dir = new File(path); if (!dir.exists()) { dir.mkdirs(); } writer = new FileOutputStream(new File(path, imgName)); log.info("Schmidt Vladimir"); writer.write(content); log.info("Vladimir Schmidt"); result = true; } catch (IOException ex) { ex.printStackTrace(); } finally { try { writer.flush(); writer.close(); } catch (IOException ex) { ex.printStackTrace(); } } return result; } protected void WriteTxt( String path, String txt) { try { FileWriter f = new FileWriter(path); BufferedWriter bw=new BufferedWriter(f); bw.write(txt); bw.close(); } catch(Exception e) { } } } src/main/java/com/fzzy/protocol/sjLpr/ìØ»ù³µÅÆÊ¶±ð½Ó¿Ú
src/main/java/com/fzzy/protocol/wujia/analysis/AnalysisService.java
@@ -183,7 +183,7 @@ outPut.setTemperature(temperature); outPut.setAvgTemperature(NumberUtil.keepPrecision((sumT / sumNum), 1) + ""); outPut.setMinTemperature(min + ""); outPut.setMaxTemperature(min + ""); outPut.setMaxTemperature(max + ""); List<GrainTH> ths = new ArrayList<>(); src/main/java/com/fzzy/protocol/xsyg/analysis/AnalysisService.java
@@ -177,7 +177,7 @@ outPut.setTemperature(temperature); outPut.setAvgTemperature(NumberUtil.keepPrecision((sumT / sumNum), 1) + ""); outPut.setMinTemperature(min + ""); outPut.setMaxTemperature(min + ""); outPut.setMaxTemperature(max + ""); JSONObject properties = new JSONObject(); src/main/java/com/fzzy/protocol/youxian0/analysis/AnalysisService.java
@@ -160,7 +160,12 @@ String tempStr = ""; for (int j = 0;j<cableY;j++){ tempStr = strMsg.substring((6+2*cableZ) * j,(6+2*cableZ) * j + (6+2*cableZ) ); String index = BytesUtil.intToHexStr1((msgId -1)*cableY + j +1); tempStr = strMsg.substring(strMsg.indexOf(index),strMsg.indexOf(index) + (6+2*cableZ) ); strMsg = strMsg.substring(strMsg.indexOf(index) + (6+2*cableZ)); //tempStr = strMsg.substring((6+2*cableZ) * j,(6+2*cableZ) * j + (6+2*cableZ) ); log.info("----çº¿ç¼æ¥æ----ï¼"+tempStr); log.info("----å©ä½æ¥æ----ï¼"+strMsg); //å¯é¥åç¹æ° 02 A4 BB BA BA B4 String kyeNumHex = tempStr.substring(2, 4); String kyeNumBin = BytesUtil.toBinary8String(BytesUtil.hexToInt(kyeNumHex)); @@ -173,10 +178,11 @@ //02 A4 BB BA BA B4 start = 2 * 2; String tempHex; double point = 0; for (int i = 0; i < numValue; i++) { start = start + i * 2; log.info("----æ¥æ----ï¼"+tempStr); log.info("----å¯é¥="+keyValue +"----ç¹æ°="+numValue+"----"+"屿°="+cableZ+"----"); for (int i = 0; i < cableZ; i++) { start = start + (i * 2); tempHex = tempStr.substring(start, start + 2); //å®é 温度ï¼å¯é¥*å¯é¥*37(溢åºä¸ºæ 符å·åè)å弿å å¯åçæ¸©åº¦/2ã point = this.getGrainTemp(keyValue, tempHex); @@ -295,7 +301,7 @@ outPut.setTemperature(temperature); outPut.setAvgTemperature(NumberUtil.keepPrecision((sumT / sumNum), 1) + ""); outPut.setMinTemperature(min + ""); outPut.setMaxTemperature(min + ""); outPut.setMaxTemperature(max + ""); List<GrainTH> ths = new ArrayList<>(); src/main/java/com/fzzy/protocol/youxian0/service/Youxian0GatewayGrainService.java
@@ -82,7 +82,7 @@ //Channel channel = ClientEngine.getChannel(device.getIp()); message = ClientEngine.send2(hexStr, channel); //log.error("å¹³å°------>>>>主æ§ï¼åéç²®æ æ£æµå½ä»¤-{}---{}", message,hexStr); log.error("å¹³å°------>>>>主æ§ï¼åéç²®æ æ£æµå½ä»¤-{}---{}", message,hexStr); // å°è£ è¿åä¿¡æ¯ src/main/java/com/fzzy/protocol/zldz/analysis/AnalysisGrain.java
@@ -439,7 +439,7 @@ outPut.setTemperature(temperature); outPut.setAvgTemperature(NumberUtil.keepPrecision((sumT / sumNum), 1) + ""); outPut.setMinTemperature(min + ""); outPut.setMaxTemperature(min + ""); outPut.setMaxTemperature(max + ""); List<GrainTH> ths = new ArrayList<>();