|
@ -9,6 +9,7 @@ import com.iflytop.handacid.hardware.type.CmdId; |
|
|
import com.iflytop.handacid.hardware.type.MId; |
|
|
import com.iflytop.handacid.hardware.type.MId; |
|
|
import com.iflytop.handacid.hardware.type.ModuleStatus; |
|
|
import com.iflytop.handacid.hardware.type.ModuleStatus; |
|
|
import com.iflytop.handacid.hardware.type.appevent.A8kCanBusOnConnectEvent; |
|
|
import com.iflytop.handacid.hardware.type.appevent.A8kCanBusOnConnectEvent; |
|
|
|
|
|
import com.iflytop.handacid.hardware.type.appevent.A8kHardwareReport; |
|
|
import com.iflytop.handacid.hardware.type.error.A8kEcode; |
|
|
import com.iflytop.handacid.hardware.type.error.A8kEcode; |
|
|
import com.iflytop.handacid.hardware.type.error.AEHardwareError; |
|
|
import com.iflytop.handacid.hardware.type.error.AEHardwareError; |
|
|
import com.iflytop.handacid.hardware.utils.OS; |
|
|
import com.iflytop.handacid.hardware.utils.OS; |
|
@ -38,8 +39,8 @@ public class A8kCanBusConnection extends WebSocketClient { |
|
|
@Resource |
|
|
@Resource |
|
|
AppEventBusService eventBus; |
|
|
AppEventBusService eventBus; |
|
|
|
|
|
|
|
|
String datachurl = null; |
|
|
|
|
|
String cmdchurl = null; |
|
|
|
|
|
|
|
|
String datachurl = null; |
|
|
|
|
|
String cmdchurl = null; |
|
|
Boolean firstCall = true; |
|
|
Boolean firstCall = true; |
|
|
|
|
|
|
|
|
@Value("${device.enableCanBus}") |
|
|
@Value("${device.enableCanBus}") |
|
@ -48,12 +49,12 @@ public class A8kCanBusConnection extends WebSocketClient { |
|
|
|
|
|
|
|
|
static class ProcessContext { |
|
|
static class ProcessContext { |
|
|
BlockingQueue<A8kPacket> receiptQueue = new LinkedBlockingQueue<>(); // |
|
|
BlockingQueue<A8kPacket> receiptQueue = new LinkedBlockingQueue<>(); // |
|
|
A8kPacket cmdPacket; |
|
|
|
|
|
Map<MId, CmdId> txcmdcache = new HashMap<>(); |
|
|
|
|
|
|
|
|
A8kPacket cmdPacket; |
|
|
|
|
|
Map<MId, CmdId> txcmdcache = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public A8kPacket getReceipt(int overtime) { |
|
|
public A8kPacket getReceipt(int overtime) { |
|
|
long end = System.currentTimeMillis() + overtime; |
|
|
|
|
|
|
|
|
long end = System.currentTimeMillis() + overtime; |
|
|
A8kPacket packet = null; |
|
|
A8kPacket packet = null; |
|
|
while (System.currentTimeMillis() < end) { |
|
|
while (System.currentTimeMillis() < end) { |
|
|
try { |
|
|
try { |
|
@ -96,7 +97,7 @@ public class A8kCanBusConnection extends WebSocketClient { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
synchronized void storageTxLastCmd(A8kPacket pack) { |
|
|
synchronized void storageTxLastCmd(A8kPacket pack) { |
|
|
MId mid = MId.valueOf(pack.getModuleId()); |
|
|
|
|
|
|
|
|
MId mid = MId.valueOf(pack.getModuleId()); |
|
|
CmdId cmdId = CmdId.valueOf(pack.getCmdId()); |
|
|
CmdId cmdId = CmdId.valueOf(pack.getCmdId()); |
|
|
if (cmdId != null && cmdId.isActionCmd()) |
|
|
if (cmdId != null && cmdId.isActionCmd()) |
|
|
txcmdcache.put(mid, cmdId); |
|
|
txcmdcache.put(mid, cmdId); |
|
@ -108,8 +109,8 @@ public class A8kCanBusConnection extends WebSocketClient { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ProcessContext context = new ProcessContext(); |
|
|
|
|
|
int packetIndex = 0;//发送包的packetIndex |
|
|
|
|
|
|
|
|
ProcessContext context = new ProcessContext(); |
|
|
|
|
|
int packetIndex = 0;//发送包的packetIndex |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public A8kCanBusConnection(String cmdchurl, String datachurl) { |
|
|
public A8kCanBusConnection(String cmdchurl, String datachurl) { |
|
@ -117,26 +118,30 @@ public class A8kCanBusConnection extends WebSocketClient { |
|
|
log.info("new A8kCanBusConnection: {} {}", cmdchurl, datachurl); |
|
|
log.info("new A8kCanBusConnection: {} {}", cmdchurl, datachurl); |
|
|
|
|
|
|
|
|
this.datachurl = datachurl; |
|
|
this.datachurl = datachurl; |
|
|
this.cmdchurl = cmdchurl; |
|
|
|
|
|
packetIndex = 0; |
|
|
|
|
|
|
|
|
this.cmdchurl = cmdchurl; |
|
|
|
|
|
packetIndex = 0; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override public void onOpen(ServerHandshake serverHandshake) { |
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void onOpen(ServerHandshake serverHandshake) { |
|
|
log.info("a8k canbus connect sucess"); |
|
|
log.info("a8k canbus connect sucess"); |
|
|
eventBus.pushEvent(new A8kCanBusOnConnectEvent()); |
|
|
eventBus.pushEvent(new A8kCanBusOnConnectEvent()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override public void onMessage(String s) { |
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void onMessage(String s) { |
|
|
log.trace("RX-RAW: {}", s); |
|
|
log.trace("RX-RAW: {}", s); |
|
|
processCanRxMessage(s); |
|
|
processCanRxMessage(s); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override public void onClose(int i, String s, boolean b) { |
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void onClose(int i, String s, boolean b) { |
|
|
log.warn("a8k canbus lost connection..."); |
|
|
log.warn("a8k canbus lost connection..."); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override public void onError(Exception e) { |
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void onError(Exception e) { |
|
|
log.info("a8k can-websocket-channel on error"); |
|
|
log.info("a8k can-websocket-channel on error"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -293,7 +298,7 @@ public class A8kCanBusConnection extends WebSocketClient { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 处理接收到的消息 |
|
|
|
|
|
|
|
|
* 处理接收到的消息 |
|
|
*/ |
|
|
*/ |
|
|
private void processCanRxMessage(String s) { |
|
|
private void processCanRxMessage(String s) { |
|
|
byte[] rx = ByteArray.hexStringToBytes(s); |
|
|
byte[] rx = ByteArray.hexStringToBytes(s); |
|
@ -321,11 +326,11 @@ public class A8kCanBusConnection extends WebSocketClient { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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) { |
|
|
log.trace("RX-ACK |RAW:{}| {}", s, packet); |
|
|
|
|
|
|
|
|
log.debug("RX-ACK |RAW:{}| {}", s, packet); |
|
|
context.pushReceipt(packet); |
|
|
context.pushReceipt(packet); |
|
|
} else if (packet.getPacketType() == A8kPacket.PACKET_TYPE_EVENT) { |
|
|
} else if (packet.getPacketType() == A8kPacket.PACKET_TYPE_EVENT) { |
|
|
log.trace("RX-REPORT |RAW:{}| {}", s, packet); |
|
|
|
|
|
// eventBus.pushEvent(new A8kHardwareReport(packet)); |
|
|
|
|
|
|
|
|
log.debug("RX-REPORT |RAW:{}| {}", s, packet); |
|
|
|
|
|
eventBus.pushEvent(new A8kHardwareReport(packet)); |
|
|
} else { |
|
|
} else { |
|
|
log.warn("RX-UNPROCESSABLE: |RAW:{}| {}", s, packet); |
|
|
log.warn("RX-UNPROCESSABLE: |RAW:{}| {}", s, packet); |
|
|
} |
|
|
} |
|
@ -342,9 +347,9 @@ public class A8kCanBusConnection extends WebSocketClient { |
|
|
|
|
|
|
|
|
public HttpResponse<String> callLocalCmd(String path) { |
|
|
public HttpResponse<String> callLocalCmd(String path) { |
|
|
// 创建一个HttpClient实例 |
|
|
// 创建一个HttpClient实例 |
|
|
HttpClient httpClient = HttpClient.newHttpClient(); |
|
|
|
|
|
HttpRequest httpRequest = HttpRequest.newBuilder().uri(URI.create(String.format("%s/%s", cmdchurl, path))).build(); |
|
|
|
|
|
HttpResponse<String> ret = null; |
|
|
|
|
|
|
|
|
HttpClient httpClient = HttpClient.newHttpClient(); |
|
|
|
|
|
HttpRequest httpRequest = HttpRequest.newBuilder().uri(URI.create(String.format("%s/%s", cmdchurl, path))).build(); |
|
|
|
|
|
HttpResponse<String> ret = null; |
|
|
try { |
|
|
try { |
|
|
ret = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString()); |
|
|
ret = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString()); |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
@ -355,9 +360,9 @@ public class A8kCanBusConnection extends WebSocketClient { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
public static void main(String[] args) { |
|
|
HttpClient httpClient = HttpClient.newHttpClient(); |
|
|
|
|
|
HttpRequest httpRequest = HttpRequest.newBuilder().uri(URI.create("http://192.168.8.10:19004/zexcan/restart")).build(); |
|
|
|
|
|
HttpResponse<String> ret = null; |
|
|
|
|
|
|
|
|
HttpClient httpClient = HttpClient.newHttpClient(); |
|
|
|
|
|
HttpRequest httpRequest = HttpRequest.newBuilder().uri(URI.create("http://192.168.8.10:19004/zexcan/restart")).build(); |
|
|
|
|
|
HttpResponse<String> ret = null; |
|
|
try { |
|
|
try { |
|
|
ret = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString()); |
|
|
ret = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString()); |
|
|
log.info("ret: \t{}", ret.body()); |
|
|
log.info("ret: \t{}", ret.body()); |
|
|