|
|
@ -52,21 +52,21 @@ public class A8kCanBusService { |
|
|
|
@Autowired |
|
|
|
private AppEventBusService eventBusService; |
|
|
|
|
|
|
|
public String uri; // assign by application.yml |
|
|
|
public String uri; // assign by application.yml |
|
|
|
private WebSocketClient client; |
|
|
|
|
|
|
|
// 接收回执上下文 |
|
|
|
public BlockingQueue<A8kPacket> receiptQueue = new LinkedBlockingQueue<A8kPacket>(); // |
|
|
|
boolean isWaitingReceipt = false; // |
|
|
|
int waitingReceiptIndex = 0;// |
|
|
|
boolean isWaitingReceipt = false; // |
|
|
|
int waitingReceiptIndex = 0;// |
|
|
|
|
|
|
|
// 发送包的packetIndex |
|
|
|
int packetIndex = 0;// |
|
|
|
|
|
|
|
// 调试标志位 |
|
|
|
boolean debugFlag = false;// |
|
|
|
boolean debugFlag = false;// |
|
|
|
// websocket自动重连时间 |
|
|
|
Timer autoConnectTimer = new Timer();// |
|
|
|
Timer autoConnectTimer = new Timer();// |
|
|
|
|
|
|
|
@PostConstruct |
|
|
|
public void init() throws URISyntaxException { |
|
|
@ -111,8 +111,7 @@ public class A8kCanBusService { |
|
|
|
client.connect(); |
|
|
|
} catch (IllegalStateException e) { |
|
|
|
} |
|
|
|
} else if (client.getReadyState().equals(ReadyState.CLOSING) |
|
|
|
|| client.getReadyState().equals(ReadyState.CLOSED)) { |
|
|
|
} else if (client.getReadyState().equals(ReadyState.CLOSING) || client.getReadyState().equals(ReadyState.CLOSED)) { |
|
|
|
client.reconnect(); |
|
|
|
} |
|
|
|
} |
|
|
@ -121,8 +120,8 @@ public class A8kCanBusService { |
|
|
|
} |
|
|
|
|
|
|
|
private A8kPacket packParamsToPacket(Integer moduleId, Integer cmdId, Integer[] params) { |
|
|
|
int subCmdId = cmdId & 0xFF; |
|
|
|
int mainCmdId = (cmdId >> 8) & 0xFFFF; |
|
|
|
int subCmdId = cmdId & 0xFF; |
|
|
|
int mainCmdId = (cmdId >> 8) & 0xFFFF; |
|
|
|
int bufferSize = 2 + 2 + 1 + 1 + 2 + 4 * params.length; // PacketIndex - MainCmdId - SubCmdId - CmdType - |
|
|
|
// ModuleId - Parameters |
|
|
|
ByteBuffer buffer = ByteBuffer.allocate(bufferSize); |
|
|
@ -296,51 +295,67 @@ public class A8kCanBusService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void waitForMod(Integer moduleId, Integer acitionOvertime) throws InterruptedException, HardwareException { |
|
|
|
long startedAt = System.currentTimeMillis(); |
|
|
|
do { |
|
|
|
try { |
|
|
|
var status = getModuleStatus(moduleId); |
|
|
|
if (status == ModuleStatus.IDLE) { |
|
|
|
break; |
|
|
|
} else if (status == ModuleStatus.ERROR) { |
|
|
|
throw new HardwareException(moduleId, moduleGetError(moduleId)); |
|
|
|
} |
|
|
|
} catch (HardwareException ignored) { |
|
|
|
} |
|
|
|
long now = System.currentTimeMillis(); |
|
|
|
if (now - startedAt > acitionOvertime) { |
|
|
|
throw new HardwareException(moduleId, Errorcode.kovertime); |
|
|
|
} |
|
|
|
|
|
|
|
Thread.sleep(100); |
|
|
|
} while (true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public A8kPacket callcmd(Integer moduleId, Integer cmdId) throws HardwareException { |
|
|
|
return this.callcmd(moduleId, cmdId, new Integer[] {}); |
|
|
|
return this.callcmd(moduleId, cmdId, new Integer[]{}); |
|
|
|
} |
|
|
|
|
|
|
|
public A8kPacket callcmd(Integer moduleId, Integer cmdId, Integer p0) throws HardwareException { |
|
|
|
return this.callcmd(moduleId, cmdId, new Integer[] { p0 }); |
|
|
|
return this.callcmd(moduleId, cmdId, new Integer[]{p0}); |
|
|
|
} |
|
|
|
|
|
|
|
public A8kPacket callcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1) throws HardwareException { |
|
|
|
return this.callcmd(moduleId, cmdId, new Integer[] { p0, p1 }); |
|
|
|
return this.callcmd(moduleId, cmdId, new Integer[]{p0, p1}); |
|
|
|
} |
|
|
|
|
|
|
|
public A8kPacket callcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1, Integer p2) |
|
|
|
throws HardwareException { |
|
|
|
return this.callcmd(moduleId, cmdId, new Integer[] { p0, p1, p2 }); |
|
|
|
public A8kPacket callcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1, Integer p2) throws HardwareException { |
|
|
|
return this.callcmd(moduleId, cmdId, new Integer[]{p0, p1, p2}); |
|
|
|
} |
|
|
|
|
|
|
|
public A8kPacket callcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1, Integer p2, Integer p3) |
|
|
|
throws HardwareException { |
|
|
|
return this.callcmd(moduleId, cmdId, new Integer[] { p0, p1, p2, p3 }); |
|
|
|
public A8kPacket callcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1, Integer p2, Integer p3) throws HardwareException { |
|
|
|
return this.callcmd(moduleId, cmdId, new Integer[]{p0, p1, p2, p3}); |
|
|
|
} |
|
|
|
|
|
|
|
public void callblockcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1, Integer p2, Integer p3, |
|
|
|
Integer acitionOvertime) throws HardwareException, InterruptedException { |
|
|
|
this.callblockcmd(moduleId, cmdId, new Integer[] { p0, p1, p2, p3 }, acitionOvertime); |
|
|
|
|
|
|
|
public void callblockcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1, Integer p2, Integer p3, Integer acitionOvertime) throws HardwareException, InterruptedException { |
|
|
|
this.callblockcmd(moduleId, cmdId, new Integer[]{p0, p1, p2, p3}, acitionOvertime); |
|
|
|
} |
|
|
|
|
|
|
|
public void callblockcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1, Integer p2, |
|
|
|
Integer acitionOvertime) throws HardwareException, InterruptedException { |
|
|
|
this.callblockcmd(moduleId, cmdId, new Integer[] { p0, p1, p2 }, acitionOvertime); |
|
|
|
public void callblockcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1, Integer p2, Integer acitionOvertime) throws HardwareException, InterruptedException { |
|
|
|
this.callblockcmd(moduleId, cmdId, new Integer[]{p0, p1, p2}, acitionOvertime); |
|
|
|
} |
|
|
|
|
|
|
|
public void callblockcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1, Integer acitionOvertime) |
|
|
|
throws HardwareException, InterruptedException { |
|
|
|
this.callblockcmd(moduleId, cmdId, new Integer[] { p0, p1 }, acitionOvertime); |
|
|
|
public void callblockcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1, Integer acitionOvertime) throws HardwareException, InterruptedException { |
|
|
|
this.callblockcmd(moduleId, cmdId, new Integer[]{p0, p1}, acitionOvertime); |
|
|
|
} |
|
|
|
|
|
|
|
public void callblockcmd(Integer moduleId, Integer cmdId, Integer p0, Integer acitionOvertime) |
|
|
|
throws HardwareException, InterruptedException { |
|
|
|
this.callblockcmd(moduleId, cmdId, new Integer[] { p0 }, acitionOvertime); |
|
|
|
public void callblockcmd(Integer moduleId, Integer cmdId, Integer p0, Integer acitionOvertime) throws HardwareException, InterruptedException { |
|
|
|
this.callblockcmd(moduleId, cmdId, new Integer[]{p0}, acitionOvertime); |
|
|
|
} |
|
|
|
|
|
|
|
public void callblockcmd(Integer moduleId, Integer cmdId, Integer acitionOvertime) |
|
|
|
throws HardwareException, InterruptedException { |
|
|
|
this.callblockcmd(moduleId, cmdId, new Integer[] {}, acitionOvertime); |
|
|
|
public void callblockcmd(Integer moduleId, Integer cmdId, Integer acitionOvertime) throws HardwareException, InterruptedException { |
|
|
|
this.callblockcmd(moduleId, cmdId, new Integer[]{}, acitionOvertime); |
|
|
|
} |
|
|
|
|
|
|
|
// TODO |
|
|
@ -374,8 +389,7 @@ public class A8kCanBusService { |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
public void callblockcmd(Integer moduleId, Integer cmdId, Integer[] params, int acitionOvertime) |
|
|
|
throws HardwareException, InterruptedException { |
|
|
|
public void callblockcmd(Integer moduleId, Integer cmdId, Integer[] params, int acitionOvertime) throws HardwareException, InterruptedException { |
|
|
|
var packet = this.packParamsToPacket(moduleId, cmdId, params); |
|
|
|
this.sendCmdAutoResend(packet, A8kPacket.CMD_OVERTIME); |
|
|
|
|
|
|
@ -385,7 +399,7 @@ public class A8kCanBusService { |
|
|
|
|
|
|
|
long startedAt = System.currentTimeMillis(); |
|
|
|
do { |
|
|
|
var pack = this.callcmd(moduleId, CmdId.kmodule_get_status, new Integer[] {}); |
|
|
|
var pack = this.callcmd(moduleId, CmdId.kmodule_get_status, new Integer[]{}); |
|
|
|
var status = pack.getContentI32(0); |
|
|
|
if (0 == status) { |
|
|
|
break; |
|
|
@ -403,7 +417,7 @@ public class A8kCanBusService { |
|
|
|
private A8kPacket sendCmd(A8kPacket pack, int overtime) throws HardwareException { |
|
|
|
pack.setPacketIndex(packetIndex); |
|
|
|
waitingReceiptIndex = packetIndex; |
|
|
|
packetIndex = packetIndex + 1; |
|
|
|
packetIndex = packetIndex + 1; |
|
|
|
if (packetIndex > 10000) { |
|
|
|
packetIndex = 1; |
|
|
|
} |
|
|
@ -458,8 +472,7 @@ public class A8kCanBusService { |
|
|
|
logger.info("RX {}:({})", packet, rx); |
|
|
|
} |
|
|
|
|
|
|
|
if (packet.getPacketType() == A8kPacket.PACKET_TYPE_ACK |
|
|
|
|| packet.getPacketType() == A8kPacket.PACKET_TYPE_ERROR_ACK) { |
|
|
|
if (packet.getPacketType() == A8kPacket.PACKET_TYPE_ACK || packet.getPacketType() == A8kPacket.PACKET_TYPE_ERROR_ACK) { |
|
|
|
if (isWaitingReceipt) { |
|
|
|
if (waitingReceiptIndex == packet.getPacketIndex()) { |
|
|
|
receiptQueue.add(packet); |
|
|
|