@@ -10,7 +10,6 @@ import com.njcn.gather.detection.pojo.param.ContrastDetectionParam;
|
|||||||
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
||||||
import com.njcn.gather.detection.pojo.param.SimulateDetectionParam;
|
import com.njcn.gather.detection.pojo.param.SimulateDetectionParam;
|
||||||
import com.njcn.gather.detection.service.PreDetectionService;
|
import com.njcn.gather.detection.service.PreDetectionService;
|
||||||
import com.njcn.gather.detection.util.socket.CnSocketUtil;
|
|
||||||
import com.njcn.web.controller.BaseController;
|
import com.njcn.web.controller.BaseController;
|
||||||
import com.njcn.web.utils.HttpResultUtil;
|
import com.njcn.web.utils.HttpResultUtil;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
@@ -181,22 +180,22 @@ public class PreDetectionController extends BaseController {
|
|||||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||||
@GetMapping("/startFreqConverter")
|
@GetMapping("/startFreqConverter")
|
||||||
@ApiOperation("开启变频器测试")
|
@ApiOperation("开启变频器测试")
|
||||||
public HttpResult<String> startFreqConverter(@RequestParam("loginName") String loginName, @RequestParam("converterId") String converterId, @RequestParam("monitorId") String monitorId) {
|
public HttpResult<String> startFreqConverter(@RequestParam("converterId") String converterId, @RequestParam("monitorId") String monitorId) {
|
||||||
String methodDescribe = getMethodDescribe("startFreqConverter");
|
String methodDescribe = getMethodDescribe("startFreqConverter");
|
||||||
LogUtil.njcnDebug(log, "{}", methodDescribe);
|
LogUtil.njcnDebug(log, "{}", methodDescribe);
|
||||||
|
|
||||||
preDetectionService.startFreqConverter(loginName, converterId, monitorId);
|
preDetectionService.startFreqConverter(converterId, monitorId);
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||||
}
|
}
|
||||||
|
|
||||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||||
@GetMapping("/stopFreqConverter")
|
@GetMapping("/stopFreqConverter")
|
||||||
@ApiOperation("关闭变频器测试")
|
@ApiOperation("关闭变频器测试")
|
||||||
public HttpResult<String> stopFreqConverter(@RequestParam("loginName") String loginName) {
|
public HttpResult<String> stopFreqConverter(@RequestParam("converterId") String converterId, @RequestParam("monitorId") String monitorId) {
|
||||||
String methodDescribe = getMethodDescribe("stopFreqConverter");
|
String methodDescribe = getMethodDescribe("stopFreqConverter");
|
||||||
LogUtil.njcnDebug(log, "{}", methodDescribe);
|
LogUtil.njcnDebug(log, "{}", methodDescribe);
|
||||||
|
|
||||||
preDetectionService.stopFreqConverter(loginName + CnSocketUtil.FREQ_CONVERTER_TAG, loginName + CnSocketUtil.DEV_TAG);
|
preDetectionService.stopFreqConverter(converterId, monitorId);
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,18 +43,18 @@ public class SocketFreqConverterDevService {
|
|||||||
/**
|
/**
|
||||||
* 连接设备Socket
|
* 连接设备Socket
|
||||||
*
|
*
|
||||||
* @param devTag 设备Channel唯一标识符
|
* @param monitorId 监测点Id
|
||||||
*/
|
*/
|
||||||
public void connectSocket(String devTag) {
|
public void connectSocket(String monitorId) {
|
||||||
if (SocketManager.isChannelActive(devTag)) {
|
if (SocketManager.isChannelActive(monitorId)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String ip = socketConnectionConfig.getDevice().getIp();
|
String ip = socketConnectionConfig.getDevice().getIp();
|
||||||
Integer port = socketConnectionConfig.getDevice().getPort();
|
Integer port = socketConnectionConfig.getDevice().getPort();
|
||||||
|
|
||||||
NettyFreqConverterDevClientHandler handler = new NettyFreqConverterDevClientHandler(devTag, this);
|
NettyFreqConverterDevClientHandler handler = new NettyFreqConverterDevClientHandler(monitorId, this);
|
||||||
CompletableFuture.runAsync(() -> {
|
CompletableFuture.runAsync(() -> {
|
||||||
NettyClient.commonConnect(ip, port, devTag, handler);
|
NettyClient.commonConnect(ip, port, monitorId, handler);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ public class SocketFreqConverterDevService {
|
|||||||
/**
|
/**
|
||||||
* 连接设备
|
* 连接设备
|
||||||
*/
|
*/
|
||||||
public void connectionDev(String devTag, String converterId, String monitorId) {
|
public void connectionDev(String converterId, String monitorId) {
|
||||||
this.init(converterId, monitorId);
|
this.init(converterId, monitorId);
|
||||||
|
|
||||||
String payload = buildSingleMonitorPayload(monitorId);
|
String payload = buildSingleMonitorPayload(monitorId);
|
||||||
@@ -78,40 +78,40 @@ public class SocketFreqConverterDevService {
|
|||||||
socketMsg.setRequestId(SourceOperateCodeEnum.YJC_SBTXJY.getValue());
|
socketMsg.setRequestId(SourceOperateCodeEnum.YJC_SBTXJY.getValue());
|
||||||
socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_INIT_GATHER_03.getValue());
|
socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_INIT_GATHER_03.getValue());
|
||||||
socketMsg.setData(payload);
|
socketMsg.setData(payload);
|
||||||
SocketManager.sendMsg(devTag, JSON.toJSONString(socketMsg));
|
SocketManager.sendMsg(monitorId, JSON.toJSONString(socketMsg));
|
||||||
FormalTestManager.freqConverterDevStep = SourceOperateCodeEnum.YJC_SBTXJY;
|
FormalTestManager.freqConverterDevStep = SourceOperateCodeEnum.YJC_SBTXJY;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleRead(String devTag, String msg) {
|
public void handleRead(String monitorId, String msg) {
|
||||||
SocketDataMsg socketDataMsg = MsgUtil.socketDataMsg(msg);
|
SocketDataMsg socketDataMsg = MsgUtil.socketDataMsg(msg);
|
||||||
|
|
||||||
switch (FormalTestManager.freqConverterDevStep) {
|
switch (FormalTestManager.freqConverterDevStep) {
|
||||||
case YJC_SBTXJY:
|
case YJC_SBTXJY:
|
||||||
handleYjcSbtxjy(devTag, socketDataMsg);
|
handleYjcSbtxjy(monitorId, socketDataMsg);
|
||||||
break;
|
break;
|
||||||
case FORMAL_REAL:
|
case FORMAL_REAL:
|
||||||
handleFormalReal(devTag, socketDataMsg);
|
handleFormalReal(monitorId, socketDataMsg);
|
||||||
break;
|
break;
|
||||||
case QUITE:
|
case QUITE:
|
||||||
handleQuit(devTag, socketDataMsg);
|
handleQuit(monitorId, socketDataMsg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleYjcSbtxjy(String devTag, SocketDataMsg socketDataMsg) {
|
private void handleYjcSbtxjy(String monitorId, SocketDataMsg socketDataMsg) {
|
||||||
SourceResponseCodeEnum responseCodeEnum = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode());
|
SourceResponseCodeEnum responseCodeEnum = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode());
|
||||||
switch (Objects.requireNonNull(responseCodeEnum)) {
|
switch (Objects.requireNonNull(responseCodeEnum)) {
|
||||||
case SUCCESS:
|
case SUCCESS:
|
||||||
this.sendGetDipDataMsg(devTag);
|
this.sendGetDipDataMsg(monitorId);
|
||||||
FormalTestManager.freqConverterDevStep = SourceOperateCodeEnum.FORMAL_REAL;
|
FormalTestManager.freqConverterDevStep = SourceOperateCodeEnum.FORMAL_REAL;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
log.info("设备响应异常,devTag={}, operateCode={}, code={}, data={}", devTag, socketDataMsg.getOperateCode(), socketDataMsg.getCode(), socketDataMsg.getData());
|
log.info("设备响应异常,monitorId={}, operateCode={}, code={}, data={}", monitorId, socketDataMsg.getOperateCode(), socketDataMsg.getCode(), socketDataMsg.getData());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleFormalReal(String devTag, SocketDataMsg socketDataMsg) {
|
private void handleFormalReal(String monitorId, SocketDataMsg socketDataMsg) {
|
||||||
SourceResponseCodeEnum responseCodeEnum = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode());
|
SourceResponseCodeEnum responseCodeEnum = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode());
|
||||||
|
|
||||||
switch (responseCodeEnum) {
|
switch (responseCodeEnum) {
|
||||||
@@ -131,27 +131,27 @@ public class SocketFreqConverterDevService {
|
|||||||
case DATA_RESOLVE:
|
case DATA_RESOLVE:
|
||||||
case NO_INIT_DEV:
|
case NO_INIT_DEV:
|
||||||
default:
|
default:
|
||||||
log.info("设备响应异常,devTag={}, operateCode={}, code={}, data={}", devTag, socketDataMsg.getOperateCode(), socketDataMsg.getCode(), socketDataMsg.getData());
|
log.info("设备响应异常,monitorId={}, operateCode={}, code={}, data={}", monitorId, socketDataMsg.getOperateCode(), socketDataMsg.getCode(), socketDataMsg.getData());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleQuit(String devTag, SocketDataMsg socketDataMsg) {
|
private void handleQuit(String monitorId, SocketDataMsg socketDataMsg) {
|
||||||
SourceResponseCodeEnum responseCodeEnum = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode());
|
SourceResponseCodeEnum responseCodeEnum = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode());
|
||||||
|
|
||||||
switch (responseCodeEnum) {
|
switch (responseCodeEnum) {
|
||||||
case SUCCESS:
|
case SUCCESS:
|
||||||
cleanup(devTag, true);
|
cleanup(monitorId, true);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
log.warn("设备关闭响应失败,devTag={}, operateCode={}, code={}, data={}", devTag, socketDataMsg.getOperateCode(), socketDataMsg.getCode(), socketDataMsg.getData());
|
log.warn("设备关闭响应失败,monitorId={}, operateCode={}, code={}, data={}", monitorId, socketDataMsg.getOperateCode(), socketDataMsg.getCode(), socketDataMsg.getData());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopTest(String converterTag, String devTag) {
|
public void stopTest(String converterId, String monitorId) {
|
||||||
FormalTestManager.freqConverterDevStep = SourceOperateCodeEnum.QUITE;
|
FormalTestManager.freqConverterDevStep = SourceOperateCodeEnum.QUITE;
|
||||||
sendQuitMsg(devTag, SourceOperateCodeEnum.QUIT_INIT_03);
|
sendQuitMsg(monitorId, SourceOperateCodeEnum.QUIT_INIT_03);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -205,11 +205,12 @@ public class SocketFreqConverterDevService {
|
|||||||
SocketManager.sendMsg(monitorId, JSON.toJSONString(socketMsg));
|
SocketManager.sendMsg(monitorId, JSON.toJSONString(socketMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendQuitMsg(String devTag, SourceOperateCodeEnum operateCodeEnum) {
|
private void sendQuitMsg(String monitorId, SourceOperateCodeEnum operateCodeEnum) {
|
||||||
SocketMsg<String> socketMsg = new SocketMsg<>();
|
SocketMsg<String> socketMsg = new SocketMsg<>();
|
||||||
socketMsg.setRequestId(SourceOperateCodeEnum.QUITE.getValue());
|
socketMsg.setRequestId(SourceOperateCodeEnum.QUITE.getValue());
|
||||||
socketMsg.setOperateCode(operateCodeEnum.getValue());
|
socketMsg.setOperateCode(operateCodeEnum.getValue());
|
||||||
SocketManager.sendMsg(devTag, JSON.toJSONString(socketMsg));
|
SocketManager.sendMsg(monitorId, JSON.toJSONString(socketMsg));
|
||||||
|
log.info("已向设备发送关闭指令,monitorId={}, operateCode={}", monitorId, operateCodeEnum.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveDipData(DevData devData) {
|
private void saveDipData(DevData devData) {
|
||||||
@@ -256,12 +257,12 @@ public class SocketFreqConverterDevService {
|
|||||||
return listDTO.getT();
|
return listDTO.getT();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cleanup(String devTag, boolean removeSocket) {
|
public void cleanup(String monitorId, boolean removeSocket) {
|
||||||
FormalTestManager.freqConverterDevStep = null;
|
FormalTestManager.freqConverterDevStep = null;
|
||||||
if (removeSocket) {
|
if (removeSocket) {
|
||||||
SocketManager.removeUser(devTag);
|
SocketManager.removeUser(monitorId);
|
||||||
} else {
|
} else {
|
||||||
SocketManager.clearUser(devTag);
|
SocketManager.clearUser(monitorId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,19 +45,19 @@ public class SocketFreqConverterService {
|
|||||||
/**
|
/**
|
||||||
* 连接变频器Socket
|
* 连接变频器Socket
|
||||||
*
|
*
|
||||||
* @param converterChannelTag 变频器Channel唯一标识符
|
* @param converterId 变频器id
|
||||||
*/
|
*/
|
||||||
public void connectSocket(String converterChannelTag) {
|
public void connectSocket(String converterId) {
|
||||||
if (SocketManager.isChannelActive(converterChannelTag)) {
|
if (SocketManager.isChannelActive(converterId)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String ip = socketConnectionConfig.getFreqConverter().getIp();
|
String ip = socketConnectionConfig.getFreqConverter().getIp();
|
||||||
Integer port = socketConnectionConfig.getFreqConverter().getPort();
|
Integer port = socketConnectionConfig.getFreqConverter().getPort();
|
||||||
|
|
||||||
NettyFreqConverterClientHandler handler = new NettyFreqConverterClientHandler(converterChannelTag, this);
|
NettyFreqConverterClientHandler handler = new NettyFreqConverterClientHandler(converterId, this);
|
||||||
|
|
||||||
CompletableFuture.runAsync(() -> {
|
CompletableFuture.runAsync(() -> {
|
||||||
NettyClient.commonConnect(ip, port, converterChannelTag, handler);
|
NettyClient.commonConnect(ip, port, converterId, handler);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ public class SocketFreqConverterService {
|
|||||||
/**
|
/**
|
||||||
* 连接变频器
|
* 连接变频器
|
||||||
*/
|
*/
|
||||||
public void connectionFreqConverter(String freqConverterTag, String converterId, String monitorId) {
|
public void connectionFreqConverter(String converterId, String monitorId) {
|
||||||
this.init(converterId, monitorId);
|
this.init(converterId, monitorId);
|
||||||
|
|
||||||
SocketMsg<Map<String, Object>> socketMsg = new SocketMsg<>();
|
SocketMsg<Map<String, Object>> socketMsg = new SocketMsg<>();
|
||||||
@@ -90,39 +90,39 @@ public class SocketFreqConverterService {
|
|||||||
map.put("timeoutMs", freqConverterConfig.getTimeoutMs());
|
map.put("timeoutMs", freqConverterConfig.getTimeoutMs());
|
||||||
socketMsg.setData(map);
|
socketMsg.setData(map);
|
||||||
|
|
||||||
SocketManager.sendMsg(freqConverterTag, JSON.toJSONString(socketMsg));
|
SocketManager.sendMsg(converterId, JSON.toJSONString(socketMsg));
|
||||||
FormalTestManager.freqConverterStep = SourceOperateCodeEnum.CMD_INIT_SERIAL;
|
FormalTestManager.freqConverterStep = SourceOperateCodeEnum.CMD_INIT_SERIAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleRead(String converterChannelTag, String msg) {
|
public void handleRead(String converterId, String msg) {
|
||||||
FreqConverterRespDTO respDTO = JSON.parseObject(msg, FreqConverterRespDTO.class);
|
FreqConverterRespDTO respDTO = JSON.parseObject(msg, FreqConverterRespDTO.class);
|
||||||
|
|
||||||
switch (FormalTestManager.freqConverterStep) {
|
switch (FormalTestManager.freqConverterStep) {
|
||||||
case CMD_PING:
|
case CMD_PING:
|
||||||
handlePing(converterChannelTag, respDTO);
|
handlePing(converterId, respDTO);
|
||||||
break;
|
break;
|
||||||
case CMD_INIT_SERIAL:
|
case CMD_INIT_SERIAL:
|
||||||
handleInitSerial(converterChannelTag, respDTO);
|
handleInitSerial(converterId, respDTO);
|
||||||
break;
|
break;
|
||||||
case CMD_GET_SERIAL_CONFIG:
|
case CMD_GET_SERIAL_CONFIG:
|
||||||
handleGetSerialConfig(converterChannelTag, respDTO);
|
handleGetSerialConfig(converterId, respDTO);
|
||||||
break;
|
break;
|
||||||
case CMD_GET_DEVICE_STATUS:
|
case CMD_GET_DEVICE_STATUS:
|
||||||
handleGetDeviceStatus(converterChannelTag, respDTO);
|
handleGetDeviceStatus(converterId, respDTO);
|
||||||
break;
|
break;
|
||||||
case CMD_CLOSE_SERIAL:
|
case CMD_CLOSE_SERIAL:
|
||||||
handleCloseSerial(converterChannelTag, respDTO);
|
handleCloseSerial(converterId, respDTO);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopTest(String converterTag, String devTag) {
|
public void stopTest(String converterId, String monitorId) {
|
||||||
FormalTestManager.freqConverterStep = SourceOperateCodeEnum.CMD_CLOSE_SERIAL;
|
FormalTestManager.freqConverterStep = SourceOperateCodeEnum.CMD_CLOSE_SERIAL;
|
||||||
this.sendClose(converterTag);
|
this.sendClose(converterId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void handlePing(String converterChannelTag, FreqConverterRespDTO respDTO) {
|
private void handlePing(String converterId, FreqConverterRespDTO respDTO) {
|
||||||
if (respDTO.getCode() == 0 && respDTO.getSuccess() && respDTO.getMessage().equals("pong")) {
|
if (respDTO.getCode() == 0 && respDTO.getSuccess() && respDTO.getMessage().equals("pong")) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
@@ -130,7 +130,7 @@ public class SocketFreqConverterService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleInitSerial(String converterChannelTag, FreqConverterRespDTO respDTO) {
|
private void handleInitSerial(String converterId, FreqConverterRespDTO respDTO) {
|
||||||
if (respDTO.getCode() == 0 && respDTO.getSuccess()) {
|
if (respDTO.getCode() == 0 && respDTO.getSuccess()) {
|
||||||
|
|
||||||
FormalTestManager.freqConverterStep = SourceOperateCodeEnum.CMD_GET_DEVICE_STATUS;
|
FormalTestManager.freqConverterStep = SourceOperateCodeEnum.CMD_GET_DEVICE_STATUS;
|
||||||
@@ -138,22 +138,23 @@ public class SocketFreqConverterService {
|
|||||||
if (Objects.isNull(FormalTestManager.scheduler)) {
|
if (Objects.isNull(FormalTestManager.scheduler)) {
|
||||||
FormalTestManager.scheduler = Executors.newScheduledThreadPool(1);
|
FormalTestManager.scheduler = Executors.newScheduledThreadPool(1);
|
||||||
FormalTestManager.scheduledFuture = FormalTestManager.scheduler.scheduleAtFixedRate(() -> {
|
FormalTestManager.scheduledFuture = FormalTestManager.scheduler.scheduleAtFixedRate(() -> {
|
||||||
this.sendGetDeviceStatusMsg(converterChannelTag);
|
this.sendGetDeviceStatusMsg(converterId);
|
||||||
}, 0l, 200l, TimeUnit.MILLISECONDS);
|
}, 0l, 200l, TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleGetSerialConfig(String converterChannelTag, FreqConverterRespDTO respDTO) {
|
private void handleGetSerialConfig(String converterId, FreqConverterRespDTO respDTO) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleGetDeviceStatus(String converterChannelTag, FreqConverterRespDTO respDTO) {
|
private void handleGetDeviceStatus(String converterId, FreqConverterRespDTO respDTO) {
|
||||||
JSONObject obj = JSONUtil.parseObj(respDTO.getData().toString());
|
JSONObject obj = JSONUtil.parseObj(respDTO.getData().toString());
|
||||||
String timestamp = (String) obj.get("Timestamp");
|
String timestamp = (String) obj.get("Timestamp");
|
||||||
timestamp = timestamp.replace("+08:00", StrUtil.EMPTY);
|
timestamp = timestamp.replace("+08:00", StrUtil.EMPTY);
|
||||||
obj.set("Timestamp", timestamp);
|
obj.set("Timestamp", timestamp);
|
||||||
|
|
||||||
FreqConverterStatus freqConverterStatus = JSON.parseObject(obj.toString(), FreqConverterStatus.class);
|
FreqConverterStatus freqConverterStatus = JSON.parseObject(obj.toString(), FreqConverterStatus.class);
|
||||||
|
freqConverterStatus.setConverterId(converterId);
|
||||||
// 变频器故障中,移除这段时期内的设备数据
|
// 变频器故障中,移除这段时期内的设备数据
|
||||||
if (freqConverterStatus.getStatusWord1() == 4) {
|
if (freqConverterStatus.getStatusWord1() == 4) {
|
||||||
FormalTestManager.stopFlag = true;
|
FormalTestManager.stopFlag = true;
|
||||||
@@ -163,9 +164,9 @@ public class SocketFreqConverterService {
|
|||||||
freqConverterService.saveFreqConverterStatus(freqConverterStatus);
|
freqConverterService.saveFreqConverterStatus(freqConverterStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleCloseSerial(String converterChannelTag, FreqConverterRespDTO respDTO) {
|
private void handleCloseSerial(String converterId, FreqConverterRespDTO respDTO) {
|
||||||
if (respDTO.getCode() == 0 && respDTO.getSuccess()) {
|
if (respDTO.getCode() == 0 && respDTO.getSuccess()) {
|
||||||
cleanup(converterChannelTag, true);
|
cleanup(converterId, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,7 +182,7 @@ public class SocketFreqConverterService {
|
|||||||
SocketManager.sendMsg(converterId, JSON.toJSONString(socketMsg));
|
SocketManager.sendMsg(converterId, JSON.toJSONString(socketMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendClose(String converterTag) {
|
private void sendClose(String converterId) {
|
||||||
SocketMsg<Map<String, Object>> socketMsg = new SocketMsg<>();
|
SocketMsg<Map<String, Object>> socketMsg = new SocketMsg<>();
|
||||||
socketMsg.setOperateCode(SourceOperateCodeEnum.CMD_CLOSE_SERIAL.getValue());
|
socketMsg.setOperateCode(SourceOperateCodeEnum.CMD_CLOSE_SERIAL.getValue());
|
||||||
String requestId = IdUtil.fastSimpleUUID();
|
String requestId = IdUtil.fastSimpleUUID();
|
||||||
@@ -189,18 +190,18 @@ public class SocketFreqConverterService {
|
|||||||
|
|
||||||
Map<String, Object> map = new HashMap<>();
|
Map<String, Object> map = new HashMap<>();
|
||||||
socketMsg.setData(map);
|
socketMsg.setData(map);
|
||||||
SocketManager.sendMsg(converterTag, JSON.toJSONString(socketMsg));
|
SocketManager.sendMsg(converterId, JSON.toJSONString(socketMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cleanup(String converterChannelTag, boolean removeSocket) {
|
public void cleanup(String converterId, boolean removeSocket) {
|
||||||
clearScheduleTask();
|
clearScheduleTask();
|
||||||
FormalTestManager.freqConverterStep = null;
|
FormalTestManager.freqConverterStep = null;
|
||||||
FormalTestManager.stopFlag = false;
|
FormalTestManager.stopFlag = false;
|
||||||
FormalTestManager.pairsIpMap.clear();
|
FormalTestManager.pairsIpMap.remove(converterId);
|
||||||
if (removeSocket) {
|
if (removeSocket) {
|
||||||
SocketManager.removeUser(converterChannelTag);
|
SocketManager.removeUser(converterId);
|
||||||
} else {
|
} else {
|
||||||
SocketManager.clearUser(converterChannelTag);
|
SocketManager.clearUser(converterId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ package com.njcn.gather.detection.service;
|
|||||||
import com.njcn.gather.detection.pojo.param.ContrastDetectionParam;
|
import com.njcn.gather.detection.pojo.param.ContrastDetectionParam;
|
||||||
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
||||||
import com.njcn.gather.detection.pojo.param.SimulateDetectionParam;
|
import com.njcn.gather.detection.pojo.param.SimulateDetectionParam;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,6 +56,7 @@ public interface PreDetectionService {
|
|||||||
void closeTestSimulate(SimulateDetectionParam param);
|
void closeTestSimulate(SimulateDetectionParam param);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
* @param param
|
* @param param
|
||||||
*/
|
*/
|
||||||
void startContrastTest(ContrastDetectionParam param);
|
void startContrastTest(ContrastDetectionParam param);
|
||||||
@@ -65,7 +70,7 @@ public interface PreDetectionService {
|
|||||||
|
|
||||||
void startCoefficient();
|
void startCoefficient();
|
||||||
|
|
||||||
void startFreqConverter(String name, String converterId, String monitorId);
|
void startFreqConverter(String converterId, String monitorId);
|
||||||
|
|
||||||
void stopFreqConverter(String converterId, String monitorId);
|
void stopFreqConverter(String converterId,String monitorId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -394,16 +394,14 @@ public class PreDetectionServiceImpl implements PreDetectionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startFreqConverter(String loginName, String converterId, String monitorId) {
|
public void startFreqConverter(String converterId, String monitorId) {
|
||||||
String freqConverterTag = loginName + CnSocketUtil.FREQ_CONVERTER_TAG;
|
socketFreqConverterService.connectSocket(converterId);
|
||||||
String devTag = loginName + CnSocketUtil.DEV_TAG;
|
socketFreqConverterDevService.connectSocket(monitorId);
|
||||||
socketFreqConverterService.connectSocket(freqConverterTag);
|
|
||||||
socketFreqConverterDevService.connectSocket(devTag);
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (SocketManager.isChannelActive(freqConverterTag) && SocketManager.isChannelActive(devTag)) {
|
if (SocketManager.isChannelActive(converterId) && SocketManager.isChannelActive(monitorId)) {
|
||||||
socketFreqConverterService.connectionFreqConverter(freqConverterTag, converterId, monitorId);
|
socketFreqConverterService.connectionFreqConverter(converterId, monitorId);
|
||||||
socketFreqConverterDevService.connectionDev(devTag, converterId, monitorId);
|
socketFreqConverterDevService.connectionDev(converterId, monitorId);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -411,9 +409,9 @@ public class PreDetectionServiceImpl implements PreDetectionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stopFreqConverter(String converterTag, String devTag) {
|
public void stopFreqConverter(String converterId, String monitorId) {
|
||||||
socketFreqConverterService.stopTest(converterTag, devTag);
|
socketFreqConverterService.stopTest(converterId, monitorId);
|
||||||
socketFreqConverterDevService.stopTest(converterTag, converterTag);
|
socketFreqConverterDevService.stopTest(converterId, monitorId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -14,8 +14,6 @@ import com.njcn.gather.detection.util.socket.websocket.WebServiceManager;
|
|||||||
*/
|
*/
|
||||||
public class CnSocketUtil {
|
public class CnSocketUtil {
|
||||||
|
|
||||||
public final static String FREQ_CONVERTER_TAG="_FreqConverter";
|
|
||||||
|
|
||||||
public final static String DEV_TAG = "_Dev";
|
public final static String DEV_TAG = "_Dev";
|
||||||
|
|
||||||
public final static String CONTRAST_DEV_TAG = "_Contrast_Dev";
|
public final static String CONTRAST_DEV_TAG = "_Contrast_Dev";
|
||||||
|
|||||||
@@ -59,15 +59,15 @@ public class NettyClient {
|
|||||||
/**
|
/**
|
||||||
* 静态方法:智能连接变频器设备(兼容性包装)
|
* 静态方法:智能连接变频器设备(兼容性包装)
|
||||||
*
|
*
|
||||||
* @param ip IP地址
|
* @param ip IP地址
|
||||||
* @param port 端口号
|
* @param port 端口号
|
||||||
* @param ChannelId Channel唯一标识
|
* @param id 唯一标识id
|
||||||
* @param handler 变频器处理器
|
* @param handler 变频器处理器
|
||||||
*/
|
*/
|
||||||
public static void commonConnect(String ip, Integer port, String ChannelId,
|
public static void commonConnect(String ip, Integer port, String id,
|
||||||
SimpleChannelInboundHandler handler) {
|
SimpleChannelInboundHandler handler) {
|
||||||
if (instance != null) {
|
if (instance != null) {
|
||||||
instance.executeCommonConnect(ip, port, ChannelId, handler);
|
instance.executeCommonConnect(ip, port, id, handler);
|
||||||
} else {
|
} else {
|
||||||
log.error("NettyClient未初始化,无法创建连接");
|
log.error("NettyClient未初始化,无法创建连接");
|
||||||
}
|
}
|
||||||
@@ -76,36 +76,36 @@ public class NettyClient {
|
|||||||
/**
|
/**
|
||||||
* 执行变频器Socket连接建立流程
|
* 执行变频器Socket连接建立流程
|
||||||
*
|
*
|
||||||
* @param ip 目标服务器IP地址
|
* @param ip 目标服务器IP地址
|
||||||
* @param port 目标服务器端口号
|
* @param port 目标服务器端口号
|
||||||
* @param ChannelId Channel唯一标识id
|
* @param id 唯一标识id
|
||||||
* @param handler 变频器业务处理器
|
* @param handler 变频器业务处理器
|
||||||
*/
|
*/
|
||||||
private static void executeCommonConnect(String ip, Integer port,
|
private static void executeCommonConnect(String ip, Integer port,
|
||||||
String ChannelId,
|
String id,
|
||||||
SimpleChannelInboundHandler handler) {
|
SimpleChannelInboundHandler handler) {
|
||||||
NioEventLoopGroup group = createEventLoopGroup();
|
NioEventLoopGroup group = createEventLoopGroup();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Bootstrap bootstrap = configureBootstrap(group);
|
Bootstrap bootstrap = configureBootstrap(group);
|
||||||
ChannelInitializer<NioSocketChannel> initializer = createCommonChannelInitializer(ChannelId, handler);
|
ChannelInitializer<NioSocketChannel> initializer = createCommonChannelInitializer(id, handler);
|
||||||
bootstrap.handler(initializer);
|
bootstrap.handler(initializer);
|
||||||
ChannelFuture channelFuture = bootstrap.connect(ip, port).sync();
|
ChannelFuture channelFuture = bootstrap.connect(ip, port).sync();
|
||||||
handleCommonConnectionResult(channelFuture, ChannelId, handler, group);
|
handleCommonConnectionResult(channelFuture, id, handler, group);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleCommonConnectionException(e, ChannelId, handler, group);
|
handleCommonConnectionException(e, id, handler, group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建通用通道初始化器
|
* 创建通用通道初始化器
|
||||||
*
|
*
|
||||||
* @param channelId Channel唯一标识id
|
* @param id 唯一标识id
|
||||||
* @param handler 通用业务处理器
|
* @param handler 通用业务处理器
|
||||||
* @return ChannelInitializer 通道初始化器
|
* @return ChannelInitializer 通道初始化器
|
||||||
*/
|
*/
|
||||||
private static ChannelInitializer<NioSocketChannel> createCommonChannelInitializer(
|
private static ChannelInitializer<NioSocketChannel> createCommonChannelInitializer(
|
||||||
String channelId, SimpleChannelInboundHandler handler) {
|
String id, SimpleChannelInboundHandler handler) {
|
||||||
return new ChannelInitializer<NioSocketChannel>() {
|
return new ChannelInitializer<NioSocketChannel>() {
|
||||||
@Override
|
@Override
|
||||||
protected void initChannel(NioSocketChannel ch) {
|
protected void initChannel(NioSocketChannel ch) {
|
||||||
@@ -123,23 +123,23 @@ public class NettyClient {
|
|||||||
* 处理通用连接结果
|
* 处理通用连接结果
|
||||||
*
|
*
|
||||||
* @param channelFuture 连接Future对象
|
* @param channelFuture 连接Future对象
|
||||||
* @param channelId Channel唯一标识符
|
* @param id id
|
||||||
* @param handler 通用业务处理器
|
* @param handler 通用业务处理器
|
||||||
* @param group 事件循环组
|
* @param group 事件循环组
|
||||||
*/
|
*/
|
||||||
private static void handleCommonConnectionResult(ChannelFuture channelFuture,
|
private static void handleCommonConnectionResult(ChannelFuture channelFuture,
|
||||||
String channelId,
|
String id,
|
||||||
SimpleChannelInboundHandler handler,
|
SimpleChannelInboundHandler handler,
|
||||||
NioEventLoopGroup group) {
|
NioEventLoopGroup group) {
|
||||||
channelFuture.addListener((ChannelFutureListener) ch -> {
|
channelFuture.addListener((ChannelFutureListener) ch -> {
|
||||||
if (!ch.isSuccess()) {
|
if (!ch.isSuccess()) {
|
||||||
log.error("连接Socket失败,channelId={}", channelId);
|
log.error("连接Socket失败,id={}", id);
|
||||||
group.shutdownGracefully();
|
group.shutdownGracefully();
|
||||||
} else {
|
} else {
|
||||||
log.info("连接Socket成功,channel={}, channelId={}",
|
log.info("连接Socket成功,id={}, channelId={}",
|
||||||
channelId, channelFuture.channel().id());
|
id, channelFuture.channel().id());
|
||||||
SocketManager.addGroup(channelId, group);
|
SocketManager.addGroup(id, group);
|
||||||
SocketManager.addUser(channelId, channelFuture.channel());
|
SocketManager.addUser(id, channelFuture.channel());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -147,15 +147,15 @@ public class NettyClient {
|
|||||||
/**
|
/**
|
||||||
* 处理通用连接异常
|
* 处理通用连接异常
|
||||||
*
|
*
|
||||||
* @param e 异常对象
|
* @param e 异常对象
|
||||||
* @param channelId Channel唯一标识id
|
* @param id 唯一标识id
|
||||||
* @param handler 通用业务处理器
|
* @param handler 通用业务处理器
|
||||||
* @param group 事件循环组
|
* @param group 事件循环组
|
||||||
*/
|
*/
|
||||||
private static void handleCommonConnectionException(Exception e, String channelId,
|
private static void handleCommonConnectionException(Exception e, String id,
|
||||||
SimpleChannelInboundHandler handler,
|
SimpleChannelInboundHandler handler,
|
||||||
NioEventLoopGroup group) {
|
NioEventLoopGroup group) {
|
||||||
log.error("连接Socket服务端发生异常,channelId={}, error={}", channelId, e.getMessage(), e);
|
log.error("连接Socket服务端发生异常,id={}, error={}", id, e.getMessage(), e);
|
||||||
group.shutdownGracefully();
|
group.shutdownGracefully();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
public class NettyFreqConverterClientHandler extends SimpleChannelInboundHandler<String> {
|
public class NettyFreqConverterClientHandler extends SimpleChannelInboundHandler<String> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 变频器Channel唯一标识符
|
* 变频器ID
|
||||||
*/
|
*/
|
||||||
private final String converterChannelTag;
|
private final String converterId;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -44,20 +44,20 @@ public class NettyFreqConverterClientHandler extends SimpleChannelInboundHandler
|
|||||||
/**
|
/**
|
||||||
* 构造方法
|
* 构造方法
|
||||||
*
|
*
|
||||||
* @param converterChannelTag 变频器Chanel唯一标识符
|
* @param converterId 变频器ID
|
||||||
* @param socketFreqConverterService 变频器Socket响应服务
|
* @param socketFreqConverterService 变频器Socket响应服务
|
||||||
*/
|
*/
|
||||||
public NettyFreqConverterClientHandler(String converterChannelTag, SocketFreqConverterService socketFreqConverterService) {
|
public NettyFreqConverterClientHandler(String converterId, SocketFreqConverterService socketFreqConverterService) {
|
||||||
this.converterChannelTag = converterChannelTag;
|
this.converterId = converterId;
|
||||||
this.socketFreqConverterService = socketFreqConverterService;
|
this.socketFreqConverterService = socketFreqConverterService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||||
log.info("变频器连接已建立,converterChannelTag={}, channelId={}", converterChannelTag, ctx.channel().id());
|
log.info("变频器连接已建立,converterId={}, channelId={}", converterId, ctx.channel().id());
|
||||||
|
|
||||||
// 注册Channel到SocketManager
|
// 注册Channel到SocketManager
|
||||||
SocketManager.addUser(converterChannelTag, ctx.channel());
|
SocketManager.addUser(converterId, ctx.channel());
|
||||||
|
|
||||||
super.channelActive(ctx);
|
super.channelActive(ctx);
|
||||||
}
|
}
|
||||||
@@ -65,39 +65,39 @@ public class NettyFreqConverterClientHandler extends SimpleChannelInboundHandler
|
|||||||
@Override
|
@Override
|
||||||
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
|
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
|
||||||
if (StrUtil.isBlank(msg)) {
|
if (StrUtil.isBlank(msg)) {
|
||||||
log.debug("收到空消息,忽略,converterChannelTag={}", converterChannelTag);
|
log.debug("收到空消息,忽略,converterId={}", converterId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("收到变频器消息,converterChannelTag={}, msg={}", converterChannelTag, msg);
|
log.info("收到变频器消息,converterId={}, msg={}", converterId, msg);
|
||||||
|
|
||||||
// 处理状态数据
|
// 处理状态数据
|
||||||
socketFreqConverterService.handleRead(converterChannelTag, msg);
|
socketFreqConverterService.handleRead(converterId, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||||
log.warn("变频器连接已断开,converterChannelTag={}", converterChannelTag);
|
log.warn("变频器连接已断开,converterId={}", converterId);
|
||||||
|
|
||||||
// 移除Channel
|
// 移除Channel
|
||||||
socketFreqConverterService.cleanup(converterChannelTag, false);
|
socketFreqConverterService.cleanup(converterId, false);
|
||||||
|
|
||||||
// 尝试重连
|
// 尝试重连
|
||||||
if (reconnectAttempts < MAX_RECONNECT_ATTEMPTS) {
|
if (reconnectAttempts < MAX_RECONNECT_ATTEMPTS) {
|
||||||
reconnectAttempts++;
|
reconnectAttempts++;
|
||||||
log.info("尝试重连变频器,converterChannelTag={}, 第{}次重连", converterChannelTag, reconnectAttempts);
|
log.info("尝试重连变频器,converterId={}, 第{}次重连", converterId, reconnectAttempts);
|
||||||
|
|
||||||
ctx.executor().schedule(() -> {
|
ctx.executor().schedule(() -> {
|
||||||
try {
|
try {
|
||||||
// 获取连接信息并重连
|
// 获取连接信息并重连
|
||||||
// 注意:这里需要根据实际情况实现重连逻辑
|
// 注意:这里需要根据实际情况实现重连逻辑
|
||||||
log.info("变频器重连逻辑待实现,converterChannelTag={}", converterChannelTag);
|
log.info("变频器重连逻辑待实现,converterId={}", converterId);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("变频器重连失败,converterChannelTag={}, error={}", converterChannelTag, e.getMessage(), e);
|
log.error("变频器重连失败,converterId={}, error={}", converterId, e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}, RECONNECT_INTERVAL_MS, java.util.concurrent.TimeUnit.MILLISECONDS);
|
}, RECONNECT_INTERVAL_MS, java.util.concurrent.TimeUnit.MILLISECONDS);
|
||||||
} else {
|
} else {
|
||||||
log.error("变频器重连失败,已达到最大重连次数,converterChannelTag={}", converterChannelTag);
|
log.error("变频器重连失败,已达到最大重连次数,converterId={}", converterId);
|
||||||
}
|
}
|
||||||
|
|
||||||
super.channelInactive(ctx);
|
super.channelInactive(ctx);
|
||||||
@@ -105,7 +105,7 @@ public class NettyFreqConverterClientHandler extends SimpleChannelInboundHandler
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||||
log.error("变频器连接发生异常,converterChannelTag={}, error={}", converterChannelTag, cause.getMessage(), cause);
|
log.error("变频器连接发生异常,converterId={}, error={}", converterId, cause.getMessage(), cause);
|
||||||
ctx.close();
|
ctx.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,7 +114,7 @@ public class NettyFreqConverterClientHandler extends SimpleChannelInboundHandler
|
|||||||
if (evt instanceof IdleStateEvent) {
|
if (evt instanceof IdleStateEvent) {
|
||||||
IdleStateEvent event = (IdleStateEvent) evt;
|
IdleStateEvent event = (IdleStateEvent) evt;
|
||||||
if (event.state() == IdleState.READER_IDLE) {
|
if (event.state() == IdleState.READER_IDLE) {
|
||||||
log.warn("变频器连接读空闲,converterChannelTag={}", converterChannelTag);
|
log.warn("变频器连接读空闲,converterId={}", converterId);
|
||||||
// 可以选择发送心跳或关闭连接
|
// 可以选择发送心跳或关闭连接
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,42 +15,42 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class NettyFreqConverterDevClientHandler extends SimpleChannelInboundHandler<String> {
|
public class NettyFreqConverterDevClientHandler extends SimpleChannelInboundHandler<String> {
|
||||||
|
|
||||||
private final String devChannelTag;
|
private final String monitorId;
|
||||||
private final SocketFreqConverterDevService socketFreqConverterDevService;
|
private final SocketFreqConverterDevService socketFreqConverterDevService;
|
||||||
|
|
||||||
public NettyFreqConverterDevClientHandler(String devChannelTag, SocketFreqConverterDevService socketFreqConverterDevService) {
|
public NettyFreqConverterDevClientHandler(String monitorId, SocketFreqConverterDevService socketFreqConverterDevService) {
|
||||||
this.devChannelTag = devChannelTag;
|
this.monitorId = monitorId;
|
||||||
this.socketFreqConverterDevService = socketFreqConverterDevService;
|
this.socketFreqConverterDevService = socketFreqConverterDevService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||||
log.info("设备连接已建立,devChannelTag={}, channelId={}", devChannelTag, ctx.channel().id());
|
log.info("设备连接已建立,monitorId={}, channelId={}", monitorId, ctx.channel().id());
|
||||||
SocketManager.addUser(devChannelTag, ctx.channel());
|
SocketManager.addUser(monitorId, ctx.channel());
|
||||||
super.channelActive(ctx);
|
super.channelActive(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
|
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
|
||||||
if (StrUtil.isBlank(msg)) {
|
if (StrUtil.isBlank(msg)) {
|
||||||
log.debug("收到空消息,忽略,devChannelTag={}", devChannelTag);
|
log.debug("收到空消息,忽略,monitorId={}", monitorId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("收到设备消息,devChannelTag={}, msg={}", devChannelTag, msg);
|
log.info("收到设备消息,monitorId={}, msg={}", monitorId, msg);
|
||||||
socketFreqConverterDevService.handleRead(devChannelTag, msg);
|
socketFreqConverterDevService.handleRead(monitorId, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||||
log.warn("设备连接已断开,devChannelTag={}", devChannelTag);
|
log.warn("设备连接已断开,monitorId={}", monitorId);
|
||||||
socketFreqConverterDevService.cleanup(devChannelTag, false);
|
socketFreqConverterDevService.cleanup(monitorId, false);
|
||||||
super.channelInactive(ctx);
|
super.channelInactive(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||||
log.error("设备连接发生异常,devChannelTag={}, error={}", devChannelTag, cause.getMessage(), cause);
|
log.error("设备连接发生异常,monitorId={}, error={}", monitorId, cause.getMessage(), cause);
|
||||||
ctx.close();
|
ctx.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ public class NettyFreqConverterDevClientHandler extends SimpleChannelInboundHand
|
|||||||
if (evt instanceof IdleStateEvent) {
|
if (evt instanceof IdleStateEvent) {
|
||||||
IdleStateEvent event = (IdleStateEvent) evt;
|
IdleStateEvent event = (IdleStateEvent) evt;
|
||||||
if (event.state() == IdleState.READER_IDLE) {
|
if (event.state() == IdleState.READER_IDLE) {
|
||||||
log.warn("设备连接读空闲,devChannelTag={}", devChannelTag);
|
log.warn("设备连接读空闲,monitorId={}", monitorId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
super.userEventTriggered(ctx, evt);
|
super.userEventTriggered(ctx, evt);
|
||||||
|
|||||||
@@ -25,6 +25,11 @@ public class FreqConverterStatus extends BaseEntity implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 变频器ID(用于区分不同变频器)
|
||||||
|
*/
|
||||||
|
private String converterId;
|
||||||
|
|
||||||
private Integer slaveAddress;
|
private Integer slaveAddress;
|
||||||
|
|
||||||
private Integer statusWord1;
|
private Integer statusWord1;
|
||||||
|
|||||||
@@ -31,6 +31,21 @@ import java.util.stream.Collectors;
|
|||||||
@Service
|
@Service
|
||||||
public class FreqConverterServiceImpl extends ServiceImpl<FreqConverterStatusMapper, FreqConverterStatus> implements IFreqConverterService {
|
public class FreqConverterServiceImpl extends ServiceImpl<FreqConverterStatusMapper, FreqConverterStatus> implements IFreqConverterService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认最大数据量阈值
|
||||||
|
*/
|
||||||
|
private static final int DEFAULT_MAX_DATA_COUNT = 10000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认数据过期天数
|
||||||
|
*/
|
||||||
|
private static final int DEFAULT_EXPIRE_DAYS = 30;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认每个变频器保留的最新数据条数
|
||||||
|
*/
|
||||||
|
private static final int DEFAULT_KEEP_LATEST_COUNT = 100;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public boolean saveFreqConverterStatus(FreqConverterStatus status) {
|
public boolean saveFreqConverterStatus(FreqConverterStatus status) {
|
||||||
@@ -39,7 +54,7 @@ public class FreqConverterServiceImpl extends ServiceImpl<FreqConverterStatusMap
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<FreqConverterStatus> listStatusHistory(String converterId) {
|
public List<FreqConverterStatus> listStatusHistory(String converterId) {
|
||||||
return this.lambdaQuery().list();
|
return this.lambdaQuery().eq(FreqConverterStatus::getConverterId, converterId).list();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user