From fc568b6542b9845d715c2c2bd541b31f35d5cff6 Mon Sep 17 00:00:00 2001 From: ZZ Date: Fri, 4 Mar 2022 13:56:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E6=9C=AA=E6=B3=A8=E5=86=8C=E7=9A=84?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E5=92=8C=E6=B6=88=E6=81=AF=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E6=97=A0=E6=83=85=E6=8A=9B=E5=BC=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pp/server/ChargingPileBinaryHandler.java | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/server/ChargingPileBinaryHandler.java b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/server/ChargingPileBinaryHandler.java index 2dc0aa97..30e3ea60 100644 --- a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/server/ChargingPileBinaryHandler.java +++ b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/server/ChargingPileBinaryHandler.java @@ -63,10 +63,10 @@ public class ChargingPileBinaryHandler implements ClientBinaryHandler { public void handleBinary(ClientHandler handler, byte[] data) throws IOException { try { + String pileNo = ChargingPileServer.getPileNo(handler); List dataList = parseDataList(data); for (byte[] d : dataList) { String dataStr = toHex(d); - String pileNo = ChargingPileServer.getPileNo(handler); log.debug("received data <<<< |{}| from pile <- ({})", dataStr, pileNo); if (d.length <= 2 || !dataStr.startsWith("68")) { log.debug("received invalid data <<<< |{}|, len[{}]", dataStr, d.length); @@ -88,7 +88,8 @@ public class ChargingPileBinaryHandler implements ClientBinaryHandler { } } - private void process(ClientHandler handler, byte[] data) throws TxException, IOException, NacosException, InterruptedException { + private void process(ClientHandler handler, byte[] data) throws TxException, IOException, NacosException, + InterruptedException { String serviceName = toHex(data, 5, 6); String version = ChargingPileServer.getVersion(handler.getName()); @@ -105,8 +106,7 @@ public class ChargingPileBinaryHandler implements ClientBinaryHandler { cachePile.put("tcfg", false); REDIS.setCacheMap(pilekey, cachePile); regHandler(handler, pileNo, req); - } - if (SERVICE_RMR.equals(serviceName) && OK.equals(resultCode)) { + } else if (SERVICE_RMR.equals(serviceName) && OK.equals(resultCode)) { setCachePileRM(pilekey); } if (result.getBinary() != null) { @@ -130,25 +130,30 @@ public class ChargingPileBinaryHandler implements ClientBinaryHandler { xhpcDeviceMessageMapper.insertByDomain(deviceMessage); } if (SERVICE_HB.equals(serviceName) && OK.equals(resultCode)) { - Boolean tcfg = (Boolean) cachePile.get("tcfg"); - if (tcfg == null || !tcfg) { - String skey = pilekey.concat(".seqhex"); - Thread.sleep(500); - Date date = Calendar.getInstance().getTime(); - String timebin = getTimeBin(seqHex(skey), pileNo, date); - cachePile.put("configTime", DateUtil.format(date, NORM_DATETIME_FORMAT)); - REDIS.setCacheMap(pilekey, cachePile); - log.debug("server send time config msg >>>> ({}) |{}|", pileNo, timebin); - if (!handler.isOpen()) { - log.error("send message failed. [{}]({}) connection lost", handler.getName(), pileNo); - removeHandler(pileNo); - } else { - handler.sendClientBinary(HexUtils.toBytes(timebin)); - if (gunId != null) { - hori2(pileNo, gunId); - } - cachePile.put("tcfg", true); + pileNo = ChargingPileServer.getPileNo(handler); + if (null == pileNo) { + handler.forceClose(); + } else { + Boolean tcfg = (Boolean) cachePile.get("tcfg"); + if (tcfg == null || !tcfg) { + String skey = pilekey.concat(".seqhex"); + Thread.sleep(500); + Date date = Calendar.getInstance().getTime(); + String timebin = getTimeBin(seqHex(skey), pileNo, date); + cachePile.put("configTime", DateUtil.format(date, NORM_DATETIME_FORMAT)); REDIS.setCacheMap(pilekey, cachePile); + log.debug("server send time config msg >>>> ({}) |{}|", pileNo, timebin); + if (!handler.isOpen()) { + log.error("send message failed. [{}]({}) connection lost", handler.getName(), pileNo); + removeHandler(pileNo); + } else { + handler.sendClientBinary(HexUtils.toBytes(timebin)); + if (gunId != null) { + hori2(pileNo, gunId); + } + cachePile.put("tcfg", true); + REDIS.setCacheMap(pilekey, cachePile); + } } } }