[620][adas]修复启动平行驾驶能力产生的空指针异常
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
package com.zhidao.support.adas.high.common;
|
||||
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.zhidao.support.adas.high.AdasManager;
|
||||
import com.zhidao.support.adas.high.OnAdasListener;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import chassis.Chassis;
|
||||
import chassis.ChassisStatesOuterClass;
|
||||
@@ -22,8 +25,8 @@ public class ParallelDrivingManager {
|
||||
private volatile Timer callbackTimer;
|
||||
private volatile Timer bootTimer;
|
||||
private OnAdasListener listener;
|
||||
private ChassisStatesOuterClass.ChassisStates chassisStates;
|
||||
private VehicleStateOuterClass.VehicleState vehicleState;
|
||||
private final AtomicReference<ChassisStatesOuterClass.ChassisStates> chassisStates = new AtomicReference<>();
|
||||
private final AtomicReference<VehicleStateOuterClass.VehicleState> vehicleState = new AtomicReference<>();
|
||||
private int autopilotState;
|
||||
/**
|
||||
* 不能启动平行驾驶的档位
|
||||
@@ -62,11 +65,11 @@ public class ParallelDrivingManager {
|
||||
}
|
||||
|
||||
public void setChassisStates(ChassisStatesOuterClass.ChassisStates chassisStates) {
|
||||
this.chassisStates = chassisStates;
|
||||
this.chassisStates.set(chassisStates);
|
||||
}
|
||||
|
||||
public void setVehicleState(VehicleStateOuterClass.VehicleState vehicleState) {
|
||||
this.vehicleState = vehicleState;
|
||||
this.vehicleState.set(vehicleState);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,31 +87,33 @@ public class ParallelDrivingManager {
|
||||
float throttle = 0;
|
||||
boolean isBrake = false;
|
||||
//检测底盘相关
|
||||
if (chassisStates != null) {
|
||||
if (chassisStates.hasBrakeSystemStates()) {
|
||||
brake = chassisStates.getBrakeSystemStates().getBrakePedalResponsePosition();
|
||||
ChassisStatesOuterClass.ChassisStates currentChassisStates = chassisStates.get();
|
||||
if (currentChassisStates != null) {
|
||||
if (currentChassisStates.hasBrakeSystemStates()) {
|
||||
brake = currentChassisStates.getBrakeSystemStates().getBrakePedalResponsePosition();
|
||||
CupidLogUtils.i(TAG, "刹车=" + brake);
|
||||
} else {
|
||||
CupidLogUtils.i(TAG, "刹车=未赋值");
|
||||
}
|
||||
if (chassisStates.hasGearSystemStates()) {
|
||||
gear = chassisStates.getGearSystemStates().getGearPosition();
|
||||
if (currentChassisStates.hasGearSystemStates()) {
|
||||
gear = currentChassisStates.getGearSystemStates().getGearPosition();
|
||||
CupidLogUtils.i(TAG, "档位=" + gear);
|
||||
} else {
|
||||
CupidLogUtils.i(TAG, "档位=未赋值");
|
||||
}
|
||||
if (chassisStates.hasDrivingSystemStates()) {
|
||||
throttle = chassisStates.getDrivingSystemStates().getThrottleResponsePosition();
|
||||
if (currentChassisStates.hasDrivingSystemStates()) {
|
||||
throttle = currentChassisStates.getDrivingSystemStates().getThrottleResponsePosition();
|
||||
CupidLogUtils.i(TAG, "油门=" + throttle);
|
||||
} else {
|
||||
CupidLogUtils.i(TAG, "油门=未赋值");
|
||||
}
|
||||
}
|
||||
if (vehicleState != null) {
|
||||
VehicleStateOuterClass.VehicleState currentVehicleState = vehicleState.get();
|
||||
if (currentVehicleState != null) {
|
||||
//TODO 关于手刹:目前只有老底盘中存在这个字段,df360开始,其他车型未知
|
||||
//电子驻车制动系统
|
||||
if (vehicleState.hasParkingBrake()) {
|
||||
isBrake = vehicleState.getParkingBrake();
|
||||
if (currentVehicleState.hasParkingBrake()) {
|
||||
isBrake = currentVehicleState.getParkingBrake();
|
||||
CupidLogUtils.i(TAG, " 手刹=" + isBrake);
|
||||
} else {
|
||||
CupidLogUtils.i(TAG, " 手刹=未赋值");
|
||||
@@ -137,7 +142,11 @@ public class ParallelDrivingManager {
|
||||
callbackTimer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
onCallback();
|
||||
try {
|
||||
onCallback();
|
||||
} catch (Exception e) {
|
||||
Log.e("[tag=" + TAG + "]", "[data=启动平行驾驶能力检测回调出现异常]", e);
|
||||
}
|
||||
}
|
||||
}, 2000L, 1000L);//延迟执行,避免刚连接成功后底盘信息无法及时同步
|
||||
}
|
||||
@@ -182,7 +191,7 @@ public class ParallelDrivingManager {
|
||||
callbackTimer.cancel();
|
||||
callbackTimer = null;
|
||||
}
|
||||
this.chassisStates = null;
|
||||
this.vehicleState = null;
|
||||
this.chassisStates.set(null);
|
||||
this.vehicleState.set(null);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user