|
@ -4,13 +4,17 @@ import a8k.a8k_can_protocol.A8kPacket; |
|
|
import a8k.a8k_can_protocol.CmdId; |
|
|
import a8k.a8k_can_protocol.CmdId; |
|
|
import a8k.a8k_can_protocol.Errorcode; |
|
|
import a8k.a8k_can_protocol.Errorcode; |
|
|
import a8k.appbean.HardwareException; |
|
|
import a8k.appbean.HardwareException; |
|
|
|
|
|
import a8k.appbean.appevent.A8kHardwareReport; |
|
|
|
|
|
import a8k.service.AppEventBusService; |
|
|
import a8k.utils.ByteArray; |
|
|
import a8k.utils.ByteArray; |
|
|
|
|
|
import ch.qos.logback.core.model.processor.AppenderModelHandler; |
|
|
import jakarta.annotation.PostConstruct; |
|
|
import jakarta.annotation.PostConstruct; |
|
|
import org.java_websocket.client.WebSocketClient; |
|
|
import org.java_websocket.client.WebSocketClient; |
|
|
import org.java_websocket.enums.ReadyState; |
|
|
import org.java_websocket.enums.ReadyState; |
|
|
import org.java_websocket.handshake.ServerHandshake; |
|
|
import org.java_websocket.handshake.ServerHandshake; |
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Component; |
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
|
import java.net.URI; |
|
|
import java.net.URI; |
|
@ -45,17 +49,25 @@ public class A8kCanBusService { |
|
|
* } |
|
|
* } |
|
|
* |
|
|
* |
|
|
*/ |
|
|
*/ |
|
|
public String uri; //assign by application.yml |
|
|
|
|
|
private WebSocketClient client; |
|
|
|
|
|
public BlockingQueue<A8kPacket> receiptQueue; |
|
|
|
|
|
public BlockingQueue<A8kPacket> eventQueue; |
|
|
|
|
|
boolean isWaitingReceipt = false; |
|
|
|
|
|
int waitingReceiptIndex = 0; |
|
|
|
|
|
int packetIndex; |
|
|
|
|
|
|
|
|
|
|
|
boolean debugFlag = false; |
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private AppEventBusService eventBusService; |
|
|
|
|
|
|
|
|
Timer autoConnectTimer = new Timer(); |
|
|
|
|
|
|
|
|
public String uri; //assign by application.yml |
|
|
|
|
|
private WebSocketClient client; |
|
|
|
|
|
|
|
|
|
|
|
//接收回执上下文 |
|
|
|
|
|
public BlockingQueue<A8kPacket> receiptQueue = new LinkedBlockingQueue<A8kPacket>(); // |
|
|
|
|
|
boolean isWaitingReceipt = false; // |
|
|
|
|
|
int waitingReceiptIndex = 0;// |
|
|
|
|
|
|
|
|
|
|
|
//发送包的packetIndex |
|
|
|
|
|
int packetIndex = 0;// |
|
|
|
|
|
|
|
|
|
|
|
//调试标志位 |
|
|
|
|
|
boolean debugFlag = false;// |
|
|
|
|
|
//websocket自动重连时间 |
|
|
|
|
|
Timer autoConnectTimer = new Timer();// |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PostConstruct |
|
|
@PostConstruct |
|
@ -68,9 +80,6 @@ public class A8kCanBusService { |
|
|
//this.uri = "ws://127.0.0.1:19005"; |
|
|
//this.uri = "ws://127.0.0.1:19005"; |
|
|
this.uri = "ws://192.168.8.10:19005"; |
|
|
this.uri = "ws://192.168.8.10:19005"; |
|
|
} |
|
|
} |
|
|
receiptQueue = new LinkedBlockingQueue<A8kPacket>(); |
|
|
|
|
|
eventQueue = new LinkedBlockingQueue<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
URI uri = new URI(this.uri); |
|
|
URI uri = new URI(this.uri); |
|
|
client = new WebSocketClient(uri) { |
|
|
client = new WebSocketClient(uri) { |
|
@ -121,15 +130,16 @@ public class A8kCanBusService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//TODO |
|
|
//TODO |
|
|
public void callblockcmd(Integer moduleId, Integer cmdId, Integer[] params,int acitionOvertime) { |
|
|
|
|
|
|
|
|
public void callblockcmd(Integer moduleId, Integer cmdId, Integer[] params, int acitionOvertime) { |
|
|
//调用sendCmdAutoResend |
|
|
//调用sendCmdAutoResend |
|
|
// 通过kmodule_get_status判断指令是否完成,超时未完成则报错,则调用module_stop,同时抛出异常 |
|
|
// 通过kmodule_get_status判断指令是否完成,超时未完成则报错,则调用module_stop,同时抛出异常 |
|
|
// |
|
|
// |
|
|
|
|
|
|
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//TODO |
|
|
//TODO |
|
|
public A8kPacket sendCmdAutoResend(A8kPacket pack, int overtime) throws HardwareException { |
|
|
|
|
|
|
|
|
public A8kPacket sendCmdAutoResend(A8kPacket pack, int overtime) throws HardwareException { |
|
|
//调用sendCmd, |
|
|
//调用sendCmd, |
|
|
// 如果捕获到超时异常,则重发,最多重发三次 |
|
|
// 如果捕获到超时异常,则重发,最多重发三次 |
|
|
// 如果是其他异常,则直接抛出异常。 |
|
|
// 如果是其他异常,则直接抛出异常。 |
|
@ -137,7 +147,7 @@ public class A8kCanBusService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private A8kPacket sendCmd(A8kPacket pack, int overtime) throws HardwareException { |
|
|
|
|
|
|
|
|
private A8kPacket sendCmd(A8kPacket pack, int overtime) throws HardwareException { |
|
|
pack.setPacketIndex(packetIndex); |
|
|
pack.setPacketIndex(packetIndex); |
|
|
waitingReceiptIndex = packetIndex; |
|
|
waitingReceiptIndex = packetIndex; |
|
|
packetIndex = packetIndex + 1; |
|
|
packetIndex = packetIndex + 1; |
|
@ -204,7 +214,9 @@ public class A8kCanBusService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (packet.getPacketType() == A8kPacket.PACKET_TYPE_EVENT) { |
|
|
if (packet.getPacketType() == A8kPacket.PACKET_TYPE_EVENT) { |
|
|
eventQueue.add(packet); |
|
|
|
|
|
|
|
|
if (eventBusService != null) { |
|
|
|
|
|
eventBusService.pushEvent(new A8kHardwareReport(packet)); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -228,7 +240,7 @@ public class A8kCanBusService { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
thread.run(); |
|
|
|
|
|
|
|
|
thread.start(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |