TBD: 60秒无心跳判定离线
This commit is contained in:
parent
2251c2f47e
commit
ee79a722be
@ -29,7 +29,7 @@ public class EarlierBeanConf {
|
|||||||
this.springContextHolder = springContextHolder;
|
this.springContextHolder = springContextHolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean ifreg(String pileNo) throws NacosException {
|
public static boolean ifcanreg(String pileNo) throws NacosException {
|
||||||
|
|
||||||
Map<String, Object> cachePile = REDIS.getCacheMap("pile:".concat(pileNo));
|
Map<String, Object> cachePile = REDIS.getCacheMap("pile:".concat(pileNo));
|
||||||
if (!cachePile.isEmpty()) {
|
if (!cachePile.isEmpty()) {
|
||||||
|
|||||||
@ -207,7 +207,7 @@ public class ChargingController {
|
|||||||
String pileNo = startChargingData.getPileNo();
|
String pileNo = startChargingData.getPileNo();
|
||||||
ClientHandler clientHandler = ChargingPileServer.getHandler(pileNo);
|
ClientHandler clientHandler = ChargingPileServer.getHandler(pileNo);
|
||||||
if (clientHandler == null) {
|
if (clientHandler == null) {
|
||||||
ChargingPileServer.removeHandler(pileNo);
|
// ChargingPileServer.removeHandler(pileNo);
|
||||||
return R.fail("充电桩没有连接到上次注册的服务器,请稍后再试一次");
|
return R.fail("充电桩没有连接到上次注册的服务器,请稍后再试一次");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -215,7 +215,7 @@ public class ChargingController {
|
|||||||
Map<String, Object> cacheGun = REDIS.getCacheMap(gunkey);
|
Map<String, Object> cacheGun = REDIS.getCacheMap(gunkey);
|
||||||
String gunstatus = (String) cacheGun.get("status");
|
String gunstatus = (String) cacheGun.get("status");
|
||||||
if (!"空闲".equals(gunstatus)) {
|
if (!"空闲".equals(gunstatus)) {
|
||||||
return R.fail("充电桩不在空闲或正常状态,稍后再试");
|
return R.fail("端口不在空闲或正常状态,稍后再试");
|
||||||
}
|
}
|
||||||
if (CacheDataUtils.hori(gunkey)) return R.fail("等待上一条指令响应");
|
if (CacheDataUtils.hori(gunkey)) return R.fail("等待上一条指令响应");
|
||||||
String skey = gunkey.concat(".seqhex");
|
String skey = gunkey.concat(".seqhex");
|
||||||
@ -255,7 +255,7 @@ public class ChargingController {
|
|||||||
|
|
||||||
ClientHandler clientHandler = ChargingPileServer.getHandler(pileNo);
|
ClientHandler clientHandler = ChargingPileServer.getHandler(pileNo);
|
||||||
if (clientHandler == null) {
|
if (clientHandler == null) {
|
||||||
ChargingPileServer.removeHandler(pileNo);
|
// ChargingPileServer.removeHandler(pileNo);
|
||||||
return R.fail("充电桩没有连接到上次注册的服务器,请稍后再试一次");
|
return R.fail("充电桩没有连接到上次注册的服务器,请稍后再试一次");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -38,7 +38,7 @@ public class RegisterLogic implements ServiceLogic {
|
|||||||
log.info("pile not in whitelist ({}) ", pileNo);
|
log.info("pile not in whitelist ({}) ", pileNo);
|
||||||
hexCode = ServiceResult.HEX_01;
|
hexCode = ServiceResult.HEX_01;
|
||||||
resultCode = ServiceResult.FAIL;
|
resultCode = ServiceResult.FAIL;
|
||||||
} else if (!EarlierBeanConf.ifreg(pileNo)) {
|
} else if (!EarlierBeanConf.ifcanreg(pileNo)) {
|
||||||
log.info("pile already registered ({}) ", pileNo);
|
log.info("pile already registered ({}) ", pileNo);
|
||||||
hexCode = ServiceResult.HEX_01;
|
hexCode = ServiceResult.HEX_01;
|
||||||
resultCode = ServiceResult.FAIL;
|
resultCode = ServiceResult.FAIL;
|
||||||
|
|||||||
@ -20,17 +20,17 @@ public class ChargingPileEventHandler implements ClientEventHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void gotConnected(ClientHandler handler) {
|
public void gotConnected(ClientHandler handler) {
|
||||||
|
|
||||||
log.info("-> [{}] <- {}", handler.getName(), handler.getSocket().getRemoteSocketAddress().toString());
|
log.info("-> [{}] - {} <-", handler.getName(), handler.getSocket().getRemoteSocketAddress().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void lostConnection(ClientHandler handler) {
|
public void lostConnection(ClientHandler handler) {
|
||||||
|
|
||||||
String pileNo = ChargingPileServer.getPileNo(handler);
|
String pileNo = ChargingPileServer.getPileNo(handler);
|
||||||
if (pileNo != null) {
|
// if (pileNo != null) {
|
||||||
ChargingPileServer.removeHandler(pileNo);
|
// ChargingPileServer.removeHandler(pileNo);
|
||||||
}
|
// }
|
||||||
log.info("-> ({}) - [{}] <- {}",
|
log.info("<- ({}) - [{}] - {} ->",
|
||||||
pileNo, handler.getName(), handler.getSocket().getRemoteSocketAddress().toString());
|
pileNo, handler.getName(), handler.getSocket().getRemoteSocketAddress().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ public class ChargingPileEventHandler implements ClientEventHandler {
|
|||||||
// cachePile.put("status", DISCONNECTED);
|
// cachePile.put("status", DISCONNECTED);
|
||||||
// REDIS.setCacheMap(pkey, cachePile);
|
// REDIS.setCacheMap(pkey, cachePile);
|
||||||
handler.closeConnection();
|
handler.closeConnection();
|
||||||
log.info("-> ({}) - [{}] <- {}", pileNo, handler.getName(), handler.getSocket().getRemoteSocketAddress().toString());
|
log.info("<- ({}) - [{}] - {} ->", pileNo, handler.getName(), handler.getSocket().getRemoteSocketAddress().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -78,6 +78,8 @@ public class ChargingPileServer {
|
|||||||
public static void removeHandler(String pileNo) {
|
public static void removeHandler(String pileNo) {
|
||||||
|
|
||||||
ClientHandler handler = handlerMap.remove(pileNo);
|
ClientHandler handler = handlerMap.remove(pileNo);
|
||||||
|
handler.closeConnection();
|
||||||
|
log.info("handler [{}] for ({}) close connection", handler.getName(), pileNo);
|
||||||
String pkey = "pile:".concat(pileNo);
|
String pkey = "pile:".concat(pileNo);
|
||||||
Map<String, Object> cachePile = REDIS.getCacheMap(pkey);
|
Map<String, Object> cachePile = REDIS.getCacheMap(pkey);
|
||||||
cachePile.put("status", DISCONNECTED);
|
cachePile.put("status", DISCONNECTED);
|
||||||
@ -102,11 +104,9 @@ public class ChargingPileServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (handler != null) {
|
log.info("remove handler [{}] for ({})", handler.getName(), pileNo);
|
||||||
log.info("remove handler [{}] for ({})", handler.getName(), pileNo);
|
pileMap.remove(handler.getName());
|
||||||
pileMap.remove(handler.getName());
|
versionMapper.remove(handler.getName());
|
||||||
versionMapper.remove(handler.getName());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendClientMsg(String pileNo, byte[] msg) {
|
public static void sendClientMsg(String pileNo, byte[] msg) {
|
||||||
|
|||||||
@ -0,0 +1,17 @@
|
|||||||
|
package com.xhpc.pp.server;
|
||||||
|
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class HBCheckTask {
|
||||||
|
|
||||||
|
@Scheduled(fixedRate = 1000)
|
||||||
|
protected void run() throws IOException {
|
||||||
|
|
||||||
|
System.out.println("hb check");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -54,4 +54,9 @@ public class CRCCalculator {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
System.out.println(calcCrc("6812001F00416985214589654800000000000000"));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user