添加备注,增加临时转发json方案,增强程序健壮性

This commit is contained in:
xinfengkun
2022-02-17 14:27:51 +08:00
parent 61ea79ab83
commit 0be79fb16b
2 changed files with 43 additions and 9 deletions

View File

@@ -45,6 +45,7 @@ import com.zhjt.service.chain.TracingConstants;
import org.json.JSONObject;
import java.nio.charset.StandardCharsets;
import java.util.List;
import mogo.webproto.WebsocketHeader;
@@ -189,11 +190,13 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
paramIndexes = {0},
clientPkFileName = "sn")
private void connectSocket(String address) {
mSocket.connectWebSocket(address);
if (mSocket != null)
mSocket.connectWebSocket(address);
}
public void closeSocket() {
mSocket.closeWebSocket();
if (mSocket != null)
mSocket.closeWebSocket();
}
public void sendLocation(MapLocationInfo mapLocationInfo) {
@@ -383,7 +386,8 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
public void onDestory() {
onPause();
mSocket.closeWebSocket();
if (mSocket != null)
mSocket.closeWebSocket();
if (configInfo != null) {
configInfo.clear();
configInfo = null;
@@ -430,15 +434,40 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
} catch (Exception e) {
e.printStackTrace();
}
// TODO 临时接续Json数据传递添加的Header 0x00表示PB数据 0x01表示Json数据
if (!isClient && onMultiDeviceListener != null) {
byte[] bytes = text.getBytes(StandardCharsets.UTF_8);
byte[] temp = new byte[bytes.length + 1];
System.arraycopy(bytes, 0, temp, 1, bytes.length);
temp[0] = 0x01;
onMultiDeviceListener.onForwardingIPCMessage(temp);
}
}
/**
* 解析工控机发送过来的数据
* 解析工控机发送过来PB的数据
*
* @param bytes 数据
*/
@Override
public void parseIPCData(byte[] bytes) {
if (bytes == null || bytes.length == 0) {
return;
}
//TODO 临时将Json数据转发并解析 0x00表示PB数据 0x01表示Json数据
if (isClient) {
byte header = bytes[0];
byte[] temp = new byte[bytes.length - 1];
System.arraycopy(bytes, 1, temp, 0, temp.length);
bytes = temp;
if (header != 0x00) {
//Json 解析
handlerWSMsg(new String(bytes, StandardCharsets.UTF_8));
return;
}
}
//PB解析
ByteString byteString = ByteString.of(bytes);
try {
if (socketReader != null) {
@@ -463,7 +492,11 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
byte[] bytes1 = bytes.toByteArray();
parseIPCData(bytes1);
if (!isClient && onMultiDeviceListener != null) {
onMultiDeviceListener.onForwardingIPCMessage(bytes1);
// TODO 临时接续Json数据传递添加的Header 0x00表示PB数据 0x01表示Json数据
byte[] temp = new byte[bytes1.length + 1];
System.arraycopy(bytes1, 0, temp, 1, bytes1.length);
temp[0] = 0x00;
onMultiDeviceListener.onForwardingIPCMessage(temp);
}
}
@@ -524,7 +557,8 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
flag = false;
if (configInfo != null && configInfo.size() > 0) {
if (isConnected) {
mSocket.doConfigChanged(configInfo);
if (mSocket != null)
mSocket.doConfigChanged(configInfo);
}
}
}
@@ -608,7 +642,7 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
@Override
public boolean isSocketConnect() {
return mSocket.getWebSocket() != null;
return mSocket != null && mSocket.getWebSocket() != null;
}
@Override

View File

@@ -86,9 +86,9 @@ public enum ActionTypeReceive {
*/
ACTION_WS_AUTOPILOT_IDENTIFY("identify", -1, "BadCase数据采集"),
/**
* 局部轨迹
* 局部轨迹 车前引导钱
*/
ACTION_WS_AUTOPILOT_TRAJECTORY("trajectory", 0x100, "局部轨迹"),
ACTION_WS_AUTOPILOT_TRAJECTORY("trajectory", 0x100, "局部轨迹 车前引导钱"),
/**
* car dock 基础信息
*/