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); + } } } }