[630][adas] 新增域控认证;优化重连机制:无限重连、用不重连、指定次数重连;优化连接状态;新增设置是否启用超时检测;新增是否自动连接;
This commit is contained in:
@@ -33,6 +33,7 @@ import com.mogo.och.common.module.biz.callback.ILoginCallback;
|
||||
import com.mogo.och.common.module.biz.constant.LoginStatusManager;
|
||||
import com.mogo.och.common.module.manager.autopilotmanager.OCHAdasAbilityManager;
|
||||
import com.mogo.och.common.module.voice.VoiceNotice;
|
||||
import com.zhjt.mogo.adas.data.AdasConstants;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -155,7 +156,7 @@ public class BusPresenter extends Presenter<BusFragment>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAutopilotSNRequest() {
|
||||
public void onAutopilotSNRequest(@NonNull AdasConstants.CertificationStatus status) {
|
||||
|
||||
}
|
||||
|
||||
@@ -242,7 +243,7 @@ public class BusPresenter extends Presenter<BusFragment>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAutopilotIpcConnectStatusChanged(int status, @Nullable String reason) {
|
||||
public void onAutopilotIpcConnectStatusChanged(@NonNull AdasConstants.IpcConnectionStatus status, @Nullable String reason) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.mogo.och.common.module.biz.bean.DriverStatusQueryRespBean;
|
||||
import com.mogo.och.common.module.biz.callback.ILoginCallback;
|
||||
import com.mogo.och.common.module.biz.constant.LoginStatusManager;
|
||||
import com.mogo.och.common.module.manager.autopilotmanager.OCHAdasAbilityManager;
|
||||
import com.zhjt.mogo.adas.data.AdasConstants;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -153,7 +154,7 @@ public class BusPresenter extends Presenter<BusFragment>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAutopilotSNRequest() {
|
||||
public void onAutopilotSNRequest(@NonNull AdasConstants.CertificationStatus status) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -234,7 +235,7 @@ public class BusPresenter extends Presenter<BusFragment>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAutopilotIpcConnectStatusChanged(int status, @Nullable String reason) {
|
||||
public void onAutopilotIpcConnectStatusChanged(@NonNull AdasConstants.IpcConnectionStatus status, @Nullable String reason) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -69,6 +69,7 @@ import com.mogo.och.data.bean.BusRoutesResult;
|
||||
import com.mogo.och.data.bean.BusStationBean;
|
||||
import com.mogo.och.data.bean.BusTransferData;
|
||||
import com.mogo.och.shuttle.passenger.network.PassengerServiceManager;
|
||||
import com.zhjt.mogo.adas.data.AdasConstants;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -528,7 +529,7 @@ public class BusPassengerModel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAutopilotIpcConnectStatusChanged(int status, @Nullable String reason) {
|
||||
public void onAutopilotIpcConnectStatusChanged(@NonNull AdasConstants.IpcConnectionStatus status, @Nullable String reason) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -539,7 +540,7 @@ public class BusPassengerModel {
|
||||
private boolean arriveAtEnd = false; //乘客app专用字段
|
||||
|
||||
@Override
|
||||
public void onAutopilotSNRequest() {
|
||||
public void onAutopilotSNRequest(@NonNull AdasConstants.CertificationStatus status) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ import com.mogo.och.sweeper.common.constant.SweeperConst;
|
||||
import com.mogo.och.sweeper.common.database.MyDataBase;
|
||||
import com.mogo.och.sweeper.common.database.bean.WeltDataBean;
|
||||
import com.mogo.och.sweeper.common.view.DebugView;
|
||||
import com.zhjt.mogo.adas.data.AdasConstants;
|
||||
import com.zhjt.mogo.adas.data.AiCloudTask;
|
||||
import com.zhjt.mogo.adas.data.sweeper.bootable.SweeperBootable;
|
||||
import com.zhjt.mogo.adas.data.sweeper.task.SweeperTask;
|
||||
@@ -701,7 +702,7 @@ public class SweeperCloudTaskModel implements IMoGoSweeperFutianCloudTaskListene
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAutopilotSNRequest() {
|
||||
public void onAutopilotSNRequest(@NonNull AdasConstants.CertificationStatus status) {
|
||||
|
||||
}
|
||||
|
||||
@@ -711,8 +712,8 @@ public class SweeperCloudTaskModel implements IMoGoSweeperFutianCloudTaskListene
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAutopilotIpcConnectStatusChanged(int status, @Nullable String reason) {
|
||||
if (status == 0x00) {//判断工控机重连后,获取当前正在执行的子任务,延时10秒,防止工控机连接上时SN为空
|
||||
public void onAutopilotIpcConnectStatusChanged(@NonNull AdasConstants.IpcConnectionStatus status, @Nullable String reason) {
|
||||
if (status == AdasConstants.IpcConnectionStatus.CONNECTED) {//判断工控机重连后,获取当前正在执行的子任务,延时10秒,防止工控机连接上时SN为空
|
||||
CallerAutoPilotControlManager.INSTANCE.setIsSubscribeBackCameraVideoVideo(0, false);//TODO 当前3.2.0版本产品未规划后摄像头展示功能
|
||||
UiThreadHandler.postDelayed(() -> {
|
||||
getCurrentTask();
|
||||
|
||||
@@ -40,6 +40,7 @@ import com.mogo.och.sweeper.operate.fragment.SweeperOperateFragment;
|
||||
import com.mogo.och.sweeper.operate.model.SweeperOperateTaskModel;
|
||||
import com.mogo.och.sweeper.common.util.SweeperFutianCmdUtil;
|
||||
import com.mogo.och.sweeper.operate.util.SweeperTrajectoryManager;
|
||||
import com.zhjt.mogo.adas.data.AdasConstants;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -220,7 +221,7 @@ public class SweeperOperatePresenter extends Presenter<SweeperOperateFragment>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAutopilotIpcConnectStatusChanged(int status, @Nullable String reason) {
|
||||
public void onAutopilotIpcConnectStatusChanged(@NonNull AdasConstants.IpcConnectionStatus status, @Nullable String reason) {
|
||||
DebugView.Companion.printInfoMsg(
|
||||
"[域控连接状态变化] status=" + status
|
||||
+ ", reason=" + reason);
|
||||
@@ -244,7 +245,7 @@ public class SweeperOperatePresenter extends Presenter<SweeperOperateFragment>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAutopilotSNRequest() {
|
||||
public void onAutopilotSNRequest(@NonNull AdasConstants.CertificationStatus status) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -83,6 +83,7 @@ import com.mogo.och.taxi.network.TaxiServiceManager;
|
||||
import com.mogo.och.taxi.utils.OrderUtil;
|
||||
import com.mogo.och.taxi.utils.TaxiAnalyticsManager;
|
||||
import com.mogo.och.taxi.utils.TaxiTrajectoryManager;
|
||||
import com.zhjt.mogo.adas.data.AdasConstants;
|
||||
import com.zhjt.service.chain.ChainLog;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -1212,7 +1213,7 @@ public class TaxiModel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAutopilotIpcConnectStatusChanged(int status, @Nullable String reason) {
|
||||
public void onAutopilotIpcConnectStatusChanged(@NonNull AdasConstants.IpcConnectionStatus status, @Nullable String reason) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1280,7 +1281,7 @@ public class TaxiModel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAutopilotSNRequest() {
|
||||
public void onAutopilotSNRequest(@NonNull AdasConstants.CertificationStatus status) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -36,6 +36,7 @@ import com.mogo.och.taxi.callback.ITaxiRoutingCallback
|
||||
import com.mogo.och.taxi.constant.TaxiUnmannedConst
|
||||
import com.mogo.och.taxi.network.TaxiRoutingServiceManager
|
||||
import com.mogo.och.taxi.ui.debug.DebugView
|
||||
import com.zhjt.mogo.adas.data.AdasConstants
|
||||
import mogo.telematics.pad.MessagePad
|
||||
import mogo_msg.MogoReportMsg
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
@@ -90,7 +91,7 @@ object TaxiRoutingModel {
|
||||
//MAP到站监听
|
||||
private val mMogoAutopilotStatusListener: IMoGoAutopilotStatusListener =
|
||||
object : IMoGoAutopilotStatusListener {
|
||||
override fun onAutopilotIpcConnectStatusChanged(status: Int, reason: String?) {
|
||||
override fun onAutopilotIpcConnectStatusChanged(status: AdasConstants.IpcConnectionStatus, reason: String?) {
|
||||
}
|
||||
|
||||
override fun onAutopilotGuardian(guardianInfo: MogoReportMsg.MogoReportMessage?) {
|
||||
|
||||
@@ -76,6 +76,7 @@ import com.mogo.och.taxi.ui.debug.DebugView
|
||||
import com.mogo.och.taxi.utils.RxJavaUtils
|
||||
import com.mogo.och.taxi.utils.TaxiAnalyticsManager
|
||||
import com.mogo.och.taxi.utils.TaxiTrajectoryManager
|
||||
import com.zhjt.mogo.adas.data.AdasConstants
|
||||
import com.zhjt.service.chain.ChainLog
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
@@ -275,7 +276,7 @@ object TaxiTaskModel {
|
||||
|
||||
private val mMogoAutopilotStatusListener: IMoGoAutopilotStatusListener =
|
||||
object : IMoGoAutopilotStatusListener {
|
||||
override fun onAutopilotIpcConnectStatusChanged(status: Int, reason: String?) {
|
||||
override fun onAutopilotIpcConnectStatusChanged(status: AdasConstants.IpcConnectionStatus, reason: String?) {
|
||||
DebugView.printInfoMsg(
|
||||
"[域控连接状态变化] status=$status, reason=${
|
||||
if (TextUtils.isEmpty(
|
||||
|
||||
@@ -55,7 +55,6 @@ import com.zhidao.support.adas.high.AdasOptions
|
||||
import com.zhidao.support.adas.high.OnMultiDeviceListener
|
||||
import com.zhidao.support.adas.high.chain.AdasChain
|
||||
import com.zhidao.support.adas.high.common.Constants
|
||||
import com.zhidao.support.adas.high.common.Constants.IPC_CONNECTION_STATUS
|
||||
import com.zhidao.support.adas.high.common.CupidLogUtils
|
||||
import com.zhjt.mogo.adas.common.MessageType
|
||||
import com.zhjt.mogo.adas.data.AdasConstants
|
||||
@@ -98,7 +97,7 @@ class MoGoAutopilotControlProvider :
|
||||
override fun init(context: Context) {
|
||||
CallerLogger.i("$M_D_C$TAG", "初始化工控机连接……")
|
||||
mContext = context
|
||||
AdasManager.getInstance().init(context)
|
||||
AdasManager.getInstance().init(context)//必须在AdasManager.getInstance().create() 和构建AdasOptions之前调用
|
||||
runCatching {
|
||||
// 初始化ADAS 域控制器
|
||||
CupidLogUtils.setEnableLog(false)
|
||||
@@ -118,13 +117,13 @@ class MoGoAutopilotControlProvider :
|
||||
// "192.168.1.102"
|
||||
val options = AdasOptions.newBuilder()
|
||||
.setConnectionMode(AdasOptions.IPC_CONNECTION_MODE.PING)
|
||||
.setPingAddressList(AdasManager.getInstance().ipcFixationIPList)
|
||||
.setPingAddressList(AdasManager.getInstance().pingAddressList)
|
||||
.setPassenger(false)
|
||||
.setUnableLaunchAutopilotGear(FunctionBuildConfig.unableLaunchAutopilotGear)
|
||||
// .setSubscribeInterfaceOptions(subscribeInterfaceOptions)//
|
||||
.build()
|
||||
|
||||
AdasManager.getInstance().create(options, MoGoAdasMsgConnectStatusListenerImpl())
|
||||
AdasManager.getInstance().create(mContext, options, MoGoAdasMsgConnectStatusListenerImpl())
|
||||
//////////////////////////////////注意先后顺序,AdasManager.getInstance().create后才可以设置监听/////////////////////////////////////////////
|
||||
// 监听ADAS-SDK获取到的工控机数据
|
||||
AdasManager.getInstance().setOnAdasListener(MoGoAdasListenerImpl())
|
||||
@@ -219,7 +218,7 @@ class MoGoAutopilotControlProvider :
|
||||
.setUnableLaunchAutopilotGear(FunctionBuildConfig.unableLaunchAutopilotGear)
|
||||
.build()
|
||||
AdasManager.getInstance()
|
||||
.create(options, MoGoAdasMsgConnectStatusListenerImpl())
|
||||
.create(mContext, options, MoGoAdasMsgConnectStatusListenerImpl())
|
||||
// 监听ADAS-SDK获取到的工控机数据
|
||||
AdasManager.getInstance().setOnAdasListener(MoGoAdasListenerImpl())
|
||||
// 接收司机屏发过来的感知、定位等数据
|
||||
@@ -246,11 +245,11 @@ class MoGoAutopilotControlProvider :
|
||||
val options = AdasOptions
|
||||
.newBuilder()
|
||||
.setConnectionMode(AdasOptions.IPC_CONNECTION_MODE.PING)
|
||||
.setPingAddressList(AdasManager.getInstance().ipcFixationIPList)
|
||||
.setPingAddressList(AdasManager.getInstance().pingAddressList)
|
||||
.setPassenger(false)// 乘客端直连工控机改为false
|
||||
.setUnableLaunchAutopilotGear(FunctionBuildConfig.unableLaunchAutopilotGear)
|
||||
.build()
|
||||
AdasManager.getInstance().create(options, MoGoAdasMsgConnectStatusListenerImpl())
|
||||
AdasManager.getInstance().create(mContext, options, MoGoAdasMsgConnectStatusListenerImpl())
|
||||
//////////////////////////////////注意先后顺序,AdasManager.getInstance().create后才可以设置监听/////////////////////////////////////////////
|
||||
// 监听ADAS-SDK获取到的工控机数据
|
||||
AdasManager.getInstance().setOnAdasListener(MoGoAdasListenerImpl())
|
||||
@@ -309,7 +308,7 @@ class MoGoAutopilotControlProvider :
|
||||
.setConnectionMode(AdasOptions.IPC_CONNECTION_MODE.SPECIFIED)
|
||||
.setSpecifiedAddress(autoPilotIp)
|
||||
.build()
|
||||
AdasManager.getInstance().create(options, MoGoAdasMsgConnectStatusListenerImpl())
|
||||
AdasManager.getInstance().create(mContext, options, MoGoAdasMsgConnectStatusListenerImpl())
|
||||
|
||||
// AdasManager.getInstance().adasOptions.isClient = false
|
||||
// AdasManager.getInstance().adasOptions.ipcConnectionMode =
|
||||
@@ -368,7 +367,7 @@ class MoGoAutopilotControlProvider :
|
||||
.sendAutoPilotModeReq(1, source, null)
|
||||
invokeAutoPilotResult(if (invokeResult) "无参自动驾驶调用成功" else "自动驾驶调用失败, socket 或者 rawPack 可能为空")
|
||||
} else {
|
||||
if (AdasManager.getInstance().ipcConnectionStatus == IPC_CONNECTION_STATUS.CONNECTED) {
|
||||
if (AdasManager.getInstance().ipcConnectionStatus == AdasConstants.IpcConnectionStatus.CONNECTED) {
|
||||
val invokeResult = AdasManager.getInstance()
|
||||
.sendAutoPilotModeReq(1, source, null)
|
||||
invokeAutoPilotResult(if (invokeResult) "无参自动驾驶调用成功" else "自动驾驶调用失败, socket 或者 rawPack 可能为空")
|
||||
@@ -384,7 +383,7 @@ class MoGoAutopilotControlProvider :
|
||||
.sendAutoPilotModeReq(1, source, controlParameters.toRouteInfo())
|
||||
invokeAutoPilotResult(if (invokeResult) "自动驾驶调用成功" else "自动驾驶调用失败, socket 或者 rawPack 可能为空")
|
||||
} else {
|
||||
if (AdasManager.getInstance().ipcConnectionStatus == IPC_CONNECTION_STATUS.CONNECTED) {
|
||||
if (AdasManager.getInstance().ipcConnectionStatus == AdasConstants.IpcConnectionStatus.CONNECTED) {
|
||||
val invokeResult = AdasManager.getInstance()
|
||||
.sendAutoPilotModeReq(1, source, controlParameters.toRouteInfo())
|
||||
invokeAutoPilotResult(if (invokeResult) "自动驾驶调用成功" else "自动驾驶调用失败, socket 或者 rawPack 可能为空")
|
||||
@@ -431,7 +430,7 @@ class MoGoAutopilotControlProvider :
|
||||
}
|
||||
|
||||
override fun cancelAutoPilot() {
|
||||
if (AdasManager.getInstance().ipcConnectionStatus == IPC_CONNECTION_STATUS.CONNECTED) {
|
||||
if (AdasManager.getInstance().ipcConnectionStatus == AdasConstants.IpcConnectionStatus.CONNECTED) {
|
||||
AdasManager.getInstance().sendAutoPilotModeReq(0, 1, null)
|
||||
} else {
|
||||
CallerLogger.e("$M_D_C$TAG", "车机与工控机链接失败,无法断开自动驾驶")
|
||||
@@ -925,7 +924,7 @@ class MoGoAutopilotControlProvider :
|
||||
* 车机与工控机是否连上了
|
||||
*/
|
||||
override fun isConnected(): Boolean {
|
||||
return AdasManager.getInstance().ipcConnectionStatus == IPC_CONNECTION_STATUS.CONNECTED
|
||||
return AdasManager.getInstance().ipcConnectionStatus == AdasConstants.IpcConnectionStatus.CONNECTED
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -58,6 +58,7 @@ import com.mogo.support.obu.ObuScene
|
||||
import com.zhidao.support.adas.high.OnAdasListener
|
||||
import com.zhjt.mogo.adas.data.bean.AdasParam
|
||||
import com.zhidao.support.adas.high.common.ProtocolStatus
|
||||
import com.zhjt.mogo.adas.data.AdasConstants
|
||||
import com.zhjt.mogo.adas.data.AiCloudTask
|
||||
import com.zhjt.mogo.adas.data.bean.AutopilotStatistics
|
||||
import com.zhjt.mogo.adas.data.bean.ReceivedAck
|
||||
@@ -357,12 +358,17 @@ class MoGoAdasListenerImpl : OnAdasListener {
|
||||
}
|
||||
}
|
||||
|
||||
// 自动驾驶设备基础信息请求
|
||||
override fun onBasicInfoReq(
|
||||
header: MessagePad.Header,
|
||||
basicInfoReq: MessagePad.BasicInfoReq?
|
||||
) {
|
||||
invokeAutopilotSNRequest()
|
||||
/**
|
||||
* 自动驾驶设备基础信息请求
|
||||
* 连接时启用认证 后才会有认证结果
|
||||
* ROOT证书异常会影响校验域控证书
|
||||
* PAD证书异常会影响域控端校验的证书校验,域控端证书校验失败将会断开连接,且并不会给出断开原因,ADAS LIB会执行重连操作(如果配置启用重连)
|
||||
* 校验域控证书认证失败会主动断开连接,且不进行重连
|
||||
*
|
||||
* @param status 域控证书认证结果{@link AdasConstants.CertificationStatus}
|
||||
*/
|
||||
override fun onBasicInfoReq(status: AdasConstants.CertificationStatus) {
|
||||
invokeAutopilotSNRequest(status)
|
||||
}
|
||||
|
||||
//工控机基础配置信息
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package com.mogo.eagle.core.function.datacenter.autopilot.adapter
|
||||
|
||||
import com.mogo.commons.debug.DebugConfig.*
|
||||
import com.mogo.commons.debug.DebugConfig.NET_MODE_DEMO
|
||||
import com.mogo.commons.debug.DebugConfig.NET_MODE_DEV
|
||||
import com.mogo.commons.debug.DebugConfig.NET_MODE_QA
|
||||
import com.mogo.commons.debug.DebugConfig.NET_MODE_RELEASE
|
||||
import com.mogo.commons.debug.DebugConfig.getNetMode
|
||||
import com.mogo.commons.storage.SharedPrefsMgr
|
||||
import com.mogo.eagle.core.data.app.AppConfigInfo
|
||||
import com.mogo.eagle.core.data.config.FunctionBuildConfig
|
||||
@@ -18,10 +22,13 @@ import com.mogo.eagle.core.utilcode.util.ToastUtils
|
||||
import com.zhidao.support.adas.high.AdasManager
|
||||
import com.zhidao.support.adas.high.OnAdasConnectStatusListener
|
||||
import com.zhidao.support.adas.high.bean.VersionCompatibility
|
||||
import com.zhidao.support.adas.high.common.Constants
|
||||
import com.zhidao.support.adas.high.common.Constants.ENVIRONMENT.*
|
||||
import com.zhidao.support.adas.high.common.Constants.ENVIRONMENT.DEMO
|
||||
import com.zhidao.support.adas.high.common.Constants.ENVIRONMENT.DEVELOP
|
||||
import com.zhidao.support.adas.high.common.Constants.ENVIRONMENT.PRODUCTION
|
||||
import com.zhidao.support.adas.high.common.Constants.ENVIRONMENT.TEST
|
||||
import com.zhidao.support.adas.high.common.Constants.TERMINAL_ROLE.DRIVER
|
||||
import com.zhidao.support.adas.high.common.Constants.TERMINAL_ROLE.PASSENGER
|
||||
import com.zhjt.mogo.adas.data.AdasConstants
|
||||
|
||||
/**
|
||||
* ADAS-SDK与工控机连接状态回调
|
||||
@@ -39,17 +46,53 @@ class MoGoAdasMsgConnectStatusListenerImpl :
|
||||
|
||||
init {
|
||||
CallerCloudListenerManager.addListener(TAG, this)
|
||||
CallerAutopilotActionsListenerManager.setConnected(AdasManager.getInstance().ipcConnectionStatus == Constants.IPC_CONNECTION_STATUS.CONNECTED)
|
||||
CallerParallelDrivingActionsListenerManager.setConnected(AdasManager.getInstance().ipcConnectionStatus == Constants.IPC_CONNECTION_STATUS.CONNECTED)
|
||||
CallerAutopilotActionsListenerManager.setConnected(AdasManager.getInstance().ipcConnectionStatus == AdasConstants.IpcConnectionStatus.CONNECTED)
|
||||
CallerParallelDrivingActionsListenerManager.setConnected(AdasManager.getInstance().ipcConnectionStatus == AdasConstants.IpcConnectionStatus.CONNECTED)
|
||||
}
|
||||
|
||||
override fun onConnectionIPCStatus(ipcConnectionStatus: Int, reason: String?) {
|
||||
CallerAutopilotActionsListenerManager.setConnected(ipcConnectionStatus == Constants.IPC_CONNECTION_STATUS.CONNECTED)
|
||||
CallerParallelDrivingActionsListenerManager.setConnected(ipcConnectionStatus == Constants.IPC_CONNECTION_STATUS.CONNECTED)
|
||||
private fun resetArgs(reason: String? = null) {
|
||||
if (connectStatus) {
|
||||
reason?.let {
|
||||
ToastUtils.showLong(it)
|
||||
}
|
||||
connectStatus = false
|
||||
}
|
||||
|
||||
CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo().connectIP =
|
||||
AdasManager.getInstance().ipcConnectedIp
|
||||
CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo().connectPort =
|
||||
AdasManager.getInstance().ipcConnectedPort
|
||||
CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo().connectStatus = false
|
||||
AppConfigInfo.isConnectAutopilot = false
|
||||
//与工控机断开连接,需要重置自动驾驶状态(包括上传至云平台缓存信息),等待连接成功后同步状态信息
|
||||
CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo().state = 0
|
||||
CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo().pilotmode = 0
|
||||
}
|
||||
|
||||
/**
|
||||
* 与工控机链接状态变化
|
||||
*
|
||||
* @param status {@link AdasConstants.IpcConnectionStatus}
|
||||
* @param reason 连接信息(需要判null),目前只有以下参数存在值,其他全部为null
|
||||
* {@link AdasConstants.IpcConnectionStatus#HEARTBEAT_TIMEOUT} 表示超时时间
|
||||
* {@link AdasConstants.IpcConnectionStatus#CONNECT_EXCEPTION} 表示连接异常原因
|
||||
* {@link AdasConstants.IpcConnectionStatus#SERVER_DISCONNECTED} 服务端断开(如果服务端关闭时发送了原因将存在,如果服务端关闭时未发送将为null)
|
||||
*/
|
||||
override fun onConnectionIPCStatus(status: AdasConstants.IpcConnectionStatus, reason: String?) {
|
||||
CallerAutopilotActionsListenerManager.setConnected(status == AdasConstants.IpcConnectionStatus.CONNECTED)
|
||||
CallerParallelDrivingActionsListenerManager.setConnected(status == AdasConstants.IpcConnectionStatus.CONNECTED)
|
||||
AppConfigInfo.connectStatusDescribe = reason
|
||||
when (ipcConnectionStatus) {
|
||||
Constants.IPC_CONNECTION_STATUS.CONNECTED -> {
|
||||
CallerLogger.d("$M_D_C$TAG", "webSocket 连接成功")
|
||||
when (status) {
|
||||
AdasConstants.IpcConnectionStatus.DISCONNECTED -> {
|
||||
CallerLogger.d(
|
||||
"$M_D_C$TAG",
|
||||
"未连接或主动断开连接(未连接:鹰眼首次启动时未调用连接函数【目前鹰眼默认启动就会调用连接函数】;主动断开连接:主动调用断开连接函数;)"
|
||||
)
|
||||
resetArgs()
|
||||
}
|
||||
|
||||
AdasConstants.IpcConnectionStatus.CONNECTED -> {
|
||||
CallerLogger.d("$M_D_C$TAG", "已连接")
|
||||
connectStatus = true
|
||||
// 初始化自动驾驶状态信息
|
||||
CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo().connectIP =
|
||||
@@ -71,38 +114,86 @@ class MoGoAdasMsgConnectStatusListenerImpl :
|
||||
//每次工控机连接成功后,需同步当前设置的雨天模式状态
|
||||
CallerAutoPilotControlManager.setRainMode(FunctionBuildConfig.isRainMode)
|
||||
}
|
||||
Constants.IPC_CONNECTION_STATUS.DISCONNECTED -> {
|
||||
CallerLogger.d("$M_D_C$TAG", "webSocket 连接失败 reason:$reason")
|
||||
if (connectStatus) {
|
||||
reason?.let {
|
||||
ToastUtils.showLong("工控机连接断开,原因:$it , 等待重连")
|
||||
}
|
||||
connectStatus = false
|
||||
}
|
||||
CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo().connectIP =
|
||||
AdasManager.getInstance().ipcConnectedIp
|
||||
CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo().connectPort =
|
||||
AdasManager.getInstance().ipcConnectedPort
|
||||
CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo().connectStatus = false
|
||||
AppConfigInfo.isConnectAutopilot = false
|
||||
//与工控机断开连接,需要重置自动驾驶状态(包括上传至云平台缓存信息),等待连接成功后同步状态信息
|
||||
CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo().state = 0
|
||||
CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo().pilotmode = 0
|
||||
|
||||
AdasConstants.IpcConnectionStatus.CONNECTING -> {
|
||||
CallerLogger.d("$M_D_C$TAG", "连接中")
|
||||
}
|
||||
Constants.IPC_CONNECTION_STATUS.CONNECTING -> {
|
||||
CallerLogger.d("$M_D_C$TAG", "webSocket 正在连接")
|
||||
|
||||
AdasConstants.IpcConnectionStatus.RECONNECTING_TIMER -> {
|
||||
CallerLogger.d("$M_D_C$TAG", "重连中(定时器)")
|
||||
}
|
||||
Constants.IPC_CONNECTION_STATUS.SEARCH_ADDRESS -> {
|
||||
CallerLogger.d("$M_D_C$TAG", "webSocket 正在搜索工控机IP")
|
||||
|
||||
AdasConstants.IpcConnectionStatus.RECONNECTING_NETWORK -> {
|
||||
CallerLogger.d("$M_D_C$TAG", "重连中(网络监听)")
|
||||
}
|
||||
Constants.IPC_CONNECTION_STATUS.NOT_FOUND_ADDRESS -> {
|
||||
CallerLogger.d("$M_D_C$TAG", "webSocket 找不到可用IP 传入的IP不可用或固定IP列表中所有IP不可用")
|
||||
|
||||
AdasConstants.IpcConnectionStatus.CONNECT_EXCEPTION -> {
|
||||
CallerLogger.d(
|
||||
"$M_D_C$TAG",
|
||||
"连接异常(表示鹰眼与域控连接失败、无法连接、非正常断开等),原因:$reason"
|
||||
)
|
||||
resetArgs("域控连接异常,等待重连。原因:${reason}")
|
||||
}
|
||||
|
||||
AdasConstants.IpcConnectionStatus.ILLEGAL_ADDRESS -> {
|
||||
CallerLogger.d(
|
||||
"$M_D_C$TAG",
|
||||
"非法地址(连接模式为指定地址时:表示当前鹰眼调用连接时传入的域控地址错误或不符合规则【不修改默认配置不会出现此问题】;连接模式为PING模式时:表示传入的PING地址列表存在问题)"
|
||||
)
|
||||
resetArgs()
|
||||
}
|
||||
|
||||
AdasConstants.IpcConnectionStatus.SEARCH_ADDRESS -> {
|
||||
CallerLogger.d(
|
||||
"$M_D_C$TAG",
|
||||
"正在搜索域控地址(表示当前鹰眼正在查找是否有可用的域控地址)"
|
||||
)
|
||||
}
|
||||
|
||||
AdasConstants.IpcConnectionStatus.NOT_FOUND_ADDRESS -> {
|
||||
CallerLogger.d(
|
||||
"$M_D_C$TAG",
|
||||
"找不到可用地址(当前鹰眼配置的域控地址列表中的全部地址均无法PING通【不修改默认配置的情况下需要排查PAD是否连接车载路由器、工控机是否连接车载路由器、工控机是否开机等】)"
|
||||
)
|
||||
resetArgs()
|
||||
}
|
||||
|
||||
AdasConstants.IpcConnectionStatus.CERTIFICATION_FAILED -> {
|
||||
CallerLogger.d(
|
||||
"$M_D_C$TAG",
|
||||
"认证异常(表示鹰眼端或鹰眼端和域控端启用认证后,认证出现异常。具体认证异常状态详情见认证状态CertificationStatus【鹰眼端验证域控证书失败会断开连接不进行重连;域控端验证鹰眼端证书失败会断开连接,但是由于域控断开并没有发送断开的原因所以鹰眼会自动重连,重连次数可配置为:用不重连、无限重连、指定次数重连】)"
|
||||
)
|
||||
resetArgs()
|
||||
}
|
||||
|
||||
AdasConstants.IpcConnectionStatus.HEARTBEAT_TIMEOUT -> {
|
||||
CallerLogger.d(
|
||||
"$M_D_C$TAG",
|
||||
"心跳超时(表示连接域控成功后在一段时间内未收到域控任何数据,默认4秒【可以配置】),超时时间:${reason}秒"
|
||||
)
|
||||
resetArgs("与域控心跳超时,等待重连")
|
||||
}
|
||||
|
||||
AdasConstants.IpcConnectionStatus.PROTOCOL_MISMATCH -> {
|
||||
CallerLogger.d(
|
||||
"$M_D_C$TAG",
|
||||
"協議不匹配(表示被连接的服务端非WebSocket协议【可能性非常低】)"
|
||||
)
|
||||
resetArgs()
|
||||
}
|
||||
|
||||
AdasConstants.IpcConnectionStatus.SERVER_DISCONNECTED -> {
|
||||
CallerLogger.d(
|
||||
"$M_D_C$TAG",
|
||||
"域控主动断开连接(表示域控主动发起断开WebSocket连接,目前主要原因有:1.证书认证失败;2.老版本MAP不支持多连接的情况下会踢掉客户端;),域控断开发送的消息:${reason}"
|
||||
)
|
||||
resetArgs("域控主动断开连接,等待重连。可能原因:证书认证失败或不支持多连接")
|
||||
}
|
||||
}
|
||||
CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo().ipcConnStatus = ipcConnectionStatus
|
||||
CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo().ipcConnStatus = status
|
||||
CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo().connectStatusDescribe = reason
|
||||
CallerAutoPilotStatusListenerManager.invokeAutoPilotStatus()
|
||||
CallerAutoPilotStatusListenerManager.invokeAutoPilotIPCStatusChanged(ipcConnectionStatus, reason)
|
||||
CallerAutoPilotStatusListenerManager.invokeAutoPilotIPCStatusChanged(status, reason)
|
||||
}
|
||||
|
||||
override fun onCompatibility(versionCompatibility: VersionCompatibility?) {
|
||||
@@ -112,7 +203,7 @@ class MoGoAdasMsgConnectStatusListenerImpl :
|
||||
/**
|
||||
* 工控机获取SN
|
||||
*/
|
||||
override fun onAutopilotSNRequest() {
|
||||
override fun onAutopilotSNRequest(status: AdasConstants.CertificationStatus) {
|
||||
syncBasicInfoToAutopilot()
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import chassis.ChassisStatesOuterClass
|
||||
import com.mogo.eagle.core.function.api.autopilot.*
|
||||
import com.mogo.eagle.core.function.call.autopilot.*
|
||||
import com.mogo.eagle.core.utilcode.kotlin.safeCancel
|
||||
import com.zhjt.mogo.adas.data.AdasConstants
|
||||
import com.zhjt.mogo_core_function_devatools.status.entity.CanStatus
|
||||
import com.zhjt.mogo_core_function_devatools.status.flow.IFlow
|
||||
import kotlinx.coroutines.Job
|
||||
@@ -74,7 +75,7 @@ internal class CanImpl(ctx: Context) :
|
||||
send(CanStatus(isCanEnabled()))
|
||||
}
|
||||
|
||||
override fun onAutopilotIpcConnectStatusChanged(status: Int, reason: String?) {
|
||||
override fun onAutopilotIpcConnectStatusChanged(status: AdasConstants.IpcConnectionStatus, reason: String?) {
|
||||
super.onAutopilotIpcConnectStatusChanged(status, reason)
|
||||
send(CanStatus(isCanEnabled()))
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.zhjt.mogo_core_function_devatools.status.flow.ipc
|
||||
import android.content.*
|
||||
import com.mogo.eagle.core.function.api.autopilot.*
|
||||
import com.mogo.eagle.core.function.call.autopilot.*
|
||||
import com.zhjt.mogo.adas.data.AdasConstants
|
||||
import com.zhjt.mogo_core_function_devatools.status.flow.IFlow
|
||||
import com.zhjt.mogo_core_function_devatools.status.entity.IpcStatus
|
||||
|
||||
@@ -12,14 +13,14 @@ internal class IpcImpl(ctx: Context): IFlow<IpcStatus>(ctx), IMoGoAutopilotStatu
|
||||
const val TAG = "IpcImpl"
|
||||
}
|
||||
|
||||
private var state: Int = -1
|
||||
private var state: AdasConstants.IpcConnectionStatus? = null
|
||||
|
||||
override fun onCreate() {
|
||||
checkAndSend()
|
||||
CallerAutoPilotStatusListenerManager.addListener(TAG, this)
|
||||
}
|
||||
|
||||
override fun onAutopilotIpcConnectStatusChanged(status: Int, reason: String?) {
|
||||
override fun onAutopilotIpcConnectStatusChanged(status: AdasConstants.IpcConnectionStatus, reason: String?) {
|
||||
super.onAutopilotIpcConnectStatusChanged(status, reason)
|
||||
if (state != status) {
|
||||
checkAndSend()
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListener
|
||||
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationWGS84ListenerManager
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.Companion.M_DEVA
|
||||
import com.zhjt.mogo.adas.data.AdasConstants
|
||||
import com.zhjt.mogo_core_function_devatools.status.entity.RTKStatus
|
||||
import com.zhjt.mogo_core_function_devatools.status.flow.IFlow
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -83,7 +84,7 @@ internal class RTKImpl(ctx: Context): IFlow<RTKStatus>(ctx), IMoGoAutopilotStatu
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAutopilotIpcConnectStatusChanged(status: Int, reason: String?) {
|
||||
override fun onAutopilotIpcConnectStatusChanged(status: AdasConstants.IpcConnectionStatus, reason: String?) {
|
||||
super.onAutopilotIpcConnectStatusChanged(status, reason)
|
||||
if (!CallerAutoPilotStatusListenerManager.isConnect()) {
|
||||
CallerLogger.d("$M_DEVA$TAG", "工控机断开了....")
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.content.*
|
||||
import com.mogo.eagle.core.function.api.autopilot.*
|
||||
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener.Companion.STATUS_AUTOPILOT_RUNNING
|
||||
import com.mogo.eagle.core.function.call.autopilot.*
|
||||
import com.zhjt.mogo.adas.data.AdasConstants
|
||||
import com.zhjt.mogo_core_function_devatools.status.entity.*
|
||||
import com.zhjt.mogo_core_function_devatools.status.entity.TracingStatus.Tracing.*
|
||||
import com.zhjt.mogo_core_function_devatools.status.flow.*
|
||||
@@ -19,7 +20,7 @@ internal class TracingImpl(ctx: Context): IFlow<TracingStatus>(ctx), IMoGoAutopi
|
||||
|
||||
private var old: TracingStatus.Tracing = UNKNOWN
|
||||
|
||||
private val ipcConnectStatus by lazy { AtomicInteger() }
|
||||
private val ipcConnectStatus by lazy { AtomicReference<AdasConstants.IpcConnectionStatus>() }
|
||||
|
||||
private val ipcStatus by lazy { AtomicInteger() }
|
||||
|
||||
@@ -54,7 +55,7 @@ internal class TracingImpl(ctx: Context): IFlow<TracingStatus>(ctx), IMoGoAutopi
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAutopilotIpcConnectStatusChanged(status: Int, reason: String?) {
|
||||
override fun onAutopilotIpcConnectStatusChanged(status: AdasConstants.IpcConnectionStatus, reason: String?) {
|
||||
super.onAutopilotIpcConnectStatusChanged(status, reason)
|
||||
try {
|
||||
if (ipcConnectStatus.get() != status) {
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.mogo.eagle.core.utilcode.kotlin.onClick
|
||||
import com.mogo.eagle.core.utilcode.util.NetworkUtils
|
||||
import com.mogo.eagle.core.utilcode.util.ToastUtils
|
||||
import com.mogo.eagle.core.utilcode.util.UiThreadHandler
|
||||
import com.zhjt.mogo.adas.data.AdasConstants
|
||||
import kotlinx.android.synthetic.main.view_blue_tooth.view.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
@@ -99,7 +100,7 @@ open class BlueToothView: LinearLayout, IMoGoMoFangProvider.OnMoFangStatusListen
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAutopilotIpcConnectStatusChanged(status: Int, reason: String?) {
|
||||
override fun onAutopilotIpcConnectStatusChanged(status: AdasConstants.IpcConnectionStatus, reason: String?) {
|
||||
super.onAutopilotIpcConnectStatusChanged(status, reason)
|
||||
if (!CallerAutoPilotStatusListenerManager.isConnect()) {
|
||||
UiThreadHandler.post {
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.mogo.eagle.core.function.hmi.notification.WarningFloat
|
||||
import com.mogo.eagle.core.function.hmi.ui.tools.DockerRebootDialog
|
||||
import com.mogo.eagle.core.utilcode.util.ThreadUtils
|
||||
import com.mogo.eagle.core.utilcode.util.ToastUtils
|
||||
import com.zhjt.mogo.adas.data.AdasConstants
|
||||
import kotlinx.android.synthetic.main.view_check_system.view.*
|
||||
|
||||
class CheckSystemView @JvmOverloads constructor(
|
||||
@@ -100,10 +101,10 @@ class CheckSystemView @JvmOverloads constructor(
|
||||
CallerAutoPilotStatusListenerManager.removeListener(TAG)
|
||||
}
|
||||
|
||||
override fun onAutopilotIpcConnectStatusChanged(status: Int, reason: String?) {
|
||||
override fun onAutopilotIpcConnectStatusChanged(status: AdasConstants.IpcConnectionStatus, reason: String?) {
|
||||
super.onAutopilotIpcConnectStatusChanged(status, reason)
|
||||
ThreadUtils.runOnUiThread {
|
||||
setViewStatus(status == 0x00)
|
||||
setViewStatus(status == AdasConstants.IpcConnectionStatus.CONNECTED)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.mogo.eagle.core.function.hmi.R
|
||||
import com.mogo.eagle.core.utilcode.util.NetworkUtils
|
||||
import com.mogo.eagle.core.utilcode.util.NetworkUtils.OnNetworkStatusChangedListener
|
||||
import com.mogo.eagle.core.utilcode.util.SpanUtils
|
||||
import com.zhjt.mogo.adas.data.AdasConstants
|
||||
import kotlinx.android.synthetic.main.view_connect_status.view.tvADASStatus
|
||||
import kotlinx.android.synthetic.main.view_connect_status.view.tvNetStatus
|
||||
|
||||
@@ -105,11 +106,14 @@ class ConnectStatusView @JvmOverloads constructor(
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAutopilotIpcConnectStatusChanged(status: Int, reason: String?) {
|
||||
override fun onAutopilotIpcConnectStatusChanged(
|
||||
status: AdasConstants.IpcConnectionStatus,
|
||||
reason: String?
|
||||
) {
|
||||
super.onAutopilotIpcConnectStatusChanged(status, reason)
|
||||
tvADASStatus.post {
|
||||
when (status) {
|
||||
IPC_CONNECTION_STATUS.CONNECTED -> {
|
||||
AdasConstants.IpcConnectionStatus.CONNECTED -> {
|
||||
// 统计代码
|
||||
val properties: MutableMap<String, Any> = HashMap()
|
||||
properties["连接状态"] = "已连接"
|
||||
@@ -135,7 +139,15 @@ class ConnectStatusView @JvmOverloads constructor(
|
||||
MogoAnalyticUtils.track("IPC_CONNECTION_STATUS", properties)
|
||||
}
|
||||
|
||||
IPC_CONNECTION_STATUS.DISCONNECTED -> {
|
||||
AdasConstants.IpcConnectionStatus.DISCONNECTED,//未连接或主动断开连接(不管是否配置重连都不进行重连)
|
||||
AdasConstants.IpcConnectionStatus.CONNECT_EXCEPTION,//连接异常
|
||||
AdasConstants.IpcConnectionStatus.ILLEGAL_ADDRESS,//非法地址不管是否配置重连都不进行重连)
|
||||
AdasConstants.IpcConnectionStatus.NOT_FOUND_ADDRESS,//找不到可用地址
|
||||
AdasConstants.IpcConnectionStatus.CERTIFICATION_FAILED,//认证异常(不管是否配置重连都不进行重连)
|
||||
AdasConstants.IpcConnectionStatus.HEARTBEAT_TIMEOUT,//心跳超时
|
||||
AdasConstants.IpcConnectionStatus.PROTOCOL_MISMATCH,//協議不匹配
|
||||
AdasConstants.IpcConnectionStatus.SERVER_DISCONNECTED,//服务端主动断开连接
|
||||
-> {
|
||||
disconnectADASCount++
|
||||
disconnectADASTime = System.currentTimeMillis()
|
||||
val adasSpan = SpanUtils.with(tvADASStatus)
|
||||
@@ -173,33 +185,4 @@ class ConnectStatusView @JvmOverloads constructor(
|
||||
CallerAutoPilotStatusListenerManager.removeListener(TAG)
|
||||
}
|
||||
|
||||
interface IPC_CONNECTION_STATUS {
|
||||
companion object {
|
||||
/**
|
||||
* 已连接
|
||||
*/
|
||||
const val CONNECTED = 0x00
|
||||
|
||||
/**
|
||||
* 未连接
|
||||
*/
|
||||
const val DISCONNECTED = 0x01
|
||||
|
||||
/**
|
||||
* 正在连接
|
||||
*/
|
||||
const val CONNECTING = 0x02
|
||||
|
||||
/**
|
||||
* 正在搜索IP
|
||||
*/
|
||||
const val SEARCH_ADDRESS = 0x03
|
||||
|
||||
/**
|
||||
* 找不到可用IP 传入的IP不可用或固定IP列表中所有IP不可用
|
||||
*/
|
||||
const val NOT_FOUND_ADDRESS = 0x04
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -51,6 +51,7 @@ import com.mogo.eagle.core.utilcode.util.UiThreadHandler
|
||||
import com.mogo.map.listener.IMogoMapListener
|
||||
import com.mogo.map.listener.MogoMapListenerHandler.Companion.mogoMapListenerHandler
|
||||
import com.mogo.map.uicontroller.EnumMapUI
|
||||
import com.zhjt.mogo.adas.data.AdasConstants
|
||||
import com.zhjt.service.chain.ChainLog
|
||||
import kotlinx.android.synthetic.main.module_main_activity_main.module_main_id_cover_up
|
||||
import kotlinx.android.synthetic.main.module_main_activity_main.rvConnectInfo
|
||||
@@ -71,8 +72,8 @@ open class MainActivity : MvpActivity<MainView?, MainPresenter?>(), MainView,
|
||||
private var isFirst = false
|
||||
private var mConnAdapter: ConnInfoAdapter? = null
|
||||
private val dataList: List<AutopilotStatusInfo> = ArrayList()
|
||||
// private var mLastStatus = 0x00
|
||||
private var mLastStatus = 0x01
|
||||
// private var mLastStatus = AdasConstants.IpcConnectionStatus.CONNECTED
|
||||
private var mLastStatus = AdasConstants.IpcConnectionStatus.DISCONNECTED
|
||||
private var isFloatingLayerHidden = false
|
||||
|
||||
override fun getLayoutId(): Int {
|
||||
@@ -323,7 +324,7 @@ open class MainActivity : MvpActivity<MainView?, MainPresenter?>(), MainView,
|
||||
MogoStatusManager.getInstance().setMainPageIsBackgroundStatus(TAG, true)
|
||||
}
|
||||
|
||||
override fun onAutopilotIpcConnectStatusChanged(status: Int, reason: String?) {
|
||||
override fun onAutopilotIpcConnectStatusChanged(status: AdasConstants.IpcConnectionStatus, reason: String?) {
|
||||
super.onAutopilotIpcConnectStatusChanged(status, reason)
|
||||
UiThreadHandler.post {
|
||||
if(mLastStatus != status){
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.mogo.eagle.core.data.autopilot
|
||||
|
||||
import com.zhjt.mogo.adas.data.AdasConstants
|
||||
import java.io.Serializable
|
||||
|
||||
/**
|
||||
@@ -62,7 +63,7 @@ open class AutopilotStatusInfo : Serializable, Cloneable {
|
||||
|
||||
// 默认未连接
|
||||
@Volatile
|
||||
var ipcConnStatus = 0x01
|
||||
var ipcConnStatus = AdasConstants.IpcConnectionStatus.DISCONNECTED
|
||||
|
||||
/**
|
||||
* 记录最后一次启动自动驾驶需要的参数,结束自动驾驶后设置为null
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.mogo.eagle.core.function.api.autopilot
|
||||
|
||||
import com.zhjt.mogo.adas.data.AdasConstants
|
||||
import mogo.telematics.pad.MessagePad
|
||||
import mogo_msg.MogoReportMsg
|
||||
import system_master.*
|
||||
@@ -35,7 +36,7 @@ interface IMoGoAutopilotStatusListener {
|
||||
/**
|
||||
* 工控机获取SN
|
||||
*/
|
||||
fun onAutopilotSNRequest() {}
|
||||
fun onAutopilotSNRequest(status: AdasConstants.CertificationStatus) {}
|
||||
|
||||
/**
|
||||
* 工控机监控节点
|
||||
@@ -45,7 +46,7 @@ interface IMoGoAutopilotStatusListener {
|
||||
/**
|
||||
* 工控机连接状态回调
|
||||
*/
|
||||
fun onAutopilotIpcConnectStatusChanged(status: Int, reason: String?) {}
|
||||
fun onAutopilotIpcConnectStatusChanged(status: AdasConstants.IpcConnectionStatus, reason: String?) {}
|
||||
|
||||
/**
|
||||
* 工控机主动查询 AdasManager#sendStatusQueryReq(),后会收到如下回调
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener
|
||||
import com.mogo.eagle.core.function.call.base.CallerBase
|
||||
import com.mogo.eagle.core.function.call.trace.CallerTrace
|
||||
import com.mogo.eagle.core.utilcode.util.GsonUtils
|
||||
import com.zhjt.mogo.adas.data.AdasConstants
|
||||
import mogo.telematics.pad.MessagePad
|
||||
import mogo_msg.MogoReportMsg
|
||||
import system_master.SsmInfo
|
||||
@@ -177,10 +178,10 @@ object CallerAutoPilotStatusListenerManager : CallerBase<IMoGoAutopilotStatusLis
|
||||
* 工控机获取SN 回调
|
||||
*/
|
||||
@Synchronized
|
||||
fun invokeAutopilotSNRequest() {
|
||||
fun invokeAutopilotSNRequest(status: AdasConstants.CertificationStatus) {
|
||||
M_LISTENERS.forEach {
|
||||
val listener = it.value
|
||||
listener.onAutopilotSNRequest()
|
||||
listener.onAutopilotSNRequest(status)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,10 +201,10 @@ object CallerAutoPilotStatusListenerManager : CallerBase<IMoGoAutopilotStatusLis
|
||||
/**
|
||||
* 工控机与车机连接状态回调
|
||||
*/
|
||||
fun invokeAutoPilotIPCStatusChanged(ipcConnectionStatus: Int, reason: String?) {
|
||||
fun invokeAutoPilotIPCStatusChanged(status: AdasConstants.IpcConnectionStatus, reason: String?) {
|
||||
M_LISTENERS.forEach {
|
||||
val listener = it.value
|
||||
listener.onAutopilotIpcConnectStatusChanged(ipcConnectionStatus, reason)
|
||||
listener.onAutopilotIpcConnectStatusChanged(status, reason)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,10 +49,10 @@ enum SsmSource{
|
||||
enum IpcConnectionStatus{
|
||||
DISCONNECTED = 0;//未连接或主动断开连接(未连接:鹰眼首次启动时未调用连接函数;主动断开连接:主动调用断开连接函数;)
|
||||
CONNECTED = 1;//已连接(表示鹰眼与域控成功建立连接)
|
||||
CONNECTING = 2;//连接中( 表示鹰眼正在与域控进行连接)
|
||||
CONNECTING = 2;//连接中(表示鹰眼正在与域控进行连接)
|
||||
RECONNECTING_TIMER = 3;//重连中(定时器)【表示鹰眼与工控机连接失败,正在尝试建立新的连接】
|
||||
RECONNECTING_NETWORK = 4;//重连中(网络监听)【表示鹰眼与工控机连接失败,正在尝试建立新的连接】
|
||||
CONNECT_EXCEPTION = 5;//连接异常( 表示鹰眼与域控连接失败、无法连接、非正常断开等,会给出具体的异常原因【提示原因为英文】)
|
||||
CONNECT_EXCEPTION = 5;//连接异常(表示鹰眼与域控连接失败、无法连接、非正常断开等,会给出具体的异常原因【提示原因为英文】)
|
||||
ILLEGAL_ADDRESS = 6;//非法地址(连接模式为指定地址时:表示当前鹰眼调用连接时传入的域控地址错误或不符合规则【不修改默认配置不会出现此问题】;连接模式为PING模式时:表示传入的PING地址列表存在问题)
|
||||
SEARCH_ADDRESS = 7;//正在搜索域控地址(表示当前鹰眼正在查找是否有可用的域控地址)
|
||||
NOT_FOUND_ADDRESS = 8;//找不到可用地址(当前鹰眼配置的域控地址列表中的全部地址均无法PING通【不修改默认配置的情况下需要排查PAD是否连接车载路由器、工控机是否连接车载路由器、工控机是否开机等】)
|
||||
|
||||
@@ -23,11 +23,12 @@ import androidx.annotation.Nullable;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import com.zhidao.support.adas.high.bean.VersionCompatibility;
|
||||
import com.zhidao.support.adas.high.common.AutopilotReview;
|
||||
import com.zhidao.support.adas.high.common.CertificateUtils;
|
||||
import com.zhidao.support.adas.high.common.Constants;
|
||||
import com.zhidao.support.adas.high.common.CupidLogUtils;
|
||||
import com.zhidao.support.adas.high.common.Define;
|
||||
import com.zhidao.support.adas.high.common.IPCFixationIPHelper;
|
||||
import com.zhidao.support.adas.high.common.ParallelDrivingManager;
|
||||
import com.zhidao.support.adas.high.common.PingAddressHelper;
|
||||
import com.zhidao.support.adas.high.common.ProtocolStatus;
|
||||
import com.zhidao.support.adas.high.common.ReceiveTimeoutManager;
|
||||
import com.zhidao.support.adas.high.common.ReceivedAckManager;
|
||||
@@ -66,7 +67,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import bag_manager.BagManagerOuterClass;
|
||||
import chassis.Chassis;
|
||||
@@ -90,7 +91,7 @@ import okio.ByteString;
|
||||
* @UpdateRemark: 更新说明:
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnectListener, IPCFixationIPHelper.IIPCFixationIPListener, DispatchHandler.OnDispatchHandlerListener, SubscribeInterface.OnSubscribeInterfaceListener {
|
||||
public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnectListener, PingAddressHelper.IPingAddressListener, DispatchHandler.OnDispatchHandlerListener, SubscribeInterface.OnSubscribeInterfaceListener {
|
||||
private static final String TAG = AdasChannel.class.getSimpleName();
|
||||
private FpgaSocket mSocket;
|
||||
private RawUnpack rawUnpack;//业务数据拆包
|
||||
@@ -100,13 +101,8 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
private final Map<MessagePad.MessageType, DispatchHandler> dispatchHandlers = new HashMap<>();//其他分发线程
|
||||
private Timer checkCompatibilityTimer;//检查版本兼容性定时器 连接成功后5秒内等待工控机发送配置信息
|
||||
private int seqSpecialVehicle = 0;//特种车辆命令发送次数
|
||||
private AdasConstants.ChassisSource usedChassisSource = AdasConstants.ChassisSource.CHASSIS_UNKNOWN;//使用的底盘类型 新老
|
||||
private AdasConstants.SsmSource usedSsmSource = AdasConstants.SsmSource.SSM_UNKNOWN;//使用的SSM类型
|
||||
|
||||
/**
|
||||
* 与工控机链接状态
|
||||
*/
|
||||
private final AtomicInteger ipcConnectionStatus = new AtomicInteger(Constants.IPC_CONNECTION_STATUS.DISCONNECTED);
|
||||
private AdasConstants.ChassisSource usedChassisSource = AdasConstants.ChassisSource.CHASSIS_UNKNOWN;//使用的底盘类型 新底盘接口还是老底盘接口
|
||||
private AdasConstants.SsmSource usedSsmSource = AdasConstants.SsmSource.SSM_UNKNOWN;//使用的SSM类型 服务接口还是定频接口
|
||||
|
||||
|
||||
/**
|
||||
@@ -140,16 +136,21 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
/**
|
||||
* IPC固定IP查询工具类
|
||||
*/
|
||||
private IPCFixationIPHelper ipcFixationIPHelper;
|
||||
private PingAddressHelper pingAddressHelper;
|
||||
/**
|
||||
* 工控机接口注册 连接成功后可以进行操作 乘客屏未null
|
||||
* 乘客屏无法进行注册或取消注册,因为乘客屏无法感知司机屏与工控机连接状态。无法重置已注册或未注册接口列表
|
||||
*/
|
||||
private SubscribeInterface subscribeInterface;
|
||||
private Timer carConfigReqTimer;//车辆基础信息请求 多次请求防止无法收到基础信息情况出现
|
||||
|
||||
private OnAdasListener mAdasListener;
|
||||
//连接状态listener
|
||||
private final OnAdasConnectStatusListener adasConnectStatusListener;
|
||||
private Context context;
|
||||
|
||||
private final ReceivedAckManager receivedAckManager = new ReceivedAckManager();//消息回执
|
||||
private final AtomicBoolean isInitConfigure = new AtomicBoolean(false);//是否进行配置初始化
|
||||
|
||||
public void setOnMultiDeviceListener(OnMultiDeviceListener onMultiDeviceListener) {
|
||||
this.onMultiDeviceListener = onMultiDeviceListener;
|
||||
@@ -157,12 +158,20 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
|
||||
@Override
|
||||
public void onStartFindIP() {
|
||||
updateConnectStatus(Constants.IPC_CONNECTION_STATUS.SEARCH_ADDRESS, "正在搜索IP");
|
||||
updateConnectStatus(AdasConstants.IpcConnectionStatus.SEARCH_ADDRESS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopFindIP() {
|
||||
updateConnectStatus(Constants.IPC_CONNECTION_STATUS.DISCONNECTED, "停止搜索IP");
|
||||
public void onIllegalAddress() {
|
||||
updateConnectStatus(AdasConstants.IpcConnectionStatus.ILLEGAL_ADDRESS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopFindIP(boolean isCall) {
|
||||
pingAddressHelper = null;
|
||||
if (isCall) {
|
||||
updateConnectStatus(AdasConstants.IpcConnectionStatus.DISCONNECTED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -172,7 +181,11 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
*/
|
||||
@Override
|
||||
public void onAvailableIP(String ip) {
|
||||
onConnectionAddress(ip);
|
||||
if (TextUtils.isEmpty(ip)) {
|
||||
updateConnectStatus(AdasConstants.IpcConnectionStatus.NOT_FOUND_ADDRESS);
|
||||
} else {
|
||||
onConnectionAddress(ip);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -186,14 +199,15 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
this.adasConnectStatusListener = listener;
|
||||
setAdasOptions(options);
|
||||
initData();
|
||||
if (!adasOptions.isPassenger() && listener != null)
|
||||
if (!adasOptions.isPassenger() && listener != null && adasOptions.isAutoConnect())
|
||||
connect();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAdasOptions(AdasOptions options) {
|
||||
//配置为null默认是乘客屏幕
|
||||
if (options == null) {
|
||||
buildAdasOptions(AdasOptions.newBuilder());
|
||||
adasOptionsBuild(AdasOptions.newBuilder());
|
||||
} else {
|
||||
this.adasOptions = options;
|
||||
}
|
||||
@@ -206,10 +220,14 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
*
|
||||
* @param builder builder
|
||||
*/
|
||||
private void buildAdasOptions(@NonNull AdasOptions.Builder builder) {
|
||||
private void adasOptionsBuild(@NonNull AdasOptions.Builder builder) {
|
||||
this.adasOptions = builder.build();
|
||||
}
|
||||
|
||||
private AdasOptions.Builder adasOptionsToBuilder() {
|
||||
return adasOptions.toBuilder();
|
||||
}
|
||||
|
||||
private void initData() {
|
||||
//原始数据解析类
|
||||
rawUnpack = new RawUnpack();
|
||||
@@ -308,10 +326,19 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
/**
|
||||
* 根据固定IP查询可用IP
|
||||
*/
|
||||
private void ipcFixationIPHelper(HashSet<String> ips) {
|
||||
if (ipcFixationIPHelper == null)
|
||||
ipcFixationIPHelper = new IPCFixationIPHelper(this);
|
||||
ipcFixationIPHelper.start(ips);
|
||||
private void startPingAddress(HashSet<String> ips) {
|
||||
if (pingAddressHelper == null) {
|
||||
pingAddressHelper = new PingAddressHelper(this);
|
||||
pingAddressHelper.start(ips);
|
||||
}
|
||||
pingAddressHelper.setReconnectCount(adasOptions.getReconnectCount());
|
||||
}
|
||||
|
||||
private void stopPingAddress(boolean isCall) {
|
||||
if (pingAddressHelper != null) {
|
||||
pingAddressHelper.stop(isCall);
|
||||
pingAddressHelper = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ChainLog(linkChainLog = CHAIN_TYPE_INIT_STATUS,
|
||||
@@ -330,7 +357,7 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
WSByteQueueManager.getInstance().initDector();
|
||||
}
|
||||
}
|
||||
// mSocket.setReconnectCount(adasOptions.getReconnectCount());
|
||||
mSocket.setReconnectCount(adasOptions.getReconnectCount());
|
||||
}
|
||||
|
||||
@ChainLog(linkChainLog = CHAIN_TYPE_INIT_STATUS,
|
||||
@@ -339,10 +366,12 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
paramIndexes = {0, 1})
|
||||
private void connectSocket(String address, int port) {
|
||||
if (mSocket != null) {
|
||||
isInitConfigure.set(false);
|
||||
mSocket.connectWebSocket(address, port);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getIpcConnectedIp() {
|
||||
return ipcConnectedIp;
|
||||
@@ -363,10 +392,6 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
return usedSsmSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUnableLaunchAutopilotGear(Set<Chassis.GearPosition> unableLaunchAutopilotGear) {
|
||||
AutopilotAbilityManager.getInstance().setUnableLaunchAutopilotGear(unableLaunchAutopilotGear);
|
||||
}
|
||||
|
||||
public void setSupportReceivedAck(int version) {
|
||||
receivedAckManager.setSupport(version);
|
||||
@@ -520,6 +545,55 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 认证超时执行
|
||||
*/
|
||||
private final Runnable certificationTimeoutRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
certification(true, null);
|
||||
}
|
||||
};
|
||||
|
||||
private void certification(boolean isTimeout, String ipcCrt) {
|
||||
AdasConstants.CertificationStatus result = AdasConstants.CertificationStatus.NOT_ENABLED;
|
||||
//检查是否开启验证
|
||||
if (adasOptions.isCertification()) {
|
||||
if (isTimeout) {
|
||||
result = AdasConstants.CertificationStatus.TIMEOUT;
|
||||
} else {
|
||||
if (defaultDispatchHandler != null) {
|
||||
defaultDispatchHandler.removeCallbacks(certificationTimeoutRunnable);
|
||||
}
|
||||
String rootCrt = adasOptions.getRootCrt();
|
||||
if (rootCrt == null || rootCrt.length() == 0) {
|
||||
//提示证书验证失败
|
||||
result = AdasConstants.CertificationStatus.ROOT_CRT_ERROR;
|
||||
} else {
|
||||
if (ipcCrt == null || ipcCrt.length() == 0) {
|
||||
//提示域控证书失败
|
||||
result = AdasConstants.CertificationStatus.IPC_CRT_ERROR;
|
||||
} else {
|
||||
boolean isSucceed = CertificateUtils.certificateChainValidation(rootCrt, ipcCrt);
|
||||
result = isSucceed ? AdasConstants.CertificationStatus.CERTIFICATE_CHAIN_SUCCESS : AdasConstants.CertificationStatus.CERTIFICATE_CHAIN_FAILED;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mAdasListener != null) {
|
||||
mAdasListener.onBasicInfoReq(result);
|
||||
}
|
||||
CupidLogUtils.log(TAG, "证书验证状态=" + result);
|
||||
if (result == AdasConstants.CertificationStatus.CERTIFICATE_CHAIN_SUCCESS) {
|
||||
//验证域控证书成功后发送数据给域控
|
||||
// initConfigure();
|
||||
} else if (result.getNumber() > AdasConstants.CertificationStatus.CERTIFICATE_CHAIN_SUCCESS.getNumber()) {
|
||||
//认证失败,断开连接
|
||||
disconnect(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 分发和解析
|
||||
*
|
||||
@@ -537,6 +611,11 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
long time = System.currentTimeMillis();
|
||||
MessagePad.ReceivedAck ack = MessagePad.ReceivedAck.parser().parseFrom(raw.originalData.toByteArray(), raw.getOffsetValue(), raw.getPackageLengthValue() - raw.getOffsetValue());
|
||||
receivedAckManager.receiveReceivedAck(time, ack);
|
||||
CupidLogUtils.log(TAG, "收到回执=" + ack);
|
||||
} else if (messageType == MessageType.TYPE_RECEIVE_BASIC_INFO_REQ.typeCode) {
|
||||
MessagePad.BasicInfoReq autopilotState = MessagePad.BasicInfoReq.parser().parseFrom(raw.originalData.toByteArray(), raw.getOffsetValue(), raw.getPackageLengthValue() - raw.getOffsetValue());
|
||||
String ipcCrt = CertificateUtils.decode(autopilotState.getCertification());
|
||||
certification(false, ipcCrt);
|
||||
} else {
|
||||
IMsg iMsg = myMessageFactory.createMessage(messageType);
|
||||
if (iMsg == null) {
|
||||
@@ -544,6 +623,11 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
return;
|
||||
}
|
||||
iMsg.handlerMsg(raw, mAdasListener);
|
||||
//存在定频数据接口,当收到域控任意定频数据,就认为通讯彻底建立成功,可以交互数据
|
||||
if (!isInitConfigure.get()) {
|
||||
isInitConfigure.set(true);
|
||||
initConfigure();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
callError(raw.getProtocolStatus(), raw.originalData.toByteArray());
|
||||
@@ -573,11 +657,10 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
//当是司机屏才启用
|
||||
if (!adasOptions.isPassenger()) {
|
||||
initSocket();
|
||||
if (ipcConnectionStatus.get() == Constants.IPC_CONNECTION_STATUS.DISCONNECTED ||
|
||||
ipcConnectionStatus.get() == Constants.IPC_CONNECTION_STATUS.NOT_FOUND_ADDRESS) {
|
||||
if (connectFinish()) {
|
||||
switch (adasOptions.getConnectionMode()) {
|
||||
case AdasOptions.IPC_CONNECTION_MODE.PING:
|
||||
ipcFixationIPHelper(adasOptions.getPingAddressList());
|
||||
startPingAddress(adasOptions.getPingAddressList());
|
||||
break;
|
||||
case AdasOptions.IPC_CONNECTION_MODE.SPECIFIED:
|
||||
onConnectionAddress(adasOptions.getSpecifiedAddress());
|
||||
@@ -592,12 +675,15 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
*/
|
||||
@Override
|
||||
public void disconnect() {
|
||||
if (ipcFixationIPHelper != null) {
|
||||
ipcFixationIPHelper.stop();
|
||||
}
|
||||
disconnect(false);
|
||||
}
|
||||
|
||||
public void disconnect(boolean isCertificationFailed) {
|
||||
stopPingAddress(true);
|
||||
isInitConfigure.set(false);
|
||||
if (!adasOptions.isPassenger()) {
|
||||
if (mSocket != null)
|
||||
mSocket.closeWebSocket();
|
||||
mSocket.closeWebSocket(isCertificationFailed);
|
||||
if (isUseQueue) {
|
||||
WebSocketQueueManager.getInstance().release();
|
||||
WSByteQueueManager.getInstance().release();
|
||||
@@ -605,46 +691,73 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnecting(String msg) {
|
||||
updateConnectStatus(Constants.IPC_CONNECTION_STATUS.CONNECTING, msg == null ? "" : msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWebSocketConnectSuccess(String ipAddress, int port) {
|
||||
/**
|
||||
* 连接成功欧配置一些参数和发送一些配置数据
|
||||
*/
|
||||
private void initConfigure() {
|
||||
startCarConfigReq();
|
||||
ipcConnectedIp = ipAddress;
|
||||
ipcConnectedPort = port;
|
||||
subscribeInterface = new SubscribeInterface(this);
|
||||
seqSpecialVehicle = 0;
|
||||
updateConnectStatus(Constants.IPC_CONNECTION_STATUS.CONNECTED, "已连接");
|
||||
//根据连接配置 进行接口订阅或取消订阅配置
|
||||
if (adasOptions != null) {
|
||||
Set<SubscribeInterfaceOption> options = adasOptions.getSubscribeInterfaceOptions();
|
||||
if (options != null && !options.isEmpty()) {
|
||||
for (SubscribeInterfaceOption option : options) {
|
||||
MessageType messageType = option.getMessageType();
|
||||
if (messageType != null) {
|
||||
subscribeInterface.subscribeInterface(option.getRole(), option.getType(), messageType);
|
||||
}
|
||||
Set<MessageType> messageTypes = option.getMessageTypes();
|
||||
if (messageTypes != null) {
|
||||
subscribeInterface.subscribeInterface(option.getRole(), option.getType(), messageTypes);
|
||||
}
|
||||
Set<SubscribeInterfaceOption> options = adasOptions.getSubscribeInterfaceOptions();
|
||||
if (options != null && !options.isEmpty()) {
|
||||
for (SubscribeInterfaceOption option : options) {
|
||||
MessageType messageType = option.getMessageType();
|
||||
if (messageType != null) {
|
||||
subscribeInterface.subscribeInterface(option.getRole(), option.getType(), messageType);
|
||||
}
|
||||
Set<MessageType> messageTypes = option.getMessageTypes();
|
||||
if (messageTypes != null) {
|
||||
subscribeInterface.subscribeInterface(option.getRole(), option.getType(), messageTypes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWebSocketConnectFailed(String t) {
|
||||
ipcConnectedIp = null;
|
||||
ipcConnectedPort = Constants.DEFAULT_PORT;
|
||||
subscribeInterface = null;
|
||||
usedChassisSource = AdasConstants.ChassisSource.CHASSIS_UNKNOWN;
|
||||
usedSsmSource = AdasConstants.SsmSource.SSM_UNKNOWN;
|
||||
receivedAckManager.stop();
|
||||
updateConnectStatus(Constants.IPC_CONNECTION_STATUS.DISCONNECTED, t == null ? "" : t);
|
||||
public void onWebSocketConnectStatus(AdasConstants.IpcConnectionStatus status, Object... args) {
|
||||
if (status == AdasConstants.IpcConnectionStatus.CONNECTED) { //连接成功
|
||||
if (args != null && args.length > 1) {
|
||||
ipcConnectedIp = (String) args[0];
|
||||
ipcConnectedPort = (int) args[1];
|
||||
}
|
||||
seqSpecialVehicle = 0;
|
||||
AutopilotAbilityManager.getInstance().start();
|
||||
ParallelDrivingManager.getInstance().start();
|
||||
startCheckCompatibility();
|
||||
updateConnectStatus(status, null);
|
||||
//更新连接成功状态之后再根据是否认证进行认证检查
|
||||
if (adasOptions.isCertification()) {
|
||||
//启动认证超时
|
||||
if (defaultDispatchHandler != null) {
|
||||
defaultDispatchHandler.start();
|
||||
defaultDispatchHandler.postRunnableDelayed(certificationTimeoutRunnable, 5000L);
|
||||
}
|
||||
} else {
|
||||
//不启用认证的时候直接进行数据发送
|
||||
// initConfigure();//注释掉统一改成等待域控定频接口存储数据的时候调用
|
||||
}
|
||||
} else {
|
||||
AutopilotAbilityManager.getInstance().stop();
|
||||
ParallelDrivingManager.getInstance().stop();
|
||||
AdasManager.getInstance().setCarConfig(null);
|
||||
stopCheckCompatibility();
|
||||
stopDispatchHandler();
|
||||
stopCarConfigReq();
|
||||
ipcConnectedIp = null;
|
||||
ipcConnectedPort = Constants.DEFAULT_PORT;
|
||||
subscribeInterface = null;
|
||||
usedChassisSource = AdasConstants.ChassisSource.CHASSIS_UNKNOWN;
|
||||
usedSsmSource = AdasConstants.SsmSource.SSM_UNKNOWN;
|
||||
receivedAckManager.stop();
|
||||
if (connectFinish()) {
|
||||
stopPingAddress(false);
|
||||
}
|
||||
String reason = null;
|
||||
if (args != null && args.length > 0) {
|
||||
reason = String.valueOf(args[0]);
|
||||
}
|
||||
updateConnectStatus(status, reason);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -673,10 +786,6 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
calculateTimeConsumingOnMessage(nowTime);
|
||||
}
|
||||
|
||||
private void notFoundAddress() {
|
||||
updateConnectStatus(Constants.IPC_CONNECTION_STATUS.NOT_FOUND_ADDRESS, "地址不可用或不合法");
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据IP和端口进行连接
|
||||
*
|
||||
@@ -686,7 +795,7 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
CupidLogUtils.e(TAG, "要连接的工控机地址=" + address);
|
||||
|
||||
if (TextUtils.isEmpty(address)) {
|
||||
notFoundAddress();
|
||||
onIllegalAddress();
|
||||
return;
|
||||
}
|
||||
String tempIp;
|
||||
@@ -694,19 +803,19 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
if (address.contains(":")) {
|
||||
String[] temp = address.split(":");
|
||||
if (temp.length < 2) {
|
||||
notFoundAddress();
|
||||
onIllegalAddress();
|
||||
return;
|
||||
}
|
||||
tempIp = temp[0];
|
||||
try {
|
||||
tempPort = Integer.parseInt(temp[1]);
|
||||
if (tempPort <= 0 || tempPort > 65535) {
|
||||
notFoundAddress();
|
||||
onIllegalAddress();
|
||||
return;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
notFoundAddress();
|
||||
onIllegalAddress();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -715,15 +824,41 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
tempPort = Constants.DEFAULT_PORT;
|
||||
}
|
||||
if (!RegexUtils.isIP(tempIp)) {
|
||||
notFoundAddress();
|
||||
onIllegalAddress();
|
||||
return;
|
||||
}
|
||||
connectSocket(tempIp, tempPort);
|
||||
}
|
||||
|
||||
private OnAdasListener mAdasListener;
|
||||
//连接状态listener
|
||||
private final OnAdasConnectStatusListener adasConnectStatusListener;
|
||||
/**
|
||||
* 连接失败未成功建立连接且不进行重连
|
||||
*/
|
||||
private boolean connectFinish() {
|
||||
AdasConstants.IpcConnectionStatus status = getIpcConnectionStatus();
|
||||
CupidLogUtils.log(TAG, "连接状态=" + status + " 是否正在重连=" + mSocket.isReconnection());
|
||||
if (status == AdasConstants.IpcConnectionStatus.DISCONNECTED) {
|
||||
return true;
|
||||
} else {
|
||||
if (mSocket != null && mSocket.isReconnection()) {
|
||||
return false;
|
||||
} else {
|
||||
return status == AdasConstants.IpcConnectionStatus.CONNECT_EXCEPTION ||
|
||||
status == AdasConstants.IpcConnectionStatus.ILLEGAL_ADDRESS ||
|
||||
status == AdasConstants.IpcConnectionStatus.NOT_FOUND_ADDRESS ||
|
||||
status == AdasConstants.IpcConnectionStatus.CERTIFICATION_FAILED ||
|
||||
status == AdasConstants.IpcConnectionStatus.SERVER_DISCONNECTED ||
|
||||
(status == AdasConstants.IpcConnectionStatus.HEARTBEAT_TIMEOUT)
|
||||
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//此状态更新两个作用:1.更改FpgaSocket中的status状态;2.更新对外连接状态
|
||||
private void updateConnectStatus(AdasConstants.IpcConnectionStatus status) {
|
||||
setConnectStatus(status);
|
||||
updateConnectStatus(status, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 工控机连接状态更新
|
||||
@@ -732,28 +867,17 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
* @param reason 状态描述
|
||||
* 如果ipcConnectionStatus == Constants.IPC_CONNECTION_STATUS.DISCONNECTED && reason==null 表示主动断开连接
|
||||
*/
|
||||
private void updateConnectStatus(@Define.IPCConnectionStatus int status, @Nullable String reason) {
|
||||
log(status, reason);
|
||||
ipcConnectionStatus.set(status);
|
||||
if (status == Constants.IPC_CONNECTION_STATUS.CONNECTED) {
|
||||
AutopilotAbilityManager.getInstance().start();
|
||||
ParallelDrivingManager.getInstance().start();
|
||||
startCheckCompatibility();
|
||||
} else {
|
||||
AutopilotAbilityManager.getInstance().stop();
|
||||
ParallelDrivingManager.getInstance().stop();
|
||||
stopCheckCompatibility();
|
||||
stopCarConfigReq();
|
||||
}
|
||||
if (status == Constants.IPC_CONNECTION_STATUS.DISCONNECTED) {
|
||||
AdasManager.getInstance().setCarConfig(null);
|
||||
stopDispatchHandler();
|
||||
stopCarConfigReq();
|
||||
}
|
||||
private void updateConnectStatus(AdasConstants.IpcConnectionStatus status, @Nullable String reason) {
|
||||
if (adasConnectStatusListener != null) {
|
||||
adasConnectStatusListener.onConnectionIPCStatus(ipcConnectionStatus.get(), reason);
|
||||
adasConnectStatusListener.onConnectionIPCStatus(status, reason);
|
||||
}
|
||||
}
|
||||
|
||||
private void setConnectStatus(AdasConstants.IpcConnectionStatus status) {
|
||||
CupidLogUtils.log("FpgaSocket", "Socket是否存在=" + (mSocket != null) + "设置域控连接状态=" + status);
|
||||
if (mSocket != null) {
|
||||
mSocket.setStatus(status);
|
||||
}
|
||||
CupidLogUtils.i(TAG, "工控机连接状态 status=" + status + " reason=" + reason);
|
||||
}
|
||||
|
||||
@ChainLog(linkChainLog = CHAIN_TYPE_INIT_STATUS,
|
||||
@@ -812,7 +936,7 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
@Override
|
||||
public VersionCompatibility getVersionCompatibility() {
|
||||
//判断是否是已连接成功
|
||||
if (ipcConnectionStatus.get() == Constants.IPC_CONNECTION_STATUS.CONNECTED) {
|
||||
if (getIpcConnectionStatus() == AdasConstants.IpcConnectionStatus.CONNECTED) {
|
||||
MessagePad.CarConfigResp carConfigResp = AdasManager.getInstance().getCarConfig();
|
||||
boolean isCompatibility = false;
|
||||
VersionCompatibility.VersionCompatibilityDegree compatibilityDegree = VersionCompatibility.VersionCompatibilityDegree.INCOMPATIBLE;
|
||||
@@ -847,8 +971,9 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIpcConnectionStatus() {
|
||||
return ipcConnectionStatus.get();
|
||||
public AdasConstants.IpcConnectionStatus getIpcConnectionStatus() {
|
||||
if (mSocket != null) return mSocket.getStatus();
|
||||
return AdasConstants.IpcConnectionStatus.DISCONNECTED;
|
||||
}
|
||||
|
||||
|
||||
@@ -880,7 +1005,7 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (getIpcConnectionStatus() == Constants.IPC_CONNECTION_STATUS.CONNECTED) {
|
||||
if (getIpcConnectionStatus() == AdasConstants.IpcConnectionStatus.CONNECTED) {
|
||||
if (AdasManager.getInstance().getCarConfig() == null) {
|
||||
num++;
|
||||
if (num > 3) {
|
||||
@@ -907,19 +1032,93 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
}
|
||||
|
||||
/**************************************************************************************************************************/
|
||||
|
||||
/**
|
||||
* 设置是否启用超时检测
|
||||
* 不会存储 下次启动恢复默认
|
||||
* 每次调用create之后需要重新设置才能生效,或者在AdasOptions中设置
|
||||
*
|
||||
* @param isEnable 是否启用
|
||||
*/
|
||||
@Override
|
||||
public void setEnableTimeoutDetection(boolean isEnable) {
|
||||
adasOptionsBuild(adasOptionsToBuilder().setEnableTimeoutDetection(isEnable));
|
||||
ReceiveTimeoutManager.getInstance().setEnable(isEnable, getIpcConnectionStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置重连次数
|
||||
* -1:不重连
|
||||
* 0:无限重连
|
||||
* >0:指定重连次数
|
||||
* 默认:0
|
||||
* 每次调用create之后需要重新设置才能生效,或者在AdasOptions中设置
|
||||
*
|
||||
* @param reconnectCount 次数
|
||||
*/
|
||||
@Override
|
||||
public void setReconnectCount(int reconnectCount) {
|
||||
adasOptionsBuild(adasOptionsToBuilder().setReconnectCount(reconnectCount));
|
||||
if (pingAddressHelper != null) {
|
||||
pingAddressHelper.setReconnectCount(reconnectCount);
|
||||
}
|
||||
if (!adasOptions.isPassenger() && mSocket != null) {
|
||||
mSocket.setReconnectCount(reconnectCount);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否启用SSL认证
|
||||
* 目前默认禁用
|
||||
* 每次调用create之后需要重新设置才能生效,或者在AdasOptions中设置
|
||||
*/
|
||||
@Override
|
||||
public void setEnableCertification(boolean enable) {
|
||||
adasOptionsBuild(adasOptionsToBuilder().setEnableCertification(enable));
|
||||
}
|
||||
|
||||
/**
|
||||
* ROOT证书
|
||||
* 启用认证必须传
|
||||
* 每次调用create之后需要重新设置才能生效,或者在AdasOptions中设置
|
||||
*
|
||||
* @param rootCrt root证书
|
||||
*/
|
||||
@Override
|
||||
public void setRootCrt(String rootCrt) {
|
||||
adasOptionsBuild(adasOptionsToBuilder().setRootCrt(rootCrt));
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动连接
|
||||
* 不会存储 下次启动恢复默认
|
||||
* 每次调用create之后需要重新设置才能生效,或者在AdasOptions中设置
|
||||
*
|
||||
* @param enable 是否启用
|
||||
*/
|
||||
@Override
|
||||
public void setAutoConnect(boolean enable) {
|
||||
adasOptionsBuild(adasOptionsToBuilder().setAutoConnect(enable));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUnableLaunchAutopilotGear(Set<Chassis.GearPosition> unableLaunchAutopilotGear) {
|
||||
AutopilotAbilityManager.getInstance().setUnableLaunchAutopilotGear(unableLaunchAutopilotGear);
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动驾驶设备基础信息应答
|
||||
*
|
||||
* @param sn SN
|
||||
* @param environment 环境 详情参见{@link Constants.ENVIRONMENT}1: 研发环境, 2:测试环境, 3:生产环境 4:演示环境
|
||||
* @param role 终端角色 详情参见{@link Constants.TERMINAL_ROLE}
|
||||
* @param versionCode 鹰眼版本号
|
||||
* @param versionName 鹰眼版本名
|
||||
* @param certification 鹰眼ssl证书
|
||||
* @param sn SN
|
||||
* @param environment 环境 详情参见{@link Constants.ENVIRONMENT}1: 研发环境, 2:测试环境, 3:生产环境 4:演示环境
|
||||
* @param role 终端角色 详情参见{@link Constants.TERMINAL_ROLE}
|
||||
* @param versionCode 鹰眼版本号
|
||||
* @param versionName 鹰眼版本名
|
||||
* @param deviceCrt 鹰眼ssl证书
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean sendBasicInfoResp(@NonNull String sn, @Define.Environment int environment, @Define.TerminalRole int role, int versionCode, String versionName, byte[] certification) {
|
||||
public boolean sendBasicInfoResp(@NonNull String sn, @Define.Environment int environment, @Define.TerminalRole int role, int versionCode, String versionName, String deviceCrt) {
|
||||
if (sn == null) {
|
||||
sn = "";
|
||||
}
|
||||
@@ -941,8 +1140,11 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
if (!TextUtils.isEmpty(version)) {
|
||||
builder.setVersion(version);
|
||||
}
|
||||
if (certification != null && certification.length > 0) {
|
||||
builder.setCertification(com.google.protobuf.ByteString.copyFrom(certification));
|
||||
if (deviceCrt != null && deviceCrt.length() > 0) {
|
||||
com.google.protobuf.ByteString crt = CertificateUtils.encode(deviceCrt);
|
||||
if (crt != null) {
|
||||
builder.setCertification(crt);
|
||||
}
|
||||
}
|
||||
MessagePad.BasicInfoResp resp = builder.build();
|
||||
return sendPBMessage(MessageType.TYPE_SEND_BASIC_INFO_RESP, resp.toByteArray());
|
||||
|
||||
@@ -61,7 +61,6 @@ public class AdasManager implements IAdasNetCommApi {
|
||||
private final Pattern pattern = Pattern.compile("\\d+\\.\\d+\\.\\d+");
|
||||
|
||||
private AdasChannel mChannel;
|
||||
private Context context;//不持有,create之后会置null
|
||||
|
||||
public static AdasManager getInstance() {
|
||||
if (ourInstance == null) {
|
||||
@@ -109,12 +108,11 @@ public class AdasManager implements IAdasNetCommApi {
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
* TODO 必须在调用任意方法之前初始化
|
||||
* TODO 必须在调用使用到MMK相关的方法之前初始化
|
||||
*
|
||||
* @param context
|
||||
*/
|
||||
public void init(Context context) {
|
||||
this.context = context;
|
||||
MMKVUtils.getInstance().init(context);
|
||||
}
|
||||
|
||||
@@ -124,14 +122,13 @@ public class AdasManager implements IAdasNetCommApi {
|
||||
* @param options 连接参数
|
||||
* @param onAdasConnectStatusListener 连接状态监听
|
||||
*/
|
||||
public synchronized void create(AdasOptions options, OnAdasConnectStatusListener onAdasConnectStatusListener) {
|
||||
public synchronized void create(Context context, AdasOptions options, OnAdasConnectStatusListener onAdasConnectStatusListener) {
|
||||
if (mChannel != null) {
|
||||
mChannel.disconnect();
|
||||
carConfig = null;
|
||||
mChannel = null;
|
||||
}
|
||||
mChannel = new AdasChannel(context, options, onAdasConnectStatusListener);
|
||||
context = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -182,17 +179,24 @@ public class AdasManager implements IAdasNetCommApi {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAdasOptions(AdasOptions options) {
|
||||
if (mChannel != null) {
|
||||
mChannel.setAdasOptions(options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前工控机的链接状态
|
||||
*
|
||||
* @return {@link Constants.IPC_CONNECTION_STATUS}
|
||||
* @return {@link AdasConstants.IpcConnectionStatus}
|
||||
*/
|
||||
@Override
|
||||
public int getIpcConnectionStatus() {
|
||||
public AdasConstants.IpcConnectionStatus getIpcConnectionStatus() {
|
||||
if (mChannel != null) {
|
||||
return mChannel.getIpcConnectionStatus();
|
||||
}
|
||||
return Constants.IPC_CONNECTION_STATUS.DISCONNECTED;
|
||||
return AdasConstants.IpcConnectionStatus.DISCONNECTED;
|
||||
}
|
||||
|
||||
|
||||
@@ -267,7 +271,7 @@ public class AdasManager implements IAdasNetCommApi {
|
||||
/**
|
||||
* 获取工控机链接配置
|
||||
*
|
||||
* @return 工控机链接参数
|
||||
* @return 工控机链接参数,如果未调用create 返回null
|
||||
*/
|
||||
@Override
|
||||
public AdasOptions getAdasOptions() {
|
||||
@@ -314,16 +318,6 @@ public class AdasManager implements IAdasNetCommApi {
|
||||
return mChannel == null ? AdasConstants.SsmSource.SSM_UNKNOWN : mChannel.getUsedSsmSource();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置不能启动自动驾驶的档位
|
||||
*
|
||||
* @param unableLaunchAutopilotGear 不能起自驾档位
|
||||
*/
|
||||
@Override
|
||||
public void setUnableLaunchAutopilotGear(Set<Chassis.GearPosition> unableLaunchAutopilotGear) {
|
||||
AutopilotAbilityManager.getInstance().setUnableLaunchAutopilotGear(unableLaunchAutopilotGear);
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动驾驶设备基础信息应答
|
||||
*
|
||||
@@ -353,30 +347,30 @@ public class AdasManager implements IAdasNetCommApi {
|
||||
/**
|
||||
* 自动驾驶设备基础信息应答
|
||||
*
|
||||
* @param sn SN
|
||||
* @param environment 环境 详情参见{@link Constants.ENVIRONMENT}1: 研发环境, 2:测试环境, 3:生产环境 4:演示环境
|
||||
* @param role 终端角色 详情参见{@link Constants.TERMINAL_ROLE}
|
||||
* @param certification 鹰眼ssl证书
|
||||
* @param sn SN
|
||||
* @param environment 环境 详情参见{@link Constants.ENVIRONMENT}1: 研发环境, 2:测试环境, 3:生产环境 4:演示环境
|
||||
* @param role 终端角色 详情参见{@link Constants.TERMINAL_ROLE}
|
||||
* @param deviceCrt 鹰眼ssl证书
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean sendBasicInfoResp(@NonNull String sn, @Define.Environment int environment, @Define.TerminalRole int role, byte[] certification) {
|
||||
return sendBasicInfoResp(sn, environment, role, -1, null, certification);
|
||||
public boolean sendBasicInfoResp(@NonNull String sn, @Define.Environment int environment, @Define.TerminalRole int role, String deviceCrt) {
|
||||
return sendBasicInfoResp(sn, environment, role, -1, null, deviceCrt);
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动驾驶设备基础信息应答
|
||||
*
|
||||
* @param sn SN
|
||||
* @param environment 环境 详情参见{@link Constants.ENVIRONMENT}1: 研发环境, 2:测试环境, 3:生产环境 4:演示环境
|
||||
* @param role 终端角色 详情参见{@link Constants.TERMINAL_ROLE}
|
||||
* @param versionCode 鹰眼版本号
|
||||
* @param versionName 鹰眼版本名
|
||||
* @param certification 鹰眼ssl证书
|
||||
* @param sn SN
|
||||
* @param environment 环境 详情参见{@link Constants.ENVIRONMENT}1: 研发环境, 2:测试环境, 3:生产环境 4:演示环境
|
||||
* @param role 终端角色 详情参见{@link Constants.TERMINAL_ROLE}
|
||||
* @param versionCode 鹰眼版本号
|
||||
* @param versionName 鹰眼版本名
|
||||
* @param deviceCrt 鹰眼ssl证书
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean sendBasicInfoResp(@NonNull String sn, @Define.Environment int environment, @Define.TerminalRole int role, int versionCode, String versionName, byte[] certification) {
|
||||
return mChannel != null && mChannel.sendBasicInfoResp(sn, environment, role, versionCode, versionName, certification);
|
||||
public boolean sendBasicInfoResp(@NonNull String sn, @Define.Environment int environment, @Define.TerminalRole int role, int versionCode, String versionName, String deviceCrt) {
|
||||
return mChannel != null && mChannel.sendBasicInfoResp(sn, environment, role, versionCode, versionName, deviceCrt);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1325,37 +1319,37 @@ public class AdasManager implements IAdasNetCommApi {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取工控机固定IP列表
|
||||
* 获取域控PING 地址列表
|
||||
*
|
||||
* @return 返回默认工控机IP列表
|
||||
*/
|
||||
public HashSet<String> getIPCFixationIPList() {
|
||||
return Constants.getIPCFixationIPList();
|
||||
public HashSet<String> getPingAddressList() {
|
||||
return Constants.getPingAddressList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加工控机固定IP
|
||||
*
|
||||
* @param ipcIP IP
|
||||
* @param address IP
|
||||
*/
|
||||
public boolean addIPCFixationIP(String ipcIP) {
|
||||
return Constants.addIPCFixationIP(ipcIP);
|
||||
public boolean addPingAddressList(String address) {
|
||||
return Constants.addPingAddressList(address);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定的工控机固定IP
|
||||
*
|
||||
* @param ipcIP IP
|
||||
* @param address IP
|
||||
*/
|
||||
public boolean delIPCFixationIP(String ipcIP) {
|
||||
return Constants.delIPCFixationIP(ipcIP);
|
||||
public boolean delPingAddressList(String address) {
|
||||
return Constants.delPingAddressList(address);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除所有工控机固定IP
|
||||
*/
|
||||
public void delIPCFixationIP() {
|
||||
Constants.delIPCFixationIP();
|
||||
public void delPingAddressList() {
|
||||
Constants.delPingAddressList();
|
||||
}
|
||||
|
||||
|
||||
@@ -1372,11 +1366,82 @@ public class AdasManager implements IAdasNetCommApi {
|
||||
/**
|
||||
* 设置是否启用超时检测
|
||||
* 不会存储 下次启动恢复默认
|
||||
* 每次调用create之后需要重新设置才能生效,或者在AdasOptions中设置
|
||||
*
|
||||
* @param isEnable 是否启用
|
||||
*/
|
||||
@Override
|
||||
public void setEnableTimeoutDetection(boolean isEnable) {
|
||||
ReceiveTimeoutManager.getInstance().setEnable(isEnable, getIpcConnectionStatus());
|
||||
if (mChannel != null) {
|
||||
mChannel.setEnableTimeoutDetection(isEnable);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置重连次数
|
||||
* -1:不重连
|
||||
* 0:无限重连
|
||||
* >0:指定重连次数
|
||||
* 默认:0
|
||||
* 每次调用create之后需要重新设置才能生效,或者在AdasOptions中设置
|
||||
*
|
||||
* @param reconnectCount 次数
|
||||
*/
|
||||
@Override
|
||||
public void setReconnectCount(int reconnectCount) {
|
||||
if (mChannel != null) {
|
||||
mChannel.setReconnectCount(reconnectCount);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否启用SSL认证
|
||||
* 目前默认禁用
|
||||
* 每次调用create之后需要重新设置才能生效,或者在AdasOptions中设置
|
||||
*/
|
||||
@Override
|
||||
public void setEnableCertification(boolean enable) {
|
||||
if (mChannel != null) {
|
||||
mChannel.setEnableCertification(enable);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ROOT证书
|
||||
* 启用认证必须传
|
||||
* 每次调用create之后需要重新设置才能生效,或者在AdasOptions中设置
|
||||
*
|
||||
* @param rootCrt root证书
|
||||
*/
|
||||
@Override
|
||||
public void setRootCrt(String rootCrt) {
|
||||
if (mChannel != null) {
|
||||
mChannel.setRootCrt(rootCrt);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动连接
|
||||
* 不会存储 下次启动恢复默认
|
||||
* 每次调用create之后需要重新设置才能生效,或者在AdasOptions中设置
|
||||
*
|
||||
* @param enable 是否启用
|
||||
*/
|
||||
@Override
|
||||
public void setAutoConnect(boolean enable) {
|
||||
if (mChannel != null) {
|
||||
mChannel.setAutoConnect(enable);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置不能启动自动驾驶的档位
|
||||
*
|
||||
* @param unableLaunchAutopilotGear 不能起自驾档位
|
||||
*/
|
||||
@Override
|
||||
public void setUnableLaunchAutopilotGear(Set<Chassis.GearPosition> unableLaunchAutopilotGear) {
|
||||
AutopilotAbilityManager.getInstance().setUnableLaunchAutopilotGear(unableLaunchAutopilotGear);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,12 +41,14 @@ public interface IAdasNetCommApi {
|
||||
void disconnect();
|
||||
|
||||
|
||||
void setAdasOptions(AdasOptions options);
|
||||
|
||||
/**
|
||||
* 获取当前工控机的链接状态
|
||||
*
|
||||
* @return {@link Constants.IPC_CONNECTION_STATUS}
|
||||
* @return {@link AdasConstants.IpcConnectionStatus}
|
||||
*/
|
||||
int getIpcConnectionStatus();
|
||||
AdasConstants.IpcConnectionStatus getIpcConnectionStatus();
|
||||
|
||||
/**
|
||||
* 获取工控机链接配置
|
||||
@@ -84,6 +86,52 @@ public interface IAdasNetCommApi {
|
||||
*/
|
||||
AdasConstants.SsmSource getUsedSsmSource();
|
||||
|
||||
/**
|
||||
* 设置是否启用超时检测
|
||||
* 不会存储 下次启动恢复默认
|
||||
* 每次调用create之后需要重新设置才能生效,或者在AdasOptions中设置
|
||||
*
|
||||
* @param isEnable 是否启用
|
||||
*/
|
||||
void setEnableTimeoutDetection(boolean isEnable);
|
||||
|
||||
/**
|
||||
* 设置重连次数
|
||||
* -1:不重连
|
||||
* 0:无限重连
|
||||
* >0:指定重连次数
|
||||
* 默认:0
|
||||
* 每次调用create之后需要重新设置才能生效,或者在AdasOptions中设置
|
||||
*
|
||||
* @param reconnectCount 次数
|
||||
*/
|
||||
void setReconnectCount(int reconnectCount);
|
||||
|
||||
/**
|
||||
* 是否启用SSL认证
|
||||
* 目前默认禁用
|
||||
* 每次调用create之后需要重新设置才能生效,或者在AdasOptions中设置
|
||||
*/
|
||||
void setEnableCertification(boolean enable);
|
||||
|
||||
/**
|
||||
* ROOT证书
|
||||
* 启用认证必须传
|
||||
* 每次调用create之后需要重新设置才能生效,或者在AdasOptions中设置
|
||||
*
|
||||
* @param rootCrt root证书
|
||||
*/
|
||||
void setRootCrt(String rootCrt);
|
||||
|
||||
/**
|
||||
* 自动连接
|
||||
* 不会存储 下次启动恢复默认
|
||||
* 每次调用create之后需要重新设置才能生效,或者在AdasOptions中设置
|
||||
*
|
||||
* @param enable 是否启用
|
||||
*/
|
||||
void setAutoConnect(boolean enable);
|
||||
|
||||
/**
|
||||
* 设置不能启动自动驾驶的档位
|
||||
*
|
||||
@@ -94,15 +142,16 @@ public interface IAdasNetCommApi {
|
||||
/**
|
||||
* 自动驾驶设备基础信息应答
|
||||
*
|
||||
* @param sn SN
|
||||
* @param environment 环境 详情参见{@link Constants.ENVIRONMENT}1: 研发环境, 2:测试环境, 3:生产环境 4:演示环境
|
||||
* @param role 终端角色 详情参见{@link Constants.TERMINAL_ROLE}
|
||||
* @param versionCode 鹰眼版本号
|
||||
* @param versionName 鹰眼版本名
|
||||
* @param certification 鹰眼ssl证书
|
||||
* @param sn SN
|
||||
* @param environment 环境 详情参见{@link Constants.ENVIRONMENT}1: 研发环境, 2:测试环境, 3:生产环境 4:演示环境
|
||||
* @param role 终端角色 详情参见{@link Constants.TERMINAL_ROLE}
|
||||
* @param versionCode 鹰眼版本号
|
||||
* @param versionName 鹰眼版本名
|
||||
* @param deviceCrt 鹰眼ssl证书
|
||||
* @return boolean
|
||||
*/
|
||||
boolean sendBasicInfoResp(@NonNull String sn, @Define.Environment int environment, @Define.TerminalRole int role, int versionCode, String versionName, byte[] certification);
|
||||
boolean sendBasicInfoResp(@NonNull String sn, @Define.Environment int environment, @Define.TerminalRole int role, int versionCode, String versionName, String deviceCrt);
|
||||
|
||||
|
||||
/**
|
||||
* 设置自动驾驶模式 启动自动驾驶
|
||||
|
||||
@@ -3,8 +3,7 @@ package com.zhidao.support.adas.high;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.zhidao.support.adas.high.bean.VersionCompatibility;
|
||||
import com.zhidao.support.adas.high.common.Constants;
|
||||
import com.zhidao.support.adas.high.common.Define;
|
||||
import com.zhjt.mogo.adas.data.AdasConstants;
|
||||
|
||||
/**
|
||||
* @author nie yunlong
|
||||
@@ -16,11 +15,13 @@ public interface OnAdasConnectStatusListener {
|
||||
/**
|
||||
* 与工控机链接状态变化
|
||||
*
|
||||
* @param ipcConnectionStatus {@link Constants.IPC_CONNECTION_STATUS}
|
||||
* @param reason 连接信息 需要判null
|
||||
* 如果ipcConnectionStatus==Constants.IPC_CONNECTION_STATUS.DISCONNECTED&&reason==null 表示主动断开连接
|
||||
* @param status {@link AdasConstants.IpcConnectionStatus}
|
||||
* @param reason 连接信息(需要判null),目前只有以下参数存在值,其他全部为null
|
||||
* {@link AdasConstants.IpcConnectionStatus#HEARTBEAT_TIMEOUT} 表示超时时间
|
||||
* {@link AdasConstants.IpcConnectionStatus#CONNECT_EXCEPTION} 表示连接异常原因
|
||||
* {@link AdasConstants.IpcConnectionStatus#SERVER_DISCONNECTED} 服务端断开(如果服务端关闭时发送了原因将存在,如果服务端关闭时未发送将为null)
|
||||
*/
|
||||
void onConnectionIPCStatus(@Define.IPCConnectionStatus int ipcConnectionStatus, @Nullable String reason);
|
||||
void onConnectionIPCStatus(AdasConstants.IpcConnectionStatus status, @Nullable String reason);
|
||||
|
||||
/**
|
||||
* 与工控机版本的兼容性
|
||||
|
||||
@@ -147,11 +147,14 @@ public interface OnAdasListener {
|
||||
|
||||
/**
|
||||
* 自动驾驶设备基础信息请求
|
||||
* 连接时启用认证 后才会有认证结果
|
||||
* ROOT证书异常会影响校验域控证书
|
||||
* PAD证书异常会影响域控端校验的证书校验,域控端证书校验失败将会断开连接,且并不会给出断开原因,ADAS LIB会执行重连操作(如果配置启用重连)
|
||||
* 校验域控证书认证失败会主动断开连接,且不进行重连
|
||||
*
|
||||
* @param header 头
|
||||
* @param basicInfoReq 数据 目前没有任何参数
|
||||
* @param status 域控证书认证结果{@link AdasConstants.CertificationStatus}
|
||||
*/
|
||||
void onBasicInfoReq(MessagePad.Header header, MessagePad.BasicInfoReq basicInfoReq);
|
||||
void onBasicInfoReq(@NonNull AdasConstants.CertificationStatus status);
|
||||
|
||||
/**
|
||||
* 车机基础信息应答
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
package com.zhidao.support.adas.high.common;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.security.cert.CertPath;
|
||||
import java.security.cert.CertPathValidator;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.PKIXParameters;
|
||||
import java.security.cert.TrustAnchor;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* 证书工具类
|
||||
* <p>
|
||||
* 认证过程:
|
||||
* 连接成功后域控发送带证书的MsgTypeBasicInfoReq请求接口
|
||||
* PAD收到后做证书校验
|
||||
* PAD校验失败断开连接
|
||||
* PAD校验成功PAD发送带证书的MsgTypeBasicInfoResp响应接口
|
||||
* 域控检验PAD证书
|
||||
* 域控校验失败会断开连接
|
||||
* 域控校验成功后会发送定频数据
|
||||
* 此时PAD收到定频数据可以认为证书校校验完成且成功,可以发送配置请求数据
|
||||
*/
|
||||
public class CertificateUtils {
|
||||
private final static char S = 25;
|
||||
|
||||
/**
|
||||
* 编码
|
||||
*
|
||||
* @param crt 证书
|
||||
* @return 编码后的证书
|
||||
*/
|
||||
public static ByteString encode(@NonNull String crt) {
|
||||
if (TextUtils.isEmpty(crt)) return null;
|
||||
char line = 0;
|
||||
crt = crt.replace("-----BEGIN CERTIFICATE-----\n", "").replace("-----END CERTIFICATE-----", "");
|
||||
byte[] chars = new byte[crt.length()];
|
||||
for (int i = 0; i < crt.length(); i++) {
|
||||
char c = crt.charAt(i);
|
||||
if (c != '\n') {
|
||||
c += S + line;
|
||||
} else {
|
||||
line++;
|
||||
}
|
||||
chars[i] = (byte) (c & 0xFF);
|
||||
}
|
||||
return ByteString.copyFrom(chars);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 解码
|
||||
*
|
||||
* @param crt 证书
|
||||
* @return 解码后的证书
|
||||
*/
|
||||
public static String decode(@NonNull ByteString crt) {
|
||||
if (crt.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
int line = 0;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("-----BEGIN CERTIFICATE-----\n");
|
||||
int size = crt.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
int unsignedInt = crt.byteAt(i) & 0xFF;
|
||||
char c = (char) unsignedInt;
|
||||
if (c != '\n') {
|
||||
c -= S + line;
|
||||
} else {
|
||||
line++;
|
||||
}
|
||||
builder.append(c);
|
||||
}
|
||||
builder.append("-----END CERTIFICATE-----");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 证书链校验
|
||||
* TODO 证书格式必须严格遵循 PEM格式 每 64 个字符后添加一个换行符,否则将会验证失败
|
||||
*
|
||||
* @param rootCert 根证书
|
||||
* @param deviceCert 设备证书
|
||||
* @return 证书链校验是否成功
|
||||
*/
|
||||
public static boolean certificateChainValidation(@NonNull String rootCert, @NonNull String deviceCert) {
|
||||
try {
|
||||
// 转换字符串为X.509证书对象
|
||||
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
|
||||
X509Certificate rootCertificate = (X509Certificate) certificateFactory.generateCertificate(
|
||||
new ByteArrayInputStream(rootCert.getBytes()));
|
||||
X509Certificate deviceCertificate = (X509Certificate) certificateFactory.generateCertificate(
|
||||
new ByteArrayInputStream(deviceCert.getBytes()));
|
||||
// 创建CertPath对象并将中间证书添加到CertPath中
|
||||
CertPath certPath = certificateFactory.generateCertPath(Collections.singletonList(deviceCertificate));
|
||||
// 创建CertPathValidator
|
||||
CertPathValidator certPathValidator = CertPathValidator.getInstance("PKIX");
|
||||
// 创建TrustAnchor(包含根证书)
|
||||
TrustAnchor trustAnchor = new TrustAnchor(rootCertificate, null);
|
||||
// 创建PKIXParameters并设置TrustAnchor
|
||||
PKIXParameters pkixParameters = new PKIXParameters(Collections.singleton(trustAnchor));
|
||||
// 禁用证书吊销检查(目前所用的证书不是完全标准的PKI)
|
||||
pkixParameters.setRevocationEnabled(false);
|
||||
// 使用CertPathValidator验证证书链
|
||||
certPathValidator.validate(certPath, pkixParameters);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
Log.e("[tag=CertificateUtils]", "[data=证书链校验失败]", e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -34,30 +34,9 @@ public class Constants {
|
||||
*/
|
||||
public static final byte[] RAW_MG = new byte[]{(byte) 0x6d, 0x67};
|
||||
|
||||
public static final String DEFAULT_IPC_FIXATION_IP = "[\"192.168.1.102\", \"192.168.8.102\"]";
|
||||
public static final String DEFAULT_PING_ADDRESS_LIST = "[\"192.168.1.102\", \"192.168.8.102\"]";
|
||||
|
||||
|
||||
public interface IPC_CONNECTION_STATUS {
|
||||
/**
|
||||
* 已连接
|
||||
*/
|
||||
int CONNECTED = 0x00;
|
||||
/**
|
||||
* 未连接
|
||||
*/
|
||||
int DISCONNECTED = 0x01;
|
||||
/**
|
||||
* 正在连接
|
||||
*/
|
||||
int CONNECTING = 0x02;
|
||||
/**
|
||||
* 正在搜索IP
|
||||
*/
|
||||
int SEARCH_ADDRESS = 0x03;
|
||||
/**
|
||||
* 找不到可用IP 传入的IP不可用或固定IP列表中所有IP不可用
|
||||
*/
|
||||
int NOT_FOUND_ADDRESS = 0x04;
|
||||
}
|
||||
|
||||
/**
|
||||
* 终端角色类型
|
||||
@@ -139,9 +118,9 @@ public class Constants {
|
||||
|
||||
private static HashSet<String> ipcFixationIPSet;//工控机固定IP列表
|
||||
|
||||
public static HashSet<String> getIPCFixationIPList() {
|
||||
public static HashSet<String> getPingAddressList() {
|
||||
if (ipcFixationIPSet == null || ipcFixationIPSet.isEmpty()) {
|
||||
String json = MMKVUtils.getInstance().getString("ipc_fixation_ip", Constants.DEFAULT_IPC_FIXATION_IP);
|
||||
String json = MMKVUtils.getInstance().getString("ping_address_list", Constants.DEFAULT_PING_ADDRESS_LIST);
|
||||
ipcFixationIPSet = JsonUtil.fromJson(json, new TypeToken<HashSet<String>>() {
|
||||
}.getType());
|
||||
|
||||
@@ -149,30 +128,30 @@ public class Constants {
|
||||
return ipcFixationIPSet;
|
||||
}
|
||||
|
||||
public static boolean addIPCFixationIP(String ipcIP) {
|
||||
public static boolean addPingAddressList(String address) {
|
||||
if (ipcFixationIPSet == null) {
|
||||
getIPCFixationIPList();
|
||||
getPingAddressList();
|
||||
}
|
||||
if (ipcFixationIPSet == null) {
|
||||
ipcFixationIPSet = new HashSet<>();
|
||||
}
|
||||
if (!ipcFixationIPSet.contains(ipcIP)) {
|
||||
ipcFixationIPSet.add(ipcIP);
|
||||
return MMKVUtils.getInstance().put("ipc_fixation_ip", JsonUtil.toJson(ipcFixationIPSet));
|
||||
if (!ipcFixationIPSet.contains(address)) {
|
||||
ipcFixationIPSet.add(address);
|
||||
return MMKVUtils.getInstance().put("ping_address_list", JsonUtil.toJson(ipcFixationIPSet));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean delIPCFixationIP(String ipcIP) {
|
||||
if (ipcFixationIPSet != null && ipcFixationIPSet.contains(ipcIP)) {
|
||||
ipcFixationIPSet.remove(ipcIP);
|
||||
return MMKVUtils.getInstance().put("ipc_fixation_ip", JsonUtil.toJson(ipcFixationIPSet));
|
||||
public static boolean delPingAddressList(String address) {
|
||||
if (ipcFixationIPSet != null && ipcFixationIPSet.contains(address)) {
|
||||
ipcFixationIPSet.remove(address);
|
||||
return MMKVUtils.getInstance().put("ping_address_list", JsonUtil.toJson(ipcFixationIPSet));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void delIPCFixationIP() {
|
||||
MMKVUtils.getInstance().removeKey("ipc_fixation_ip");
|
||||
public static void delPingAddressList() {
|
||||
MMKVUtils.getInstance().removeKey("ping_address_list");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,15 +10,6 @@ import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
public final class Define {
|
||||
|
||||
@IntDef(flag = true, value = {Constants.IPC_CONNECTION_STATUS.CONNECTED,
|
||||
Constants.IPC_CONNECTION_STATUS.DISCONNECTED,
|
||||
Constants.IPC_CONNECTION_STATUS.CONNECTING,
|
||||
Constants.IPC_CONNECTION_STATUS.SEARCH_ADDRESS,
|
||||
Constants.IPC_CONNECTION_STATUS.NOT_FOUND_ADDRESS})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface IPCConnectionStatus {
|
||||
}
|
||||
|
||||
|
||||
@IntDef(flag = true, value = {VersionCompatibility.VERSION_COMPATIBILITY_DEGREE.INCOMPATIBLE,
|
||||
VersionCompatibility.VERSION_COMPATIBILITY_DEGREE.COMPATIBILITY,
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.util.Log;
|
||||
|
||||
import com.zhidao.support.adas.high.AdasManager;
|
||||
import com.zhidao.support.adas.high.OnAdasListener;
|
||||
import com.zhjt.mogo.adas.data.AdasConstants;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
@@ -167,7 +168,7 @@ public class ParallelDrivingManager {
|
||||
bootTimer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (mapVersion == -1 && AdasManager.getInstance().getIpcConnectionStatus() == Constants.IPC_CONNECTION_STATUS.CONNECTED) {
|
||||
if (mapVersion == -1 && AdasManager.getInstance().getIpcConnectionStatus() == AdasConstants.IpcConnectionStatus.CONNECTED) {
|
||||
mapVersion = 30600;//获取 CarConfig获取失败就认为是Taxi版本大于等于360
|
||||
isDF = true;
|
||||
startCallback();
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.zhidao.support.adas.high.common;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.zhidao.support.adas.high.AdasOptions;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -14,33 +18,36 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* 工控机固定IP查询
|
||||
* PING 连接方式帮助类
|
||||
* 根据提供的地址进行ping连通性检测
|
||||
*/
|
||||
public class IPCFixationIPHelper {
|
||||
private static final String TAG = IPCFixationIPHelper.class.getSimpleName();
|
||||
private final IIPCFixationIPListener listener;
|
||||
private final List<Future> futures = new ArrayList<>();
|
||||
public class PingAddressHelper {
|
||||
private static final String TAG = PingAddressHelper.class.getSimpleName();
|
||||
private final IPingAddressListener listener;
|
||||
private final List<Future<?>> futures = new ArrayList<>();
|
||||
private final AtomicBoolean isCallListener = new AtomicBoolean(false);//是否已经调用了回调
|
||||
private final AtomicInteger unavailableCount = new AtomicInteger(0);//不可用IP个数
|
||||
private volatile int queryCount;//要查询的IP个数
|
||||
private Timer retryTimer;
|
||||
private final AtomicBoolean isEnableReconnect = new AtomicBoolean(true);//是否启用重连机制
|
||||
private int reconnectCount = AdasOptions.DEFAULT.RECONNECT_COUNT;//是否启用重连机制
|
||||
private int currentCount = 0;//重连次数
|
||||
|
||||
public IPCFixationIPHelper(IIPCFixationIPListener listener) {
|
||||
if (listener == null)
|
||||
throw new RuntimeException("工控机固定IP查询回调不能为空");
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public interface IIPCFixationIPListener {
|
||||
public interface IPingAddressListener {
|
||||
/**
|
||||
* 开始查找可用IP
|
||||
*/
|
||||
void onStartFindIP();
|
||||
|
||||
/**
|
||||
* 非法地址
|
||||
*/
|
||||
void onIllegalAddress();
|
||||
|
||||
/**
|
||||
* 主动停止
|
||||
*/
|
||||
void onStopFindIP();
|
||||
void onStopFindIP(boolean isCall);
|
||||
|
||||
/**
|
||||
* 轮询结果可连通的IP
|
||||
@@ -50,10 +57,18 @@ public class IPCFixationIPHelper {
|
||||
void onAvailableIP(String ip);
|
||||
}
|
||||
|
||||
public PingAddressHelper(@NonNull IPingAddressListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public synchronized void setReconnectCount(int count) {
|
||||
reconnectCount = count;
|
||||
}
|
||||
|
||||
private boolean interrupted() {
|
||||
boolean isEm = futures.isEmpty();
|
||||
if (!isEm) {
|
||||
for (Future future : futures) {
|
||||
for (Future<?> future : futures) {
|
||||
if (!future.isCancelled()) {
|
||||
future.cancel(true);
|
||||
}
|
||||
@@ -63,14 +78,24 @@ public class IPCFixationIPHelper {
|
||||
return isEm;
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
private boolean isNeedReconnect() {
|
||||
if (reconnectCount == -1) {
|
||||
return false;
|
||||
} else if (reconnectCount == 0) {
|
||||
return true;
|
||||
} else {
|
||||
return currentCount < reconnectCount;
|
||||
}
|
||||
}
|
||||
|
||||
public void stop(boolean isCall) {
|
||||
if (retryTimer != null) {
|
||||
retryTimer.cancel();
|
||||
retryTimer = null;
|
||||
}
|
||||
isCallListener.set(true);
|
||||
if (!interrupted()) {
|
||||
listener.onStopFindIP();
|
||||
listener.onStopFindIP(isCall);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,55 +103,74 @@ public class IPCFixationIPHelper {
|
||||
* 开始根据固定IP列表惊醒PING 方式查找可用工控机
|
||||
*/
|
||||
public void start(final HashSet<String> ips) {
|
||||
listener.onStartFindIP();
|
||||
if (retryTimer != null) {
|
||||
retryTimer.cancel();
|
||||
retryTimer = null;
|
||||
}
|
||||
currentCount = 0;
|
||||
startFind(ips);
|
||||
}
|
||||
|
||||
private void startFind(final HashSet<String> ips) {
|
||||
if (ips == null || ips.isEmpty()) {
|
||||
listener.onAvailableIP(null);
|
||||
listener.onIllegalAddress();
|
||||
} else {
|
||||
currentCount++;
|
||||
listener.onStartFindIP();
|
||||
if (retryTimer != null) {
|
||||
retryTimer.cancel();
|
||||
retryTimer = null;
|
||||
}
|
||||
interrupted();
|
||||
queryCount = ips.size();
|
||||
unavailableCount.set(0);
|
||||
isCallListener.set(false);
|
||||
for (final String temp : ips) {
|
||||
Runnable runnable = () -> {
|
||||
CupidLogUtils.i(TAG, "ip=" + temp);
|
||||
boolean isAvailable = ping(temp);
|
||||
if (isAvailable) {
|
||||
if (!isCallListener.get() && !Thread.currentThread().isInterrupted()) {
|
||||
isCallListener.set(true);
|
||||
listener.onAvailableIP(temp);
|
||||
CupidLogUtils.i(TAG, "可用IP=" + temp);
|
||||
interrupted();
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
CupidLogUtils.i(TAG, "ip=" + temp);
|
||||
boolean isAvailable = ping(temp);
|
||||
if (isAvailable) {
|
||||
if (!isCallListener.get() && !Thread.currentThread().isInterrupted()) {
|
||||
isCallListener.set(true);
|
||||
listener.onAvailableIP(temp);
|
||||
CupidLogUtils.i(TAG, "可用IP=" + temp);
|
||||
interrupted();
|
||||
}
|
||||
} else {
|
||||
allNotAvailable(ips);
|
||||
}
|
||||
} else {
|
||||
allNotAvailable(ips);
|
||||
}
|
||||
};
|
||||
Future future = ThreadPoolManager.getsInstance().submit(runnable);
|
||||
Future<?> future = ThreadPoolManager.getsInstance().submit(runnable);
|
||||
futures.add(future);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 所有地址均无法PING通
|
||||
*
|
||||
* @param ips 地址
|
||||
*/
|
||||
private synchronized void allNotAvailable(final HashSet<String> ips) {
|
||||
if (queryCount == unavailableCount.incrementAndGet()) {
|
||||
if (!isCallListener.get()) {
|
||||
isCallListener.set(true);
|
||||
listener.onAvailableIP(null);
|
||||
CupidLogUtils.i(TAG, "所有IP均不可用");
|
||||
//当配置中的所有IP都ping不通时,需要继续ping
|
||||
if (retryTimer == null) {
|
||||
retryTimer = new Timer();
|
||||
retryTimer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
start(ips);
|
||||
}
|
||||
}, 4 * 1000L);//延时
|
||||
if (isNeedReconnect()) {
|
||||
//当配置中的所有IP都ping不通时,需要继续ping
|
||||
if (retryTimer == null) {
|
||||
retryTimer = new Timer();
|
||||
retryTimer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
startFind(ips);
|
||||
}
|
||||
}, 4 * 1000L);//延时
|
||||
}
|
||||
} else {
|
||||
stop(false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.zhidao.support.adas.high.common;
|
||||
|
||||
import com.zhjt.mogo.adas.data.AdasConstants;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
@@ -52,11 +54,11 @@ public class ReceiveTimeoutManager {
|
||||
* @param isEnable 是否启用超时检测
|
||||
* @param ipcConnectionStatus 当前连接状态
|
||||
*/
|
||||
public void setEnable(boolean isEnable, @Define.IPCConnectionStatus int ipcConnectionStatus) {
|
||||
public void setEnable(boolean isEnable, AdasConstants.IpcConnectionStatus ipcConnectionStatus) {
|
||||
this.isEnable.set(isEnable);
|
||||
//如果启动并且当前已连接
|
||||
if (this.isEnable.get()) {
|
||||
if (ipcConnectionStatus == Constants.IPC_CONNECTION_STATUS.CONNECTED)
|
||||
if (ipcConnectionStatus == AdasConstants.IpcConnectionStatus.CONNECTED)
|
||||
start();
|
||||
} else {
|
||||
stop();
|
||||
|
||||
@@ -3,13 +3,16 @@ package com.zhidao.support.adas.high.common;
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.Network;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.NetworkRequest;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
||||
import com.zhidao.support.adas.high.AdasOptions;
|
||||
import com.zhjt.mogo.adas.data.AdasConstants;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
@@ -20,18 +23,21 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
public class ReconnectManager {
|
||||
private static final String TAG = ReconnectManager.class.getSimpleName();
|
||||
private static final long RECONNECT_INTERVAL = 4 * 1000L;//重连间隔
|
||||
private final AtomicBoolean isReconnection = new AtomicBoolean(false);//是否正在重连
|
||||
private final AtomicBoolean isReconnection = new AtomicBoolean(false);//是否已经启动重连流程
|
||||
private final OnReconnectListener listener;
|
||||
private volatile Timer timer;
|
||||
private final Context context;
|
||||
private final AtomicBoolean isRegisterNetworkCallback = new AtomicBoolean(false);
|
||||
private volatile ConnectivityManager connectivityManager;
|
||||
|
||||
private int reconnectCount = AdasOptions.DEFAULT.RECONNECT_COUNT;//是否启用重连机制
|
||||
private int currentCount = 0;//重连次数
|
||||
|
||||
public interface OnReconnectListener {
|
||||
void onReconnection(String tag);
|
||||
void onReconnection(AdasConstants.IpcConnectionStatus status);
|
||||
}
|
||||
|
||||
|
||||
public ReconnectManager(Context context, OnReconnectListener listener) {
|
||||
public ReconnectManager(Context context, @NonNull OnReconnectListener listener) {
|
||||
this.context = context;
|
||||
this.listener = listener;
|
||||
}
|
||||
@@ -43,39 +49,74 @@ public class ReconnectManager {
|
||||
return isReconnection.get();
|
||||
}
|
||||
|
||||
public void setReconnectCount(int reconnectCount) {
|
||||
this.reconnectCount = reconnectCount;
|
||||
CupidLogUtils.log(TAG, "是否启动自动重连=" + reconnectCount);
|
||||
if (!isNeedReconnect()) {
|
||||
stop(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 是否需要重连
|
||||
*/
|
||||
private boolean isNeedReconnect() {
|
||||
if (reconnectCount == -1) {
|
||||
return false;
|
||||
} else if (reconnectCount == 0) {
|
||||
return true;
|
||||
} else {
|
||||
return currentCount < reconnectCount;
|
||||
}
|
||||
}
|
||||
|
||||
private void callOnReconnection(AdasConstants.IpcConnectionStatus status) {
|
||||
if (isNeedReconnect()) {
|
||||
currentCount++;
|
||||
listener.onReconnection(status);
|
||||
} else {
|
||||
stop(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动重连
|
||||
*/
|
||||
public synchronized void start() {
|
||||
if (!isReconnection.get()) {
|
||||
CupidLogUtils.i(TAG, "开始重连");
|
||||
isReconnection.set(true);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkRequest networkRequest = new NetworkRequest.Builder().build();
|
||||
connMgr.registerNetworkCallback(networkRequest, networkCallback);
|
||||
isRegisterNetworkCallback.set(true);
|
||||
}
|
||||
if (timer == null) {
|
||||
timer = new Timer();
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (isReconnection.get()) {
|
||||
if (listener != null)
|
||||
listener.onReconnection("定时器");
|
||||
if (isNeedReconnect()) {
|
||||
if (!isReconnection.get()) {
|
||||
CupidLogUtils.log(TAG, "开始重连");
|
||||
isReconnection.set(true);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && connectivityManager == null) {
|
||||
connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkRequest networkRequest = new NetworkRequest.Builder().build();
|
||||
connectivityManager.registerNetworkCallback(networkRequest, networkCallback);
|
||||
}
|
||||
if (timer == null) {
|
||||
timer = new Timer();
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (isNeedReconnect()) {
|
||||
callOnReconnection(AdasConstants.IpcConnectionStatus.RECONNECTING_TIMER);
|
||||
} else {
|
||||
stop(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 0, RECONNECT_INTERVAL);//延时
|
||||
}, RECONNECT_INTERVAL, RECONNECT_INTERVAL);//延时
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void stop() {
|
||||
CupidLogUtils.i(TAG, "停止重连");
|
||||
public synchronized void stop(boolean isResetCurrentCount) {
|
||||
CupidLogUtils.log(TAG, "停止重连");
|
||||
isReconnection.set(false);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && isRegisterNetworkCallback.get()) {
|
||||
ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
connMgr.unregisterNetworkCallback(networkCallback);
|
||||
isRegisterNetworkCallback.set(false);
|
||||
if (isResetCurrentCount) {
|
||||
currentCount = 0;
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && connectivityManager != null) {
|
||||
connectivityManager.unregisterNetworkCallback(networkCallback);
|
||||
}
|
||||
if (timer != null) {
|
||||
timer.cancel();
|
||||
@@ -88,10 +129,21 @@ public class ReconnectManager {
|
||||
@Override
|
||||
public void onAvailable(@NonNull Network network) {
|
||||
super.onAvailable(network);
|
||||
Log.i(TAG, "网络连接成功");
|
||||
if (listener != null)
|
||||
listener.onReconnection("网络监听");
|
||||
CupidLogUtils.log(TAG, "网络连接成功");
|
||||
if (isReconnection.get() && !isNetworkConnected()) {
|
||||
callOnReconnection(AdasConstants.IpcConnectionStatus.RECONNECTING_NETWORK);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//判断网络是否连接
|
||||
private Boolean isNetworkConnected() {
|
||||
if (connectivityManager != null) {
|
||||
NetworkInfo mNetworkInfo = connectivityManager.getActiveNetworkInfo();
|
||||
if (mNetworkInfo != null) {
|
||||
return mNetworkInfo.isAvailable();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,15 +2,14 @@ package com.zhidao.support.adas.high.common.autopilot.ability;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.zhidao.support.adas.high.AdasManager;
|
||||
import com.zhidao.support.adas.high.OnAdasListener;
|
||||
import com.zhidao.support.adas.high.common.Constants;
|
||||
import com.zhidao.support.adas.high.common.CupidLogUtils;
|
||||
import com.zhjt.mogo.adas.data.AdasConstants;
|
||||
import com.zhjt.mogo.adas.data.bean.UnableLaunchData;
|
||||
import com.zhjt.mogo.adas.data.bean.UnableLaunchReason;
|
||||
|
||||
@@ -273,7 +272,7 @@ public class AutopilotAbilityManager implements AutopilotAbility230.OnAutopilotA
|
||||
|
||||
private void initAutopilotAbility() {
|
||||
if (mapVersion >= 30600 && isFutianSweeper) {
|
||||
Log.i(TAG, "能否启动自驾能力检测使用版本:360清扫车专用");
|
||||
CupidLogUtils.log(TAG, "能否启动自驾能力检测使用版本:360清扫车专用");
|
||||
stop230();
|
||||
stop250();
|
||||
stop330();
|
||||
@@ -284,7 +283,7 @@ public class AutopilotAbilityManager implements AutopilotAbility230.OnAutopilotA
|
||||
}
|
||||
|
||||
} else if ((mapVersion >= 30500 && (isJinlvM1 || isHQ)) || mapVersion >= 30600) {
|
||||
Log.i(TAG, "能否启动自驾能力检测使用版本:350和360共用");
|
||||
CupidLogUtils.log(TAG, "能否启动自驾能力检测使用版本:350和360共用");
|
||||
stop230();
|
||||
stop250();
|
||||
stop330();
|
||||
@@ -295,7 +294,7 @@ public class AutopilotAbilityManager implements AutopilotAbility230.OnAutopilotA
|
||||
}
|
||||
|
||||
} else if (mapVersion >= 30300 && isFutianSweeper) {//目前只有MAP330的清扫车用的新的FSM状态原因查询
|
||||
Log.i(TAG, "能否启动自驾能力检测使用版本:330清扫车专用");
|
||||
CupidLogUtils.log(TAG, "能否启动自驾能力检测使用版本:330清扫车专用");
|
||||
stop230();
|
||||
stop250();
|
||||
stop350And360();
|
||||
@@ -305,7 +304,7 @@ public class AutopilotAbilityManager implements AutopilotAbility230.OnAutopilotA
|
||||
autopilotAbility330.start(this);
|
||||
}
|
||||
} else if (mapVersion >= 20500) {
|
||||
Log.i(TAG, "能否启动自驾能力检测使用版本:250");
|
||||
CupidLogUtils.log(TAG, "能否启动自驾能力检测使用版本:250");
|
||||
stop230();
|
||||
stop330();
|
||||
stop350And360();
|
||||
@@ -315,7 +314,7 @@ public class AutopilotAbilityManager implements AutopilotAbility230.OnAutopilotA
|
||||
autopilotAbility250.start(this);
|
||||
}
|
||||
} else {
|
||||
Log.i(TAG, "能否启动自驾能力检测使用版本:230");
|
||||
CupidLogUtils.log(TAG, "能否启动自驾能力检测使用版本:230");
|
||||
stop250();
|
||||
stop330();
|
||||
stop350And360();
|
||||
@@ -380,7 +379,7 @@ public class AutopilotAbilityManager implements AutopilotAbility230.OnAutopilotA
|
||||
startTimer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (mapVersion == -1 && AdasManager.getInstance().getIpcConnectionStatus() == Constants.IPC_CONNECTION_STATUS.CONNECTED) {
|
||||
if (mapVersion == -1 && AdasManager.getInstance().getIpcConnectionStatus() == AdasConstants.IpcConnectionStatus.CONNECTED) {
|
||||
mapVersion = 20300;
|
||||
initAutopilotAbility();
|
||||
}
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
package com.zhidao.support.adas.high.msg;
|
||||
|
||||
import android.os.SystemClock;
|
||||
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import com.zhidao.support.adas.high.AdasChannel;
|
||||
import com.zhidao.support.adas.high.OnAdasListener;
|
||||
import com.zhidao.support.adas.high.common.CupidLogUtils;
|
||||
import com.zhidao.support.adas.high.protocol.RawData;
|
||||
|
||||
import mogo.telematics.pad.MessagePad;
|
||||
|
||||
/**
|
||||
* 自动驾驶设备基础信息请求
|
||||
*/
|
||||
public class BasicInfoReqMessage extends MyAbstractMessageHandler {
|
||||
|
||||
@Override
|
||||
public void handlerMsg(RawData raw, OnAdasListener adasListener) throws InvalidProtocolBufferException {
|
||||
MessagePad.BasicInfoReq autopilotState = MessagePad.BasicInfoReq.parser().parseFrom(raw.originalData.toByteArray(), raw.getOffsetValue(), raw.getPackageLengthValue() - raw.getOffsetValue());
|
||||
AdasChannel.calculateTimeConsumingOnDispatchRaw("自动驾驶设备基础信息请求", raw.receiveTime);
|
||||
long nowTime = 0;
|
||||
if (CupidLogUtils.isEnableLog())
|
||||
nowTime = SystemClock.elapsedRealtime();
|
||||
if (adasListener != null) {
|
||||
adasListener.onBasicInfoReq(raw.getHeader(), autopilotState);
|
||||
}
|
||||
AdasChannel.calculateTimeConsumingBusiness("自动驾驶设备基础信息请求", nowTime);
|
||||
// CupidLogUtils.e("自动驾驶设备基础信息请求--->" + autopilotState.toString());
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ public class CarConfigRespMessage extends MyAbstractMessageHandler {
|
||||
adasListener.onCarConfigResp(raw.getHeader(), carConfigResp);
|
||||
}
|
||||
AdasChannel.calculateTimeConsumingBusiness("车机基础信息应答", nowTime);
|
||||
CupidLogUtils.e("CarConfigRespMessage", "车机基础信息应答--->" + carConfigResp);
|
||||
CupidLogUtils.e("CarConfigRespMessage", "车机基础信息应答--->" + carConfigResp.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.zhidao.support.adas.high.msg;
|
||||
|
||||
import android.os.SystemClock;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import com.zhidao.support.adas.high.AdasChannel;
|
||||
|
||||
@@ -23,7 +23,6 @@ public class MyMessageFactory implements IMyMessageFactory {
|
||||
private IMsg predictionObstacleTrajectoryMessage;//他车轨迹预测
|
||||
private IMsg planningObjectsMessage;//planning障碍物
|
||||
|
||||
private IMsg basicInfoReqMessage;//自动驾驶设备基础信息请求
|
||||
private IMsg carConfigRespMessage;//车机基础信息应答
|
||||
private IMsg recordResultMessage;//数据采集结果
|
||||
private IMsg globalPathRespMessage;//自动驾驶路径应答
|
||||
@@ -121,12 +120,6 @@ public class MyMessageFactory implements IMyMessageFactory {
|
||||
planningObjectsMessage = new PlanningObjectsMessage();
|
||||
}
|
||||
return planningObjectsMessage;
|
||||
} else if (messageType == MessageType.TYPE_RECEIVE_BASIC_INFO_REQ.typeCode) {
|
||||
//自动驾驶设备基础信息请求
|
||||
if (basicInfoReqMessage == null) {
|
||||
basicInfoReqMessage = new BasicInfoReqMessage();
|
||||
}
|
||||
return basicInfoReqMessage;
|
||||
} else if (messageType == MessageType.TYPE_RECEIVE_CAR_CONFIG_RESP.typeCode) {
|
||||
//车机基础信息应答
|
||||
if (carConfigRespMessage == null) {
|
||||
|
||||
@@ -20,13 +20,14 @@ import com.zhidao.support.adas.high.common.ReceiveTimeoutManager;
|
||||
import com.zhidao.support.adas.high.common.ReconnectManager;
|
||||
import com.zhidao.support.adas.high.queue.WSByteQueueManager;
|
||||
import com.zhidao.support.adas.high.queue.WebSocketQueueManager;
|
||||
import com.zhjt.mogo.adas.data.AdasConstants;
|
||||
import com.zhjt.mogo.adas.utils.ByteUtil;
|
||||
import com.zhjt.service.chain.ChainLog;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
@@ -50,48 +51,40 @@ import okio.ByteString;
|
||||
*/
|
||||
public class FpgaSocket implements IWebSocket {
|
||||
private static final String TAG = FpgaSocket.class.getSimpleName();
|
||||
private OkHttpClient client;
|
||||
private final OkHttpClient client;
|
||||
|
||||
private volatile RealWebSocket mWebSocket;
|
||||
|
||||
private EchoWebSocketListener listener;
|
||||
private IWebSocketConnectListener mWebSocketConnectListener;
|
||||
private ReconnectManager reconnectManager;
|
||||
private IWebSocketConnectListener listener;
|
||||
private final ReconnectManager reconnectManager;
|
||||
|
||||
private String wsHost;
|
||||
private String ipAddress;
|
||||
private int port;
|
||||
private boolean isEnableReconnect = true;//是否启用重连机制
|
||||
/**
|
||||
* 是否是用户主动关闭socket
|
||||
* 0:未调用 1:用户调用 2:认证失败调用 3:被动调用
|
||||
*/
|
||||
private final AtomicBoolean isUserClose = new AtomicBoolean(false);
|
||||
/**
|
||||
* 是否是被动关闭
|
||||
*/
|
||||
private final AtomicBoolean isPassiveClose = new AtomicBoolean(false);
|
||||
/**
|
||||
* 是否已经连接成功
|
||||
*/
|
||||
private final AtomicBoolean isConnected = new AtomicBoolean(false);
|
||||
private final AtomicReference<AdasConstants.IpcConnectionStatus> status = new AtomicReference<>(AdasConstants.IpcConnectionStatus.DISCONNECTED);
|
||||
|
||||
public interface IWebSocketConnectListener {
|
||||
/**
|
||||
* websocket 连接状态
|
||||
*
|
||||
* @param status 状态
|
||||
* @param args {@link AdasConstants.IpcConnectionStatus#CONNECTED}args有两个参数 分别是ipAddress(String类型)、port(Int类型)
|
||||
* {@link AdasConstants.IpcConnectionStatus#CONNECT_EXCEPTION}args有一个参数 连接失败的原因(String类型)
|
||||
*/
|
||||
void onWebSocketConnectStatus(AdasConstants.IpcConnectionStatus status, Object... args);
|
||||
|
||||
void onMessage(String message);
|
||||
|
||||
//TODO 计算耗时 临时测试
|
||||
void onMessage(long receiveTime, ByteString bytes) throws InvalidProtocolBufferException;
|
||||
}
|
||||
|
||||
/**
|
||||
* 接收数据超时原因 null时表示不是接收数据超时的原因
|
||||
*/
|
||||
private volatile String receiveTimeoutReason = null;
|
||||
private Context context;
|
||||
|
||||
public FpgaSocket(Context context) {
|
||||
this.context = context;
|
||||
init();
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return isConnected.get();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
listener = new EchoWebSocketListener();
|
||||
OkHttpClient.Builder okBuilder = new OkHttpClient.Builder();
|
||||
okBuilder.writeTimeout(4, TimeUnit.SECONDS)
|
||||
.readTimeout(4, TimeUnit.SECONDS)
|
||||
@@ -99,99 +92,111 @@ public class FpgaSocket implements IWebSocket {
|
||||
ReceiveTimeoutManager.getInstance().setListener(new ReceiveTimeoutManager.OnTimeoutListener() {
|
||||
@Override
|
||||
public void onTimeout(double time) {
|
||||
receiveTimeoutReason = "心跳超时(" + time + "秒)";
|
||||
onPassiveClose(1001, receiveTimeoutReason);
|
||||
setStatus(AdasConstants.IpcConnectionStatus.HEARTBEAT_TIMEOUT);
|
||||
callConnectStatus(time);
|
||||
close(false, 1001);
|
||||
reconnectStart();
|
||||
}
|
||||
});
|
||||
reconnectManager = new ReconnectManager(context, new ReconnectManager.OnReconnectListener() {
|
||||
@Override
|
||||
public void onReconnection(AdasConstants.IpcConnectionStatus status) {
|
||||
setStatus(status);
|
||||
connect();
|
||||
}
|
||||
});
|
||||
client = okBuilder.build();
|
||||
}
|
||||
|
||||
public void setWebSocketListener(IWebSocketConnectListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return status.get() == AdasConstants.IpcConnectionStatus.CONNECTED;
|
||||
}
|
||||
|
||||
|
||||
public void setStatus(AdasConstants.IpcConnectionStatus s) {
|
||||
CupidLogUtils.log(TAG, "当前状态=" + s);
|
||||
status.set(s);
|
||||
}
|
||||
|
||||
public AdasConstants.IpcConnectionStatus getStatus() {
|
||||
return status.get();
|
||||
}
|
||||
|
||||
//配置是否启用重连
|
||||
public void setEnableReconnect(boolean enableReconnect) {
|
||||
isEnableReconnect = enableReconnect;
|
||||
Log.i(TAG, "是否启动自动重连=" + enableReconnect);
|
||||
if (isEnableReconnect) {
|
||||
if (reconnectManager == null)
|
||||
reconnectManager = new ReconnectManager(context, new ReconnectManager.OnReconnectListener() {
|
||||
@Override
|
||||
public void onReconnection(String tag) {
|
||||
connect("重连中(" + tag + ")");
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (reconnectManager != null) {
|
||||
reconnectManager.stop();
|
||||
reconnectManager = null;
|
||||
}
|
||||
}
|
||||
public void setReconnectCount(int count) {
|
||||
// if (!isNeedReconnect()) {
|
||||
// setStatus(AdasConstants.IpcConnectionStatus.DISCONNECTED);//如果不进行重连将重置状态,否则会导致无法连
|
||||
// }
|
||||
reconnectManager.setReconnectCount(count);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否正在重连
|
||||
*
|
||||
* @return 是否正在重连
|
||||
*/
|
||||
public boolean isReconnection() {
|
||||
return reconnectManager.isReconnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectWebSocket(String address, int port) {
|
||||
this.ipAddress = address;
|
||||
this.port = port;
|
||||
isUserClose.set(false);
|
||||
isPassiveClose.set(false);
|
||||
setStatus(AdasConstants.IpcConnectionStatus.CONNECTING);
|
||||
wsHost = WS_IP_HOST_HEAD + address + String.format(Locale.getDefault(), RESOURCE_PATH, port);
|
||||
CupidLogUtils.i(TAG, "WebSocket 主动连接= " + wsHost);
|
||||
connect("连接中");
|
||||
connect();
|
||||
}
|
||||
|
||||
private synchronized void connect(String msg) {
|
||||
/**
|
||||
* 连接
|
||||
*/
|
||||
private synchronized void connect() {
|
||||
if (mWebSocket == null) {
|
||||
if (mWebSocketConnectListener != null)
|
||||
mWebSocketConnectListener.onConnecting(msg);
|
||||
callConnectStatus();
|
||||
Request request = new Request.Builder()
|
||||
.url(wsHost)
|
||||
.build();
|
||||
mWebSocket = new RealWebSocket(request, listener, new Random(), client.pingIntervalMillis());
|
||||
mWebSocket = new RealWebSocket(request, new EchoWebSocketListener(), new Random(), client.pingIntervalMillis());
|
||||
mWebSocket.connect(client);
|
||||
// mWebSocket = client.newWebSocket(request, listener);
|
||||
}
|
||||
}
|
||||
|
||||
private void reconnectCmd(boolean isStart) {
|
||||
if (reconnectManager != null) {
|
||||
if (isStart) {
|
||||
if (isEnableReconnect) {
|
||||
reconnectManager.start();
|
||||
}
|
||||
} else {
|
||||
reconnectManager.stop();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 启动重连功能
|
||||
*/
|
||||
private void reconnectStart() {
|
||||
ReceiveTimeoutManager.getInstance().stop();
|
||||
reconnectManager.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* 重连
|
||||
*/
|
||||
private void reconnect() {
|
||||
if (!isUserClose.get()) {
|
||||
reconnectCmd(true);
|
||||
} else {
|
||||
isUserClose.set(false);
|
||||
}
|
||||
private void reconnectStop(boolean isResetCurrentCount) {
|
||||
reconnectManager.stop(isResetCurrentCount);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void closeWebSocket() {
|
||||
public void closeWebSocket(boolean isCertificationFailed) {
|
||||
if (AdasChannel.isUseQueue) {
|
||||
WebSocketQueueManager.getInstance().release();
|
||||
WSByteQueueManager.getInstance().release();
|
||||
}
|
||||
isUserClose.set(true);
|
||||
isPassiveClose.set(false);
|
||||
reconnectCmd(false);
|
||||
if (mWebSocket != null) {
|
||||
close(true, 1000);
|
||||
} else {
|
||||
onConnectFailed(null);
|
||||
}
|
||||
setStatus(isCertificationFailed ? AdasConstants.IpcConnectionStatus.CERTIFICATION_FAILED : AdasConstants.IpcConnectionStatus.DISCONNECTED);
|
||||
reconnectStop(true);//停止重连
|
||||
ReceiveTimeoutManager.getInstance().stop();//关闭超时
|
||||
close(false, isCertificationFailed ? 1001 : 1000);//关闭连接
|
||||
callConnectStatus();//回调状态
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sendDataWebSocket(String data) {
|
||||
if (mWebSocket != null && isConnected.get()) {
|
||||
if (mWebSocket != null && isConnected()) {
|
||||
boolean result = mWebSocket.send(data);
|
||||
CupidLogUtils.i(TAG, "WebSocket send String= " + data + ", result= " + result);
|
||||
return result;
|
||||
@@ -201,36 +206,15 @@ public class FpgaSocket implements IWebSocket {
|
||||
|
||||
@Override
|
||||
public boolean sendDataWebSocket(ByteString data) {
|
||||
if (mWebSocket != null && isConnected.get()) {
|
||||
if (mWebSocket != null && isConnected()) {
|
||||
boolean result = mWebSocket.send(data);
|
||||
// CupidLogUtils.i(TAG, "WebSocket send ByteString=" + ByteUtil.byteArrToHex(data.toByteArray()) + ", result= " + result);
|
||||
Log.i("[tag=" + TAG + "]", "[data=WebSocket send ByteString=" + ByteUtil.byteArrToHex(data.toByteArray()) + ", result= " + result + "]");
|
||||
CupidLogUtils.log(TAG, "WebSocket send ByteString=" + ByteUtil.byteArrToHex(data.toByteArray()) + ", result= " + result);
|
||||
return result;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public interface IWebSocketConnectListener {
|
||||
/**
|
||||
* 正在连接
|
||||
*/
|
||||
void onConnecting(String msg);
|
||||
|
||||
void onWebSocketConnectSuccess(String ipAddress, int port);
|
||||
|
||||
void onWebSocketConnectFailed(String t);
|
||||
|
||||
void onMessage(String message);
|
||||
|
||||
//TODO 计算耗时 临时测试
|
||||
void onMessage(long receiveTime, ByteString bytes) throws InvalidProtocolBufferException;
|
||||
}
|
||||
|
||||
public void setWebSocketListener(IWebSocketConnectListener listener) {
|
||||
mWebSocketConnectListener = listener;
|
||||
}
|
||||
|
||||
public class EchoWebSocketListener extends WebSocketListener {
|
||||
|
||||
@ChainLog(linkChainLog = CHAIN_TYPE_INIT_STATUS,
|
||||
@@ -242,15 +226,16 @@ public class FpgaSocket implements IWebSocket {
|
||||
super.onOpen(webSocket, response);
|
||||
// mWebSocket = webSocket;
|
||||
boolean isConnect = response.code() == 101;
|
||||
isConnected.set(isConnect);
|
||||
if (!isConnect) {
|
||||
onPassiveClose(1001, "協議不匹配");
|
||||
} else {
|
||||
reconnectCmd(false);
|
||||
setStatus(isConnect ? AdasConstants.IpcConnectionStatus.CONNECTED : AdasConstants.IpcConnectionStatus.PROTOCOL_MISMATCH);
|
||||
if (isConnect) {
|
||||
reconnectStop(false);//不重置重连次数的原因是因为,域控踢掉的时候要记录重连的次数
|
||||
ReceiveTimeoutManager.getInstance().start();
|
||||
CupidLogUtils.i(TAG, "WebSocket 连接成功");
|
||||
if (mWebSocketConnectListener != null)
|
||||
mWebSocketConnectListener.onWebSocketConnectSuccess(ipAddress, port);
|
||||
callConnectStatus(ipAddress, port);
|
||||
} else {
|
||||
close(false, 1001);
|
||||
callConnectStatus();
|
||||
reconnectStart();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,8 +248,8 @@ public class FpgaSocket implements IWebSocket {
|
||||
if (AdasChannel.isUseQueue) {
|
||||
WebSocketQueueManager.getInstance().addQueueData(text);
|
||||
} else {
|
||||
if (mWebSocketConnectListener != null)
|
||||
mWebSocketConnectListener.onMessage(text);
|
||||
if (listener != null)
|
||||
listener.onMessage(text);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,8 +275,8 @@ public class FpgaSocket implements IWebSocket {
|
||||
WSByteQueueManager.getInstance().addQueueData(bytes);
|
||||
} else {
|
||||
try {
|
||||
if (mWebSocketConnectListener != null)
|
||||
mWebSocketConnectListener.onMessage(nowTime, bytes);
|
||||
if (listener != null)
|
||||
listener.onMessage(nowTime, bytes);
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -305,16 +290,27 @@ public class FpgaSocket implements IWebSocket {
|
||||
@Override
|
||||
public void onClosing(@NonNull WebSocket webSocket, int code, @NonNull String reason) {
|
||||
super.onClosing(webSocket, code, reason);
|
||||
String msg = "Closing Code=" + code + " reason=";
|
||||
if (TextUtils.isEmpty(reason))
|
||||
reason = "服务端关闭";
|
||||
msg += reason;
|
||||
CupidLogUtils.e(TAG, msg);
|
||||
|
||||
if (status.get() == AdasConstants.IpcConnectionStatus.DISCONNECTED //用户主动关闭
|
||||
|| status.get() == AdasConstants.IpcConnectionStatus.RECONNECTING_TIMER //重连关闭
|
||||
|| status.get() == AdasConstants.IpcConnectionStatus.RECONNECTING_NETWORK //重连关闭
|
||||
|| status.get() == AdasConstants.IpcConnectionStatus.CERTIFICATION_FAILED //认证失败关闭
|
||||
|| status.get() == AdasConstants.IpcConnectionStatus.HEARTBEAT_TIMEOUT //心跳超时关闭
|
||||
|| status.get() == AdasConstants.IpcConnectionStatus.PROTOCOL_MISMATCH //協議不匹配关闭
|
||||
) {
|
||||
CupidLogUtils.log(TAG, "关闭 Closing Code=" + code + " Reason=" + reason + " Status=" + status.get());
|
||||
return;
|
||||
}
|
||||
setStatus(AdasConstants.IpcConnectionStatus.SERVER_DISCONNECTED);
|
||||
CupidLogUtils.log(TAG, "关闭 Closing Code=" + code + " Reason=" + reason + " Status=" + status.get());
|
||||
int clientCloseCode = 1000;
|
||||
if (code != 1000) {
|
||||
clientCloseCode = 1001;
|
||||
}
|
||||
onPassiveClose(clientCloseCode, msg);
|
||||
close(false, clientCloseCode);
|
||||
callConnectStatus(reason);
|
||||
//当服务端关闭时,停止超时检测并启动重连
|
||||
reconnectStart();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -323,7 +319,7 @@ public class FpgaSocket implements IWebSocket {
|
||||
@Override
|
||||
public void onClosed(@NonNull WebSocket webSocket, int code, @NonNull String reason) {
|
||||
super.onClosed(webSocket, code, reason);
|
||||
CupidLogUtils.e(TAG, code + " Closed reason= " + reason);
|
||||
CupidLogUtils.log(TAG, "关闭完成 Closed Code=" + code + " Reason=" + reason + " Status=" + status.get());
|
||||
// String msg = "Code=" + code + " ";
|
||||
// if (TextUtils.isEmpty(reason))
|
||||
// reason = "未知原因";
|
||||
@@ -334,71 +330,59 @@ public class FpgaSocket implements IWebSocket {
|
||||
@Override
|
||||
public void onFailure(@NonNull WebSocket webSocket, @NonNull Throwable t, Response response) {
|
||||
super.onFailure(webSocket, t, response);
|
||||
CupidLogUtils.e(TAG, "WebSocket onFailure 是否是被动关闭:" + isPassiveClose + " Throwable=" + t);
|
||||
if (isPassiveClose.get()) {
|
||||
isPassiveClose.set(false);
|
||||
CupidLogUtils.log(TAG, "WebSocket onFailure Throwable=" + t);
|
||||
AdasConstants.IpcConnectionStatus s = status.get();
|
||||
if (s == AdasConstants.IpcConnectionStatus.DISCONNECTED ||
|
||||
s == AdasConstants.IpcConnectionStatus.CERTIFICATION_FAILED ||
|
||||
s == AdasConstants.IpcConnectionStatus.HEARTBEAT_TIMEOUT ||
|
||||
s == AdasConstants.IpcConnectionStatus.PROTOCOL_MISMATCH) {
|
||||
return;
|
||||
}
|
||||
String reason = t.toString();
|
||||
setStatus(AdasConstants.IpcConnectionStatus.CONNECT_EXCEPTION);
|
||||
String message = t.getLocalizedMessage();
|
||||
String reason = (message != null) ? message : t.getClass().getSimpleName();
|
||||
//连接异常或关闭异常不进行堆栈打印
|
||||
if (!reason.toLowerCase().contains("failed to connect to") && !reason.contains("Socket closed"))
|
||||
CupidLogUtils.e(TAG, "WebSocket onFailure", t);
|
||||
if (TextUtils.isEmpty(reason))
|
||||
reason = "未知原因";
|
||||
if (!TextUtils.isEmpty(receiveTimeoutReason)) {
|
||||
reason = receiveTimeoutReason;
|
||||
receiveTimeoutReason = null;
|
||||
}
|
||||
if (mWebSocket != null) {
|
||||
close(false, 1001);
|
||||
}
|
||||
onConnectFailed("Failure " + reason);
|
||||
Log.e("[tag=" + TAG + "]", "[data=WebSocket onFailure]", t);
|
||||
close(true, 1001);
|
||||
callConnectStatus(reason);
|
||||
reconnectStart();
|
||||
}
|
||||
}
|
||||
|
||||
private void onConnectFailed(String reason) {
|
||||
receiveTimeoutReason = null;
|
||||
ReceiveTimeoutManager.getInstance().stop();
|
||||
if (mWebSocketConnectListener != null) {
|
||||
reason = "未连接 " + reason;
|
||||
if (isUserClose.get())
|
||||
reason = null;
|
||||
mWebSocketConnectListener.onWebSocketConnectFailed(reason);
|
||||
|
||||
private void callConnectStatus(Object... reason) {
|
||||
if (listener != null) {
|
||||
listener.onWebSocketConnectStatus(status.get(), reason);
|
||||
}
|
||||
reconnect();
|
||||
}
|
||||
|
||||
/**
|
||||
* 被动关闭 包含:服务断开 心跳超时 等
|
||||
* 关闭
|
||||
*
|
||||
* @param reason
|
||||
* @param isCancel 发生异常的时候true
|
||||
* @param code 关闭码
|
||||
*/
|
||||
private void onPassiveClose(int code, String reason) {
|
||||
isPassiveClose.set(true);
|
||||
if (mWebSocket != null) {
|
||||
close(false, code);
|
||||
}
|
||||
onConnectFailed(reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param isInitiative 是否是主动断开
|
||||
* @param code code
|
||||
*/
|
||||
private synchronized void close(boolean isInitiative, int code) {
|
||||
isConnected.set(false);
|
||||
private synchronized void close(boolean isCancel, int code) {
|
||||
if (mWebSocket != null) {
|
||||
String closeReason = null;
|
||||
if (isInitiative) {
|
||||
AdasConstants.IpcConnectionStatus s = status.get();
|
||||
if (s == AdasConstants.IpcConnectionStatus.DISCONNECTED) {
|
||||
closeReason = "用户主动关闭";
|
||||
} else if (s == AdasConstants.IpcConnectionStatus.CERTIFICATION_FAILED) {
|
||||
closeReason = "认证失败";
|
||||
} else if (s == AdasConstants.IpcConnectionStatus.HEARTBEAT_TIMEOUT) {
|
||||
closeReason = "心跳超时";
|
||||
} else if (s == AdasConstants.IpcConnectionStatus.PROTOCOL_MISMATCH) {
|
||||
closeReason = "協議不匹配";
|
||||
}
|
||||
boolean isClose = mWebSocket.close(code, closeReason);
|
||||
CupidLogUtils.i(TAG, "WebSocket " + (isInitiative ? "主动" : "被动") + "断开连接是否成功= " + isClose);
|
||||
if (!isInitiative) {
|
||||
CupidLogUtils.log(TAG, "WebSocket code=" + code + " isCancel=" + isCancel + " 断开连接是否成功= " + isClose);
|
||||
if (isCancel) {
|
||||
mWebSocket.cancel();
|
||||
}
|
||||
mWebSocket = null;
|
||||
}
|
||||
mWebSocket = null;
|
||||
}
|
||||
|
||||
public WebSocket getWebSocket() {
|
||||
|
||||
@@ -22,8 +22,10 @@ public interface IWebSocket {
|
||||
|
||||
/**
|
||||
* 关闭webSocket
|
||||
*
|
||||
* @param isCertificationFailed 是否验证失败
|
||||
*/
|
||||
void closeWebSocket();
|
||||
void closeWebSocket(boolean isCertificationFailed);
|
||||
|
||||
/**
|
||||
* websocket send data
|
||||
|
||||
@@ -63,7 +63,7 @@ public class DispatchHandler {
|
||||
|
||||
public void sendRawMessage(RawData raw) {
|
||||
start();
|
||||
if (messageType == MessagePad.MessageType.MsgTypePointCloud) {
|
||||
if (messageType == MessagePad.MessageType.MsgTypePointCloud && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
boolean isIdle = mBaseHandler.getLooper().getQueue().isIdle();
|
||||
// Log.i("TimeConsuming", mThread.getName() + " 当前消息队列是否处于空闲状态=" + isIdle);
|
||||
if (!isIdle) {
|
||||
@@ -128,6 +128,11 @@ public class DispatchHandler {
|
||||
mBaseHandler.postDelayed(runnable, delayMillis);
|
||||
}
|
||||
|
||||
public void removeCallbacks(Runnable runnable) {
|
||||
if (mBaseHandler != null) {
|
||||
mBaseHandler.removeCallbacks(runnable);
|
||||
}
|
||||
}
|
||||
|
||||
protected static class BaseHandler extends Handler {
|
||||
private final WeakReference<DispatchHandler> mObjects;
|
||||
|
||||
Reference in New Issue
Block a user