|
|
@ -30,14 +30,14 @@ public class DeviceCommandService { |
|
|
|
|
|
|
|
public CommandFuture executeCommand(DeviceCommand cmdToDevice) { |
|
|
|
CommandFuture cmdFuture = new CommandFuture(); |
|
|
|
commandFutureMap.put(cmdToDevice.getCommandId(), cmdFuture); |
|
|
|
commandFutureMap.put(cmdToDevice.getCmdId(), cmdFuture); |
|
|
|
if (!deviceTcpClient.sendToJSON(cmdToDevice)) { |
|
|
|
commandFutureMap.remove(cmdToDevice.getCommandId()); |
|
|
|
commandFutureMap.remove(cmdToDevice.getCmdId()); |
|
|
|
throw new RuntimeException("向设备发送指令失败"); |
|
|
|
} |
|
|
|
|
|
|
|
cmdFuture.getResponseFuture().whenComplete((result, ex) -> |
|
|
|
commandFutureMap.remove(cmdToDevice.getCommandId())); |
|
|
|
commandFutureMap.remove(cmdToDevice.getCmdId())); |
|
|
|
return cmdFuture; |
|
|
|
} |
|
|
|
|
|
|
@ -47,7 +47,7 @@ public class DeviceCommandService { |
|
|
|
commandFuture.getAckFuture().thenApply(result -> { |
|
|
|
Boolean status = result.getBool("status"); |
|
|
|
if (!status) { //ack失败 |
|
|
|
String message = deviceCommand.getCommandName() + "指令,设备ack错误"; |
|
|
|
String message = deviceCommand.getCmdName() + "指令,设备ack错误"; |
|
|
|
throw new RuntimeException(message); |
|
|
|
} |
|
|
|
return result; |
|
|
@ -56,7 +56,7 @@ public class DeviceCommandService { |
|
|
|
commandFuture.getResponseFuture().thenApply(result -> { |
|
|
|
Boolean status = result.getBool("status"); |
|
|
|
if (!status) { //response失败 |
|
|
|
String message = deviceCommand.getCommandName() + "指令,设备response错误"; |
|
|
|
String message = deviceCommand.getCmdName() + "指令,设备response错误"; |
|
|
|
throw new RuntimeException(message); |
|
|
|
} |
|
|
|
return result.get("data"); |
|
|
@ -67,26 +67,26 @@ public class DeviceCommandService { |
|
|
|
|
|
|
|
public CommandFuture sendCommand(String cmdId, String cmdCode, DeviceCommand deviceCommand) throws IOException { |
|
|
|
CommandFuture commandFuture = executeCommand(deviceCommand); |
|
|
|
webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.SEND, "已向设备发送了" + deviceCommand.getCommandName() + "指令", deviceCommand)); |
|
|
|
webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.SEND, "已向设备发送了" + deviceCommand.getCmdName() + "指令", deviceCommand)); |
|
|
|
commandFuture.getAckFuture().thenApply(result -> { |
|
|
|
Boolean status = result.getBool("status"); |
|
|
|
if (!status) { //ack失败 |
|
|
|
String message = deviceCommand.getCommandName() + "指令,设备ack错误"; |
|
|
|
String message = deviceCommand.getCmdName() + "指令,设备ack错误"; |
|
|
|
webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.SEND, message, result)); |
|
|
|
throw new RuntimeException(message); |
|
|
|
} |
|
|
|
webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.RESULT, deviceCommand.getCommandName() + "指令,设备ack正常", result)); |
|
|
|
webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.RESULT, deviceCommand.getCmdName() + "指令,设备ack正常", result)); |
|
|
|
return result; |
|
|
|
}); |
|
|
|
|
|
|
|
commandFuture.getResponseFuture().thenApply(result -> { |
|
|
|
Boolean status = result.getBool("status"); |
|
|
|
if (!status) { //response失败 |
|
|
|
String message = deviceCommand.getCommandName() + "指令,设备response错误"; |
|
|
|
String message = deviceCommand.getCmdName() + "指令,设备response错误"; |
|
|
|
webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.SEND, message, result)); |
|
|
|
throw new RuntimeException(message); |
|
|
|
} |
|
|
|
webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.RESULT, deviceCommand.getCommandName() + "指令,设备response正常", result)); |
|
|
|
webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.RESULT, deviceCommand.getCmdName() + "指令,设备response正常", result)); |
|
|
|
return result.get("data"); |
|
|
|
}); |
|
|
|
|
|
|
|