[Update]Adas多屏接口添加
This commit is contained in:
@@ -48,7 +48,7 @@ android {
|
||||
|
||||
protobuf {
|
||||
protoc {
|
||||
artifact = 'com.google.protobuf:protoc:3.6.1'
|
||||
artifact = 'com.google.protobuf:protoc:3.6.1:osx-x86_64'
|
||||
}
|
||||
|
||||
generateProtoTasks {
|
||||
|
||||
@@ -16,7 +16,6 @@ import com.zhidao.support.adas.high.bean.AutopilotSpeedParam;
|
||||
import com.zhidao.support.adas.high.bean.BaseInfo;
|
||||
import com.zhidao.support.adas.high.bean.BasicInfo;
|
||||
import com.zhidao.support.adas.high.bean.ConfigInfo;
|
||||
import com.zhidao.support.adas.high.bean.DemoModeInfo;
|
||||
import com.zhidao.support.adas.high.bean.FaceLoginResponse;
|
||||
import com.zhidao.support.adas.high.bean.MapLocationInfo;
|
||||
import com.zhidao.support.adas.high.bean.SSHResult;
|
||||
@@ -100,27 +99,38 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
*/
|
||||
private MyMessageFactory myMessageFactory;
|
||||
private AutopilotSpeedParam speedParam;
|
||||
private String ipAddr;//工控机IP
|
||||
/**
|
||||
* 工控机IP
|
||||
*/
|
||||
private String ipcIp;
|
||||
private RecordCauseParam recordCauseParam;
|
||||
private SSH ssh;
|
||||
/**
|
||||
* 是否是客户端
|
||||
*/
|
||||
private boolean isClient = true;
|
||||
private OnMultiDeviceListener onMultiDeviceListener;
|
||||
|
||||
public void setOnMultiDeviceListener(OnMultiDeviceListener onMultiDeviceListener) {
|
||||
this.onMultiDeviceListener = onMultiDeviceListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIPCIp(String ipAddr) {
|
||||
this.ipAddr = ipAddr;
|
||||
public void setIPCIp(String ipcIp) {
|
||||
this.ipcIp = ipcIp;
|
||||
}
|
||||
|
||||
AdasChannel(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
|
||||
AdasChannel(Context context, String ipAddr) {
|
||||
AdasChannel(Context context, AdasOptions options) {
|
||||
initData(context);
|
||||
this.ipAddr = ipAddr;
|
||||
initSocket();
|
||||
if (TextUtils.isEmpty(ipAddr))
|
||||
initUdpServer();
|
||||
|
||||
if (options != null) {
|
||||
this.isClient = options.isClient();
|
||||
this.ipcIp = options.getIpcIp();
|
||||
}
|
||||
if (!isClient) {
|
||||
initSocket();
|
||||
if (TextUtils.isEmpty(ipcIp))
|
||||
initUdpServer();
|
||||
}
|
||||
}
|
||||
|
||||
private void initData(Context context) {
|
||||
@@ -166,9 +176,9 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
WSByteQueueManager.getInstance().initDector();
|
||||
}
|
||||
//TODO 写死IP
|
||||
if (!TextUtils.isEmpty(ipAddr)) {
|
||||
if (!TextUtils.isEmpty(ipcIp)) {
|
||||
isRunning = true;
|
||||
getOnConnectionAddress(ipAddr);
|
||||
getOnConnectionAddress(ipcIp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,7 +230,7 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
location.put("bearing", mapLocationInfo.getBearing() + "");
|
||||
jsonObject.put("location", location);
|
||||
|
||||
mSocket.sendDataWebSocket(jsonObject.toString());
|
||||
sendWsMessage(jsonObject.toString());
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@@ -237,7 +247,7 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
return;
|
||||
}
|
||||
String msg = gson.toJson(basicInfo);
|
||||
mSocket.sendDataWebSocket(msg);
|
||||
sendWsMessage(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -251,14 +261,13 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
return;
|
||||
}
|
||||
String msg = gson.toJson(info);
|
||||
Log.i("SendBaseInfo=", msg);
|
||||
mSocket.sendDataWebSocket(msg);
|
||||
sendWsMessage(msg);
|
||||
}
|
||||
|
||||
private void sendIPCCmd(final String cmd) {
|
||||
if (ssh == null) {
|
||||
// String ip = ipAddr;
|
||||
if (TextUtils.isEmpty(ipAddr)) {
|
||||
// String ip = ipcIp;
|
||||
if (TextUtils.isEmpty(ipcIp)) {
|
||||
//尝试从缓存中获取工控机IP
|
||||
// String ip = AppPreferenceHelper.getInstance(MgContextUtils.getContext()).getUdpClientAddress();
|
||||
// if (TextUtils.isEmpty(ip)) {
|
||||
@@ -276,7 +285,7 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
String privateKey = "MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEA127FFvuPolaxYTBg5wkyDIrEbcNKXoIjf0bK7QUQ991Lsbv5Ktv/XM2F6qJFssVF1KTkStVBSQGxJB1eZLwJEwIDAQABAkBM39AgpV/Z1Amz3qmVh+h+JT521ItDMjksf7yF25r0dzGjOfGLQmMAqQXT68B+cQX5HSoFMwk/rE1hnXgifyNBAiEA6uNE2TfPj51mPOZztGy1Q8p4exWohfotiy64g/CyVeMCIQDqy9e7bGeZEi6p1zemEgFVtwgZZvLn/BOP4UO7NjJnEQIhAJBnprUwha/SYb+BIpNC3fHOcWGigBfWJdfSomejO9BnAiEApfojLqKbOWHZCsbQ19yyhN02JH7aB5PyYCtlrdnKF4ECIHR1P2LOQLddXO8PwgoF6gtCTO2sxIqdvu8fUruWyouQ";
|
||||
try {
|
||||
String pwd = RSATool.decodeByPrivateKey(encodePwd, Base64.decodeBase64(privateKey));
|
||||
ssh.connect(ipAddr, 22, "titan", pwd);
|
||||
ssh.connect(ipcIp, 22, "titan", pwd);
|
||||
SSHResult result = ssh.exec(cmd, pwd);
|
||||
if (mAdasListener != null)
|
||||
mAdasListener.onSSHResult(result);
|
||||
@@ -308,13 +317,8 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableDemoMode() {
|
||||
sendBaseInfo(DemoModeInfo.enable());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableDemoMode() {
|
||||
sendBaseInfo(DemoModeInfo.disable());
|
||||
public boolean isClient() {
|
||||
return isClient;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -327,7 +331,7 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
return;
|
||||
}
|
||||
String msg = gson.toJson(configInfo);
|
||||
mSocket.sendDataWebSocket(msg);
|
||||
sendWsMessage(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -348,10 +352,10 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
CupidLogUtils.e(TAG, "===>onResume isRunning===>" + isRunning);
|
||||
if (!isRunning) {
|
||||
isRunning = true;
|
||||
if (TextUtils.isEmpty(ipAddr)) {
|
||||
if (TextUtils.isEmpty(ipcIp)) {
|
||||
initUdpServer();
|
||||
} else {
|
||||
getOnConnectionAddress(ipAddr);
|
||||
getOnConnectionAddress(ipcIp);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -405,7 +409,7 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
*
|
||||
* @param text
|
||||
*/
|
||||
public void handlerWSMsg(String text) {
|
||||
private void handlerWSMsg(String text) {
|
||||
try {
|
||||
JSONObject jsonObjectWs = new JSONObject(text);
|
||||
String action = jsonObjectWs.optString("action");
|
||||
@@ -419,14 +423,21 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
}
|
||||
}
|
||||
|
||||
public void handlerWSMsg(ByteString bytes) {
|
||||
/**
|
||||
* 解析工控机发送过来的数据
|
||||
*
|
||||
* @param bytes 数据
|
||||
*/
|
||||
@Override
|
||||
public void parseIPCData(byte[] bytes) {
|
||||
ByteString byteString = ByteString.of(bytes);
|
||||
try {
|
||||
if (socketReader != null) {
|
||||
OriginReadData read = socketReader.read(bytes);
|
||||
OriginReadData read = socketReader.read(byteString);
|
||||
if (read == null) {
|
||||
//read 解析为空 默认解析view
|
||||
CupidLogUtils.w("--->websocket byte read null, analysis view");
|
||||
myMessageFactory.createMessage(0x101).handlerMsg(gson, mAdasListener, bytes.toByteArray());
|
||||
myMessageFactory.createMessage(0x101).handlerMsg(gson, mAdasListener, bytes);
|
||||
return;
|
||||
}
|
||||
WebsocketHeader.Header_websock header = WebsocketHeader.Header_websock.parseFrom(read.getHeader());
|
||||
@@ -439,6 +450,14 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
}
|
||||
}
|
||||
|
||||
private void handlerWSMsg(ByteString bytes) {
|
||||
byte[] bytes1 = bytes.toByteArray();
|
||||
parseIPCData(bytes1);
|
||||
if (!isClient && onMultiDeviceListener != null) {
|
||||
onMultiDeviceListener.onForwardingIPCMessage(bytes1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onWebSocketConnectSuccess(WebSocket webSocket) {
|
||||
@@ -488,7 +507,7 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
|
||||
@Override
|
||||
public void getOnConnectionAddress(String address) {
|
||||
ipAddr = address;
|
||||
ipcIp = address;
|
||||
CupidLogUtils.e(TAG, "--->getOnConnectionAddress" + address);
|
||||
AppPreferenceHelper.getInstance(MgContextUtils.getContext()).saveUdpClientAddress(address);
|
||||
connectSocket(address);
|
||||
|
||||
@@ -45,6 +45,11 @@ public class AdasManager implements IAdasNetCommApi {
|
||||
|
||||
}
|
||||
|
||||
public void setOnMultiDeviceListener(OnMultiDeviceListener l) {
|
||||
if (mChannel != null) {
|
||||
mChannel.setOnMultiDeviceListener(l);
|
||||
}
|
||||
}
|
||||
|
||||
public void setOnAdasListener(OnAdasListener l) {
|
||||
if (mChannel != null) {
|
||||
@@ -63,17 +68,12 @@ public class AdasManager implements IAdasNetCommApi {
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void create(Context context) {
|
||||
public synchronized void create(Context context, AdasOptions options) {
|
||||
if (mChannel == null) {
|
||||
mChannel = new AdasChannel(context);
|
||||
mChannel = new AdasChannel(context, options);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void create(Context context, String ipcIp) {
|
||||
if (mChannel == null) {
|
||||
mChannel = new AdasChannel(context, ipcIp);
|
||||
}
|
||||
}
|
||||
|
||||
public void pause() {
|
||||
if (mChannel != null) {
|
||||
@@ -323,16 +323,14 @@ public class AdasManager implements IAdasNetCommApi {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableDemoMode() {
|
||||
public void parseIPCData(byte[] bytes) {
|
||||
if (mChannel != null) {
|
||||
mChannel.enableDemoMode();
|
||||
mChannel.parseIPCData(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableDemoMode() {
|
||||
if (mChannel != null) {
|
||||
mChannel.disableDemoMode();
|
||||
}
|
||||
public boolean isClient() {
|
||||
return mChannel == null || mChannel.isClient();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
package com.zhidao.support.adas.high;
|
||||
|
||||
/**
|
||||
* Date:2019/5/31。
|
||||
* Note: Adas相关配置。
|
||||
*/
|
||||
public class AdasOptions {
|
||||
|
||||
|
||||
/**
|
||||
* 是否是客户端
|
||||
*/
|
||||
private boolean isClient;
|
||||
/**
|
||||
* 工控机IP
|
||||
*/
|
||||
private String ipcIp;
|
||||
|
||||
private AdasOptions() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 静态内部类
|
||||
*/
|
||||
public static class Builder {
|
||||
AdasOptions options;
|
||||
|
||||
// 首先获得一个默认的配置
|
||||
public Builder() {
|
||||
this(getDefaultOptions());
|
||||
}
|
||||
|
||||
public Builder(AdasOptions defaultOptions) {
|
||||
options = defaultOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置当前是客户端还是服务端
|
||||
*
|
||||
* @param isClient true:客户度 false:服务端
|
||||
* @return
|
||||
*/
|
||||
public Builder setClient(boolean isClient) {
|
||||
options.isClient = isClient;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置IPC主机地址
|
||||
*
|
||||
* @param ipcIp
|
||||
* @return
|
||||
*/
|
||||
public Builder setIPCIp(String ipcIp) {
|
||||
options.ipcIp = ipcIp;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public AdasOptions build() {
|
||||
return options;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取默认的配置
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static AdasOptions getDefaultOptions() {
|
||||
AdasOptions options = new AdasOptions();
|
||||
options.isClient = true;
|
||||
options.ipcIp = null;
|
||||
return options;
|
||||
}
|
||||
|
||||
public boolean isClient() {
|
||||
return isClient;
|
||||
}
|
||||
|
||||
public String getIpcIp() {
|
||||
return ipcIp;
|
||||
}
|
||||
}
|
||||
@@ -120,6 +120,20 @@ public interface IAdasNetCommApi {
|
||||
*/
|
||||
void rebootAPDocker();
|
||||
|
||||
/**
|
||||
* 解析工控机发送过来的数据
|
||||
*
|
||||
* @param bytes 数据
|
||||
*/
|
||||
void parseIPCData(byte[] bytes);
|
||||
|
||||
/**
|
||||
* 是否是客户端
|
||||
*
|
||||
* @return true:客户度 false:服务端
|
||||
*/
|
||||
boolean isClient();
|
||||
|
||||
/**
|
||||
* 打开演示模式
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.zhidao.support.adas.high;
|
||||
|
||||
/**
|
||||
* 多设备监听
|
||||
* 服务端实现此监听,将工控机发送过来的数据通过其他方式传递出去
|
||||
*/
|
||||
public interface OnMultiDeviceListener {
|
||||
|
||||
/**
|
||||
* 转发工控机消息
|
||||
* 如果是客户端此回调不会被调用
|
||||
*
|
||||
* @param bytes 数据
|
||||
*/
|
||||
void onForwardingIPCMessage(byte[] bytes);
|
||||
}
|
||||
Reference in New Issue
Block a user