[opt3.0][adas lib] 1.能否启动自驾检测接口兼容MAP250以下版本;2.获取车机基础信息接口增加多次获取逻辑,目前会尝试3次获取;3.修改错别字
This commit is contained in:
@@ -23,7 +23,6 @@ import androidx.annotation.Nullable;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import com.zhidao.support.adas.high.bean.AutopilotStatistics;
|
||||
import com.zhidao.support.adas.high.bean.VersionCompatibility;
|
||||
import com.zhidao.support.adas.high.common.AutopilotAbilityManager;
|
||||
import com.zhidao.support.adas.high.common.AutopilotReview;
|
||||
import com.zhidao.support.adas.high.common.ByteUtil;
|
||||
import com.zhidao.support.adas.high.common.Constants;
|
||||
@@ -34,6 +33,7 @@ import com.zhidao.support.adas.high.common.MessageType;
|
||||
import com.zhidao.support.adas.high.common.ProtocolStatus;
|
||||
import com.zhidao.support.adas.high.common.ReceiveTimeoutManager;
|
||||
import com.zhidao.support.adas.high.common.RegexUtils;
|
||||
import com.zhidao.support.adas.high.common.autopilot.ability.AutopilotAbilityManager;
|
||||
import com.zhidao.support.adas.high.msg.IMsg;
|
||||
import com.zhidao.support.adas.high.msg.MyMessageFactory;
|
||||
import com.zhidao.support.adas.high.protocol.RawData;
|
||||
@@ -129,6 +129,7 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
* 乘客屏无法进行注册或取消注册,因为乘客屏无法感知司机屏与工控机连接状态。无法重置已注册或未注册接口列表
|
||||
*/
|
||||
private SubscribeInterface subscribeInterface;
|
||||
private Timer carConfigReqTimer;//车辆基础信息请求 多次请求防止无法收到基础信息情况出现
|
||||
|
||||
public void setOnMultiDeviceListener(OnMultiDeviceListener onMultiDeviceListener) {
|
||||
this.onMultiDeviceListener = onMultiDeviceListener;
|
||||
@@ -535,7 +536,7 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
|
||||
@Override
|
||||
public void onWebSocketConnectSuccess(String ipAddress, int port) {
|
||||
sendCarConfigReq();
|
||||
startCarConfigReq();
|
||||
ipcConnectedIp = ipAddress;
|
||||
ipcConnectedPort = port;
|
||||
subscribeInterface = new SubscribeInterface(this);
|
||||
@@ -662,6 +663,7 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
if (status == Constants.IPC_CONNECTION_STATUS.DISCONNECTED) {
|
||||
AdasManager.getInstance().setCarConfig(null);
|
||||
stopDispatchHandler();
|
||||
stopCarConfigReq();
|
||||
}
|
||||
if (adasConnectStatusListener != null) {
|
||||
adasConnectStatusListener.onConnectionIPCStatus(ipcConnectionStatus.get(), reason);
|
||||
@@ -775,6 +777,40 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
|
||||
CupidLogUtils.setEnableLog(isEnableLog);
|
||||
}
|
||||
|
||||
//车辆基础信息请求
|
||||
private void startCarConfigReq() {
|
||||
if (carConfigReqTimer == null) {
|
||||
carConfigReqTimer = new Timer();
|
||||
carConfigReqTimer.schedule(new TimerTask() {
|
||||
int num = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (getIpcConnectionStatus() == Constants.IPC_CONNECTION_STATUS.CONNECTED) {
|
||||
if (AdasManager.getInstance().getCarConfig() == null) {
|
||||
num++;
|
||||
if (num > 3) {
|
||||
CupidLogUtils.i(TAG, "最后一次也未获取到车机基础信息");
|
||||
stopCarConfigReq();
|
||||
} else {
|
||||
CupidLogUtils.i(TAG, "第" + num + "次获取车机基础信息");
|
||||
sendCarConfigReq();
|
||||
}
|
||||
} else {
|
||||
stopCarConfigReq();
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 10, 2000L);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void stopCarConfigReq() {
|
||||
if (carConfigReqTimer != null) {
|
||||
carConfigReqTimer.cancel();
|
||||
carConfigReqTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************************************************************/
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.zhidao.support.adas.high;
|
||||
|
||||
import com.zhidao.support.adas.high.common.AutopilotAbilityManager;
|
||||
import com.zhidao.support.adas.high.common.autopilot.ability.AutopilotAbilityManager;
|
||||
import com.zhidao.support.adas.high.subscribe.SubscribeInterfaceOptions;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
package com.zhidao.support.adas.high.common.autopilot.ability;
|
||||
|
||||
import com.zhidao.support.adas.high.OnAdasListener;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import chassis.Chassis;
|
||||
import chassis.ChassisStatesOuterClass;
|
||||
|
||||
/**
|
||||
* 是否可以启动自动驾驶能力检测 工控机版本>=230&& <250 使用此类
|
||||
* 目前监控了底盘的一些状态和查询节点状态应答的数据
|
||||
* 没有使用监控事件报告的原因是因为,部分异常没进行正常恢复通知,例如收到了异常监控数据,但是异常恢复之后没有恢复的通知
|
||||
* <p>
|
||||
* 此定时器不能停止 鹰眼中存在UI更新依赖循环查询系统状态
|
||||
*/
|
||||
public class AutopilotAbility230 {
|
||||
private static final String TAG = AutopilotAbility230.class.getSimpleName();
|
||||
private static final long DEFAULT_DETECTION_TIME = 3 * 1000L;//默认检测时间
|
||||
private volatile Timer timer;
|
||||
private ChassisStatesOuterClass.ChassisStates chassisStates;
|
||||
|
||||
public AutopilotAbility230() {
|
||||
}
|
||||
|
||||
|
||||
public void setChassisStates(ChassisStatesOuterClass.ChassisStates chassisStates) {
|
||||
this.chassisStates = chassisStates;
|
||||
}
|
||||
|
||||
private void onCallback() {
|
||||
//金旅、开沃小巴乘客端 不能启动自动驾驶
|
||||
if (AutopilotAbilityManager.getInstance().isBusPassenger()) {
|
||||
return;
|
||||
}
|
||||
boolean isAutopilotAbility = true;//是否能启动自动驾驶
|
||||
String unableAutopilotReason = null;//不能启动自动驾驶原因
|
||||
//检测底盘相关
|
||||
if (chassisStates != null) {
|
||||
if (chassisStates.hasBrakeSystemStates()) {
|
||||
float brake = chassisStates.getBrakeSystemStates().getBrakePedalResponsePosition();
|
||||
if (brake > 0) {
|
||||
isAutopilotAbility = false;
|
||||
unableAutopilotReason = "制动踏板被踩下";
|
||||
}
|
||||
}
|
||||
if (isAutopilotAbility) {
|
||||
/**
|
||||
* 档位状态判断 目前判断的车型包括 东风Taxi 红旗Taxi 金旅Bus 金旅M1 金旅M1 福田清扫车 开沃
|
||||
* TODO 如果 identityMode 未赋值以及目前已知其他车型判断逻辑跟东风Taxi和红旗 走
|
||||
*/
|
||||
//开沃任何档位都能启动自驾
|
||||
if (!AutopilotAbilityManager.getInstance().isBusDriverVan()) {
|
||||
if (chassisStates.hasGearSystemStates()) {
|
||||
Chassis.GearPosition gear = chassisStates.getGearSystemStates().getGearPosition();
|
||||
//金旅Bus和清扫车 档位不正常
|
||||
if (AutopilotAbilityManager.getInstance().isBusDriver()) {
|
||||
if (gear == Chassis.GearPosition.GEAR_N || gear == Chassis.GearPosition.GEAR_R) {
|
||||
isAutopilotAbility = false;
|
||||
unableAutopilotReason = "档位不正常";
|
||||
}
|
||||
} else if (AutopilotAbilityManager.getInstance().isSweeperDriverFutian()) {
|
||||
if (gear == Chassis.GearPosition.GEAR_N) {
|
||||
isAutopilotAbility = false;
|
||||
unableAutopilotReason = "档位不正常";
|
||||
}
|
||||
} else {
|
||||
//东风Taxi和红旗 司机端和乘客端 档位不正常
|
||||
if (gear == Chassis.GearPosition.GEAR_P || gear == Chassis.GearPosition.GEAR_R) {
|
||||
isAutopilotAbility = false;
|
||||
unableAutopilotReason = "档位不正常";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//TODO 关于手刹:不同车型的实现不同所以目前没法使用此字段
|
||||
// if (isAutopilotAbility) {
|
||||
// //电子驻车制动系统
|
||||
// if (chassisStates.hasEpbSystemStates()) {
|
||||
// ChassisStatesOuterClass.EPBSystemStates epb = chassisStates.getEpbSystemStates();
|
||||
// if (epb.hasEpbEnableState()){
|
||||
// epb.getEpbWorkState();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
if (AutopilotAbilityManager.getInstance().getListener() != null) {
|
||||
AutopilotAbilityManager.getInstance().getListener().onAutopilotAbility(isAutopilotAbility, unableAutopilotReason);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void start() {
|
||||
if (timer == null) {
|
||||
timer = new Timer();
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
onCallback();
|
||||
}
|
||||
}, 2000L, DEFAULT_DETECTION_TIME);//延迟执行,避免刚连接成功后底盘信息无法及时同步
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void stop() {
|
||||
if (timer != null) {
|
||||
timer.cancel();
|
||||
timer = null;
|
||||
}
|
||||
this.chassisStates = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,106 +1,41 @@
|
||||
package com.zhidao.support.adas.high.common;
|
||||
package com.zhidao.support.adas.high.common.autopilot.ability;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.zhidao.support.adas.high.AdasManager;
|
||||
import com.zhidao.support.adas.high.OnAdasListener;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import chassis.Chassis;
|
||||
import chassis.ChassisStatesOuterClass;
|
||||
import system_master.SystemStatusInfo;
|
||||
|
||||
/**
|
||||
* 是否可以启动自动驾驶能力检测
|
||||
* 是否可以启动自动驾驶能力检测 工控机版本>=250使用此类
|
||||
* 目前监控了底盘的一些状态和查询节点状态应答的数据
|
||||
* 没有使用监控事件报告的原因是因为,部分异常没进行正常恢复通知,例如收到了异常监控数据,但是异常恢复之后没有恢复的通知
|
||||
* <p>
|
||||
* 此定时器不能停止 鹰眼中存在UI更新依赖循环查询系统状态
|
||||
*/
|
||||
public class AutopilotAbilityManager {
|
||||
private static final String TAG = AutopilotAbilityManager.class.getSimpleName();
|
||||
public class AutopilotAbility250 {
|
||||
private static final String TAG = AutopilotAbility250.class.getSimpleName();
|
||||
private static final int WHAT_TIMEOUT = 0;
|
||||
private static final int DEFAULT_TIMEOUT = 1500;
|
||||
private static final long DEFAULT_DETECTION_TIME = 3 * 1000L;//默认检测时间
|
||||
private static final String[] NODE_INFO_STATE = {"未知状态 ", "依赖未就绪 ", "启动中 ", "运行 ", "停止 ", "无法启动状态 ", "人为启动状态 ", "人为关闭状态 "};
|
||||
private static volatile AutopilotAbilityManager INSTANCE;
|
||||
private OnAdasListener listener;
|
||||
private volatile Timer timer;
|
||||
private final Pattern pattern = Pattern.compile("\\d+.\\d+.\\d+");
|
||||
private ChassisStatesOuterClass.ChassisStates chassisStates;
|
||||
private Handler handler;
|
||||
private OnAutopilotAbilityListener onAutopilotAbilityListener;
|
||||
/**
|
||||
* 身份/车型
|
||||
*/
|
||||
private String identityMode;
|
||||
|
||||
public interface OnAutopilotAbilityListener {
|
||||
void onStatusQuery();//查询是被调用
|
||||
public AutopilotAbility250() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 身份规则定义根据app/productFlavors/README.md
|
||||
* * taxi司机屏 Taxi_Driver_Base (东风、红旗司机端)
|
||||
* * taxi乘客屏 Taxi_Passenger_Base (东风、红旗乘客端)
|
||||
* * bus司机屏 Bus_Driver_Base (金旅小巴司机端)
|
||||
* * Bus_Driver_Van (开沃小巴司机端)
|
||||
* * bus乘客屏 Bus_Passenger_Base (金旅、开沃小巴乘客端)
|
||||
* * Bus_Passenger_M1 (M1小巴乘客端)
|
||||
* * Bus_Passenger_M2 (M2小巴乘客端)
|
||||
* * 清扫车 Sweeper_Driver_FT (福田清扫车司机端)
|
||||
* <p>
|
||||
* 此定义不区分角色,只区分业务线和车型
|
||||
*/
|
||||
private interface IDENTITY_MODE {
|
||||
String TAXI_DRIVER_BASE = "Taxi_Driver_Base";//(东风、红旗司机端)
|
||||
String TAXI_PASSENGER_BASE = "Taxi_Passenger_Base";//(东风、红旗乘客端)
|
||||
String BUS_DRIVER_BASE = "Bus_Driver_Base";//(金旅小巴司机端)
|
||||
String BUS_DRIVER_VAN = "Bus_Driver_Van";//(开沃小巴司机端)
|
||||
String BUS_PASSENGER_BASE = "Bus_Passenger_Base";//(金旅、开沃小巴乘客端)
|
||||
String BUS_PASSENGER_M1 = "Bus_Passenger_M1";//(M1小巴乘客端)
|
||||
String BUS_PASSENGER_M2 = "Bus_Passenger_M2";//(M2小巴乘客端)
|
||||
String SWEEPER_DRIVER_FT = "Sweeper_Driver_FT";//(福田清扫车司机端)
|
||||
}
|
||||
|
||||
|
||||
public void setIdentityMode(String identityMode) {
|
||||
this.identityMode = identityMode;
|
||||
}
|
||||
|
||||
public void setOnAdasListener(OnAdasListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public void setOnAutopilotAbilityListener(OnAutopilotAbilityListener onAutopilotAbilityListener) {
|
||||
this.onAutopilotAbilityListener = onAutopilotAbilityListener;
|
||||
}
|
||||
|
||||
private AutopilotAbilityManager() {
|
||||
}
|
||||
|
||||
public static AutopilotAbilityManager getInstance() {
|
||||
if (INSTANCE == null) {
|
||||
synchronized (AutopilotAbilityManager.class) {
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE = new AutopilotAbilityManager();
|
||||
}
|
||||
}
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public void setStatusInfo(SystemStatusInfo.StatusInfo statusInfo) {
|
||||
if (handler != null) {
|
||||
if (handler.hasMessages(WHAT_TIMEOUT))
|
||||
handler.removeMessages(WHAT_TIMEOUT);
|
||||
if (AutopilotAbilityManager.getInstance().getHandler() != null) {
|
||||
if (AutopilotAbilityManager.getInstance().getHandler().hasMessages(WHAT_TIMEOUT))
|
||||
AutopilotAbilityManager.getInstance().getHandler().removeMessages(WHAT_TIMEOUT);
|
||||
}
|
||||
onCallback(statusInfo);
|
||||
}
|
||||
@@ -111,7 +46,7 @@ public class AutopilotAbilityManager {
|
||||
|
||||
private void onCallback(SystemStatusInfo.StatusInfo statusInfo) {
|
||||
//金旅、开沃小巴乘客端 不能启动自动驾驶
|
||||
if (IDENTITY_MODE.BUS_PASSENGER_BASE.equalsIgnoreCase(identityMode)) {
|
||||
if (AutopilotAbilityManager.getInstance().isBusPassenger()) {
|
||||
return;
|
||||
}
|
||||
boolean isAutopilotAbility = true;//是否能启动自动驾驶
|
||||
@@ -122,20 +57,7 @@ public class AutopilotAbilityManager {
|
||||
if (statusInfo.hasMasterVersion()) {
|
||||
//截取Master Version
|
||||
String masterVersion = statusInfo.getMasterVersion();
|
||||
if (!TextUtils.isEmpty(masterVersion)) {
|
||||
try {
|
||||
Matcher matcher = pattern.matcher(masterVersion);
|
||||
if (matcher.find()) {
|
||||
String group = matcher.group();
|
||||
if (!TextUtils.isEmpty(group)) {
|
||||
String v = group.split("\\.")[0];
|
||||
version = Integer.parseInt(v);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
version = AutopilotAbilityManager.getInstance().parseVersion(false, masterVersion);
|
||||
}
|
||||
//如果 maser version 大于1,还需要判断AutoPilotReady字段是否存在,以确保MAP版本和SSM Maser版本不陪配情况逻辑能正常执行
|
||||
if (version > 1 && statusInfo.hasAutoPilotReady()) {
|
||||
@@ -204,24 +126,26 @@ public class AutopilotAbilityManager {
|
||||
* 档位状态判断 目前判断的车型包括 东风Taxi 红旗Taxi 金旅Bus 金旅M1 金旅M1 福田清扫车 开沃
|
||||
* TODO 如果 identityMode 未赋值以及目前已知其他车型判断逻辑跟东风Taxi和红旗 走
|
||||
*/
|
||||
if (chassisStates.hasGearSystemStates()) {
|
||||
Chassis.GearPosition gear = chassisStates.getGearSystemStates().getGearPosition();
|
||||
if (TextUtils.isEmpty(identityMode)) {
|
||||
identityMode = "";
|
||||
}
|
||||
//开沃任何档位都能启动自驾
|
||||
if (!IDENTITY_MODE.BUS_DRIVER_VAN.equalsIgnoreCase(identityMode)) {
|
||||
//开沃任何档位都能启动自驾
|
||||
if (!AutopilotAbilityManager.getInstance().isBusDriverVan()) {
|
||||
if (chassisStates.hasGearSystemStates()) {
|
||||
Chassis.GearPosition gear = chassisStates.getGearSystemStates().getGearPosition();
|
||||
//金旅Bus和清扫车 档位不正常
|
||||
if (IDENTITY_MODE.BUS_DRIVER_BASE.equalsIgnoreCase(identityMode) || IDENTITY_MODE.SWEEPER_DRIVER_FT.equalsIgnoreCase(identityMode)) {
|
||||
if (AutopilotAbilityManager.getInstance().isBusDriver()) {
|
||||
if (gear == Chassis.GearPosition.GEAR_N || gear == Chassis.GearPosition.GEAR_R) {
|
||||
isAutopilotAbility = false;
|
||||
unableAutopilotReason = "挡位不正常";
|
||||
unableAutopilotReason = "档位不正常";
|
||||
}
|
||||
} else if (AutopilotAbilityManager.getInstance().isSweeperDriverFutian()) {
|
||||
if (gear == Chassis.GearPosition.GEAR_N) {
|
||||
isAutopilotAbility = false;
|
||||
unableAutopilotReason = "档位不正常";
|
||||
}
|
||||
} else {
|
||||
//东风Taxi和红旗 司机端和乘客端 档位不正常
|
||||
if (gear == Chassis.GearPosition.GEAR_P || gear == Chassis.GearPosition.GEAR_R) {
|
||||
isAutopilotAbility = false;
|
||||
unableAutopilotReason = "挡位不正常";
|
||||
unableAutopilotReason = "档位不正常";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -239,8 +163,8 @@ public class AutopilotAbilityManager {
|
||||
// }
|
||||
// }
|
||||
}
|
||||
if (listener != null) {
|
||||
listener.onAutopilotAbility(isAutopilotAbility, unableAutopilotReason);
|
||||
if (AutopilotAbilityManager.getInstance().getListener() != null) {
|
||||
AutopilotAbilityManager.getInstance().getListener().onAutopilotAbility(isAutopilotAbility, unableAutopilotReason);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,14 +174,14 @@ public class AutopilotAbilityManager {
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (onAutopilotAbilityListener != null) {
|
||||
onAutopilotAbilityListener.onStatusQuery();
|
||||
if (AutopilotAbilityManager.getInstance().getOnAutopilotAbilityListener() != null) {
|
||||
AutopilotAbilityManager.getInstance().getOnAutopilotAbilityListener().onStatusQuery();
|
||||
}
|
||||
AdasManager.getInstance().sendStatusQueryReq();
|
||||
if (handler != null) {
|
||||
if (handler.hasMessages(WHAT_TIMEOUT))
|
||||
handler.removeMessages(WHAT_TIMEOUT);
|
||||
handler.sendEmptyMessageDelayed(WHAT_TIMEOUT, DEFAULT_TIMEOUT);
|
||||
if (AutopilotAbilityManager.getInstance().getHandler() != null) {
|
||||
if (AutopilotAbilityManager.getInstance().getHandler().hasMessages(WHAT_TIMEOUT))
|
||||
AutopilotAbilityManager.getInstance().getHandler().removeMessages(WHAT_TIMEOUT);
|
||||
AutopilotAbilityManager.getInstance().getHandler().sendEmptyMessageDelayed(WHAT_TIMEOUT, DEFAULT_TIMEOUT);
|
||||
}
|
||||
}
|
||||
}, 2000L, DEFAULT_DETECTION_TIME);//延迟执行,避免刚连接成功后底盘信息无法及时同步
|
||||
@@ -269,18 +193,15 @@ public class AutopilotAbilityManager {
|
||||
timer.cancel();
|
||||
timer = null;
|
||||
}
|
||||
handler = null;
|
||||
this.chassisStates = null;
|
||||
}
|
||||
|
||||
public void setHandler(Handler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
|
||||
public void onHandleMessage(Message msg) {
|
||||
if (msg.what == WHAT_TIMEOUT) {
|
||||
onCallback(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,274 @@
|
||||
package com.zhidao.support.adas.high.common.autopilot.ability;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
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 java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import chassis.ChassisStatesOuterClass;
|
||||
import mogo.telematics.pad.MessagePad;
|
||||
import system_master.SystemStatusInfo;
|
||||
|
||||
/**
|
||||
* 是否可以启动自动驾驶能力检测
|
||||
* 目前监控了底盘的一些状态和查询节点状态应答的数据
|
||||
* 没有使用监控事件报告的原因是因为,部分异常没进行正常恢复通知,例如收到了异常监控数据,但是异常恢复之后没有恢复的通知
|
||||
* <p>
|
||||
* 此定时器不能停止 鹰眼中存在UI更新依赖循环查询系统状态
|
||||
*/
|
||||
public class AutopilotAbilityManager {
|
||||
private static final String TAG = AutopilotAbilityManager.class.getSimpleName();
|
||||
private static volatile AutopilotAbilityManager INSTANCE;
|
||||
private OnAdasListener listener;
|
||||
private final Pattern pattern = Pattern.compile("\\d+\\.\\d+\\.\\d+");
|
||||
private Handler handler;
|
||||
private OnAutopilotAbilityListener onAutopilotAbilityListener;
|
||||
private int dockerVersion = -1;//工控机版本
|
||||
private AutopilotAbility230 autopilotAbility230;
|
||||
private AutopilotAbility250 autopilotAbility250;
|
||||
private Timer startTimer;
|
||||
/**
|
||||
* 身份/车型
|
||||
*/
|
||||
private String identityMode;
|
||||
|
||||
public interface OnAutopilotAbilityListener {
|
||||
void onStatusQuery();//查询是被调用
|
||||
}
|
||||
|
||||
/**
|
||||
* 身份规则定义根据app/productFlavors/README.md
|
||||
* * taxi司机屏 Taxi_Driver_Base (东风、红旗司机端)
|
||||
* * taxi乘客屏 Taxi_Passenger_Base (东风、红旗乘客端)
|
||||
* * bus司机屏 Bus_Driver_Base (金旅小巴司机端)
|
||||
* * Bus_Driver_Van (开沃小巴司机端)
|
||||
* * bus乘客屏 Bus_Passenger_Base (金旅、开沃小巴乘客端)
|
||||
* * Bus_Passenger_M1 (M1小巴乘客端)
|
||||
* * Bus_Passenger_M2 (M2小巴乘客端)
|
||||
* * 清扫车 Sweeper_Driver_FT (福田清扫车司机端)
|
||||
* <p>
|
||||
* 此定义不区分角色,只区分业务线和车型
|
||||
*/
|
||||
private interface IDENTITY_MODE {
|
||||
String TAXI_DRIVER_BASE = "Taxi_Driver_Base";//(东风、红旗司机端)
|
||||
String TAXI_PASSENGER_BASE = "Taxi_Passenger_Base";//(东风、红旗乘客端)
|
||||
String BUS_DRIVER_BASE = "Bus_Driver_Base";//(金旅小巴司机端)
|
||||
String BUS_DRIVER_VAN = "Bus_Driver_Van";//(开沃小巴司机端)
|
||||
String BUS_PASSENGER_BASE = "Bus_Passenger_Base";//(金旅、开沃小巴乘客端)
|
||||
String BUS_PASSENGER_M1 = "Bus_Passenger_M1";//(M1小巴乘客端)
|
||||
String BUS_PASSENGER_M2 = "Bus_Passenger_M2";//(M2小巴乘客端)
|
||||
String SWEEPER_DRIVER_FT = "Sweeper_Driver_FT";//(福田清扫车司机端)
|
||||
}
|
||||
|
||||
private AutopilotAbilityManager() {
|
||||
}
|
||||
|
||||
public static AutopilotAbilityManager getInstance() {
|
||||
if (INSTANCE == null) {
|
||||
synchronized (AutopilotAbilityManager.class) {
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE = new AutopilotAbilityManager();
|
||||
}
|
||||
}
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public void setIdentityMode(String identityMode) {
|
||||
this.identityMode = identityMode;
|
||||
}
|
||||
|
||||
public void setCarConfig(MessagePad.CarConfigResp carConfig) {
|
||||
if (dockerVersion == -1) {
|
||||
String v = carConfig.getDockVersion();
|
||||
int version = parseVersion(true, v);
|
||||
if (version != -1) {
|
||||
stopTimer();
|
||||
dockerVersion = version;
|
||||
Log.i("dddd", "工控机版本=" + dockerVersion);
|
||||
initAutopilotAbility();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setOnAdasListener(OnAdasListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public OnAdasListener getListener() {
|
||||
return listener;
|
||||
}
|
||||
|
||||
public void setHandler(Handler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public Handler getHandler() {
|
||||
return handler;
|
||||
}
|
||||
|
||||
public void setOnAutopilotAbilityListener(OnAutopilotAbilityListener onAutopilotAbilityListener) {
|
||||
this.onAutopilotAbilityListener = onAutopilotAbilityListener;
|
||||
}
|
||||
|
||||
public OnAutopilotAbilityListener getOnAutopilotAbilityListener() {
|
||||
return onAutopilotAbilityListener;
|
||||
}
|
||||
|
||||
|
||||
public void setStatusInfo(SystemStatusInfo.StatusInfo statusInfo) {
|
||||
if (autopilotAbility250 != null) {
|
||||
autopilotAbility250.setStatusInfo(statusInfo);
|
||||
}
|
||||
}
|
||||
|
||||
public void setChassisStates(ChassisStatesOuterClass.ChassisStates chassisStates) {
|
||||
if (autopilotAbility230 != null) {
|
||||
autopilotAbility230.setChassisStates(chassisStates);
|
||||
}
|
||||
if (autopilotAbility250 != null) {
|
||||
autopilotAbility250.setChassisStates(chassisStates);
|
||||
}
|
||||
}
|
||||
|
||||
public void onHandleMessage(Message msg) {
|
||||
if (autopilotAbility250 != null) {
|
||||
autopilotAbility250.onHandleMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
private void initAutopilotAbility() {
|
||||
if (dockerVersion >= 250) {
|
||||
stop230();
|
||||
if (autopilotAbility250 == null) {
|
||||
autopilotAbility250 = new AutopilotAbility250();
|
||||
autopilotAbility250.start();
|
||||
}
|
||||
} else {
|
||||
stop250();
|
||||
if (autopilotAbility230 == null) {
|
||||
autopilotAbility230 = new AutopilotAbility230();
|
||||
autopilotAbility230.start();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void stop230() {
|
||||
if (autopilotAbility230 != null) {
|
||||
autopilotAbility230.stop();
|
||||
autopilotAbility230 = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void stop250() {
|
||||
if (autopilotAbility250 != null) {
|
||||
autopilotAbility250.stop();
|
||||
autopilotAbility250 = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void stopTimer() {
|
||||
if (startTimer != null) {
|
||||
startTimer.cancel();
|
||||
startTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接工控机成功调用此函数,如果dockerVersion还未获取到将启动最低版本的启动自动驾驶能力检测
|
||||
* 此函数为保险措施 以防无法获取工控机版本时 也能 正常执行逻辑
|
||||
*/
|
||||
public synchronized void start() {
|
||||
if (startTimer == null) {
|
||||
startTimer = new Timer();
|
||||
startTimer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (dockerVersion == -1 && AdasManager.getInstance().getIpcConnectionStatus() == Constants.IPC_CONNECTION_STATUS.CONNECTED) {
|
||||
dockerVersion = 230;
|
||||
initAutopilotAbility();
|
||||
}
|
||||
}
|
||||
}, 8000L);//延迟执行,避免刚连接成功后底盘信息无法及时同步
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public synchronized void stop() {
|
||||
stopTimer();
|
||||
stop230();
|
||||
stop250();
|
||||
handler = null;
|
||||
dockerVersion = -1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 解析版本 格式 xxx.xxx.xxx(x的数量不固定)
|
||||
*
|
||||
* @param isUserAll 是否使用全部截取数据 true:表示 12.34.56 截取之后 123456 false:表示12.34.56 截取之后 12
|
||||
* @param ver 版本字符串
|
||||
* @return -1表示解析失败
|
||||
*/
|
||||
public int parseVersion(boolean isUserAll, String ver) {
|
||||
int version = -1;
|
||||
if (!TextUtils.isEmpty(ver)) {
|
||||
try {
|
||||
Matcher matcher = pattern.matcher(ver);
|
||||
if (matcher.find()) {
|
||||
String group = matcher.group();
|
||||
if (!TextUtils.isEmpty(group)) {
|
||||
if (isUserAll) {
|
||||
group = group.replace(".", "");
|
||||
} else {
|
||||
group = group.split("\\.")[0];
|
||||
}
|
||||
version = Integer.parseInt(group);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
CupidLogUtils.e(TAG, "版本解析失败=" + ver, e);
|
||||
}
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
/**
|
||||
* 金旅、开沃小巴乘客端
|
||||
*/
|
||||
public boolean isBusPassenger() {
|
||||
return IDENTITY_MODE.BUS_PASSENGER_BASE.equalsIgnoreCase(identityMode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 开沃小巴司机端
|
||||
*/
|
||||
public boolean isBusDriverVan() {
|
||||
return IDENTITY_MODE.BUS_DRIVER_VAN.equalsIgnoreCase(identityMode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 金旅小巴司机端
|
||||
*/
|
||||
public boolean isBusDriver() {
|
||||
return IDENTITY_MODE.BUS_DRIVER_BASE.equalsIgnoreCase(identityMode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 福田清扫车司机端
|
||||
*/
|
||||
public boolean isSweeperDriverFutian() {
|
||||
return IDENTITY_MODE.SWEEPER_DRIVER_FT.equalsIgnoreCase(identityMode);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import com.zhidao.support.adas.high.AdasChannel;
|
||||
import com.zhidao.support.adas.high.AdasManager;
|
||||
import com.zhidao.support.adas.high.OnAdasListener;
|
||||
import com.zhidao.support.adas.high.common.CupidLogUtils;
|
||||
import com.zhidao.support.adas.high.common.autopilot.ability.AutopilotAbilityManager;
|
||||
import com.zhidao.support.adas.high.protocol.RawData;
|
||||
|
||||
import mogo.telematics.pad.MessagePad;
|
||||
@@ -20,6 +21,7 @@ public class CarConfigRespMessage extends MyAbstractMessageHandler {
|
||||
public void handlerMsg(RawData raw, OnAdasListener adasListener) throws InvalidProtocolBufferException {
|
||||
MessagePad.CarConfigResp carConfigResp = MessagePad.CarConfigResp.parser().parseFrom(raw.originalData.toByteArray(), raw.getOffsetValue(), raw.getPackageLengthValue() - raw.getOffsetValue());
|
||||
AdasChannel.calculateTimeConsumingOnDispatchRaw("车机基础信息应答", raw.receiveTime);
|
||||
AutopilotAbilityManager.getInstance().setCarConfig(carConfigResp);
|
||||
AdasManager.getInstance().setCarConfig(carConfigResp);
|
||||
long nowTime = 0;
|
||||
if (CupidLogUtils.isEnableLog())
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.zhidao.support.adas.high.msg;
|
||||
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import com.zhidao.support.adas.high.OnAdasListener;
|
||||
import com.zhidao.support.adas.high.common.AutopilotAbilityManager;
|
||||
import com.zhidao.support.adas.high.common.autopilot.ability.AutopilotAbilityManager;
|
||||
import com.zhidao.support.adas.high.protocol.RawData;
|
||||
|
||||
import chassis.ChassisStatesOuterClass;
|
||||
|
||||
@@ -5,7 +5,7 @@ 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.AutopilotAbilityManager;
|
||||
import com.zhidao.support.adas.high.common.autopilot.ability.AutopilotAbilityManager;
|
||||
import com.zhidao.support.adas.high.common.CupidLogUtils;
|
||||
import com.zhidao.support.adas.high.protocol.RawData;
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ 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.AutopilotAbilityManager;
|
||||
import com.zhidao.support.adas.high.common.autopilot.ability.AutopilotAbilityManager;
|
||||
import com.zhidao.support.adas.high.common.CupidLogUtils;
|
||||
import com.zhidao.support.adas.high.protocol.RawData;
|
||||
|
||||
@@ -141,7 +141,7 @@ public class VehicleStateMessage extends MyAbstractMessageHandler {
|
||||
ChassisStatesOuterClass.GearSystemStates.Builder gearSystemStates = null;
|
||||
if (vehicleState.hasGear()) {
|
||||
gearSystemStates = ChassisStatesOuterClass.GearSystemStates.newBuilder();
|
||||
//挂挡档位数据
|
||||
//档位数据
|
||||
gearSystemStates.setGearPosition(vehicleState.getGear());//鹰眼已用
|
||||
}
|
||||
if (vehicleState.hasGearSwitchInference()) {
|
||||
|
||||
Reference in New Issue
Block a user