整理ADAS相关代码

Signed-off-by: donghongyu <donghongyu@zhidaoauto.com>
This commit is contained in:
donghongyu
2022-02-08 19:07:28 +08:00
parent 14c2128a1e
commit 117897d576
19 changed files with 255 additions and 417 deletions

View File

@@ -52,15 +52,22 @@ dependencies {
kapt rootProject.ext.dependencies.aroutercompiler
implementation rootProject.ext.dependencies.adasHigh
implementation rootProject.ext.dependencies.mogoami
if (Boolean.valueOf(USE_MAVEN_PACKAGE)) {
implementation rootProject.ext.dependencies.modulecommon
implementation rootProject.ext.dependencies.mogo_core_data
implementation rootProject.ext.dependencies.mogo_core_utils
implementation rootProject.ext.dependencies.mogo_core_network
implementation rootProject.ext.dependencies.mogo_core_function_api
implementation rootProject.ext.dependencies.mogo_core_function_call
} else {
implementation project(':modules:mogo-module-common')
implementation project(':core:mogo-core-data')
implementation project(':core:mogo-core-utils')
implementation project(':core:mogo-core-network')
implementation project(':core:mogo-core-function-api')
implementation project(':core:mogo-core-function-call')
}

View File

@@ -6,13 +6,16 @@ import androidx.annotation.RequiresPermission
import com.alibaba.android.arouter.facade.annotation.Route
import com.mogo.eagle.core.data.autopilot.AutopilotControlCmdParameter
import com.mogo.eagle.core.data.autopilot.AutopilotControlParameters
import com.mogo.eagle.core.data.config.FunctionBuildConfig
import com.mogo.eagle.core.data.constants.MoGoConfig
import com.mogo.eagle.core.data.constants.MogoServicePaths
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotProvider
import com.mogo.eagle.core.function.autopilot.adapter.MoGoAdasListenerImpl
import com.mogo.eagle.core.function.autopilot.adapter.MoGoAdasMsgConnectStatusListenerImpl
import com.mogo.eagle.core.function.autopilot.server.AsyncDataToAutopilotServer
import com.mogo.eagle.core.utilcode.mogo.logger.Logger
import com.mogo.eagle.core.utilcode.mogo.storage.SharedPrefsMgr
import com.mogo.eagle.core.utilcode.util.GsonUtils
import com.mogo.eagle.core.utilcode.util.LogUtils
import com.mogo.eagle.core.utilcode.util.ThreadUtils
import com.zhidao.support.adas.high.AdasManager
import com.zhidao.support.adas.high.bean.IPCUpgradeInfo
@@ -34,9 +37,26 @@ class MoGoAutopilotProvider :
get() = TAG
override fun init(context: Context) {
Logger.d(TAG, "初始化工控机连接……")
mContext = context
// 初始化ADAS 域控制器
//AdasManager.getInstance().create(context)
CupidLogUtils.setEnableLog(false)
CupidLogUtils.setIsWriteLog(false)
// TODO 临时方案根据不同的身份标识连接不同的工控机IP
when (FunctionBuildConfig.appIdentityMode) {
0 -> // 司机
AdasManager.getInstance().create(context, "192.168.1.102")
1 -> // 乘客
AdasManager.getInstance().create(context, "192.168.1.103")
else -> // 默认采用UDP寻址方式
AdasManager.getInstance().create(context)
}
//////////////////////////////////注意先后顺序AdasManager.getInstance().create后才可以设置监听/////////////////////////////////////////////
// 监听 adas 连接状态
AdasManager.getInstance().setOnAdasConnectStatusListener(MoGoAdasMsgConnectStatusListenerImpl())
// 监听ADAS-SDK获取到的工控机数据
AdasManager.getInstance().setOnAdasListener(MoGoAdasListenerImpl())
// 同步数据给工控机的服务
AsyncDataToAutopilotServer.INSTANCE.initServer()
}
@@ -72,7 +92,7 @@ class MoGoAutopilotProvider :
val parameter = AutopilotControlCmdParameter("aiCloudToStartAutopilot", result)
AdasManager.getInstance().aiCloudToAdasData(GsonUtils.toJson(parameter))
} else {
LogUtils.eTag(TAG, "车机与工控机链接失败,无法开启自动驾驶")
Logger.e(TAG, "车机与工控机链接失败,无法开启自动驾驶")
}
}
@@ -84,7 +104,7 @@ class MoGoAutopilotProvider :
if (AdasManager.getInstance().isSocketConnect) {
AdasManager.getInstance().controlAutopilotCarHead()
} else {
LogUtils.eTag(TAG, "车机与工控机链接失败,无法断开自动驾驶")
Logger.e(TAG, "车机与工控机链接失败,无法断开自动驾驶")
}
}

View File

@@ -0,0 +1,249 @@
package com.mogo.eagle.core.function.autopilot.adapter;
import android.util.Log;
import com.mogo.eagle.core.data.autopilot.ADASTrajectoryInfo;
import com.mogo.eagle.core.data.autopilot.AutoPilotRecordResult;
import com.mogo.eagle.core.data.autopilot.AutopilotCarStateInfo;
import com.mogo.eagle.core.data.autopilot.AutopilotGuardianStatusInfo;
import com.mogo.eagle.core.data.autopilot.AutopilotRouteInfo;
import com.mogo.eagle.core.data.autopilot.AutopilotStationInfo;
import com.mogo.eagle.core.data.autopilot.AutopilotStatusInfo;
import com.mogo.eagle.core.data.autopilot.AutopilotWarnMessage;
import com.mogo.eagle.core.data.config.HdMapBuildConfig;
import com.mogo.eagle.core.data.traffic.TrafficData;
import com.mogo.eagle.core.function.autopilot.utils.AdasObjectConvertUtils;
import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager;
import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotCarStatusListenerManager;
import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotIdentifyListenerManager;
import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotPlanningListenerManager;
import com.mogo.eagle.core.function.call.hmi.CallerHmiManager;
import com.mogo.eagle.core.utilcode.mogo.logger.Logger;
import com.zhidao.support.adas.high.AdasManager;
import com.zhidao.support.adas.high.OnAdasListener;
import com.zhidao.support.adas.high.bean.AutopilotRoute;
import com.zhidao.support.adas.high.bean.AutopilotStatus;
import com.zhidao.support.adas.high.bean.AutopilotWayArrive;
import com.zhidao.support.adas.high.bean.CarLaneInfo;
import com.zhidao.support.adas.high.bean.CarStateInfo;
import com.zhidao.support.adas.high.bean.IPCUpgradeStateInfo;
import com.zhidao.support.adas.high.bean.LightStatueInfo;
import com.zhidao.support.adas.high.bean.ObstaclesInfo;
import com.zhidao.support.adas.high.bean.RectInfo;
import com.zhidao.support.adas.high.bean.SSHResult;
import com.zhidao.support.adas.high.bean.TrajectoryInfo;
import com.zhidao.support.adas.high.bean.WarnMessageInfo;
import com.zhidao.support.adas.high.bean.guardian.AutopilotGuardianInfo;
import com.zhidao.support.adas.high.bean.record.AutopilotRecordResult;
import com.zhidao.support.obu.ami.AmiClientManager;
import java.util.ArrayList;
import java.util.List;
/**
* @author congtaowang
* @since 2020/10/22
* <p>
* 适配ADAS 回调监听分发
*/
public class MoGoAdasListenerImpl implements OnAdasListener {
private final String TAG = "OnAdasListenerAdapter";
@Override
public void onRectData(RectInfo rectInfo) {
if (HdMapBuildConfig.isMapLoaded) {
ArrayList<TrafficData> recognizedListResults = AdasObjectConvertUtils.INSTANCE.regroupTrafficDataData(rectInfo.getModels());
CallerAutopilotIdentifyListenerManager.INSTANCE.invokeAutopilotIdentifyDataUpdate(recognizedListResults);
}
}
@Override
public void onCarStateData(CarStateInfo carStateInfo) {
if (HdMapBuildConfig.isMapLoaded) {
// Logger.d(TAG, "--------carStateInfo.toString() = " + carStateInfo.toString());
//can数据转发
CarStateInfo.ValuesBean bean = carStateInfo.getValues();
// Log.w("DHY-location", bean.getLon() + "," + bean.getLat() + " OnAdasListenerAdapter-onCarStateData");
if (bean != null) {
int turnLight = bean.getTurnLightOften(); //转向灯状态 0是正常 1是左转 2是右转
AmiClientManager.getInstance().setTurnLightState(turnLight);
int brakeLight = bean.getBrake_light(); //TODO
// Logger.d(TAG, "onCarStateData ---- turnLight = " + turnLight + "---brakeLight = " + brakeLight);
//设置转向灯
CallerHmiManager.INSTANCE.showTurnLight(turnLight);
//设置刹车信息
CallerHmiManager.INSTANCE.showBrakeLight(brakeLight);
} else {
Logger.e(TAG, "bean == null ");
}
AutopilotCarStateInfo autopilotCarStateInfo = AdasObjectConvertUtils.INSTANCE.fromAdasCarStateInfoObject(carStateInfo);
CallerAutopilotCarStatusListenerManager.INSTANCE.invokeAutopilotCarStateData(autopilotCarStateInfo);
}
}
@Override
public void autopilotStatus(AutopilotStatus autopilotStatus) {
if (HdMapBuildConfig.isMapLoaded) {
AutopilotStatus.ValuesBean autopilotStatusValues = autopilotStatus.getValues();
if (autopilotStatusValues != null) {
// 初始化自动驾驶状态信息
AutopilotStatusInfo autopilotStatusInfo = CallerAutoPilotStatusListenerManager.INSTANCE.getAutoPilotStatusInfo();
autopilotStatusInfo.setState(autopilotStatusValues.getState());
autopilotStatusInfo.setPilotmode(autopilotStatusValues.getPilotmode());
autopilotStatusInfo.setControl_pilotmode(autopilotStatusValues.getControl_pilotmode());
autopilotStatusInfo.setReason(autopilotStatusValues.getReason());
autopilotStatusInfo.setCamera(autopilotStatusValues.getCamera());
autopilotStatusInfo.setRtk(autopilotStatusValues.getRtk());
autopilotStatusInfo.setRadar(autopilotStatusValues.getRadar());
autopilotStatusInfo.setSpeed(autopilotStatusValues.getSpeed());
// 初始化自动驾驶状态信息
autopilotStatusInfo.setVersion(AdasManager.getInstance().getAdasConfig().getVersion());
autopilotStatusInfo.setConnectIP(AdasManager.getInstance().getAdasConfig().getAddress());
autopilotStatusInfo.setDockVersion(AdasManager.getInstance().getAdasConfig().getDockVersion());
CallerAutoPilotStatusListenerManager.INSTANCE.invokeAutoPilotStatus();
}
}
}
@Override
public void autopilotArrive(AutopilotWayArrive autopilotWayArrive) {
if (HdMapBuildConfig.isMapLoaded) {
Logger.d(TAG, "autopilotArrive : " + autopilotWayArrive);
if (autopilotWayArrive != null) {
AutopilotWayArrive.ResultBean result = autopilotWayArrive.getResult();
if (result != null) {
AutopilotWayArrive.ResultBean.EndLatLonBean endLatLon = result.getEndLatLon();
if (endLatLon != null) {
AutopilotStationInfo stationInfo = new AutopilotStationInfo(result.getCarType(), endLatLon.getLon(), endLatLon.getLat());
CallerAutoPilotStatusListenerManager.INSTANCE.invokeArriveAtStation(stationInfo);
}
}
}
}
}
@Override
public void onAutopilotRoute(AutopilotRoute route) {
if (HdMapBuildConfig.isMapLoaded) {
Logger.d(TAG, "onAutopilotRoute : " + route.toString());
AutopilotRouteInfo autopilotRoute = AdasObjectConvertUtils.INSTANCE.fromAdasAutopilotRoute(route);
CallerAutopilotPlanningListenerManager.INSTANCE.invokeAutopilotRotting(autopilotRoute);
}
}
@Override
public void onAutopilotTrajectory(List<TrajectoryInfo> trajectoryList) {
if (HdMapBuildConfig.isMapLoaded) {
Logger.d(TAG, "onAutopilotTrajectory : " + trajectoryList);
ArrayList<ADASTrajectoryInfo> trajectoryInfoArrayList = new ArrayList<>();
if (trajectoryList != null && trajectoryList.size() > 0) {
for (TrajectoryInfo trajectory : trajectoryList) {
ADASTrajectoryInfo adasTrajectoryInfo = new ADASTrajectoryInfo();
adasTrajectoryInfo.setLat(trajectory.getLat());
adasTrajectoryInfo.setLon(trajectory.getLon());
adasTrajectoryInfo.setAcceleration(trajectory.getAcceleration());
adasTrajectoryInfo.setAccumulatedDis(trajectory.getAccumulatedDis());
adasTrajectoryInfo.setTime(trajectory.getTime());
adasTrajectoryInfo.setVelocity(trajectory.getVelocity());
adasTrajectoryInfo.setAlt(trajectory.getAlt());
adasTrajectoryInfo.setKappa(trajectory.getKappa());
adasTrajectoryInfo.setTheta(trajectory.getTheta());
trajectoryInfoArrayList.add(adasTrajectoryInfo);
}
Log.e(TAG, "time:" + System.currentTimeMillis() + "trajectoryInfoArrayList:" + trajectoryInfoArrayList);
}
CallerAutopilotPlanningListenerManager.INSTANCE.invokeAutopilotTrajectory(trajectoryInfoArrayList);
}
}
@Override
public void onAutopilotSNRequest() {
CallerAutoPilotStatusListenerManager.INSTANCE.invokeAutopilotSNRequest();
}
@Override
public void onAutopilotGuardian(AutopilotGuardianInfo guardianInfo) {
if (HdMapBuildConfig.isMapLoaded) {
AutopilotGuardianStatusInfo autopilotRoute = AdasObjectConvertUtils.INSTANCE.fromAutopilotGuardianInfo(guardianInfo);
CallerAutoPilotStatusListenerManager.INSTANCE.invokeAutopilotGuardian(autopilotRoute);
}
}
@Override
public void onAutopilotRecord(AutopilotRecordResult result) {
if (result != null) {
AutoPilotRecordResult real = new AutoPilotRecordResult();
real.setDiskFree(result.getDiskFree());
real.setId(result.getId());
real.setDuration(result.getDuration());
real.setNote(result.getNote());
real.setTotal(result.getTotalSize());
real.setType(result.getType());
real.setFileName(result.getFilename());
real.setKey(result.getKey());
real.setStat(result.getStat());
real.setTimestamp(result.getTimestamp());
CallerAutopilotIdentifyListenerManager.INSTANCE.invokeAutopilotRecordResult(real);
}
}
@Override
public void onLightStateData(LightStatueInfo lightStatueInfo) {
}
@Override
public void onObstaclesInfo(ObstaclesInfo obstaclesInfo) {
}
@Override
public void onCarLaneInfo(CarLaneInfo carLaneInfo) {
}
@Override
public void onWarnMessage(WarnMessageInfo warnMessageInfo) {
final AutopilotWarnMessage warnMessage = AdasObjectConvertUtils.INSTANCE.fromAdasObject(warnMessageInfo);
CallerAutopilotIdentifyListenerManager.INSTANCE.invokeAutopilotWarnMessage(warnMessage);
}
@Override
public void onVideoSize(int width, int height) {
}
/**
* 工控机升级状态
* @param info 工控机升级状态
*/
@Override
public void onUpgradeStateInfo(IPCUpgradeStateInfo info) {
if(info != null){
Logger.d(TAG,"onUpgradeStateInfo "+
" upgrade mode="+info.getUpgradeMode()+
" download status="+info.getDownloadStatus()+
" download progress current="+info.getProgress().getCurrent()+
" download progress total="+info.getProgress().getTotal()+
" download version="+info.getImages()+
" upgrade status="+info.getUpgradeStatus());
CallerHmiManager.INSTANCE.showAdUpgradeStatus(info.getUpgradeMode(),info.getDownloadStatus(),info.getProgress().getCurrent(),
info.getProgress().getTotal(),info.getImages(),info.getUpgradeStatus());
}else{
Logger.d(TAG,"onUpgradeStateInfo : upgrade state info is null");
}
}
@Override
public void onSSHResult(SSHResult info) {
}
}

View File

@@ -0,0 +1,100 @@
package com.mogo.eagle.core.function.autopilot.adapter
import com.mogo.cloud.passport.MoGoAiCloudClientConfig
import com.mogo.eagle.core.data.autopilot.AutopilotStationInfo
import com.mogo.eagle.core.data.autopilot.AutopilotStatusInfo
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener
import com.mogo.eagle.core.function.autopilot.network.AdasServiceModel
import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager
import com.mogo.eagle.core.utilcode.mogo.logger.Logger
import com.zhidao.support.adas.high.AdasManager
import com.zhidao.support.adas.high.OnAdasMsgConnectStatusListener
import com.zhidao.support.adas.high.bean.BasicInfo
import io.reactivex.Flowable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import java.util.concurrent.TimeUnit
/**
* ADAS-SDK与工控机连接状态回调
*
* @author donghongyu
*/
class MoGoAdasMsgConnectStatusListenerImpl : OnAdasMsgConnectStatusListener, IMoGoAutopilotStatusListener {
private val TAG = "MoGoAdasMsgConnectStatusListenerImpl"
//自动驾驶状态
private var mCurrentAutopilotStatus = -1
//自动驾驶车速度
private var mCurrentAutopilotSpeed = 0f
override fun onWebSocketConnectSuccess() {
Logger.d(TAG, "webSocket 连接成功")
// 初始化自动驾驶状态信息
CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo().connectIP = AdasManager.getInstance().adasConfig.address
CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo().connectStatus = true
CallerAutoPilotStatusListenerManager.invokeAutoPilotStatus()
// 同步SN给工控机
syncBasicInfoToAutopilot()
// 开启轮训上传自动驾驶状态
updateDriveStatusTask()
}
override fun onWebSocketConnectFailed(reason: String) {
Logger.d(TAG, "webSocket 连接失败 reason:$reason")
CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo().connectIP = AdasManager.getInstance().adasConfig.address
CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo().connectStatus = false
CallerAutoPilotStatusListenerManager.invokeAutoPilotStatus()
}
/**
* 工控机获取SN
*/
override fun onAutopilotSNRequest() {
syncBasicInfoToAutopilot()
}
override fun onAutopilotArriveAtStation(autopilotWayArrive: AutopilotStationInfo?) {
if (autopilotWayArrive != null) {
val lon = autopilotWayArrive.lon
val lat = autopilotWayArrive.lat
AdasServiceModel.getInstance().reportSite(lon, lat)
}
}
override fun onAutopilotStatusResponse(autoPilotStatusInfo: AutopilotStatusInfo) {
val state = autoPilotStatusInfo.state
val speed = autoPilotStatusInfo.speed
mCurrentAutopilotStatus = state
mCurrentAutopilotSpeed = speed
}
/**
* 同步SN信息给工控机
*/
fun syncBasicInfoToAutopilot() {
Logger.d(TAG, "同步PAD的SN给工控机……")
val info = BasicInfo()
info.setSn(MoGoAiCloudClientConfig.getInstance().sn)
AdasManager.getInstance().setBasicInfo(info)
}
/**
* 上传自动驾驶状态任务
*/
fun updateDriveStatusTask() {
Logger.d(TAG, "updateDriveStatusTask")
Flowable.interval(0, 5, TimeUnit.SECONDS)
.subscribeOn(Schedulers.io())
.unsubscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe { aLong: Long? ->
AdasServiceModel.getInstance().updateDriveStatus(mCurrentAutopilotStatus, mCurrentAutopilotSpeed)
}
}
}

View File

@@ -1,38 +0,0 @@
package com.mogo.eagle.core.function.autopilot.adapter;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.mogo.eagle.core.data.autopilot.AutopilotGuardianStatusInfo;
import com.mogo.eagle.core.data.autopilot.AutopilotStationInfo;
import com.mogo.eagle.core.data.autopilot.AutopilotStatusInfo;
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener;
/**
* @author xiaoyuzhou
* @date 2021/10/20 1:02 下午
* 自动驾驶状态回调用
*/
public class MoGoAutopilotStatusListenerImpl implements IMoGoAutopilotStatusListener {
@Override
public void onAutopilotStatusResponse(@NonNull AutopilotStatusInfo autoPilotStatusInfo) {
}
@Override
public void onAutopilotArriveAtStation(@Nullable AutopilotStationInfo autopilotWayArrive) {
}
@Override
public void onAutopilotSNRequest() {
}
@Override
public void onAutopilotGuardian(@Nullable AutopilotGuardianStatusInfo guardianInfo) {
}
}

View File

@@ -0,0 +1,41 @@
package com.mogo.eagle.core.function.autopilot.entity;
/**
* Created by XuYong on 2021/5/28 16:12
*/
public class AutonomousDriveStatusBean {
private String sn;
private int status;
private float vehicleSpeed;
public AutonomousDriveStatusBean(String sn, int status, float vehicleSpeed) {
this.sn = sn;
this.status = status;
this.vehicleSpeed = vehicleSpeed;
}
public String getSn() {
return sn;
}
public void setSn(String sn) {
this.sn = sn;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public float getVehicleSpeed() {
return vehicleSpeed;
}
public void setVehicleSpeed(float vehicleSpeed) {
this.vehicleSpeed = vehicleSpeed;
}
}

View File

@@ -0,0 +1,40 @@
package com.mogo.eagle.core.function.autopilot.entity;
/**
* Created by XuYong on 2021/5/31 16:24
*/
public class ReportSiteBean {
private String sn;
private double lon;
private double lat;
public ReportSiteBean(String sn, double lon, double lat) {
this.sn = sn;
this.lon = lon;
this.lat = lat;
}
public String getSn() {
return sn;
}
public void setSn(String sn) {
this.sn = sn;
}
public double getLon() {
return lon;
}
public void setLon(double lon) {
this.lon = lon;
}
public double getLat() {
return lat;
}
public void setLat(double lat) {
this.lat = lat;
}
}

View File

@@ -0,0 +1,98 @@
package com.mogo.eagle.core.function.autopilot.network;
import com.mogo.cloud.passport.MoGoAiCloudClientConfig;
import com.mogo.commons.context.ContextHolderUtil;
import com.mogo.eagle.core.data.BaseData;
import com.mogo.eagle.core.function.autopilot.entity.AutonomousDriveStatusBean;
import com.mogo.eagle.core.function.autopilot.entity.ReportSiteBean;
import com.mogo.eagle.core.network.RequestOptions;
import com.mogo.eagle.core.network.SubscribeImpl;
import com.mogo.eagle.core.network.utils.GsonUtil;
import com.mogo.eagle.core.utilcode.mogo.logger.Logger;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.constants.HostConst;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import okhttp3.MediaType;
import okhttp3.RequestBody;
/**
* 将自动驾驶状态及站点信息上传给云平台,云平台会根据此数据做路线的绘制
*
* @author dongghongyu
*/
public class AdasServiceModel {
private static final String TAG = "AdasServiceModel";
private static volatile AdasServiceModel instance;
private static final byte[] obj = new byte[0];
private final IAdasApiService mAdasApiService;
private AdasServiceModel() {
this.mAdasApiService = MogoApisHandler.getInstance().getApis().getNetworkApi().create(IAdasApiService.class, HostConst.DATA_SERVICE_HOST);
}
public static AdasServiceModel getInstance() {
if (instance == null) {
synchronized (obj) {
if (instance == null) {
instance = new AdasServiceModel();
}
}
}
return instance;
}
public void updateDriveStatus(int autoPilotStatus, float autoPilotSpeed) {
String sn = MoGoAiCloudClientConfig.getInstance().getSn();
AutonomousDriveStatusBean request = new AutonomousDriveStatusBean(sn, autoPilotStatus, autoPilotSpeed);
RequestBody requestBody = RequestBody.create(MediaType.get("application/json;charset=UTF-8"), GsonUtil.jsonFromObject(request));
mAdasApiService.updateAutonomousDriveStatus(requestBody).
subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
.subscribe(new SubscribeImpl<BaseData>(RequestOptions.create(ContextHolderUtil.getContext())) {
@Override
public void onError(String message, int code) {
super.onError(message, code);
}
@Override
public void onError(Throwable e) {
super.onError(e);
}
@Override
public void onSuccess(BaseData o) {
super.onSuccess(o);
Logger.d(TAG, "updateDriveStatus success");
}
});
}
public void reportSite(double lon, double lat) {
String sn = MoGoAiCloudClientConfig.getInstance().getSn();
ReportSiteBean reportSiteBean = new ReportSiteBean(sn, lon, lat);
RequestBody requestBody = RequestBody.create(MediaType.get("application/json;charset=UTF-8"), GsonUtil.jsonFromObject(reportSiteBean));
mAdasApiService.updateReportSite(requestBody).
subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
.subscribe(new SubscribeImpl<BaseData>(RequestOptions.create(ContextHolderUtil.getContext())) {
@Override
public void onError(String message, int code) {
super.onError(message, code);
}
@Override
public void onError(Throwable e) {
super.onError(e);
}
@Override
public void onSuccess(BaseData o) {
super.onSuccess(o);
Logger.d(TAG, "autopilotArrive success");
}
});
}
}

View File

@@ -0,0 +1,31 @@
package com.mogo.eagle.core.function.autopilot.network;
import com.mogo.eagle.core.data.BaseData;
import io.reactivex.Observable;
import okhttp3.RequestBody;
import retrofit2.http.Body;
import retrofit2.http.Headers;
import retrofit2.http.POST;
public interface IAdasApiService {
/**
* 上传自动驾驶状态接口
* @param requestBody
* @return
*/
@Headers({"Content-Type:application/json;charset=UTF-8"})
@POST("/dataService/autonomousDrive/updateAutonomousDriveStatus")
Observable<BaseData> updateAutonomousDriveStatus(@Body RequestBody requestBody);
/**
* 站点上报 用于网约车业务 云平台绘制路线使用
* @param requestBody
* @return
*/
@Headers({"Content-Type:application/json;charset=UTF-8"})
@POST("/dataService/autonomousDrive/reportSite")
Observable<BaseData> updateReportSite(@Body RequestBody requestBody);
}

View File

@@ -1,10 +1,102 @@
package com.mogo.eagle.core.function.autopilot.utils
import com.mogo.eagle.core.data.autopilot.AutopilotCarStateInfo
import com.mogo.eagle.core.data.autopilot.AutopilotGuardianStatusInfo
import com.mogo.eagle.core.data.autopilot.AutopilotRouteInfo
import com.mogo.eagle.core.data.autopilot.AutopilotWarnMessage
import com.mogo.eagle.core.data.enums.TrafficTypeEnum
import com.mogo.eagle.core.data.traffic.TrafficData
import com.zhidao.support.adas.high.bean.AutopilotRoute
import com.zhidao.support.adas.high.bean.CarStateInfo
import com.zhidao.support.adas.high.bean.RectInfo
import com.zhidao.support.adas.high.bean.WarnMessageInfo
import com.zhidao.support.adas.high.bean.guardian.AutopilotGuardianInfo
import com.zhidao.utils.common.GsonUtil
/**
* @author xiaoyuzhou
* @date 2021/10/18 1:32 下午
*/
class AdasObjectConvertUtils {
object AdasObjectConvertUtils {
val TAG = "AdasObjectConvertUtils"
fun fromAutopilotGuardianInfo(autopilotGuardianInfo: AutopilotGuardianInfo): AutopilotGuardianStatusInfo? {
return GsonUtil.objectFromJson(
GsonUtil.jsonFromObject(autopilotGuardianInfo),
AutopilotGuardianStatusInfo::class.java
)
}
fun fromAdasAutopilotRoute(carStateInfo: AutopilotRoute): AutopilotRouteInfo? {
return GsonUtil.objectFromJson(
GsonUtil.jsonFromObject(carStateInfo),
AutopilotRouteInfo::class.java
)
}
fun fromAdasCarStateInfoObject(carStateInfo: CarStateInfo): AutopilotCarStateInfo? {
return GsonUtil.objectFromJson(
GsonUtil.jsonFromObject(carStateInfo),
AutopilotCarStateInfo::class.java
)
}
fun fromAdasObject(info: WarnMessageInfo?): AutopilotWarnMessage? {
if (info == null) {
return null
}
val warnMessage = AutopilotWarnMessage()
warnMessage.content = info.content
warnMessage.level = info.level
try {
warnMessage.type = info.type.toInt()
} catch (e: NumberFormatException) {
return null
}
warnMessage.value = info.value
return warnMessage
}
fun regroupTrafficDataData(datums: List<RectInfo.RectBean?>?): ArrayList<TrafficData>? {
if (datums == null || datums.isEmpty()) {
return null
}
val recognizedListResults: ArrayList<TrafficData> = ArrayList()
for (model in datums) {
if (model == null) {
continue
}
val recognizedListResult = fromAdasTrafficDataObject(model)
if (recognizedListResult != null) {
recognizedListResults.add(recognizedListResult)
}
}
return recognizedListResults
}
fun fromAdasTrafficDataObject(model: RectInfo.RectBean?): TrafficData? {
if (model == null) {
return null
}
val result = TrafficData()
result.uuid = model.uuid
result.lat = model.lat
result.lon = model.lon
result.type = TrafficTypeEnum.getType(model.type.toInt())
result.heading = model.heading
result.systemTime = model.systemTime.toLong()
result.satelliteTime = model.satelliteTime.toLong()
result.alt = model.alt
result.speed = model.speed
result.carId = model.carId
result.dataAccuracy = model.dataAccuracy
result.distance = model.distance
result.threatLevel = model.drawlevel
//Log.d(TAG, "TrafficData = $result")
return result
}
}