|
@ -31,6 +31,7 @@ public class WebSocketCommandBusImpl implements CommandBus { |
|
|
private WebSocketClient webSocketClient; |
|
|
private WebSocketClient webSocketClient; |
|
|
private CountDownLatch countDownLatch; |
|
|
private CountDownLatch countDownLatch; |
|
|
private DataPacket lastDataPacket; |
|
|
private DataPacket lastDataPacket; |
|
|
|
|
|
private Integer packetIndex = 0; |
|
|
|
|
|
|
|
|
public static final int PACKET_TYPE_CMD = 0xA0; |
|
|
public static final int PACKET_TYPE_CMD = 0xA0; |
|
|
public static final int PACKET_TYPE_ACK = 0xA1; |
|
|
public static final int PACKET_TYPE_ACK = 0xA1; |
|
@ -48,6 +49,11 @@ public class WebSocketCommandBusImpl implements CommandBus { |
|
|
public synchronized DataPacket waitForCommandExec(DataPacket commandPacket, Integer timeout, TimeUnit unit) |
|
|
public synchronized DataPacket waitForCommandExec(DataPacket commandPacket, Integer timeout, TimeUnit unit) |
|
|
throws CommandExecTimeoutException, HardwareErrorException, IOException, InterruptedException { |
|
|
throws CommandExecTimeoutException, HardwareErrorException, IOException, InterruptedException { |
|
|
try { |
|
|
try { |
|
|
|
|
|
packetIndex = packetIndex + 1; |
|
|
|
|
|
if (packetIndex > 30000) { |
|
|
|
|
|
packetIndex = 1; |
|
|
|
|
|
} |
|
|
|
|
|
commandPacket.setPacketIndex(packetIndex); |
|
|
this.countDownLatch = new CountDownLatch(1); |
|
|
this.countDownLatch = new CountDownLatch(1); |
|
|
this.session.getBasicRemote().sendText(commandPacket.toByteString()); |
|
|
this.session.getBasicRemote().sendText(commandPacket.toByteString()); |
|
|
boolean isTimeout = this.countDownLatch.await(timeout, unit); |
|
|
boolean isTimeout = this.countDownLatch.await(timeout, unit); |
|
@ -57,7 +63,7 @@ public class WebSocketCommandBusImpl implements CommandBus { |
|
|
commandPacket.getModuleId(), commandPacket.getCmdId(), unit.toMillis(timeout)); |
|
|
commandPacket.getModuleId(), commandPacket.getCmdId(), unit.toMillis(timeout)); |
|
|
throw new CommandExecTimeoutException(); |
|
|
throw new CommandExecTimeoutException(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
log.debug("收到数据包{}", this.lastDataPacket); |
|
|
// 在指定的时间内得到了响应 |
|
|
// 在指定的时间内得到了响应 |
|
|
if (this.lastDataPacket.getPacketType() == PACKET_TYPE_ERROR_ACK) { |
|
|
if (this.lastDataPacket.getPacketType() == PACKET_TYPE_ERROR_ACK) { |
|
|
log.error("moduleId={}执行command={}发送硬件错误", this.lastDataPacket.getModuleId(), this.lastDataPacket.getCmdId()); |
|
|
log.error("moduleId={}执行command={}发送硬件错误", this.lastDataPacket.getModuleId(), this.lastDataPacket.getCmdId()); |
|
|