[adas lib]能否启动自驾以及启动命令下发后成功或失败统计优化

This commit is contained in:
xinfengkun
2023-02-07 14:51:42 +08:00
parent 082bc80870
commit 7fdd6dae57
27 changed files with 802 additions and 265 deletions

View File

@@ -11,11 +11,8 @@ import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotActionsListene
import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotStatisticsListenerManager;
import com.mogo.eagle.core.utilcode.mogo.logger.Logger;
import com.mogo.och.common.module.callback.OchAdasStartFailureCallback;
import com.zhidao.support.adas.high.bean.AutopilotAbility;
import com.zhidao.support.adas.high.bean.AutopilotStatistics;
import chassis.Chassis;
import system_master.SystemStatusInfo;
/**
* Created on 2022/10/9
@@ -77,36 +74,9 @@ public class OCHAdasAbilityManager implements IMoGoAutopilotActionsListener, IMo
}
@Override
public void onAutopilotAbility(@Nullable AutopilotAbility ability) {
isAutopilotAbility = true;
autopilotAbilityReason = null;
if (ability.gear == null || ability.gear == Chassis.GearPosition.GEAR_P ||
ability.gear == Chassis.GearPosition.GEAR_R) {
isAutopilotAbility = false;
autopilotAbilityReason = "挡位不正常";
}
if (DebugConfig.getProductFlavor() == "fPadLenovoOchBus" &&
ability.gear == Chassis.GearPosition.GEAR_N){ //bus档位不正常
isAutopilotAbility = false;
autopilotAbilityReason = "挡位不正常";
}
if (isAutopilotAbility)
if (ability.brake > 0) {
isAutopilotAbility = false;
autopilotAbilityReason = "制动踏板被踩下";
}
if (isAutopilotAbility)
if (ability.statusInfo.getSysState() == SystemStatusInfo.SystemState.SYS_STARTING) {
isAutopilotAbility = false;
autopilotAbilityReason = "系统正在启动";
}
if (isAutopilotAbility)
if (ability.statusInfo.getSysState() == SystemStatusInfo.SystemState.SYS_EXITING) {
isAutopilotAbility = false;
autopilotAbilityReason = "系统正在关闭";
}
public void onAutopilotAbility(boolean isAutopilotAbility, String unableAutopilotReason) {
this.isAutopilotAbility = isAutopilotAbility;
this.autopilotAbilityReason = unableAutopilotReason;
Logger.d(TAG, "是否可以启动自动驾驶=" + isAutopilotAbility + " 原因=" + autopilotAbilityReason);
}

View File

@@ -36,7 +36,10 @@ public class ConfigAdapter extends BaseAdapter<Config, ConfigAdapter.ViewHolder>
}
viewHolder.name.setText(data.name);
viewHolder.value.setText(data.value);
if (data.color == -1) {
data.color = R.color.colorSlateGray;
}
viewHolder.value.setTextColor(mContext.getResources().getColor(data.color));
}
@Override

View File

@@ -48,6 +48,10 @@ public abstract class BaseAdapter<D, VH extends BaseViewHolder> extends Recycler
notifyDataSetChanged();
}
public List<D> getData() {
return mDatas;
}
public void setOnItemClickListener(OnItemClickListener<D> listener) {
mItemClick = listener;
}

View File

@@ -1,11 +1,26 @@
package com.zhidao.adas.client.bean;
import java.util.Objects;
public class Config {
public final String name;
public final String value;
public String value;
public int color = -1;
public Config(String name, String value) {
this.name = name;
this.value = value;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Config config = (Config) o;
return Objects.equals(name, config.name);
}
public void cover(Config config) {
this.value = config.value;
}
}

View File

@@ -88,7 +88,6 @@ import com.zhidao.support.adas.high.AdasOptions;
import com.zhidao.support.adas.high.OnAdasConnectStatusListener;
import com.zhidao.support.adas.high.OnAdasListener;
import com.zhidao.support.adas.high.OnMultiDeviceListener;
import com.zhidao.support.adas.high.bean.AutopilotAbility;
import com.zhidao.support.adas.high.bean.AutopilotStatistics;
import com.zhidao.support.adas.high.bean.VersionCompatibility;
import com.zhidao.support.adas.high.common.ByteUtil;
@@ -114,7 +113,6 @@ import java.util.Locale;
import java.util.concurrent.ScheduledExecutorService;
import bag_manager.BagManagerOuterClass;
import chassis.Chassis;
import chassis.VehicleStateOuterClass;
import io.netty.channel.Channel;
import mogo.telematics.pad.MessagePad;
@@ -171,8 +169,6 @@ public class MainActivity extends BaseActivity implements OnAdasListener, OnAdas
private ListPopupWindow listPopupWindow;
private FloatWindow floatWindow;
private View include_title;
private boolean isAutopilotAbility = true;
private String autopilotAbilityReason;
private List<SpecialVehicleBean> specialVehicleBeanList;//特种车辆
// @Override
// protected void onStart() {
@@ -822,47 +818,12 @@ public class MainActivity extends BaseActivity implements OnAdasListener, OnAdas
}
@Override
public void onAutopilotAbility(AutopilotAbility ability) {
isAutopilotAbility = true;
autopilotAbilityReason = null;
if (ability.gear == null || ability.gear == Chassis.GearPosition.GEAR_P || ability.gear == Chassis.GearPosition.GEAR_R) {
isAutopilotAbility = false;
autopilotAbilityReason = "挡位不正常";
public void onAutopilotAbility(boolean isAutopilotAbility, String unableAutopilotReason) {
if (fromFragment instanceof VersionFragment) {
VersionFragment fragment = (VersionFragment) fromFragment;
fragment.autopilotAbility(isAutopilotAbility, unableAutopilotReason);
}
if (isAutopilotAbility)
if (ability.brake > 0) {
isAutopilotAbility = false;
autopilotAbilityReason = "制动踏板被踩下";
}
if (isAutopilotAbility)
if (ability.statusInfo == null) {
isAutopilotAbility = false;
autopilotAbilityReason = "系统Topic不正常";
}
if (isAutopilotAbility)
if (ability.statusInfo.getSysState() == SystemStatusInfo.SystemState.SYS_STARTING) {
isAutopilotAbility = false;
autopilotAbilityReason = "系统正在启动";
}
if (isAutopilotAbility)
if (ability.statusInfo.getSysState() == SystemStatusInfo.SystemState.SYS_EXITING) {
isAutopilotAbility = false;
autopilotAbilityReason = "系统正在关闭";
}
if (isAutopilotAbility)
if (ability.statusInfo.getSysState() == SystemStatusInfo.SystemState.SYS_FAULT) {
isAutopilotAbility = false;
autopilotAbilityReason = "系统异常";
}
if (isAutopilotAbility)
for (SystemStatusInfo.HealthInfo healthInfo : ability.statusInfo.getHealthInfoList()) {
if (healthInfo.getState() == SystemStatusInfo.HealthState.FAULT) {
isAutopilotAbility = false;
autopilotAbilityReason = healthInfo.getName() + " 节点异常";
break;
}
}
Log.i(TAG, "是否可以启动自动驾驶=" + isAutopilotAbility + " 原因=" + autopilotAbilityReason);
Log.i(TAG, "是否可以启动自动驾驶=" + isAutopilotAbility + " 原因=" + unableAutopilotReason);
}
@Override
@@ -967,7 +928,12 @@ public class MainActivity extends BaseActivity implements OnAdasListener, OnAdas
BasicInfoReq info = new BasicInfoReq(header, basicInfoReq, sdf);
DataDistribution.getInstance().addData(info);
AdasManager.getInstance().sendBasicInfoResp("", 0, com.zhidao.support.adas.high.common.Constants.TERMINAL_ROLE.DEBUG);
showToastCenter("收到车机基础信息请求:" + info.toString());
runOnUiThread(new Runnable() {
@Override
public void run() {
showToastCenter("收到车机基础信息请求:" + info.toString());
}
});
}
@Override

View File

@@ -30,6 +30,7 @@ import com.zhidao.adas.client.adapter.InterfaceAdapter;
import com.zhidao.adas.client.base.BaseFragment;
import com.zhidao.adas.client.bean.Config;
import com.zhidao.adas.client.bean.InterfaceModel;
import com.zhidao.adas.client.utils.RandomColor;
import com.zhidao.support.adas.high.AdasManager;
import com.zhidao.support.adas.high.bean.VersionCompatibility;
import com.zhidao.support.adas.high.common.Constants;
@@ -213,10 +214,44 @@ public class VersionFragment extends BaseFragment {
}
list.add(new Config("ADAS LIB版本:", AdasManager.getInstance().getAdasVersion()));
list.add(new Config("APP构建时间:", BuildConfig.BUILD_TIME));
list.add(getAutopilotAbilityConfig(""));
adapter.setData(list);
}
private Config getAutopilotAbilityConfig(String value) {
return new Config("能否启动自动驾驶:", value);
}
public void autopilotAbility(boolean isAutopilotAbility, String unableAutopilotReason) {
List<Config> list = adapter.getData();
if (list != null) {
Config temp = getAutopilotAbilityConfig(isAutopilotAbility + ",原因:" + unableAutopilotReason);
int index = list.indexOf(temp);
if (index < 0) {
list.add(temp);
if (getActivity() != null)
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
adapter.notifyItemInserted(list.size() - 1);
}
});
} else {
Config config = list.get(index);
config.cover(temp);
config.color = RandomColor.randomColor();
if (getActivity() != null)
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
adapter.notifyItemChanged(index);
}
});
}
}
}
@Override
protected void onRefreshView() {
showVersion();

View File

@@ -0,0 +1,29 @@
package com.zhidao.adas.client.utils;
import com.zhidao.adas.client.R;
import java.util.Random;
public class RandomColor {
//随机颜色,且不与上一次重复
private static Random randomColor;
private static int tempColorIndex;
private static int[] colors = {R.color.color1, R.color.color2, R.color.color3, R.color.color4, R.color.color5};
public static int randomColor() {
randomColorTemp();
return colors[tempColorIndex];
}
private static void randomColorTemp() {
if (randomColor == null)
randomColor = new Random();
int colorInt = randomColor.nextInt(colors.length);
if (tempColorIndex == colorInt) {
randomColorTemp();
} else {
tempColorIndex = colorInt;
}
}
}

View File

@@ -17,4 +17,9 @@
<color name="connect_status_connecting">#FF00FF</color>
<color name="connect_status_disconnecting">#DAA520</color>
<color name="connect_status_search_address">#1E90FF</color>
<color name="color1">#FFC0CB</color>
<color name="color2">#FF8F00</color>
<color name="color3">#FFE500</color>
<color name="color4">#B9ED3E</color>
<color name="color5">#2EEDEB</color>
</resources>

View File

@@ -44,7 +44,6 @@ import com.zhidao.support.adas.high.AdasManager;
import com.zhidao.support.adas.high.AdasOptions;
import com.zhidao.support.adas.high.OnAdasConnectStatusListener;
import com.zhidao.support.adas.high.OnAdasListener;
import com.zhidao.support.adas.high.bean.AutopilotAbility;
import com.zhidao.support.adas.high.bean.AutopilotStatistics;
import com.zhidao.support.adas.high.bean.VersionCompatibility;
import com.zhidao.support.adas.high.common.Constants.IPC_CONNECTION_STATUS;
@@ -818,10 +817,11 @@ public class MainActivity extends BaseActivity implements OnAdasListener, OnAdas
}
@Override
public void onAutopilotAbility(AutopilotAbility ability) {
public void onAutopilotAbility(boolean isAutopilotAbility, String unableAutopilotReason) {
}
@Override
public void onStartAutopilotFailed(MogoReportMsg.MogoReportMessage message) {

View File

@@ -109,6 +109,7 @@ class MoGoAutopilotProvider :
.setIpcConnectionMode(AdasOptions.IPC_CONNECTION_MODE.FIXATION)
.setIpcFixationIP(AdasManager.getInstance().getIPCFixationIPList(mContext))
.setClient(false)
.setIdentityMode(FunctionBuildConfig.appIdentityMode)
// .setSubscribeInterfaceOptions(subscribeInterfaceOptions)//
.build()
@@ -199,6 +200,7 @@ class MoGoAutopilotProvider :
val options = AdasOptions
.Builder()
.setClient(true)
.setIdentityMode(FunctionBuildConfig.appIdentityMode)
.build()
AdasManager.getInstance()
.create(options, MoGoAdasMsgConnectStatusListenerImpl())
@@ -226,6 +228,7 @@ class MoGoAutopilotProvider :
.setIpcConnectionMode(AdasOptions.IPC_CONNECTION_MODE.FIXATION)
.setIpcFixationIP(AdasManager.getInstance().getIPCFixationIPList(mContext))
.setClient(false)// 乘客端直连工控机改为false
.setIdentityMode(FunctionBuildConfig.appIdentityMode)
.build()
AdasManager.getInstance().create(options, MoGoAdasMsgConnectStatusListenerImpl())
//////////////////////////////////注意先后顺序AdasManager.getInstance().create后才可以设置监听/////////////////////////////////////////////

View File

@@ -57,7 +57,6 @@ import com.mogo.eagle.core.function.call.obucombine.CallerObuDcCombineListenerMa
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
import com.zhidao.support.adas.high.AdasManager
import com.zhidao.support.adas.high.OnAdasListener
import com.zhidao.support.adas.high.bean.AutopilotAbility
import com.zhidao.support.adas.high.bean.AutopilotStatistics
import com.zhidao.support.adas.high.common.ProtocolStatus
import com.zhjt.service.chain.ChainLog
@@ -466,10 +465,9 @@ class MoGoAdasListenerImpl : OnAdasListener {
/**
* 是否可以启动自动驾驶
* 使用方法查看app_ipc_monitoring/uiMainActivity/onAutopilotAbility
*/
override fun onAutopilotAbility(ability: AutopilotAbility?) {
invokeAutopilotAbility(ability)
override fun onAutopilotAbility(isAutopilotAbility: Boolean, unableAutopilotReason: String?) {
invokeAutopilotAbility(isAutopilotAbility, unableAutopilotReason)
}
/**

View File

@@ -1,6 +1,5 @@
package com.mogo.eagle.core.function.api.autopilot
import com.zhidao.support.adas.high.bean.AutopilotAbility
interface IMoGoAutopilotActionsListener {
@@ -8,5 +7,5 @@ interface IMoGoAutopilotActionsListener {
/**
* pnc actions 决策 驾驶的意图
*/
fun onAutopilotAbility(ability: AutopilotAbility?)
fun onAutopilotAbility(isAutopilotAbility: Boolean, unableAutopilotReason: String?)
}

View File

@@ -1,6 +1,5 @@
package com.mogo.eagle.core.function.api.autopilot
import com.zhidao.support.adas.high.bean.AutopilotAbility
import mogo_msg.MogoReportMsg

View File

@@ -3,7 +3,6 @@ package com.mogo.eagle.core.function.call.autopilot
import androidx.annotation.Nullable
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotActionsListener
import com.mogo.eagle.core.function.call.base.CallerBase
import com.zhidao.support.adas.high.bean.AutopilotAbility
import java.util.concurrent.ConcurrentHashMap
@@ -51,10 +50,10 @@ object CallerAutopilotActionsListenerManager : CallerBase() {
}
@Synchronized
fun invokeAutopilotAbility(ability: AutopilotAbility?) {
fun invokeAutopilotAbility(isAutopilotAbility: Boolean, unableAutopilotReason: String?) {
M_AUTOPILOT_ACTIONS_LISTENER.forEach {
val listener = it.value
listener.onAutopilotAbility(ability)
listener.onAutopilotAbility(isAutopilotAbility, unableAutopilotReason)
}
}
}

View File

@@ -12,6 +12,8 @@ import static com.zhidao.support.adas.high.chain.AdasChain.CHAIN_LINK_ADAS;
import static com.zhidao.support.adas.high.chain.AdasChain.CHAIN_LINK_LOG_CONNECT_STATUS;
import static com.zhidao.support.adas.high.chain.AdasChain.CHAIN_LINK_LOG_WEB_SOCKET_AUTOPILOT;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.text.TextUtils;
@@ -79,6 +81,7 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
private RawUnpack rawUnpack;//业务数据拆包
private RawPack rawPack;//数据打包
private DispatchHandler defaultDispatchHandler;//默认分发线程分发
private DispatchHandler statusQueryRespDispatchHandler;//状态查询应答分发线程分发
private final Map<MessagePad.MessageType, DispatchHandler> dispatchHandlers = new HashMap<>();//其他分发线程
private Timer checkCompatibilityTimer;//检查版本兼容性定时器 连接成功后5秒内等待工控机发送配置信息
private int seqSpecialVehicle = 0;//特种车辆命令发送次数
@@ -181,6 +184,12 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
//启用线程分发
defaultDispatchHandler = new DispatchHandler(MessagePad.MessageType.MsgTypeDefault, this);//默认分发线程 不要添加到Map中
initOtherDispatchHandler();
AutopilotAbilityManager.getInstance().setOnAutopilotAbilityListener(new AutopilotAbilityManager.OnAutopilotAbilityListener() {
@Override
public void onStatusQuery() {
statusQueryRespDispatchHandler.start();
}
});
}
/**
@@ -231,8 +240,9 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
// dispatchHandlers.put(MessagePad.MessageType.MsgTypeWarn, new DispatchHandler(MessagePad.MessageType.MsgTypeWarn, this));
//到站提醒
// dispatchHandlers.put(MessagePad.MessageType.MsgTypeArrivalNotification, new DispatchHandler(MessagePad.MessageType.MsgTypeArrivalNotification, this));
//状态查询应答
// dispatchHandlers.put(MessagePad.MessageType.MsgTypeStatusQueryResp, new DispatchHandler(MessagePad.MessageType.MsgTypeStatusQueryResp, this));
//状态查询应答 TODO 此线程更新频率目前为3秒但是由于会在此接口中做一些其他数据处理所以单独开启线程
statusQueryRespDispatchHandler = new DispatchHandler(MessagePad.MessageType.MsgTypeStatusQueryResp, this);
dispatchHandlers.put(MessagePad.MessageType.MsgTypeStatusQueryResp, statusQueryRespDispatchHandler);
//数据采集配置
// dispatchHandlers.put(MessagePad.MessageType.MsgTypeRecordDataConfigResp, new DispatchHandler(MessagePad.MessageType.MsgTypeRecordDataConfigResp, this));
//Planning决策状态
@@ -396,6 +406,20 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
}
}
@Override
public void onHandler(MessagePad.MessageType type, Handler handler) {
if (type == MessagePad.MessageType.MsgTypeStatusQueryResp) {
AutopilotAbilityManager.getInstance().setHandler(handler);
}
}
@Override
public void onHandleMessage(MessagePad.MessageType type, Message msg) {
if (type == MessagePad.MessageType.MsgTypeStatusQueryResp) {
AutopilotAbilityManager.getInstance().onHandleMessage(msg);
}
}
/**
* 分发和解析
*

View File

@@ -1,5 +1,6 @@
package com.zhidao.support.adas.high;
import com.zhidao.support.adas.high.common.AutopilotAbilityManager;
import com.zhidao.support.adas.high.subscribe.SubscribeInterfaceOptions;
import java.util.HashSet;
@@ -124,6 +125,17 @@ public class AdasOptions {
return this;
}
/**
* 身份/车型
*
* @param identityMode 车型
* @return
*/
public Builder setIdentityMode(int identityMode) {
options.setIdentityMode(identityMode);
return this;
}
public AdasOptions build() {
return options;
}
@@ -141,6 +153,7 @@ public class AdasOptions {
options.ipcAssignIP = null;
options.ipcFixationIP = null;
options.subscribeInterfaceOptions = null;
options.setIdentityMode(0x00);
return options;
}
@@ -183,4 +196,8 @@ public class AdasOptions {
public void setSubscribeInterfaceOptions(SubscribeInterfaceOptions subscribeInterfaceOptions) {
this.subscribeInterfaceOptions = subscribeInterfaceOptions;
}
public void setIdentityMode(int identityMode) {
AutopilotAbilityManager.getInstance().setIdentityMode(identityMode);
}
}

View File

@@ -1,6 +1,5 @@
package com.zhidao.support.adas.high;
import com.zhidao.support.adas.high.bean.AutopilotAbility;
import com.zhidao.support.adas.high.bean.AutopilotStatistics;
import com.zhidao.support.adas.high.common.ProtocolStatus;
@@ -201,9 +200,10 @@ public interface OnAdasListener {
/**
* 是否有能力启动自动驾驶
*
* @param ability 是否可以启动自动驾驶
* @param isAutopilotAbility 是否能启动自动驾驶
* @param unableAutopilotReason 不能启动自动驾驶原因
*/
void onAutopilotAbility(AutopilotAbility ability);
void onAutopilotAbility(boolean isAutopilotAbility, String unableAutopilotReason);
/**
* 启动自动驾驶失败回调

View File

@@ -1,41 +0,0 @@
package com.zhidao.support.adas.high.bean;
import chassis.Chassis;
import system_master.SystemStatusInfo;
/**
* 自动驾驶能力 能否启动自动驾驶
* 未赋值表示接口通讯异常或者工控机相关节点异常 如果回调持续都是未赋值的状态表示此问题是持久性的
*/
public class AutopilotAbility {
/**
* 刹车踏板开度 0~100
* -1表示未赋值
* 值为0时表示 制动踏板未踩下
*/
public final float brake;
/**
* 挡位
* null表示未赋值
* 挡位处于P挡和R挡时不能启动自动驾驶
*/
public final Chassis.GearPosition gear;
/**
* 状态查询结果
* null表示未赋值
* 不能启动自动驾驶的判断
* statusInfo.getHealthInfoList().get().getState()== SystemStatusInfo.HealthState.FAULT
* statusInfo.getSysState()== SystemStatusInfo.SystemState.SYS_STARTING
* statusInfo.getSysState()== SystemStatusInfo.SystemState.SYS_EXITING
* statusInfo.getSysState()== SystemStatusInfo.SystemState.SYS_FAULT
*/
public final SystemStatusInfo.StatusInfo statusInfo;
public AutopilotAbility(float brake, Chassis.GearPosition gear, SystemStatusInfo.StatusInfo statusInfo) {
this.brake = brake;
this.gear = gear;
this.statusInfo = statusInfo;
}
}

View File

@@ -15,7 +15,6 @@ public class AutopilotStatistics {
* 0 成功
* 1 失败
* 2 取消
* 3 超时
* {@link com.zhidao.support.adas.high.common.Constants.AUTOPILOT_START_STATUS}
*/
@Define.AutopilotStartStatus

View File

@@ -1,37 +1,64 @@
package com.zhidao.support.adas.high.common;
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 com.zhidao.support.adas.high.bean.AutopilotAbility;
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.VehicleStateOuterClass;
import chassis.ChassisStatesOuterClass;
import system_master.SystemStatusInfo;
/**
* 是否可以启动自动驾驶能力检测
* 目前监控了底盘的一些状态和查询节点状态应答的数据
* 没有使用监控事件报告的原因是因为,部分异常没进行正常恢复通知,例如收到了异常监控数据,但是异常恢复之后没有恢复的通知
*
* <p>
* 此定时器不能停止 鹰眼中存在UI更新依赖循环查询系统状态
*/
public class AutopilotAbilityManager {
private static final String TAG = AutopilotAbilityManager.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 int identityMode;
private VehicleStateOuterClass.VehicleState vehicleState;
public interface OnAutopilotAbilityListener {
void onStatusQuery();//查询是被调用
}
public void setIdentityMode(int identityMode) {
this.identityMode = identityMode;
}
public void setOnAdasListener(OnAdasListener listener) {
this.listener = listener;
}
public void setOnAutopilotAbilityListener(OnAutopilotAbilityListener onAutopilotAbilityListener) {
this.onAutopilotAbilityListener = onAutopilotAbilityListener;
}
private AutopilotAbilityManager() {
}
@@ -47,19 +74,140 @@ public class AutopilotAbilityManager {
}
public void setStatusInfo(SystemStatusInfo.StatusInfo statusInfo) {
if (listener != null) {
float brake = -1;
Chassis.GearPosition gear = null;
if (vehicleState != null) {
brake = vehicleState.getBrake();
gear = vehicleState.getGear();
}
listener.onAutopilotAbility(new AutopilotAbility(brake, gear, statusInfo));
if (handler != null) {
if (handler.hasMessages(WHAT_TIMEOUT))
handler.removeMessages(WHAT_TIMEOUT);
}
onCallback(statusInfo);
}
public void setVehicleState(VehicleStateOuterClass.VehicleState vehicleState) {
this.vehicleState = vehicleState;
public void setChassisStates(ChassisStatesOuterClass.ChassisStates chassisStates) {
this.chassisStates = chassisStates;
}
private void onCallback(SystemStatusInfo.StatusInfo statusInfo) {
//金旅、开沃小巴乘客端 不能启动自动驾驶
if (isBus(identityMode) && isPassenger(identityMode)) {
return;
}
boolean isAutopilotAbility = true;//是否能启动自动驾驶
String unableAutopilotReason = null;//不能启动自动驾驶原因
//检测节点状态相关
if (statusInfo != null) {
int version = -1;
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();
}
}
}
if (version > 1) {
isAutopilotAbility = statusInfo.getAutoPilotReady();
if (!isAutopilotAbility) {
SystemStatusInfo.NodeFaultList nodeFaultList = statusInfo.getAutoPilotUnreadyList();
if (nodeFaultList.getSum() > 0) {
List<SystemStatusInfo.NodeInfo> list = nodeFaultList.getNodeList();
StringBuilder builder = new StringBuilder();
for (SystemStatusInfo.NodeInfo info : list) {
builder.append(info.getNodeName());
int state = info.getState();
if (state < NODE_INFO_STATE.length) {
builder.append(NODE_INFO_STATE[state]);
} else {
builder.append("未知 ");
}
}
unableAutopilotReason = builder.toString();
} else {
unableAutopilotReason = "未知";
}
}
} else {
SystemStatusInfo.SystemState systemState = statusInfo.getSysState();
if (systemState != SystemStatusInfo.SystemState.SYS_RUNNING && systemState != SystemStatusInfo.SystemState.PILOT_READY) {
isAutopilotAbility = false;
if (systemState == SystemStatusInfo.SystemState.SYS_STARTING) {
unableAutopilotReason = "系统正在启动";
} else if (systemState == SystemStatusInfo.SystemState.SYS_EXITING) {
unableAutopilotReason = "系统正在关闭";
} else if (systemState == SystemStatusInfo.SystemState.SYS_FAULT) {
unableAutopilotReason = "系统异常";
} else if (systemState == SystemStatusInfo.SystemState.AUTO_PILOT_STARTING) {
unableAutopilotReason = "正在开始自动驾驶";
} else if (systemState == SystemStatusInfo.SystemState.AUTO_PILOT_RUNNING) {
unableAutopilotReason = "自动驾驶运行中";
} else if (systemState == SystemStatusInfo.SystemState.REMOTE_PILOT_STARTING) {
unableAutopilotReason = "平行驾驶启动中";
} else if (systemState == SystemStatusInfo.SystemState.REMOTE_PILOT_RUNNING) {
unableAutopilotReason = "平行驾驶运行中";
} else {
unableAutopilotReason = "未知";
}
}
}
} else {
isAutopilotAbility = false;//是否能启动自动驾驶
unableAutopilotReason = "SSM状态查询超时无响应";//不能启动自动驾驶原因
}
//检测底盘相关
if (chassisStates != null) {
if (isAutopilotAbility) {
if (chassisStates.hasBrakeSystemStates()) {
float brake = chassisStates.getBrakeSystemStates().getBrakePedalResponsePosition();
if (brake > 0) {
isAutopilotAbility = false;
unableAutopilotReason = "制动踏板被踩下";
}
}
}
if (isAutopilotAbility) {
/**
* 档位状态判断 目前判断的车型包括 东风Taxi 红旗Taxi 金旅Bus
*/
if (chassisStates.hasGearSystemStates()) {
Chassis.GearPosition gear = chassisStates.getGearSystemStates().getGearPosition();
//金旅Bus和清扫车 档位不正常
if (isBus(identityMode)) {
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 (listener != null) {
listener.onAutopilotAbility(isAutopilotAbility, unableAutopilotReason);
}
}
public synchronized void start() {
@@ -68,7 +216,15 @@ public class AutopilotAbilityManager {
timer.schedule(new TimerTask() {
@Override
public void run() {
if (onAutopilotAbilityListener != null) {
onAutopilotAbilityListener.onStatusQuery();
}
AdasManager.getInstance().sendStatusQueryReq();
if (handler != null) {
if (handler.hasMessages(WHAT_TIMEOUT))
handler.removeMessages(WHAT_TIMEOUT);
handler.sendEmptyMessageDelayed(WHAT_TIMEOUT, DEFAULT_TIMEOUT);
}
}
}, 2000L, DEFAULT_DETECTION_TIME);//延迟执行,避免刚连接成功后底盘信息无法及时同步
}
@@ -79,8 +235,35 @@ public class AutopilotAbilityManager {
timer.cancel();
timer = null;
}
this.vehicleState = 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);
}
}
private boolean isDriver(int appIdentityMode) {
return (appIdentityMode & 0x01) != 0x01;
}
private boolean isPassenger(int appIdentityMode) {
return (appIdentityMode & 0x01) == 0x01;
}
private boolean isBus(int appIdentityMode) {
return (appIdentityMode & 0xA0) == 0xA0;
}
private boolean isTaxi(int appIdentityMode) {
return (appIdentityMode & 0xA0) != 0xA0;
}
}

View File

@@ -16,13 +16,6 @@ import mogo_msg.MogoReportMsg;
* 自动驾驶状态检查/统计
*/
public class AutopilotReview {
/**
* 默认启动自驾超时时间
*/
private static final long DEFAULT_TIMEOUT = 15 * 1000L;
private Timer timer;
/**
* 下发的启动自动驾驶命令
*/
@@ -45,7 +38,6 @@ public class AutopilotReview {
}
private void onCallback(@Define.AutopilotStartStatus int status) {
stopTimer();
long usedTime = SystemClock.elapsedRealtime() - startTime;
if (listener != null) {
listener.onReview(new AutopilotStatistics(status, usedTime, startReq, failedMessage));
@@ -55,27 +47,6 @@ public class AutopilotReview {
failedMessage = null;
}
private void startTimer() {
if (timer == null) {
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
//超时
onCallback(Constants.AUTOPILOT_START_STATUS.TIMEOUT);
}
}, DEFAULT_TIMEOUT);
}
}
private void stopTimer() {
if (timer != null) {
timer.cancel();
timer = null;
}
}
/**
* 自动驾命令
*
@@ -86,7 +57,6 @@ public class AutopilotReview {
//启动自动驾驶
startReq = req;
startTime = SystemClock.elapsedRealtime();
startTimer();
} else {
onCallback(Constants.AUTOPILOT_START_STATUS.CANCEL);
}

View File

@@ -126,10 +126,6 @@ public class Constants {
* 取消
*/
int CANCEL = 2;
/**
* 超时
*/
int TIMEOUT = 3;
}
}

View File

@@ -49,8 +49,7 @@ public final class Define {
@IntDef(flag = true, value = {Constants.AUTOPILOT_START_STATUS.SUCCESSFUL,
Constants.AUTOPILOT_START_STATUS.FAILED,
Constants.AUTOPILOT_START_STATUS.CANCEL,
Constants.AUTOPILOT_START_STATUS.TIMEOUT})
Constants.AUTOPILOT_START_STATUS.CANCEL})
@Retention(RetentionPolicy.SOURCE)
public @interface AutopilotStartStatus {
}

View File

@@ -2,7 +2,7 @@ package com.zhidao.support.adas.high.common;
/**
* 监控事件报告中定义的事件以及解释
* 根据MAP2.10.0消息定义编写
* 根据MAP2.11.0消息定义编写
*/
public class MogoReport {
public static final String RESULT_AUTOPILOT_SYSTEM_UNSTARTED = "RESULT_AUTOPILOT_SYSTEM_UNSTARTED";
@@ -12,33 +12,15 @@ public class MogoReport {
public static final String RESULT_REMOTEPILOT_INFERIOR = "RESULT_REMOTEPILOT_INFERIOR";
public static final String RESULT_SHOW_WARNING = "RESULT_SHOW_WARNING";
// private static final String RESULT_DISCONNECTED_WITH_PAD = "RESULT_DISCONNECTED_WITH_PAD";
// private static final String RESULT_PAD_CANNOT_CONNECT_TELEMATICS = "RESULT_PAD_CANNOT_CONNECT_TELEMATICS";
// private static final String RESULT_PAD_INFO_LOST = "RESULT_PAD_INFO_LOST";
// private static final String RESULT_PAD_CANNOT_GET_AUTOPILOT_STATUS = "RESULT_PAD_CANNOT_GET_AUTOPILOT_STATUS";
// private static final String RESULT_PAD_CANNOT_GET_GNS_CHASSIS_STATUS = "RESULT_PAD_CANNOT_GET_GNS_CHASSIS_STATUS";
// private static final String RESULT_PAD_CANNOT_GET_OBSTACLE_INFO = "RESULT_PAD_CANNOT_GET_OBSTACLE_INFO";
// private static final String RESULT_NO_CONNECTION_TO_AICLOUD = "RESULT_NO_CONNECTION_TO_AICLOUD";
// private static final String RESULT_AICLOUD_INFO_LOST = "RESULT_AICLOUD_INFO_LOST";
// private static final String RESULT_CANNOT_CHANGE_LIGHT = "RESULT_CANNOT_CHANGE_LIGHT";
public enum Result {
AUTOPILOT_SYSTEM_UNSTARTED(RESULT_AUTOPILOT_SYSTEM_UNSTARTED, "自动驾驶系统启动过程中出错pad可能无法连接云端监控可能无法上报"),
AUTOPILOT_DISABLE(RESULT_AUTOPILOT_DISABLE, "无法启动自动驾驶"),
AUTOPILOT_INFERIOR(RESULT_AUTOPILOT_INFERIOR, "自动驾驶部分功能受影响,演示模式可以考虑强行启动,联系人员排查问题。\n例如定位偏移camera无数据算法严重丢帧属于自动驾驶可以启动但是效果受影响。"),
AUTOPILOT_INFERIOR(RESULT_AUTOPILOT_INFERIOR, "自动驾驶部分功能受严重影响,演示模式可以考虑强行启动,非演示模式下建议停止自动驾驶,联系人员排查问题。\n例如定位偏移camera无数据算法非常严重丢帧,属于自动驾驶可以启动,但是效果受影响。"),
REMOTEPILOT_DISABLE(RESULT_REMOTEPILOT_DISABLE, "无法启动远程驾驶"),
REMOTEPILOT_INFERIOR(RESULT_REMOTEPILOT_INFERIOR, "远程驾驶部分功能受影响。例如网络高延迟"),
SHOW_WARNING(RESULT_SHOW_WARNING, "一般为过渡状态存在不确定因素有可能对自动驾驶有微弱影响需要在pad端显示为黄色告警。\n如果偶尔上报该result可忽略如果频繁上报需联系人员进行排查。 目前仅有RTK无法确认状态事件。");
// DISCONNECTED_WITH_PAD(RESULT_DISCONNECTED_WITH_PAD, "未检测到来自pad的链接如果只报了这个result可以通过后台/远程驾驶启动自动驾驶"),
// PAD_CANNOT_CONNECT_TELEMATICS(RESULT_PAD_INFO_LOST, "Pad无法连接到工控机"),
// PAD_INFO_LOST(RESULT_PAD_CANNOT_CONNECT_TELEMATICS, "Pad工控机之间指令信息丢失"),
// PAD_CANNOT_GET_AUTOPILOT_STATUS(RESULT_PAD_CANNOT_GET_AUTOPILOT_STATUS, "Pad端无法拿到自动驾驶状态信息"),
// PAD_CANNOT_GET_GNS_CHASSIS_STATUS(RESULT_PAD_CANNOT_GET_GNS_CHASSIS_STATUS, "Pad端无法拿到自车状态和底盘状态信息"),
// PAD_CANNOT_GET_OBSTACLE_INFO(RESULT_PAD_CANNOT_GET_OBSTACLE_INFO, "Pad端无法拿到障碍物信息"),
// NO_CONNECTION_TO_AICLOUD(RESULT_NO_CONNECTION_TO_AICLOUD, "无法和云端通信"),
// AICLOUD_INFO_LOST(RESULT_AICLOUD_INFO_LOST, "云端工控机之间信息丢失"),
// CANNOT_CHANGE_LIGHT(RESULT_CANNOT_CHANGE_LIGHT, "变灯失败");
/**
* 消息result code
@@ -69,25 +51,6 @@ public class MogoReport {
return REMOTEPILOT_INFERIOR.desc;
case RESULT_SHOW_WARNING:
return SHOW_WARNING.desc;
// case RESULT_DISCONNECTED_WITH_PAD:
// return DISCONNECTED_WITH_PAD.desc;
// case RESULT_PAD_CANNOT_CONNECT_TELEMATICS:
// return PAD_CANNOT_CONNECT_TELEMATICS.desc;
// case RESULT_PAD_INFO_LOST:
// return PAD_INFO_LOST.desc;
// case RESULT_PAD_CANNOT_GET_AUTOPILOT_STATUS:
// return PAD_CANNOT_GET_AUTOPILOT_STATUS.desc;
// case RESULT_PAD_CANNOT_GET_GNS_CHASSIS_STATUS:
// return PAD_CANNOT_GET_GNS_CHASSIS_STATUS.desc;
// case RESULT_PAD_CANNOT_GET_OBSTACLE_INFO:
// return PAD_CANNOT_GET_OBSTACLE_INFO.desc;
// case RESULT_NO_CONNECTION_TO_AICLOUD:
// return NO_CONNECTION_TO_AICLOUD.desc;
// case RESULT_AICLOUD_INFO_LOST:
// return AICLOUD_INFO_LOST.desc;
// case RESULT_CANNOT_CHANGE_LIGHT:
// return CANNOT_CHANGE_LIGHT.desc;
default:
return resultCode;
@@ -104,6 +67,7 @@ public class MogoReport {
public static final String ACTION_CHECK_GEAR = "ACTION_CHECK_GEAR";
public static final String ACTION_CHECK_NETWORK = "ACTION_CHECK_NETWORK";
public static final String ACTION_TRY_AGAIN_LATER = "ACTION_TRY_AGAIN_LATER";
public static final String ACTION_REMOTEPILOT_REQUEST = "ACTION_REMOTEPILOT_REQUEST";
public enum Action {
@@ -114,7 +78,8 @@ public class MogoReport {
REBOOT_VEHICLE(ACTION_REBOOT_VEHICLE, "重启车辆"),
CHECK_GEAR(ACTION_CHECK_GEAR, "检查车辆档位等影响自动驾驶的因素"),
CHECK_NETWORK(ACTION_CHECK_NETWORK, "检查网络连接和路由器等影响通信的因素"),
TRY_AGAIN_LATER(ACTION_TRY_AGAIN_LATER, "请稍后重试");
TRY_AGAIN_LATER(ACTION_TRY_AGAIN_LATER, "请稍后重试"),
REMOTEPILOT_REQUEST(ACTION_REMOTEPILOT_REQUEST, "请求远程驾驶");
/**
* 消息Action code
@@ -303,6 +268,20 @@ public class MogoReport {
String TASK_CONFIG_EMPTY = "ERECORD_TASK_CONFIG_EMPTY";//配置为空
String TASK_QUEUE_EMPTY = "ERECORD_TASK_QUEUE_EMPTY";//数据队列为空
}
/**
* 平行驾驶相关异常
*/
interface EPARALLEL {
String AICLOUD_CONNECTION_ERROR = "EPARALLEL_AICLOUD_CONNECTION_ERROR";//平行驾驶长连接异常
}
/**
* 车辆处于困境,等待平行驾驶接管
*/
interface EVEHICLE {
String IN_TROUBLE = "EVEHICLE_IN_TROUBLE";//planning 检测到车处于困境,把困境状态汇报给 SSMssm 发出该事件,等待驾舱端开始平行驾驶
}
}
/**
@@ -344,9 +323,10 @@ public class MogoReport {
}
/**
* 系统状态 常规信息
* 系统状态
*/
interface ISYS {
/*******常规信息*******/
String STARTING = "ISYS_STARTING";//系统启动中
String RUNNING = "ISYS_RUNNING";//所有Xavier启动完成
String EXITING = "ISYS_EXITING";//系统退出中
@@ -362,19 +342,14 @@ public class MogoReport {
String SYSTEM_IN_IDLE = "ISYS_SYSTEM_IN_IDLE";//系统进入空闲状态
String SYSTEM_OUT_IDLE = "ISYS_SYSTEM_OUT_IDLE";//系统退出空闲状态
String FUNC_YY_START = "ISYS_FUNC_YY_START";//产品状态检查开始
String FUNC_YY_FINISH = "ISYS_FUNC_YY_FINISH";//产品状态达成第一次ready
String FUNC_YY_TIMEOUT = "ISYS_FUNC_YY_TIMEOUT";//产品状态检查超时
String FUNC_YY_ABORT = "ISYS_FUNC_YY_ABORT";//产品状态检查中止
String FUNC_YY_UNREADY = "ISYS_FUNC_YY_UNREADY";//产品状态未就绪
String FUNC_YY_READY = "ISYS_FUNC_YY_READY";//产品状态就绪
/*******轨迹下载相关*******/
String INIT_TRAJECTORY_START = "ISYS_INIT_TRAJECTORY_START";//轨迹管理_轨迹开始下载
String INIT_TRAJECTORY_SUCCESS = "ISYS_INIT_TRAJECTORY_SUCCESS";//轨迹管理_轨迹下载成功
String INIT_TRAJECTORY_FAILURE = "ISYS_INIT_TRAJECTORY_FAILURE";//轨迹管理_轨迹下载失败本地无对应轨迹
String INIT_TRAJECTORY_WARNING = "ISYS_INIT_TRAJECTORY_WARNING";//轨迹管理_轨迹下载失败本地有对应轨迹认为成功
String INIT_TRAJECTORY_TIMEOUT = "ISYS_INIT_TRAJECTORY_TIMEOUT";//轨迹管理_轨迹下载超时
/*******配置更新相关*******/
String CONFIG_UPDATE_HADMAP = "ISYS_CONFIG_UPDATE_HADMAP";//需要重启升级高精地图
String CONFIG_UPDATE_AI_MODEL = "ISYS_CONFIG_UPDATE_AI_MODEL";//需要重启升级AI模型
String CONFIG_UPDATE_SLAM_MAP = "ISYS_CONFIG_UPDATE_SLAM_MAP";//需要重启升级SLAM地图
@@ -390,13 +365,65 @@ public class MogoReport {
interface ISSM {
String INIT = "ISSM_INIT";//SSM系统上电初始化
String RESTARTED = "ISSM_RESTARTED";//SSM系统发生重启
String MODE_XX_START = "ISSM_MODE_XX_START";//SSM变更模式开始
String MODE_XX_FINISH = "ISSM_MODE_XX_FINISH";//SSM变更模式完成第一次ready
String MODE_XX_ABORT = "ISSM_MODE_XX_ABORT";//SSM变更模式中止
String MODE_XX_TIMEOUT = "ISSM_MODE_XX_TIMEOUT";//SSM变更模式超时
String MODE_XX_READY = "ISSM_MODE_XX_READY";//SSM模式就绪
String MODE_XX_UNREADY = "ISSM_MODE_XX_UNREADY";//SSM未就绪
// String MODE_XX_START = "ISSM_MODE_XX_START";//SSM变更模式开始
// String MODE_XX_FINISH = "ISSM_MODE_XX_FINISH";//SSM变更模式完成第一次ready
// String MODE_XX_ABORT = "ISSM_MODE_XX_ABORT";//SSM变更模式中止
// String MODE_XX_TIMEOUT = "ISSM_MODE_XX_TIMEOUT";//SSM变更模式超时
// String MODE_XX_READY = "ISSM_MODE_XX_READY";//SSM模式就绪
// String MODE_XX_UNREADY = "ISSM_MODE_XX_UNREADY";//SSM未就绪
//以上6组被注释掉的字段 中的MODE_XX分别替换成MODE_RUN、MODE_IDLE、MODE_STOP
String MODE_RUN_START = "ISSM_MODE_RUN_START";//SSM变更模式开始
String MODE_RUN_FINISH = "ISSM_MODE_RUN_FINISH";//SSM变更模式完成第一次ready
String MODE_RUN_ABORT = "ISSM_MODE_RUN_ABORT";//SSM变更模式中止
String MODE_RUN_TIMEOUT = "ISSM_MODE_RUN_TIMEOUT";//SSM变更模式超时
String MODE_RUN_READY = "ISSM_MODE_RUN_READY";//SSM模式就绪
String MODE_RUN_UNREADY = "ISSM_MODE_RUN_UNREADY";//SSM未就绪
String MODE_IDLE_START = "ISSM_MODE_IDLE_START";//SSM变更模式开始
String MODE_IDLE_FINISH = "ISSM_MODE_IDLE_FINISH";//SSM变更模式完成第一次ready
String MODE_IDLE_ABORT = "ISSM_MODE_IDLE_ABORT";//SSM变更模式中止
String MODE_IDLE_TIMEOUT = "ISSM_MODE_IDLE_TIMEOUT";//SSM变更模式超时
String MODE_IDLE_READY = "ISSM_MODE_IDLE_READY";//SSM模式就绪
String MODE_IDLE_UNREADY = "ISSM_MODE_IDLE_UNREADY";//SSM未就绪
String MODE_STOP_START = "ISSM_MODE_STOP_START";//SSM变更模式开始
String MODE_STOP_FINISH = "ISSM_MODE_STOP_FINISH";//SSM变更模式完成第一次ready
String MODE_STOP_ABORT = "ISSM_MODE_STOP_ABORT";//SSM变更模式中止
String MODE_STOP_TIMEOUT = "ISSM_MODE_STOP_TIMEOUT";//SSM变更模式超时
String MODE_STOP_READY = "ISSM_MODE_STOP_READY";//SSM模式就绪
String MODE_STOP_UNREADY = "ISSM_MODE_STOP_UNREADY";//SSM未就绪
// String FUNC_YY_START = "ISSM_FUNC_YY_START";//产品状态检查开始
// String FUNC_YY_FINISH = "ISSM_FUNC_YY_FINISH";//产品状态达成第一次ready
// String FUNC_YY_TIMEOUT = "ISSM_FUNC_YY_TIMEOUT";//产品状态检查超时
// String FUNC_YY_ABORT = "ISSM_FUNC_YY_ABORT";//产品状态检查中止
// String FUNC_YY_UNREADY = "ISSM_FUNC_YY_UNREADY";//产品状态未就绪
// String FUNC_YY_READY = "ISSM_FUNC_YY_READY";//产品状态就绪
//以上6组被注释掉的字段 中的FUNC_YY分别替换成FUNC_COLD_START、FUNC_AUTO_PILOT、FUNC_REMOTE_PILOT
String FUNC_COLD_START_START = "ISSM_FUNC_COLD_START_START";//产品状态检查开始
String FUNC_COLD_START_FINISH = "ISSM_FUNC_COLD_START_FINISH";//产品状态达成第一次ready
String FUNC_COLD_START_TIMEOUT = "ISSM_FUNC_COLD_START_TIMEOUT";//产品状态检查超时
String FUNC_COLD_START_ABORT = "ISSM_FUNC_COLD_START_ABORT";//产品状态检查中止
String FUNC_COLD_START_UNREADY = "ISSM_FUNC_COLD_START_UNREADY";//产品状态未就绪
String FUNC_COLD_START_READY = "ISSM_FUNC_COLD_START_READY";//产品状态就绪
String FUNC_AUTO_PILOT_START = "ISSM_FUNC_AUTO_PILOT_START";//产品状态检查开始
String FUNC_AUTO_PILOT_FINISH = "ISSM_FUNC_AUTO_PILOT_FINISH";//产品状态达成第一次ready
String FUNC_AUTO_PILOT_TIMEOUT = "ISSM_FUNC_AUTO_PILOT_TIMEOUT";//产品状态检查超时
String FUNC_AUTO_PILOT_ABORT = "ISSM_FUNC_AUTO_PILOT_ABORT";//产品状态检查中止
String FUNC_AUTO_PILOT_UNREADY = "ISSM_FUNC_AUTO_PILOT_UNREADY";//产品状态未就绪
String FUNC_AUTO_PILOT_READY = "ISSM_FUNC_AUTO_PILOT_READY";//产品状态就绪
String FUNC_REMOTE_PILOT_START = "ISSM_FUNC_REMOTE_PILOT_START";//产品状态检查开始
String FUNC_REMOTE_PILOT_FINISH = "ISSM_FUNC_REMOTE_PILOT_FINISH";//产品状态达成第一次ready
String FUNC_REMOTE_PILOT_TIMEOUT = "ISSM_FUNC_REMOTE_PILOT_TIMEOUT";//产品状态检查超时
String FUNC_REMOTE_PILOT_ABORT = "ISSM_FUNC_REMOTE_PILOT_ABORT";//产品状态检查中止
String FUNC_REMOTE_PILOT_UNREADY = "ISSM_FUNC_REMOTE_PILOT_UNREADY";//产品状态未就绪
String FUNC_REMOTE_PILOT_READY = "ISSM_FUNC_REMOTE_PILOT_READY";//产品状态就绪
}
interface IAGENT {
@@ -427,6 +454,20 @@ public class MogoReport {
String TASK_AUTO = "IRECORDER_TASK_AUTO";//自动录包任务创建
String TASK_CMD = "IRECORDER_TASK_CMD";//指令录包任务创建
}
/**
* 平行驾驶相关
*/
interface IPARALLEL {
String AICLOUD_CONNECTION_OK = "IPARALLEL_AICLOUD_CONNECTION_OK";//长连接连接恢复后, 5s 内如果长连状态一直 ok 的话,会触发该事件 建议鹰眼展示该事件
}
/**
* 车辆处于困境相关
*/
interface IVEHICLE {
String NOT_IN_TROUBLE = "IVEHICLE_NOT_IN_TROUBLE";//车辆脱离困境,恢复正常,可继续开始自动驾驶了 触发频率:处于困境中,触发一次; 脱困后,触发一次 云端驾舱会接入该事件 建议鹰眼也接入,展示困境状态/脱困状态
}
}
}
}

View File

@@ -10,7 +10,8 @@ import com.zhidao.support.adas.high.common.CupidLogUtils;
import com.zhidao.support.adas.high.common.MogoReport;
import com.zhidao.support.adas.high.protocol.RawData;
import java.util.List;
import java.util.HashSet;
import java.util.Set;
import mogo_msg.MogoReportMsg;
@@ -19,9 +20,28 @@ import mogo_msg.MogoReportMsg;
*/
public class ReportMessage extends MyAbstractMessageHandler {
private final AutopilotReview autopilotReview;
private final Set<String> startAutopilotFailCode = new HashSet<String>();//启动自驾失败Code
public ReportMessage(AutopilotReview autopilotReview) {
this.autopilotReview = autopilotReview;
initStartAutopilotFailCode();
}
private void initStartAutopilotFailCode() {
//ssm_master的失败事件
startAutopilotFailCode.add(MogoReport.Code.Error.ESYS.AUTOPILOT_FAILED);//在尝试启动自动驾驶,但是超过指定时间后底盘未进入,会发送此事件
startAutopilotFailCode.add(MogoReport.Code.Error.ESYS.ROUTING_REQ_TIMEOUT);//算路请求响应超时或轨迹加载超时
startAutopilotFailCode.add(MogoReport.Code.Error.ESYS.PLANNING_CHANGE_FAILIED);//planning切换失败仅df hq有此事件
startAutopilotFailCode.add(MogoReport.Code.Error.ESYS.CHECK_TRAJECTORY_FAILURE);//轨迹下载检查不可用
//controller的失败事件 EMAP_ENTRY_AUTOPILOT_XXX 底盘启动失败
startAutopilotFailCode.add(MogoReport.Code.Error.EMAP.ENTRY_AUTOPILOT_FOR_CANADAPTER_TIMEOUT);//can_adapter消息超时未进入自驾
startAutopilotFailCode.add(MogoReport.Code.Error.EMAP.ENTRY_AUTOPILOT_FOR_PLANNING_TIMEOUT);//PLANNING消息超时未进自驾
startAutopilotFailCode.add(MogoReport.Code.Error.EMAP.ENTRY_AUTOPILOT_FOR_LOCATION_TIMEOUT);//定位消息超时未进自驾
startAutopilotFailCode.add(MogoReport.Code.Error.EMAP.ENTRY_AUTOPILOT_FOR_BRAKE);//制动踏板干预未进自驾
startAutopilotFailCode.add(MogoReport.Code.Error.EMAP.ENTRY_AUTOPILOT_FOR_ACCEL);//加速踏板干预未进自驾
startAutopilotFailCode.add(MogoReport.Code.Error.EMAP.ENTRY_AUTOPILOT_FOR_STEER);//方向盘干预未进自驾
startAutopilotFailCode.add(MogoReport.Code.Error.EMAP.ENTRY_AUTOPILOT_FOR_GEAR_SWITCH);//档位切换干预未进自驾
startAutopilotFailCode.add(MogoReport.Code.Error.EMAP.ENTRY_AUTOPILOT_FOR_OTHER_CTL);//其他干预未进自驾,请检查仪表盘和开关项(如双闪,制动灯灯等 可在msg中补充原因信息
}
@Override
@@ -36,8 +56,8 @@ public class ReportMessage extends MyAbstractMessageHandler {
}
AdasChannel.calculateTimeConsumingBusiness("监控事件报告", nowTime);
//分发自动驾驶启动失败相关回调
List<String> results = mogoReportMessage.getResultList();
if (!results.isEmpty() && results.contains(MogoReport.RESULT_AUTOPILOT_DISABLE)) {
String code = mogoReportMessage.getCode();
if (startAutopilotFailCode.contains(code)) {
if (adasListener != null) {
adasListener.onStartAutopilotFailed(mogoReportMessage);//启动自动驾驶失败回调
}

View File

@@ -9,7 +9,10 @@ import com.zhidao.support.adas.high.common.AutopilotAbilityManager;
import com.zhidao.support.adas.high.common.CupidLogUtils;
import com.zhidao.support.adas.high.protocol.RawData;
import chassis.Chassis;
import chassis.ChassisStatesOuterClass;
import chassis.VehicleStateOuterClass;
import common.HeaderOuterClass;
/**
* 底盘信息, 透传底盘状态pb参考底盘
@@ -20,7 +23,7 @@ public class VehicleStateMessage extends MyAbstractMessageHandler {
public void handlerMsg(RawData raw, OnAdasListener adasListener) throws InvalidProtocolBufferException {
VehicleStateOuterClass.VehicleState vehicleState = VehicleStateOuterClass.VehicleState.parser().parseFrom(raw.originalData.toByteArray(), raw.getOffsetValue(), raw.getPackageLengthValue() - raw.getOffsetValue());
AdasChannel.calculateTimeConsumingOnDispatchRaw("底盘信息", raw.receiveTime);
AutopilotAbilityManager.getInstance().setVehicleState(vehicleState);
compatibility(vehicleState);
long nowTime = 0;
if (CupidLogUtils.isEnableLog())
nowTime = SystemClock.elapsedRealtime();
@@ -30,4 +33,291 @@ public class VehicleStateMessage extends MyAbstractMessageHandler {
AdasChannel.calculateTimeConsumingBusiness("底盘信息", nowTime);
// CupidLogUtils.e("底盘信息--->" + vehicleState.toString());
}
/**
* 将老地盘数据转换成新地盘数据
* 字段注释中 鹰眼已用 的 已和底盘相关开发 确认过,其他字段均为确认对应关系
* 新底盘中未找到字段:
* parking_brake longitude_driving_mode eps_steering_mode
* steering_sign location_missing trajectory_missing
* chassis_status_missing pilot_mode_condition_met vehicletakeoverstatus
* fuel_value robo_taxi_state robo_bus_state
* robo_bus_jinlv_m1_state
*/
private ChassisStatesOuterClass.ChassisStates compatibility(VehicleStateOuterClass.VehicleState vehicleState) throws InvalidProtocolBufferException {
/**************老地盘转换成新地盘PB***************/
ChassisStatesOuterClass.ChassisStates.Builder builder = ChassisStatesOuterClass.ChassisStates.newBuilder();
//工控机所用Header
if (vehicleState.hasHeader()) {
builder.setHeader(HeaderOuterClass.Header.parseFrom(vehicleState.getHeader().toByteArray()));
}
setBCMSystemStates(builder, vehicleState);
setSteerSystemStates(builder, vehicleState);
setGearSystemStates(builder, vehicleState);
setVehicleMotionStates(builder, vehicleState);
setDrivingSystemStates(builder, vehicleState);
setBrakeSystemStates(builder, vehicleState);
setChassisAutopilotAssistanceInformation(builder, vehicleState);
//电子驻车制动系统
if (vehicleState.hasEpb()) {
Chassis.EPBWorkStatus old = vehicleState.getEpb();
ChassisStatesOuterClass.EPBWorkStates epb = null;
if (old == Chassis.EPBWorkStatus.EPBSTATUS_NONE) {
epb = ChassisStatesOuterClass.EPBWorkStates.EPB_STATE_NONE;
} else if (old == Chassis.EPBWorkStatus.EPBSTATUS_LOCKED) {
epb = ChassisStatesOuterClass.EPBWorkStates.EPB_STATE_LOCKED;
} else if (old == Chassis.EPBWorkStatus.EPBSTATUS_RELEASED) {
epb = ChassisStatesOuterClass.EPBWorkStates.EPB_STATE_RELEASED;
} else if (old == Chassis.EPBWorkStatus.EPBSTATUS_LOCKED_FAIL) {
epb = ChassisStatesOuterClass.EPBWorkStates.EPB_STATE_LOCKED_FAIL;
} else if (old == Chassis.EPBWorkStatus.EPBSTATUS_RELEASE_FAIL) {
epb = ChassisStatesOuterClass.EPBWorkStates.EPB_STATE_RELEASE_FAIL;
} else if (old == Chassis.EPBWorkStatus.EPBSTATUS_FAULT) {
epb = ChassisStatesOuterClass.EPBWorkStates.EPB_STATE_FAULT;
}
if (epb != null) {
builder.setEpbSystemStates(ChassisStatesOuterClass.EPBSystemStates.newBuilder()
.setEpbWorkState(epb));
}
}
// 整车故障状态
if (vehicleState.hasVehiclefaultlevel()) {
Chassis.VehicleFaultLevel vehicleFaultLevel = vehicleState.getVehiclefaultlevel();
ChassisStatesOuterClass.VehicleFaultLevels vehicleFaultLevels = null;
if (vehicleFaultLevel == Chassis.VehicleFaultLevel.None_Fault) {
vehicleFaultLevels = ChassisStatesOuterClass.VehicleFaultLevels.NONE_FAULT;
} else if (vehicleFaultLevel == Chassis.VehicleFaultLevel.General_Fault) {
vehicleFaultLevels = ChassisStatesOuterClass.VehicleFaultLevels.GENERAL_FAULT;
} else if (vehicleFaultLevel == Chassis.VehicleFaultLevel.Serious_Fault) {
vehicleFaultLevels = ChassisStatesOuterClass.VehicleFaultLevels.SERIOUS_FAULT;
} else if (vehicleFaultLevel == Chassis.VehicleFaultLevel.Critical_Fault) {
vehicleFaultLevels = ChassisStatesOuterClass.VehicleFaultLevels.CRITICAL_FAULT;
}
if (vehicleFaultLevels != null) {
builder.setVehicleChassisFaultInformation(ChassisStatesOuterClass.VehicleChassisFaultInformation.newBuilder()
.setVehiclefaultlevel(vehicleFaultLevels));
}
}
//电量
if (vehicleState.hasBmsSoc()) {
builder.setBmsSystemStates(ChassisStatesOuterClass.BMSSystemStates.newBuilder().setBmsSoc(vehicleState.getBmsSoc()));
}
//清扫车(福田)清扫控制系统状态
if (vehicleState.hasSweeperFutianCleanSystemState()) {
byte[] bytes = vehicleState.getSweeperFutianCleanSystemState().toByteArray();
builder.setTaskSystemStates(ChassisStatesOuterClass.TaskSystemStates.newBuilder()
.setSweeperFutianTaskSystemStates(ChassisStatesOuterClass.SweeperFuTianTaskSystemStates.parseFrom(bytes)));//鹰眼已用 清扫车专用
}
ChassisStatesOuterClass.ChassisStates chassisStates = builder.build();
AutopilotAbilityManager.getInstance().setChassisStates(chassisStates);
return chassisStates;
}
private void setChassisAutopilotAssistanceInformation(ChassisStatesOuterClass.ChassisStates.Builder builder, VehicleStateOuterClass.VehicleState vehicleState) {
ChassisStatesOuterClass.ChassisAutopilotAssistanceInformation.Builder chassisAutopilotAssistanceInformation = null;
if (vehicleState.hasPilotMode()) {
chassisAutopilotAssistanceInformation = ChassisStatesOuterClass.ChassisAutopilotAssistanceInformation.newBuilder();
chassisAutopilotAssistanceInformation.setChassisPilotModeState(vehicleState.getPilotMode());
}
if (vehicleState.hasEmergencyStopSwitch()) {
if (chassisAutopilotAssistanceInformation == null) {
chassisAutopilotAssistanceInformation = ChassisStatesOuterClass.ChassisAutopilotAssistanceInformation.newBuilder();
}
// 急停开关状态
chassisAutopilotAssistanceInformation.setEmergencyStopSwitchState(vehicleState.getEmergencyStopSwitch());
}
if (chassisAutopilotAssistanceInformation != null) {
builder.setChassisAutopilotAssistanceInformation(chassisAutopilotAssistanceInformation);
}
}
/**
* 档位
*/
private void setGearSystemStates(ChassisStatesOuterClass.ChassisStates.Builder builder, VehicleStateOuterClass.VehicleState vehicleState) {
ChassisStatesOuterClass.GearSystemStates.Builder gearSystemStates = null;
if (vehicleState.hasGear()) {
gearSystemStates = ChassisStatesOuterClass.GearSystemStates.newBuilder();
//挂挡档位数据
gearSystemStates.setGearPosition(vehicleState.getGear());//鹰眼已用
}
if (vehicleState.hasGearSwitchInference()) {
if (gearSystemStates == null) {
gearSystemStates = ChassisStatesOuterClass.GearSystemStates.newBuilder();
}
//档位干预
gearSystemStates.setGearSwitchInferenceState(vehicleState.getGearSwitchInference());
}
if (gearSystemStates != null) {
builder.setGearSystemStates(gearSystemStates);
}
}
/**
* 油门
*/
private void setDrivingSystemStates(ChassisStatesOuterClass.ChassisStates.Builder builder, VehicleStateOuterClass.VehicleState vehicleState) {
ChassisStatesOuterClass.DrivingSystemStates.Builder drivingSystemStates = null;
if (vehicleState.hasThrottle()) {
drivingSystemStates = ChassisStatesOuterClass.DrivingSystemStates.newBuilder();
//油门
drivingSystemStates.setThrottleResponsePosition(vehicleState.getThrottle());//鹰眼已用
}
if (vehicleState.hasAccelInference()) {
if (drivingSystemStates == null) {
drivingSystemStates = ChassisStatesOuterClass.DrivingSystemStates.newBuilder();
}
//加速踏板干预
drivingSystemStates.setAccelerationPedalInferenceState(vehicleState.getAccelInference());
}
if (drivingSystemStates != null) {
builder.setDrivingSystemStates(drivingSystemStates);
}
}
/**
* 刹车
*/
private void setBrakeSystemStates(ChassisStatesOuterClass.ChassisStates.Builder builder, VehicleStateOuterClass.VehicleState vehicleState) {
ChassisStatesOuterClass.BrakeSystemStates.Builder brakeSystemStates = null;
if (vehicleState.hasBrake()) {
brakeSystemStates = ChassisStatesOuterClass.BrakeSystemStates.newBuilder();
//刹车
brakeSystemStates.setBrakePedalResponsePosition(vehicleState.getBrake());//鹰眼已用
}
if (vehicleState.hasBrakeInference()) {
if (brakeSystemStates == null) {
brakeSystemStates = ChassisStatesOuterClass.BrakeSystemStates.newBuilder();
}
//刹车干预
brakeSystemStates.setBrakePedalInferenceState(vehicleState.getBrakeInference());
}
if (brakeSystemStates != null) {
builder.setBrakeSystemStates(brakeSystemStates);
}
}
/**
* 方向盘
*/
private void setSteerSystemStates(ChassisStatesOuterClass.ChassisStates.Builder builder, VehicleStateOuterClass.VehicleState vehicleState) {
ChassisStatesOuterClass.SteerSystemStates.Builder steerSystemStates = null;
if (vehicleState.hasSteering()) {
steerSystemStates = ChassisStatesOuterClass.SteerSystemStates.newBuilder();
//方向盘转向角数据
steerSystemStates.setSteeringWheelAngle(vehicleState.getSteering());//鹰眼已用
}
if (vehicleState.hasSteerInference()) {
if (steerSystemStates == null) {
steerSystemStates = ChassisStatesOuterClass.SteerSystemStates.newBuilder();
}
//方向盘干预
steerSystemStates.setSteeringWheelInferenceState(vehicleState.getSteerInference());
}
if (vehicleState.hasSteeringSpd()) {
if (steerSystemStates == null) {
steerSystemStates = ChassisStatesOuterClass.SteerSystemStates.newBuilder();
}
steerSystemStates.setSteeringWheelSpeed(vehicleState.getSteeringSpd());
}
if (vehicleState.hasLeftFrontWheelAngle()) {
if (steerSystemStates == null) {
steerSystemStates = ChassisStatesOuterClass.SteerSystemStates.newBuilder();
}
steerSystemStates.setFrontLeftWheelAngle(vehicleState.getLeftFrontWheelAngle());
}
if (vehicleState.hasRightFrontWheelAngle()) {
if (steerSystemStates == null) {
steerSystemStates = ChassisStatesOuterClass.SteerSystemStates.newBuilder();
}
steerSystemStates.setFrontRightWheelAngle(vehicleState.getRightFrontWheelAngle());
}
if (steerSystemStates != null) {
builder.setSteerSystemStates(steerSystemStates);
}
}
private void setVehicleMotionStates(ChassisStatesOuterClass.ChassisStates.Builder builder, VehicleStateOuterClass.VehicleState vehicleState) {
ChassisStatesOuterClass.VehicleMotionStates.Builder vehicleMotionStates = null;
if (vehicleState.hasSpeed()) {
vehicleMotionStates = ChassisStatesOuterClass.VehicleMotionStates.newBuilder();
vehicleMotionStates.setSpeed(vehicleState.getSpeed());
}
if (vehicleState.hasAccel()) {
if (vehicleMotionStates == null) {
vehicleMotionStates = ChassisStatesOuterClass.VehicleMotionStates.newBuilder();
}
//加速度
vehicleMotionStates.setAcceleration(vehicleState.getAccel());//鹰眼已用
}
if (vehicleMotionStates != null) {
builder.setVehicleMotionStates(vehicleMotionStates);
}
}
/**
* 车身控制模块
*/
private void setBCMSystemStates(ChassisStatesOuterClass.ChassisStates.Builder builder, VehicleStateOuterClass.VehicleState vehicleState) {
ChassisStatesOuterClass.BCMSystemStates.Builder bcmSystemStates = null;
if (vehicleState.hasLight()) {
bcmSystemStates = ChassisStatesOuterClass.BCMSystemStates.newBuilder();
//转向灯数据
bcmSystemStates.setTurnLightState(vehicleState.getLight());//鹰眼已用
}
if (vehicleState.hasBrakeLightStatus()) {
if (bcmSystemStates == null) {
bcmSystemStates = ChassisStatesOuterClass.BCMSystemStates.newBuilder();
}
//刹车灯数据
bcmSystemStates.setBrakeLightState(vehicleState.getBrakeLightStatus() ? 1 : 0);//鹰眼已用
}
if (vehicleState.hasHorn()) {
if (bcmSystemStates == null) {
bcmSystemStates = ChassisStatesOuterClass.BCMSystemStates.newBuilder();
}
//鸣笛
bcmSystemStates.setHornState(vehicleState.getHorn() ? 1 : 0);
}
if (vehicleState.hasHighbeam()) {
if (bcmSystemStates == null) {
bcmSystemStates = ChassisStatesOuterClass.BCMSystemStates.newBuilder();
}
//远光灯
bcmSystemStates.setHighbeamState(vehicleState.getHighbeam() ? 1 : 0);
}
if (vehicleState.hasLowbeam()) {
if (bcmSystemStates == null) {
bcmSystemStates = ChassisStatesOuterClass.BCMSystemStates.newBuilder();
}
//近光灯
bcmSystemStates.setLowbeamState(vehicleState.getLowbeam() ? 1 : 0);
}
if (vehicleState.hasFoglight()) {
if (bcmSystemStates == null) {
bcmSystemStates = ChassisStatesOuterClass.BCMSystemStates.newBuilder();
}
//雾灯 新底盘分前后雾灯 老地盘只有一个 所以同时赋值
bcmSystemStates.setFrontFoglightState(vehicleState.getFoglight() ? 1 : 0);
bcmSystemStates.setBackFoglightState(vehicleState.getFoglight() ? 1 : 0);
}
if (vehicleState.hasClearanceLamps()) {
if (bcmSystemStates == null) {
bcmSystemStates = ChassisStatesOuterClass.BCMSystemStates.newBuilder();
}
//示廓灯
bcmSystemStates.setClearanceLampsState(vehicleState.getClearanceLamps() ? 1 : 0);
}
if (vehicleState.hasWarnLight()) {
if (bcmSystemStates == null) {
bcmSystemStates = ChassisStatesOuterClass.BCMSystemStates.newBuilder();
}
//报警灯
bcmSystemStates.setAlarmLightState(vehicleState.getWarnLight() ? 1 : 0);
}
if (bcmSystemStates != null) {
builder.setBcmSystemStates(bcmSystemStates);
}
}
}

View File

@@ -22,11 +22,16 @@ import mogo.telematics.pad.MessagePad;
public class DispatchHandler {
private final MessagePad.MessageType messageType;
private final OnDispatchHandlerListener listener;
private static final int WHAT_DISPATCH = 999999;
private HandlerThread mThread;
private BaseHandler mBaseHandler;
public interface OnDispatchHandlerListener {
void onDispatchRaw(MessagePad.MessageType name, RawData raw);
void onHandler(MessagePad.MessageType type, Handler handler);
void onHandleMessage(MessagePad.MessageType type, Message msg);
void onDispatchRaw(MessagePad.MessageType type, RawData raw);
}
@@ -35,6 +40,16 @@ public class DispatchHandler {
this.messageType = messageType;
}
public void start() {
if (mThread == null) {
String name = "Dispatch-" + messageType.name().replace("MsgType", "");
mThread = new HandlerThread(name);
mThread.start();
initHandler(mThread.getLooper());
listener.onHandler(messageType, mBaseHandler);
}
}
public void stop() {
if (mBaseHandler != null) {
mBaseHandler.removeCallbacksAndMessages(null);
@@ -47,14 +62,10 @@ public class DispatchHandler {
}
public void sendRawMessage(RawData raw) {
if (mThread == null) {
String name = "Dispatch-" + messageType.name().replace("MsgType", "");
mThread = new HandlerThread(name);
mThread.start();
initHandler(mThread.getLooper());
}
start();
Message msg = Message.obtain();
msg.obj = raw;
msg.what = WHAT_DISPATCH;
mBaseHandler.sendMessage(msg);
}
@@ -67,16 +78,19 @@ public class DispatchHandler {
* @param msg
*/
protected void handleMessage(Message msg) {
//TODO 计算耗时 临时测试
if (CupidLogUtils.isEnableLog())
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (mThread != null) {
MessageQueue queue = mThread.getLooper().getQueue();
CupidLogUtils.i("TimeConsuming", mThread.getName() + " 当前消息队列是否处于空闲状态=" + queue.isIdle());
if (msg.what == WHAT_DISPATCH) {
//TODO 计算耗时 临时测试
if (CupidLogUtils.isEnableLog())
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (mThread != null) {
MessageQueue queue = mThread.getLooper().getQueue();
CupidLogUtils.i("TimeConsuming", mThread.getName() + " 当前消息队列是否处于空闲状态=" + queue.isIdle());
}
}
}
listener.onDispatchRaw(messageType, (RawData) msg.obj);
listener.onDispatchRaw(messageType, (RawData) msg.obj);
} else {
listener.onHandleMessage(messageType, msg);
}
}
/**