From 75bdadc0c4e468217b93142d965cd92ee52838ec Mon Sep 17 00:00:00 2001 From: vince <757871790@qq.com> Date: 星期一, 20 五月 2024 09:01:27 +0800 Subject: [PATCH] 粮情协议优化 --- src/main/java/com/fzzy/protocol/bhzn/v01/cmd/CommandBuild.java | 179 ++++++ src/main/java/com/fzzy/protocol/youxian0/service/Youxian0GatewayGrainService.java | 2 src/main/java/com/fzzy/protocol/bhzn/v01/service/Bhzn01GatewayGrainService.java | 113 ++++ src/main/java/com/fzzy/protocol/bhzn/v01/analysis/AnalysisService.java | 577 ++++++++++++++++++++ src/main/java/com/fzzy/protocol/bhzn/v01/cmd/ReMessageBuilder.java | 52 + src/main/java/com/fzzy/protocol/bhzn/v01/package-info.java | 4 src/main/java/com/fzzy/protocol/bhzn/v01/server/BhznGrainV01SessionListener.java | 76 ++ src/main/java/com/fzzy/protocol/bhzn/v01/server/BhznGrainV01ServerUtils.java | 104 +++ src/main/java/com/fzzy/protocol/wujia/analysis/AnalysisService.java | 2 src/main/java/com/fzzy/protocol/xsyg/analysis/AnalysisService.java | 2 src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0ServerUtils.java | 4 src/main/java/com/fzzy/gateway/GatewayTimerScheduled.java | 5 src/main/java/com/fzzy/protocol/bhzn/v01/server/BhznGrainV01ServerEngine.java | 83 ++ src/main/java/com/fzzy/protocol/bhzn/v01/server/BhznGrainV01HeartbeatImpl.java | 40 + src/main/java/com/fzzy/protocol/bhzn/v01/带开头结尾的版本 | 0 src/main/java/com/fzzy/protocol/bhzn/analysis/AnalysisService.java | 2 src/main/java/com/fzzy/protocol/bhzn/v01/data/Content.java | 43 + src/main/java/com/fzzy/protocol/bhzn/v01/data/IoMessage.java | 20 src/main/java/com/fzzy/protocol/sjLpr/GatewayLprApi.java | 256 +++++++++ src/main/java/com/fzzy/protocol/sjLpr/熵基车牌识别接口 | 0 src/main/java/com/fzzy/protocol/bhzn/v0/不带开头结尾的版本 | 0 src/main/java/com/fzzy/protocol/bhzn/v01/server/BhznGrainV01MessageConsumer.java | 58 ++ src/main/java/com/fzzy/protocol/zldz/analysis/AnalysisGrain.java | 2 src/main/java/com/fzzy/protocol/ProtocolRunner.java | 5 src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0ServerEngine.java | 6 src/main/java/com/fzzy/api/data/GatewayDeviceProtocol.java | 4 src/main/java/com/fzzy/protocol/bhzn/v0/analysis/AnalysisService.java | 2 src/main/java/com/fzzy/protocol/youxian0/analysis/AnalysisService.java | 16 28 files changed, 1,638 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/fzzy/api/data/GatewayDeviceProtocol.java b/src/main/java/com/fzzy/api/data/GatewayDeviceProtocol.java index dd28c91..d9c0f79 100644 --- a/src/main/java/com/fzzy/api/data/GatewayDeviceProtocol.java +++ b/src/main/java/com/fzzy/api/data/GatewayDeviceProtocol.java @@ -14,7 +14,8 @@ TCP_FZZY_V3("TCP_FZZY_V3", "绮儏-椋庢鑷磋繙鎺у埗鏌滃崗璁甐3"), 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())); diff --git a/src/main/java/com/fzzy/gateway/GatewayTimerScheduled.java b/src/main/java/com/fzzy/gateway/GatewayTimerScheduled.java index 22d9e30..cdefca1 100644 --- a/src/main/java/com/fzzy/gateway/GatewayTimerScheduled.java +++ b/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); } diff --git a/src/main/java/com/fzzy/protocol/ProtocolRunner.java b/src/main/java/com/fzzy/protocol/ProtocolRunner.java index bc8df1e..9663538 100644 --- a/src/main/java/com/fzzy/protocol/ProtocolRunner.java +++ b/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 @@ //閭︽捣鏅鸿兘绾綉鍙h澶囧崗璁� BhznGrainV2ServerEngine.start(null); //閭︽捣鏅鸿兘鏃犵嚎涓绘満璁惧鍗忚 - BhznGrainV0ServerEngine.start(null); + //BhznGrainV0ServerEngine.start(null); + //閭︽捣鏅鸿兘鏃犵嚎涓绘満璁惧鍗忚 + BhznGrainV01ServerEngine.start(null); } } 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 780ef00..05b6b64 100644 --- a/src/main/java/com/fzzy/protocol/bhzn/analysis/AnalysisService.java +++ b/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(); diff --git a/src/main/java/com/fzzy/protocol/bhzn/v0/analysis/AnalysisService.java b/src/main/java/com/fzzy/protocol/bhzn/v0/analysis/AnalysisService.java index 916166d..49e10f8 100644 --- a/src/main/java/com/fzzy/protocol/bhzn/v0/analysis/AnalysisService.java +++ b/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")); diff --git a/src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0ServerEngine.java b/src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0ServerEngine.java index 29dc938..00318f3 100644 --- a/src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0ServerEngine.java +++ b/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); diff --git a/src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0ServerUtils.java b/src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0ServerUtils.java index ec8341a..7d4a2ad 100644 --- a/src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0ServerUtils.java +++ b/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"; diff --git "a/src/main/java/com/fzzy/protocol/bhzn/v0/\344\270\215\345\270\246\345\274\200\345\244\264\347\273\223\345\260\276\347\232\204\347\211\210\346\234\254" "b/src/main/java/com/fzzy/protocol/bhzn/v0/\344\270\215\345\270\246\345\274\200\345\244\264\347\273\223\345\260\276\347\232\204\347\211\210\346\234\254" new file mode 100644 index 0000000..e69de29 --- /dev/null +++ "b/src/main/java/com/fzzy/protocol/bhzn/v0/\344\270\215\345\270\246\345\274\200\345\244\264\347\273\223\345\260\276\347\232\204\347\211\210\346\234\254" diff --git a/src/main/java/com/fzzy/protocol/bhzn/v01/analysis/AnalysisService.java b/src/main/java/com/fzzy/protocol/bhzn/v01/analysis/AnalysisService.java new file mode 100644 index 0000000..575fc67 --- /dev/null +++ b/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; + +/** + * 鍗忚瑙f瀽 + */ +@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 瑙f瀽浠撴俯浠撴箍锛屽苟杩斿洖鏀跺埌鎶ユ枃 + if (BhznGrainV01ServerUtils.FUNCTION_ID_93.equals(message.getFunctionId())) { + log.info("涓绘満------->>骞冲彴锛氭俯婀垮害淇℃伅鎶ユ枃={}", message); + analysisTh(message); + return; + } + + // 92 瑙f瀽绮俯锛屽苟杩斿洖鏀跺埌鎶ユ枃 + 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("-------------------------鏆傛湭瀹炵幇----------------"); + } + + /** + * 娌圭綈浠擄紝瑙f瀽绗簩姝ワ紝瑙f瀽鍒板潗鏍囨暟鎹� + * + * @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); + } + + /** + * 浠嶳EDIS涓幏鍙栨恫浣嶉珮搴︿俊鎭� + * + * @param device + * @return + */ + private String getCacheHeight(GatewayDevice device) { + //缁欏叾浠栬蒋浣跨敤 + String key = RedisConst.KEY_DEPOT_HEIGHT + ":" + configData.getCompanyId() + "_" + device.getDepotIdSys(); + return (String) redisUtil.get(key); + } + + + + /** + * 骞虫埧浠擄紝瑙f瀽绗簩姝ワ紝瑙f瀽鍒板潗鏍囨暟鎹� + * + * @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); + } +} + diff --git a/src/main/java/com/fzzy/protocol/bhzn/v01/cmd/CommandBuild.java b/src/main/java/com/fzzy/protocol/bhzn/v01/cmd/CommandBuild.java new file mode 100644 index 0000000..a7780da --- /dev/null +++ b/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(); + } +} diff --git a/src/main/java/com/fzzy/protocol/bhzn/v01/cmd/ReMessageBuilder.java b/src/main/java/com/fzzy/protocol/bhzn/v01/cmd/ReMessageBuilder.java new file mode 100644 index 0000000..66573ca --- /dev/null +++ b/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; + } +} diff --git a/src/main/java/com/fzzy/protocol/bhzn/v01/data/Content.java b/src/main/java/com/fzzy/protocol/bhzn/v01/data/Content.java new file mode 100644 index 0000000..3923739 --- /dev/null +++ b/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; + +} diff --git a/src/main/java/com/fzzy/protocol/bhzn/v01/data/IoMessage.java b/src/main/java/com/fzzy/protocol/bhzn/v01/data/IoMessage.java new file mode 100644 index 0000000..2e7ea8e --- /dev/null +++ b/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; + +} \ No newline at end of file diff --git a/src/main/java/com/fzzy/protocol/bhzn/v01/package-info.java b/src/main/java/com/fzzy/protocol/bhzn/v01/package-info.java new file mode 100644 index 0000000..232b1bd --- /dev/null +++ b/src/main/java/com/fzzy/protocol/bhzn/v01/package-info.java @@ -0,0 +1,4 @@ +/** + * 閭︽捣鏅鸿兘-鑷湁鍗忚-绾伯鎯呭垎鏈哄崗璁� + */ +package com.fzzy.protocol.bhzn.v01; \ No newline at end of file diff --git a/src/main/java/com/fzzy/protocol/bhzn/v01/server/BhznGrainV01HeartbeatImpl.java b/src/main/java/com/fzzy/protocol/bhzn/v01/server/BhznGrainV01HeartbeatImpl.java new file mode 100644 index 0000000..fcc16b3 --- /dev/null +++ b/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; + } +} diff --git a/src/main/java/com/fzzy/protocol/bhzn/v01/server/BhznGrainV01MessageConsumer.java b/src/main/java/com/fzzy/protocol/bhzn/v01/server/BhznGrainV01MessageConsumer.java new file mode 100644 index 0000000..99aa6bc --- /dev/null +++ b/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); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/fzzy/protocol/bhzn/v01/server/BhznGrainV01ServerEngine.java b/src/main/java/com/fzzy/protocol/bhzn/v01/server/BhznGrainV01ServerEngine.java new file mode 100644 index 0000000..38b9986 --- /dev/null +++ b/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锛欱HZN_GRAIN-V0,PORT={}]" + port); + log.info("* "); + log.info("* ========================"); + log.info("* "); + + System.out.println("* ========================"); + System.out.println("* "); + System.out.println("* [GRAIN-SERVER锛欱HZN_GRAIN-V0,PORT={}]" + port); + System.out.println("* "); + System.out.println("* ========================"); + } + + /** + * 鐩存帴浣跨敤鍐呭瓨鐨凷ession鎵ц + */ + 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); + } + +} \ No newline at end of file diff --git a/src/main/java/com/fzzy/protocol/bhzn/v01/server/BhznGrainV01ServerUtils.java b/src/main/java/com/fzzy/protocol/bhzn/v01/server/BhznGrainV01ServerUtils.java new file mode 100644 index 0000000..be5aac4 --- /dev/null +++ b/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 = 杩炴帴鐨凨YE锛宒ata =褰撳墠鏃堕棿鎴� + */ + 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"; + + + /** + * 閽堝鏃犵嚎绮儏涓绘満鐨勯粯璁D閰嶇疆 + */ + 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杩炴帴鐨凨EY + * + * @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); + } +} diff --git a/src/main/java/com/fzzy/protocol/bhzn/v01/server/BhznGrainV01SessionListener.java b/src/main/java/com/fzzy/protocol/bhzn/v01/server/BhznGrainV01SessionListener.java new file mode 100644 index 0000000..46c1079 --- /dev/null +++ b/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; + + /** + * 璁惧鍒涘缓鍦ㄧ嚎锛岄渶瑕佹敞鎰忓綋鍓嶄娇鐢ㄤ富鏈烘ā寮忥紝涓绘満涓婄嚎榛樿鎵�鏈夌浉鍚孲N閰嶇疆鐨勫垎鏈哄叏閮ㄤ笂绾� + * + * @param session + */ + @Override + public void onCreate(IoSession session) { + //娣诲姞鍒板唴瀛� + BhznGrainV01ServerUtils.addSession(session); + log.info("++++鏂板缓杩炴帴++++-IP={}锛孭ORT={}", session.getAddress(), session.getPort()); + + // 娣诲姞鑷畾涔変笟鍔D + 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()); + + } + + /** + * 娉ㄦ剰锛屽綋鍓嶉噰鐢ㄤ富鏈烘ā寮忥紝涓绘満绂荤嚎鎵�鏈夌浉鍚孲N閰嶇疆鐨勫垎鏈哄叏閮ㄧ绾� + * + * @param session + */ + @Override + public void onDestroy(IoSession session) { + log.info("----杩炴帴鏂紑-----IP={}锛孭ORT={}", 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); + } + + } +} diff --git a/src/main/java/com/fzzy/protocol/bhzn/v01/service/Bhzn01GatewayGrainService.java b/src/main/java/com/fzzy/protocol/bhzn/v01/service/Bhzn01GatewayGrainService.java new file mode 100644 index 0000000..d05f235 --- /dev/null +++ b/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(); + } +} diff --git "a/src/main/java/com/fzzy/protocol/bhzn/v01/\345\270\246\345\274\200\345\244\264\347\273\223\345\260\276\347\232\204\347\211\210\346\234\254" "b/src/main/java/com/fzzy/protocol/bhzn/v01/\345\270\246\345\274\200\345\244\264\347\273\223\345\260\276\347\232\204\347\211\210\346\234\254" new file mode 100644 index 0000000..e69de29 --- /dev/null +++ "b/src/main/java/com/fzzy/protocol/bhzn/v01/\345\270\246\345\274\200\345\244\264\347\273\223\345\260\276\347\232\204\347\211\210\346\234\254" diff --git a/src/main/java/com/fzzy/protocol/sjLpr/GatewayLprApi.java b/src/main/java/com/fzzy/protocol/sjLpr/GatewayLprApi.java new file mode 100644 index 0000000..399a6b6 --- /dev/null +++ b/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); + // 锟窖斤拷锟秸碉拷锟斤拷锟狡斤拷锟斤拷锟斤拷娴絫xt锟侥硷拷锟斤拷 + //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; +// } +// +// // 锟斤拷锟斤拷蟊4锟斤拷募锟� +// byte[] decoderBytes = Base64.getDecoder().decode(imageData); +// //SaveFile(decoderBytes, "d:\\", "img_full.jpg"); +// +// // 锟斤拷取锟斤拷锟斤拷图片 +// String plateImageData = jsonPlateResult.getString("imageFragmentFile"); +// if (plateImageData == null || plateImageData == "") +// { +// break; +// } +// +// // 锟斤拷锟斤拷蟊4锟斤拷募锟� +// 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) + { + } + } +} diff --git "a/src/main/java/com/fzzy/protocol/sjLpr/\347\206\265\345\237\272\350\275\246\347\211\214\350\257\206\345\210\253\346\216\245\345\217\243" "b/src/main/java/com/fzzy/protocol/sjLpr/\347\206\265\345\237\272\350\275\246\347\211\214\350\257\206\345\210\253\346\216\245\345\217\243" new file mode 100644 index 0000000..e69de29 --- /dev/null +++ "b/src/main/java/com/fzzy/protocol/sjLpr/\347\206\265\345\237\272\350\275\246\347\211\214\350\257\206\345\210\253\346\216\245\345\217\243" diff --git a/src/main/java/com/fzzy/protocol/wujia/analysis/AnalysisService.java b/src/main/java/com/fzzy/protocol/wujia/analysis/AnalysisService.java index 1f30819..53a2974 100644 --- a/src/main/java/com/fzzy/protocol/wujia/analysis/AnalysisService.java +++ b/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<>(); diff --git a/src/main/java/com/fzzy/protocol/xsyg/analysis/AnalysisService.java b/src/main/java/com/fzzy/protocol/xsyg/analysis/AnalysisService.java index 42a20ae..59ebe4f 100644 --- a/src/main/java/com/fzzy/protocol/xsyg/analysis/AnalysisService.java +++ b/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(); diff --git a/src/main/java/com/fzzy/protocol/youxian0/analysis/AnalysisService.java b/src/main/java/com/fzzy/protocol/youxian0/analysis/AnalysisService.java index 4eae202..0d38c29 100644 --- a/src/main/java/com/fzzy/protocol/youxian0/analysis/AnalysisService.java +++ b/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<>(); diff --git a/src/main/java/com/fzzy/protocol/youxian0/service/Youxian0GatewayGrainService.java b/src/main/java/com/fzzy/protocol/youxian0/service/Youxian0GatewayGrainService.java index f0f8637..50ff78b 100644 --- a/src/main/java/com/fzzy/protocol/youxian0/service/Youxian0GatewayGrainService.java +++ b/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); // 灏佽杩斿洖淇℃伅 diff --git a/src/main/java/com/fzzy/protocol/zldz/analysis/AnalysisGrain.java b/src/main/java/com/fzzy/protocol/zldz/analysis/AnalysisGrain.java index 0ac790d..babacdc 100644 --- a/src/main/java/com/fzzy/protocol/zldz/analysis/AnalysisGrain.java +++ b/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<>(); -- Gitblit v1.9.3