[driver passenger ] Bus司机屏增加全路径上传

This commit is contained in:
wangmingjun
2022-04-25 17:06:11 +08:00
parent 6d25cf9ad4
commit 8a8c4cac5f
12 changed files with 366 additions and 4 deletions

View File

@@ -0,0 +1,30 @@
package com.mogo.och.bus.bean;
import java.util.List;
/**
* Created by pangfan on 2021/8/19
*
* 订单状态更新请求数据结构
*/
public class BusRoutePlanningUpdateReqBean {
public String sn;
public int lineId;
public int startSiteId;
public int endSiteId;
public List<Result> points;
public static class Result {
public Double latitude;
public Double longitude;
}
public BusRoutePlanningUpdateReqBean(String sn, int lineId, int startSiteId
, int endSiteId, List<Result> points) {
this.sn = sn;
this.lineId = lineId;
this.startSiteId = startSiteId;
this.endSiteId = endSiteId;
this.points = points;
}
}

View File

@@ -41,6 +41,7 @@ import com.mogo.module.common.constants.DataTypes;
import com.mogo.module.common.view.OnPreventFastClickListener;
import com.mogo.och.bus.R;
import com.mogo.och.bus.ui.BusTrafficLightView;
import com.mogo.och.bus.util.BDRouteDataTestUtils;
import com.mogo.och.bus.view.BusArcView;
import com.mogo.och.bus.view.SlidePanelView;
@@ -198,6 +199,8 @@ public abstract class BaseBusTabFragment<V extends IView, P extends Presenter<V>
debugArrivedStation()
);
findViewById(R.id.btnAutopilotRoute).setOnClickListener(view -> debugArrivedRoute());
tvOperationStatus.setOnClickListener(view -> {
onChangeOperationStatus();
});
@@ -227,6 +230,10 @@ public abstract class BaseBusTabFragment<V extends IView, P extends Presenter<V>
CallerHmiManager.INSTANCE.registerUpgradeTipsCallback(() -> mUpgradeTipIv);
}
private void debugArrivedRoute() {
BDRouteDataTestUtils.converToRouteData();
}
@Override
public void onDestroyView() {
super.onDestroyView();

View File

@@ -1,4 +1,4 @@
package com.mogo.och.bus.presenter;
package com.mogo.och.bus.model;
import android.content.Context;

View File

@@ -1,4 +1,4 @@
package com.mogo.och.bus.presenter;
package com.mogo.och.bus.model;
import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_BUS;
import static com.mogo.och.bus.constant.BusConst.STATION_STATUS_STOPPED;
@@ -9,15 +9,19 @@ import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.commons.debug.DebugConfig;
import com.mogo.commons.voice.AIAssist;
import com.mogo.eagle.core.data.BaseData;
import com.mogo.eagle.core.data.autopilot.AutopilotControlParameters;
import com.mogo.eagle.core.data.config.FunctionBuildConfig;
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotPlanningListener;
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener;
import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotManager;
import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager;
import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotPlanningListenerManager;
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
import com.mogo.eagle.core.utilcode.mogo.toast.TipToast;
import com.mogo.eagle.core.utilcode.util.NetworkUtils;
@@ -27,6 +31,7 @@ import com.mogo.module.common.MogoApisHandler;
import com.mogo.och.bus.bean.BusOperationStatusResponse;
import com.mogo.och.bus.bean.BusOrderBean;
import com.mogo.och.bus.bean.BusOrdersResponse;
import com.mogo.och.bus.bean.BusRoutePlanningUpdateReqBean;
import com.mogo.och.bus.bean.BusRoutesResponse;
import com.mogo.och.bus.bean.BusRoutesResult;
import com.mogo.och.bus.bean.BusStationBean;
@@ -38,7 +43,9 @@ import com.mogo.och.bus.callback.ISlidePannelHideCallback;
import com.mogo.och.bus.constant.BusConst;
import com.mogo.och.bus.net.BusServiceManager;
import com.mogo.och.bus.net.IBusServiceCallback;
import com.mogo.och.bus.presenter.BusModelLoopManager;
import com.mogo.och.bus.util.BusAnalyticsUtil;
import com.mogo.och.bus.util.CoordinateCalculateRouteUtil;
import com.mogo.och.bus.util.PinYinUtil;
import com.mogo.service.statusmanager.IMogoStatusChangedListener;
import com.mogo.service.statusmanager.StatusDescriptor;
@@ -94,6 +101,8 @@ public class BusOrderModel {
private ISlidePannelHideCallback slidePannelHideCallback;
private IBusControllerStatusCallback mControllerStatusCallback; //Model->PresenterVR mode等
List<BusRoutePlanningUpdateReqBean.Result> points = new ArrayList<>();//全路径信息
private boolean hadQueryLeaveAwayPassager = false;
private final Handler handler = new Handler(new Handler.Callback() {
@@ -135,6 +144,9 @@ public class BusOrderModel {
.getApis()
.getStatusManagerApi()
.registerStatusChangedListener( TAG, StatusDescriptor.VR_MODE, mMogoStatusChangedListener );
//自动驾驶路线规划接口
CallerAutopilotPlanningListenerManager.INSTANCE.addListener(TAG, moGoAutopilotPlanningListener);
}
//2022.1.28
@@ -194,6 +206,57 @@ public class BusOrderModel {
this.mControllerStatusCallback = callback;
}
private final IMoGoAutopilotPlanningListener moGoAutopilotPlanningListener = new IMoGoAutopilotPlanningListener() {
@Override
public void onAutopilotTrajectory(@NonNull List<MessagePad.TrajectoryPoint> trajectoryInfos) {
}
@Override
public void onAutopilotRotting(MessagePad.GlobalPathResp routeList) {
if (null != routeList && routeList.getWayPointsList().size() > 0){
points.clear();
points.addAll(CoordinateCalculateRouteUtil.coordinateConverterWgsToGcjList(mContext,routeList.getWayPointsList()));
updateOrderRoute();
}
}
};
/**
* 上报订单全路径规划数据
*/
public void updateOrderRoute() {
if (currentStationIndex >= stationList.size() && points.size() > 0){
return;
}
BusStationBean currentStation = stationList.get( currentStationIndex -1);
BusStationBean nextStation = stationList.get( currentStationIndex);
BusServiceManager.getInstance().updateOrderRoute(mContext, currentLineId, currentStation.getSiteId()
, nextStation.getSiteId(), points, new IBusServiceCallback<BaseData>() {
@Override
public void onSuccess(BaseData o) {
}
@Override
public void onFail(String failMsg) {
if (isGoingToNextStation){//重试
updateOrderRoute();
}
}
});
}
public void debugUpdateOrderRoute(List<MessagePad.Location> list){
points.clear();
points.addAll(CoordinateCalculateRouteUtil.coordinateConverterWgsToGcjList(mContext,list));
updateOrderRoute();
}
/**
* 轮询bus待服务订单
*/
@@ -262,6 +325,9 @@ public class BusOrderModel {
.getApis()
.getRegisterCenterApi()
.unregisterCarLocationChangedListener(TAG, mCarLocationChangedListener2);
//自动驾驶路线规划接口
CallerAutopilotPlanningListenerManager.INSTANCE.removeListener(moGoAutopilotPlanningListener);
}
private Object readResolve() {
@@ -563,6 +629,8 @@ public class BusOrderModel {
public void onFail(String failMsg) {
if (!NetworkUtils.isConnected(mContext)) {
TipToast.shortTip("网络异常,请稍后重试");
}else {
TipToast.shortTip(failMsg);
}
}
});

View File

@@ -11,6 +11,7 @@ import com.mogo.eagle.core.network.RequestOptions;
import com.mogo.eagle.core.network.SubscribeImpl;
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
import com.mogo.och.bus.bean.BusQueryLinesResponse;
import com.mogo.och.bus.bean.BusRoutePlanningUpdateReqBean;
import com.mogo.och.bus.bean.BusRoutesResponse;
import com.mogo.och.bus.bean.CarHeartbeatReqBean;
import com.mogo.och.bus.bean.BusOperationStatusRequest;
@@ -22,7 +23,9 @@ import com.mogo.och.bus.bean.BusUpdateSiteStatusRequest;
import com.mogo.och.bus.bean.QueryLeaveAwayPassengersRequest;
import com.mogo.och.bus.bean.QueryLeaveAwayPassengersResponse;
import com.mogo.och.bus.constant.BusConst;
import com.mogo.och.bus.presenter.BusOrderModel;
import com.mogo.och.bus.model.BusOrderModel;
import java.util.List;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
@@ -192,6 +195,18 @@ public class BusServiceManager {
.subscribe(getSubscribeImpl(context,callback,"queryBusLines"));
}
public void updateOrderRoute(Context context,int lineId, int startSiteId, int endSiteId
, List< BusRoutePlanningUpdateReqBean.Result > points
, IBusServiceCallback<BaseData> callback){
mService.updateOrderRoute(MoGoAiCloudClientConfig.getInstance().getServiceAppId()
,MoGoAiCloudClientConfig.getInstance().getToken()
,new BusRoutePlanningUpdateReqBean(MoGoAiCloudClientConfig.getInstance().getSn()
,lineId,startSiteId,endSiteId, points))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(getSubscribeImpl(context,callback,"updateOrderRoute"));
}
/**
* 车机端上传心跳数据(只在出车状态时上传):包含高德坐标系经纬度
* @param context

View File

@@ -3,6 +3,7 @@ import com.mogo.eagle.core.data.BaseData;
import com.mogo.och.bus.bean.BusOperationStatusRequest;
import com.mogo.och.bus.bean.BusOrdersResponse;
import com.mogo.och.bus.bean.BusQueryLinesResponse;
import com.mogo.och.bus.bean.BusRoutePlanningUpdateReqBean;
import com.mogo.och.bus.bean.BusRoutesResponse;
import com.mogo.och.bus.bean.CarHeartbeatReqBean;
import com.mogo.och.bus.bean.BusQueryLineStationsRequest;
@@ -145,5 +146,10 @@ public interface IBusApiService {
// @GET("/autopilot-car-hailing/line/v2/driver/bindLine/query")
@GET("/autopilot-car-hailing/line/v2/driver/bus/bindLine/query")
Observable<BusQueryLinesResponse> queryBusLines(@Header ("appId") String appId, @Header("ticket") String ticket, @Query("sn") String sn);
@Headers( {"Content-type:application/json;charset=UTF-8"} )
// @POST( "/autopilot-car-hailing/location/v2/driver/heartbeat" )
@POST( "/autopilot-car-hailing/location/v2/driver/bus/heartbeat" )
Observable<BaseData> updateOrderRoute(@Header ("appId") String appId, @Header("ticket") String ticket, @Body BusRoutePlanningUpdateReqBean data);
}

View File

@@ -9,6 +9,8 @@ import com.mogo.commons.mvp.Presenter;
import com.mogo.eagle.core.utilcode.util.UiThreadHandler;
import com.mogo.och.bus.bean.BusQueryLinesResponse;
import com.mogo.och.bus.callback.IBusLinesCallback;
import com.mogo.och.bus.model.BusLineModel;
import com.mogo.och.bus.model.BusOrderModel;
import com.mogo.och.bus.ui.BusSwitchLineView;
/**

View File

@@ -4,6 +4,7 @@ import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_BUS
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
import com.mogo.och.bus.constant.BusConst;
import com.mogo.och.bus.model.BusOrderModel;
import java.util.concurrent.TimeUnit;

View File

@@ -21,6 +21,7 @@ import com.mogo.och.bus.callback.IBusControllerStatusCallback;
import com.mogo.och.bus.callback.IRefreshBusStationsCallback;
import com.mogo.och.bus.callback.ISlidePannelHideCallback;
import com.mogo.och.bus.fragment.BusFragment;
import com.mogo.och.bus.model.BusOrderModel;
import org.jetbrains.annotations.NotNull;

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,177 @@
package com.mogo.och.bus.util;
import android.content.Context;
import com.amap.api.maps.CoordinateConverter;
import com.amap.api.maps.model.LatLng;
import com.mogo.cloud.commons.utils.CoordinateUtils;
import com.mogo.eagle.core.utilcode.mogo.logger.Logger;
import com.mogo.och.bus.bean.BusRoutePlanningUpdateReqBean;
import java.util.ArrayList;
import java.util.List;
import mogo.telematics.pad.MessagePad;
import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_BUS;
/**
* @author: wangmingjun
* @date: 2022/3/28
*/
public class CoordinateCalculateRouteUtil {
public static float calculateRouteSumLength(List<LatLng> points){
if (null == points || points.size() == 0) return 0;
float sumLength = 0;
//计算全路径总距离
for (int i = 0;i + 1< points.size();i++){
double preLat = points.get(i).latitude;
double preLon = points.get(i).longitude;
double laLat = points.get(i+1).latitude;
double laLon = points.get(i+1).longitude;
float length = CoordinateUtils.calculateLineDistance(laLon,laLat,preLon,preLat);
sumLength += length;
}
return sumLength;
}
public static List<LatLng> coordinateConverterWgsToGcjListCommon(Context mContext, List<MessagePad.Location> models) {
//转成MogoLatLng集合
List<LatLng> list = new ArrayList<>();
for (MessagePad.Location m : models) {
LatLng mogoLatLng = coordinateConverterWgsToGcj(mContext, m);
list.add(mogoLatLng);
}
return list;
}
public static LatLng coordinateConverterWgsToGcj(Context mContext, MessagePad.Location mogoLatLng) {
CoordinateConverter mCoordinateConverter = new CoordinateConverter(mContext);
mCoordinateConverter.from(CoordinateConverter.CoordType.GPS);
mCoordinateConverter.coord(new LatLng(mogoLatLng.getLatitude(), mogoLatLng.getLongitude()));
LatLng latLng = mCoordinateConverter.convert();
return latLng;
}
public static List<BusRoutePlanningUpdateReqBean.Result> coordinateConverterWgsToGcjList(Context mContext, List<MessagePad.Location> mogoLatLngList) {
List<BusRoutePlanningUpdateReqBean.Result> points = new ArrayList<>();
for (MessagePad.Location m : mogoLatLngList) {
LatLng mogoLatLng = CoordinateCalculateRouteUtil.coordinateConverterWgsToGcj(mContext, m);
BusRoutePlanningUpdateReqBean.Result result = new BusRoutePlanningUpdateReqBean.Result();
result.latitude = mogoLatLng.latitude;
result.longitude = mogoLatLng.longitude;
points.add(result);
}
return points;
}
/**
* 根据实时定位的坐标确定出已行驶到那个坐标点 todo 有问题 暂不使用
* @param mRoutePoints
* @param realLon
* @param realLat
* @return 返回剩余路径集合
*/
@Deprecated
public static List<LatLng> getCurrentPoinByCompare(List<LatLng> mRoutePoints, double realLon, double realLat) {
// 疑似坐标 先以坐标中间1/2为第一个比对点
int currentIndex = Math.round(mRoutePoints.size()/2);
LatLng currentLatLng = mRoutePoints.get(currentIndex);
//差值初始化
float baseDiffDis = CoordinateUtils.calculateLineDistance(realLon,realLat
,currentLatLng.longitude,currentLatLng.latitude);// lon,lat, prelon, prelat
List<LatLng> latePoints = new ArrayList<>();
//与选中点左右比较
if (currentIndex -1 >= 0 && currentIndex+1<= mRoutePoints.size()-1){
LatLng leftCurrentLatLng = mRoutePoints.get(currentIndex -1);
LatLng rightCurentLatLng = mRoutePoints.get(currentIndex + 1);
float leftDiffDis = CoordinateUtils.calculateLineDistance(realLon,realLat
,leftCurrentLatLng.longitude,leftCurrentLatLng.latitude);
float rightDiffDis = CoordinateUtils.calculateLineDistance(realLon,realLat,rightCurentLatLng.longitude,rightCurentLatLng.latitude);
if (rightDiffDis < leftDiffDis){ //靠近了右半边
baseDiffDis = rightDiffDis;
for (int i = currentIndex +1; i+1 <mRoutePoints.size() ;i++){
float diff = CoordinateUtils.calculateLineDistance(realLon,realLat
,mRoutePoints.get(i).longitude,mRoutePoints.get(i).latitude);
Logger.d(M_BUS + "Compare右半边集合", "点:"+i+"------------baseDiffDis = "+baseDiffDis+"---diff="+diff);
if (baseDiffDis >= diff){
baseDiffDis = diff;
currentIndex = i;
if (i == mRoutePoints.size()-1){
latePoints.addAll(mRoutePoints);
}
}else {
latePoints.addAll(mRoutePoints.subList(currentIndex,mRoutePoints.size()-1));
return latePoints;
}
}
}else if (rightDiffDis > leftDiffDis){ //靠近左半边
baseDiffDis = leftDiffDis;
for (int j = currentIndex-1; j -1 >=0 ;j++){
float diff = CoordinateUtils.calculateLineDistance(realLon,realLat,mRoutePoints.get(j).longitude,mRoutePoints.get(j).latitude);
Logger.d(M_BUS + "Compare左半边集合", "点:"+j+"------------baseDiffDis = "+baseDiffDis+"---diff="+diff);
if (baseDiffDis >= diff){
baseDiffDis = diff;
currentIndex = j;
if (j == 0){
latePoints.addAll(mRoutePoints);
}
}else {
latePoints.addAll(mRoutePoints.subList(currentIndex,mRoutePoints.size()-1));
return latePoints;
}
}
}else {
Logger.d(M_BUS + "正好相等", "点:"+currentIndex+"------------baseDiffDis = "+baseDiffDis+"---diff="+leftDiffDis);
latePoints.addAll(mRoutePoints.subList(currentIndex,currentIndex));
return latePoints;
}
}
return latePoints;
}
/**
* 简单粗暴 直接比较 todo 需要优化
* @param mRoutePoints
* @param realLon
* @param realLat
* @return
*/
public static List<LatLng> getRemainPointListByCompare(List<LatLng> mRoutePoints,double realLon,double realLat) {
List<LatLng> latePoints = new ArrayList<>();
int currentIndex = 0; //记录疑似点
if (mRoutePoints.size() > 0){
//基础点
LatLng baseLatLng = mRoutePoints.get(0);
float baseDiffDis = CoordinateUtils.calculateLineDistance(realLon,realLat
,baseLatLng.longitude,baseLatLng.latitude);// lon,lat, prelon, prelat
for (int i= 1; i < mRoutePoints.size(); i++){
LatLng latLng = mRoutePoints.get(i);
float diff = CoordinateUtils.calculateLineDistance(realLon,realLat
,latLng.longitude,latLng.latitude);
if (baseDiffDis > diff){
// Logger.d(M_TAXI + "calculateRouteSumLength", "点:"+i+"-------先记录点----- ");
baseDiffDis = diff;
currentIndex = i;
}
}
Logger.d(M_BUS + "calculateRouteSumLength", "点:"+currentIndex+"-------是最近的点------ ");
if (currentIndex == mRoutePoints.size()-1){
latePoints.add(mRoutePoints.get(currentIndex));
}else {
latePoints.addAll(mRoutePoints.subList(currentIndex,mRoutePoints.size()-1));
}
return latePoints;
}
return latePoints;
}
}

View File

@@ -222,13 +222,23 @@
android:textSize="30sp"
app:layout_constraintRight_toRightOf="@id/btnAutopilotDisable"
app:layout_constraintTop_toBottomOf="@id/btnAutopilotRunning" />
<Button
android:id="@+id/btnAutopilotRoute"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#023D35"
android:text="上传全路径"
android:textSize="30sp"
app:layout_constraintRight_toRightOf="@id/btnAutopilotDisable"
app:layout_constraintTop_toBottomOf="@id/btnAutopilotArrive" />
<androidx.constraintlayout.widget.Group
android:id="@+id/groupTestPanel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:constraint_referenced_ids="btnAutopilotArrive,btnAutopilotDisable,btnAutopilotEnable,btnAutopilotRunning"
app:constraint_referenced_ids="btnAutopilotArrive,btnAutopilotDisable,btnAutopilotEnable
,btnAutopilotRunning,btnAutopilotRoute"
tools:visibility="visible" />
<!-- <com.mogo.och.bus.ui.BusTrafficLightView-->