对未注册的连接和消息进行无情抛弃

This commit is contained in:
ZZ 2022-03-04 13:56:43 +08:00
parent 18e4f0a99d
commit fc568b6542

View File

@ -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<byte[]> 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);
}
}
}
}