Merge branch 'qa_hengyang_base' into feature/feature_hengyang_base

This commit is contained in:
董宏宇
2021-07-15 17:26:43 +08:00
51 changed files with 800 additions and 1293 deletions

View File

@@ -45,7 +45,7 @@ dependencies {
// 现有的ADAS的通讯SDK需要将里面的东西融合到我们项目中
compileOnly rootProject.ext.dependencies.adasapi
api "com.zhidao.support.adas:high:1.2.0.1"
api "com.zhidao.support.adas:high:1.2.0.2"
annotationProcessor rootProject.ext.dependencies.aroutercompiler
if (Boolean.valueOf(RELEASE)) {

View File

@@ -1,16 +1,11 @@
package com.mogo.module.adas;
import com.google.gson.Gson;
import com.mogo.cloud.passport.MoGoAiCloudClientConfig;
import com.mogo.commons.data.BaseData;
import com.mogo.commons.network.SubscribeImpl;
import com.mogo.module.adas.entity.AutonomousDriveStatusBean;
import com.mogo.module.adas.entity.ReportSiteBean;
import com.mogo.module.adas.entity.WarnMessageModel;
import com.mogo.module.adas.model.AdasServiceModel;
import com.mogo.module.adas.network.IAdasApiService;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.utils.logger.Logger;
import com.mogo.utils.network.RequestOptions;
import com.mogo.utils.network.utils.GsonUtil;
import com.zhidao.autopilotservice.model.AdasAIDLAutopilotArriveModel;
import com.zhidao.autopilotservice.model.AdasAIDLAutopilotStateModel;
@@ -32,14 +27,9 @@ import java.util.concurrent.TimeUnit;
import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import static com.mogo.commons.context.ContextHolderUtil.getContext;
import static com.mogo.module.adas.AdasConstant.getBaseUrl;
/**
@@ -54,8 +44,7 @@ public class AdasEventManager implements OnAdasListener, OnAdasMsgConnectStatusL
private final Gson gson;
private final ArrayList<IAdasDataListener> iAdasEventListeners = new ArrayList<>();
private final ArrayList<AdasStatusListener> iAdasStatusListeners = new ArrayList<>();
private IAdasApiService mAdasApiService;
private final ArrayList<IAdasStatusListener> iAdasStatusListeners = new ArrayList<>();
private Disposable uploadAutopilotStatus;
//自动驾驶状态
private int mCurrentAutopilotStatus = -1;
@@ -65,9 +54,10 @@ public class AdasEventManager implements OnAdasListener, OnAdasMsgConnectStatusL
//自动驾驶状态
private AutopilotStatus.ValuesBean mAutopilotValuesStatus = null;
private IAdasProviderBizListener providerBizListener;
private AdasEventManager() {
gson = GsonUtil.getGson();
mAdasApiService = MogoApisHandler.getInstance().getApis().getNetworkApi().create(IAdasApiService.class, getBaseUrl());
}
public static AdasEventManager getInstance() {
@@ -94,7 +84,7 @@ public class AdasEventManager implements OnAdasListener, OnAdasMsgConnectStatusL
iAdasEventListeners.remove(listener);
}
public void addStatusListener(AdasStatusListener listener) {
public void addStatusListener(IAdasStatusListener listener) {
Logger.d(TAG, "添加adas状态事件监听");
if (iAdasStatusListeners.contains(listener)) {
return;
@@ -102,7 +92,7 @@ public class AdasEventManager implements OnAdasListener, OnAdasMsgConnectStatusL
iAdasStatusListeners.add(listener);
}
public void removeStatusListener(AdasStatusListener listener) {
public void removeStatusListener(IAdasStatusListener listener) {
Logger.d(TAG, "注销adas状态事件监听");
iAdasStatusListeners.remove(listener);
}
@@ -116,15 +106,9 @@ public class AdasEventManager implements OnAdasListener, OnAdasMsgConnectStatusL
public void onWarnMessage(WarnMessageInfo warnMessageInfo) {
Logger.d(TAG, "onWarnMessage " + warnMessageInfo);
//报警model
WarnMessageModel warnMessageModel = null;
for (IAdasDataListener listener : iAdasEventListeners) {
if (listener != null) {
if (warnMessageModel == null) {
warnMessageModel = new WarnMessageModel();
warnMessageModel.setAction(MsgActionType.ACTION_WS_MSG_WARNING_TYPE.getmActionType());
}
warnMessageModel.setValues(warnMessageInfo);
listener.cameraEyeDetectResult(gson.toJson(warnMessageModel));
listener.onWarnMessage(warnMessageInfo);
}
}
}
@@ -144,7 +128,7 @@ public class AdasEventManager implements OnAdasListener, OnAdasMsgConnectStatusL
try {
for (IAdasDataListener listener : iAdasEventListeners) {
if (listener != null) {
listener.cameraEyeDetectResult(gson.toJson(rectInfo));
listener.onRectData(rectInfo);
}
}
} catch (Exception e) {
@@ -236,10 +220,10 @@ public class AdasEventManager implements OnAdasListener, OnAdasMsgConnectStatusL
@Override
public void onAutopilotRoute(AutopilotRoute autopilotRoute) {
if (autopilotRoute.getModels() == null || autopilotRoute.getModels().size() == 0) {
Logger.d(TAG,"onAutopilotRoute is null !");
Logger.d(TAG, "onAutopilotRoute is null !");
return;
}
Logger.d(TAG,"onAutopilotRoute : " + autopilotRoute.toString());
Logger.d(TAG, "onAutopilotRoute : " + autopilotRoute.toString());
for (IAdasDataListener listener : iAdasEventListeners) {
if (listener != null) {
listener.autopilotRoute(autopilotRoute);
@@ -247,10 +231,19 @@ public class AdasEventManager implements OnAdasListener, OnAdasMsgConnectStatusL
}
}
@Override
public void onAutopilotSNRequest() {
if (providerBizListener != null) {
providerBizListener.getDeviceSn();
} else {
Logger.e(TAG, "onAutopilotSNRequest providerBizListener is null");
}
}
@Override
public void onWebSocketConnectSuccess() {
Logger.d(TAG, "webSocket 连接成功");
for (AdasStatusListener listener : iAdasStatusListeners) {
for (IAdasStatusListener listener : iAdasStatusListeners) {
listener.onServiceConnected();
}
updateDriveStatusTask();
@@ -259,7 +252,7 @@ public class AdasEventManager implements OnAdasListener, OnAdasMsgConnectStatusL
@Override
public void onWebSocketConnectFailed() {
Logger.d(TAG, "webSocket 连接失败");
for (AdasStatusListener listener : iAdasStatusListeners) {
for (IAdasStatusListener listener : iAdasStatusListeners) {
listener.onServiceDisconnected();
}
}
@@ -270,65 +263,18 @@ public class AdasEventManager implements OnAdasListener, OnAdasMsgConnectStatusL
.subscribeOn(Schedulers.io())
.unsubscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<Long>() {
@Override
public void accept(@NonNull Long aLong) throws Exception {
updateDriveStatus();
}
});
.subscribe(aLong -> updateDriveStatus());
}
private void updateDriveStatus() {
String sn = MoGoAiCloudClientConfig.getInstance().getSn();
AutonomousDriveStatusBean request = new AutonomousDriveStatusBean(sn, mCurrentAutopilotStatus, mCurrentAutopilotSpeed);
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(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");
}
});
AdasServiceModel.getInstance().updateDriveStatus(mCurrentAutopilotStatus, mCurrentAutopilotSpeed);
}
private 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(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");
}
});
AdasServiceModel.getInstance().reportSite(lon, lat);
}
public AutopilotStatus.ValuesBean getAutopilotValuesStatus(){
public AutopilotStatus.ValuesBean getAutopilotValuesStatus() {
return mAutopilotValuesStatus;
}
@@ -342,5 +288,7 @@ public class AdasEventManager implements OnAdasListener, OnAdasMsgConnectStatusL
return adasAIDLAutopilotStateModel;
}
public void setProviderBizListener(IAdasProviderBizListener listener) {
providerBizListener = listener;
}
}

View File

@@ -31,7 +31,7 @@ public class AdasProvider implements IProvider {
initAdas(context, adasEventManager);
initAutoPilotBusiness(context);
addAdasStatusListener(new AdasStatusListener() {
addAdasStatusListener(new IAdasStatusListener() {
@Override
public void onServiceConnected() {
Logger.d(TAG, "adas statusListener connected & send sn");
@@ -49,6 +49,7 @@ public class AdasProvider implements IProvider {
AdasManager.getInstance().create(context);
AdasManager.getInstance().setOnAdasListener(adasEventManager);
AdasManager.getInstance().setOnAdasConnectStatusListener(adasEventManager);
adasEventManager.setProviderBizListener(this::setBasicInfo);
}
private void initAutoPilotBusiness(Context context) {
@@ -73,11 +74,11 @@ public class AdasProvider implements IProvider {
adasEventManager.removeEventListener(listener);
}
public void addAdasStatusListener(AdasStatusListener listener) {
public void addAdasStatusListener(IAdasStatusListener listener) {
adasEventManager.addStatusListener(listener);
}
public void removeAdasStatusListener(AdasStatusListener listener) {
public void removeAdasStatusListener(IAdasStatusListener listener) {
adasEventManager.removeStatusListener(listener);
}

View File

@@ -1,35 +1,32 @@
package com.mogo.module.adas;
import com.mogo.module.adas.entity.WarnMessageModel;
import com.zhidao.autopilotservice.model.AdasAIDLAutopilotArriveModel;
import com.zhidao.autopilotservice.model.AdasAIDLAutopilotStateModel;
import com.zhidao.autopilotservice.model.AdasAIDLOwnerCarRectModel;
import com.zhidao.autopilotservice.model.AdasAIDLOwnerCarStateModel;
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.LightStatueInfo;
import com.zhidao.support.adas.high.bean.ObstaclesInfo;
import com.zhidao.support.adas.high.bean.RectInfo;
import com.zhidao.support.adas.high.bean.WarnMessageInfo;
import java.util.List;
/**
* Created by XuYong on 2021/4/25 16:52
*/
public interface IAdasDataListener {
default void sendMsg( String msg ){
default void sendMsg(String msg) {
};
default void cameraEyeDetectResult( String detectResult ) {
}
default void selectCarModelUrl( String carStyleUrl ) {
default void onRectData(RectInfo rectInfo) {
}
default void onWarnMessage(WarnMessageInfo warnMessageInfo) {
}
default void selectCarModelUrl(String carStyleUrl) {
}
default void requestGetCarModelListInfo() {
@@ -38,42 +35,41 @@ public interface IAdasDataListener {
default void clickSettingBack() {
}
default void showToast( String msg ) {
default void showToast(String msg) {
}
/**
* 自动驾驶到达站点回调接口
*
* @param autopilotArriveModel
*/
default void autopilotArrive( AdasAIDLAutopilotArriveModel autopilotArriveModel ) {
default void autopilotArrive(AdasAIDLAutopilotArriveModel autopilotArriveModel) {
}
/**
* 自动驾驶路线回调
*
* @param autopilotRoute {@link AutopilotRoute}
*/
default void autopilotRoute(AutopilotRoute autopilotRoute){
default void autopilotRoute(AutopilotRoute autopilotRoute) {
}
/**
* 自车定位信息
*
* @param ownerCarStateInfo
*/
default void ownerCarStateInfo( String ownerCarStateInfo ) {
}
default void notifyOwnerCarState( AdasAIDLOwnerCarStateModel ownerCarStateModel ) {
default void ownerCarStateInfo(String ownerCarStateInfo) {
}
/**
* 自动驾驶状态信息
*
* @param autopilotStatus {@link AutopilotStatus}
*/
default void notifyAutopilotState( AutopilotStatus autopilotStatus ) {
default void notifyAutopilotState(AutopilotStatus autopilotStatus) {
}
default void notifyOwnerCarRect( List<AdasAIDLOwnerCarRectModel> ownerCarStateRectList ) {
}
}

View File

@@ -0,0 +1,6 @@
package com.mogo.module.adas;
public interface IAdasProviderBizListener {
void getDeviceSn();
}

View File

@@ -3,7 +3,7 @@ package com.mogo.module.adas;
/**
* Created by XuYong on 4/28/21 16:19
*/
public interface AdasStatusListener {
public interface IAdasStatusListener {
void onServiceConnected();

View File

@@ -1,10 +1,11 @@
package com.mogo.module.adas.model;
import com.google.gson.Gson;
import com.mogo.cloud.passport.MoGoAiCloudClientConfig;
import com.mogo.commons.data.BaseData;
import com.mogo.commons.network.SubscribeImpl;
import com.mogo.module.adas.entity.AutonomousDriveStatusBean;
import com.mogo.module.adas.entity.ReportDispatchResult;
import com.mogo.module.adas.entity.ReportSiteBean;
import com.mogo.module.adas.entity.ReportedRoute;
import com.mogo.module.adas.network.IAdasApiService;
import com.mogo.module.common.MogoApisHandler;
@@ -14,16 +15,16 @@ import com.mogo.utils.network.utils.GsonUtil;
import com.zhidao.support.adas.high.bean.AutopilotRoute;
import com.zhidao.support.adas.high.bean.AutopilotStatus;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import static com.mogo.commons.context.ContextHolderUtil.getContext;
import static com.mogo.module.adas.AdasConstant.getBaseUrl;
import static com.mogo.module.common.constants.HostConst.DATA_SERVICE_HOST;
public class AdasServiceModel {
@@ -126,7 +127,7 @@ public class AdasServiceModel {
*
* @param dispatchResultType int
*/
public void dispatchResultUpload(int dispatchResultType,IDispatch dispatch) {
public void dispatchResultUpload(int dispatchResultType, IDispatch dispatch) {
String sn = MoGoAiCloudClientConfig.getInstance().getSn();
ReportDispatchResult reportDispatchResult = new ReportDispatchResult(sn, dispatchResultType);
Map<String, Object> map = new HashMap<>();
@@ -157,4 +158,54 @@ public class AdasServiceModel {
});
}
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(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(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

@@ -1,6 +1,7 @@
package com.mogo.module.common.drawer;
import android.os.Build;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
@@ -11,6 +12,7 @@ import com.mogo.map.marker.IMogoMarker;
import com.mogo.map.marker.MogoMarkerOptions;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.constants.DataTypes;
import com.mogo.module.common.drawer.bean.SpeedData;
import com.mogo.module.common.utils.Trigonometric;
import com.mogo.service.adas.entity.ADASRecognizedResult;
@@ -19,6 +21,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import static com.mogo.cloud.socket.entity.SocketDownDataHelper.FROM_ADAS;
@@ -76,6 +79,7 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
* @param resultList
*/
public void renderAdasRecognizedResult(List<ADASRecognizedResult> resultList) {
final long start = System.nanoTime();
if (resultList == null || resultList.isEmpty() || !DebugConfig.isUseAdasRecognize()) {
clearOldMarker();
return;
@@ -100,9 +104,9 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
String uniqueKey = recognizedListResult.uuid;
IMogoMarker marker = mMarkersCaches.remove(uniqueKey);
if (marker != null && !marker.isDestroyed()) {
Log.d(TAG, "发现缓存marker id : " + uniqueKey);
// Log.d(TAG, "发现缓存marker id : " + uniqueKey);
updateCacheMarkerRes(marker, recognizedListResult);
renderAdasOneFrame(true, marker, uniqueKey, recognizedListResult, newAdasRecognizedMarkersCaches);
renderAdasOneFrame(marker, uniqueKey, recognizedListResult, newAdasRecognizedMarkersCaches);
} else {
// 新增添加进差集
newDiffSet.add(recognizedListResult);
@@ -110,37 +114,11 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
}
removeUselessMarker(mMarkersCaches);
removeUselessLastRecord();
// 能复用的 marker 数量
// int cachedMarkerSize = mMarkersCaches.size();
// 需要新增的 marker 数量
Log.d("ADAS数据延时绘制", "查找缓存绘制 cost : " + TimeUnit.NANOSECONDS.toMillis((System.nanoTime() - start)));
int newDiffSetSize = newDiffSet.size();
Log.d(TAG, "原数据量 " + resultList.size() + " 新增marker数量 " + newDiffSetSize);
// 能复用的数量
// int size = Math.min(cachedMarkerSize, newDiffSetSize);
// Log.d(TAG, "原数据量 " + resultList.size() + " 新增marker数量 " + newDiffSetSize);
// 复用过期 marker
if (newDiffSetSize > 0) {
// Iterator<Map.Entry<String, IMogoMarker>> entryIterator = mMarkersCaches.entrySet().iterator();
// for (int i = 0; i < size; i++) {
// ADASRecognizedResult recognizedListResult = newDiffSet.get(i);
// String uniqueKey = recognizedListResult.uuid;
// Map.Entry<String, IMogoMarker> entry = entryIterator.next();
// entryIterator.remove();
// ADASRecognizedResult old = mLastPositions.remove(entry.getKey());
// IMogoMarker marker = entry.getValue();
// if (marker == null) {
// continue;
// }
// // 复用更新marker 3D资源
// if (old == null || old.type != recognizedListResult.type) {
// updateCacheMarkerRes(marker, recognizedListResult);
// }
// Log.d(TAG,"复用marker id : " + uniqueKey);
// renderAdasOneFrame(false, marker, uniqueKey, recognizedListResult, newAdasRecognizedMarkersCaches);
// }
// 复用过后还需新增的 marker
// for (int i = size; i < newDiffSetSize; i++) {
for (int i = 0; i < newDiffSetSize; i++) {
ADASRecognizedResult recognizedListResult = newDiffSet.get(i);
String uniqueKey = recognizedListResult.uuid;
@@ -148,18 +126,15 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
if (marker == null) {
continue;
}
Log.d(TAG, "新增marker id : " + uniqueKey);
renderAdasOneFrame(false, marker, uniqueKey, recognizedListResult, newAdasRecognizedMarkersCaches);
// Log.d(TAG, "新增marker id : " + uniqueKey);
renderAdasOneFrame(marker, uniqueKey, recognizedListResult, newAdasRecognizedMarkersCaches);
}
}
// if (cachedMarkerSize - size > 0) {
// sendMessage(MSG_REMOVE_DIRTY_MARKERS, mMarkersCaches);
// }
sendMessage(MSG_REMOVE_DIRTY_MARKERS, mMarkersCaches);
mMarkersCaches.clear();
mMarkersCaches = newAdasRecognizedMarkersCaches;
Log.d(TAG, "更新缓存marker, size : " + mMarkersCaches.size());
// Log.d(TAG, "更新缓存marker, size : " + mMarkersCaches.size());
Log.d("ADAS数据延时绘制", "render 接收数据 -> 处理结束 " + TimeUnit.NANOSECONDS.toMillis((System.nanoTime() - start)) + "ms");
}
/**
@@ -242,7 +217,7 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
while (iterator.hasNext()) {
ADASRecognizedResult result = iterator.next();
long internal = result.satelliteTime - getCurSatelliteTime();
if (internal > 300) {
if (internal > 3000) { //防止帧率过低导致误删除上一个节点对象,从而出现跳跃现象
iterator.remove();
}
}
@@ -271,14 +246,14 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
* @param recognizedListResult {@link ADASRecognizedResult}
* @param newAdasRecognizedMarkersCaches 缓存集合
*/
private void renderAdasOneFrame(boolean useCache, IMogoMarker marker,
private void renderAdasOneFrame(IMogoMarker marker,
String uniqueKey,
ADASRecognizedResult recognizedListResult,
Map<String, IMogoMarker> newAdasRecognizedMarkersCaches) {
final long start = System.currentTimeMillis();
Log.d(TAG, "renderAdasOneFrame uuid : " + uniqueKey + " type : " + recognizedListResult.type);
final long start = System.nanoTime();
// Log.d(TAG, "renderAdasOneFrame uuid : " + uniqueKey + " type : " + recognizedListResult.type + " heading : " + recognizedListResult.heading);
ADASRecognizedResult lastPosition = mLastPositions.remove(uniqueKey);
// 道路吸附
// double lastLon = -1;
// double lastLat = -1;
// if (lastPosition != null) {
@@ -292,19 +267,17 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
// Log.d( "matchRoad", "cost = %s", System.currentTimeMillis() - start );
mLastPositions.put(uniqueKey, recognizedListResult);
if (useCache) {
Log.d(TAG, "使用缓存 id : " + uniqueKey);
long interval = computeAnimDuration(lastPosition.systemTime, recognizedListResult.systemTime, lastPosition.satelliteTime, recognizedListResult.satelliteTime);
final MogoLatLng renderLoc = new MogoLatLng(recognizedListResult.lat, recognizedListResult.lon);
long cost = System.currentTimeMillis() - start;
final long intervalRef = interval - cost;
marker.addDynamicAnchorPosition(renderLoc, (float) recognizedListResult.heading, intervalRef);
} else {
Log.d(TAG, "未使用缓存 id : " + uniqueKey);
marker.setRotateAngle(((float) recognizedListResult.heading));
marker.setPosition(recognizedListResult.lat, recognizedListResult.lon);
// Log.d(TAG, "使用缓存 id : " + uniqueKey);
long interval = 45;
if (lastPosition != null) {
interval = computeAnimDuration(lastPosition.satelliteTime, recognizedListResult.satelliteTime);
}
final MogoLatLng renderLoc = new MogoLatLng(recognizedListResult.lat, recognizedListResult.lon);
long cost = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start);
Log.d("ADAS动画数据","cost : " + cost);
final long intervalRef = interval - cost;
Log.d("ADAS动画数据", "最终赋值 : " + intervalRef + " 两帧间隔 : " + interval + " uuid : " + recognizedListResult.uuid);
marker.addDynamicAnchorPosition(renderLoc, (float) recognizedListResult.heading, intervalRef);
String carColor = recognizedListResult.color;
if (TextUtils.isEmpty(carColor)) {
carColor = getModelRenderColor(recognizedListResult.type, FROM_ADAS, recognizedListResult.speed, recognizedListResult.lon, recognizedListResult.lat, recognizedListResult.heading);
@@ -313,9 +286,18 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
newAdasRecognizedMarkersCaches.put(uniqueKey, marker);
// if (shouldShowSpeed(recognizedListResult.type)) {
// showSelfSpeed(marker, recognizedListResult.speed, recognizedListResult.uuid, recognizedListResult.type, recognizedListResult.heading, MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode());
// }
if (shouldShowSpeed(recognizedListResult.type)) {
Message msg = mRenderThreadHandler.obtainMessage();
msg.obj = new SpeedData(marker
, recognizedListResult.speed
, recognizedListResult.uuid
, recognizedListResult.type
, recognizedListResult.heading
, MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode());
msg.what = MSG_DISPLAY_SPEED;
msg.sendToTarget();
}
Log.d("ADAS数据延时", "render 刷新一台车 cost : " + TimeUnit.NANOSECONDS.toMillis((System.nanoTime() - start)));
}
/**
@@ -325,6 +307,7 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
* @return {@link IMogoMarker}
*/
private IMogoMarker drawAdasRecognizedDataMarker(ADASRecognizedResult recognizedListResult) {
long start = System.nanoTime();
if (recognizedListResult == null) {
return null;
}
@@ -349,6 +332,7 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
.position(new MogoLatLng(recognizedListResult.lat, recognizedListResult.lon));
IMogoMarker marker = MogoApisHandler.getInstance().getApis().getMapServiceApi().getMarkerManager(mContext).addMarker(DataTypes.TYPE_MARKER_ADAS, options);
cacheMarkerIconResMd5Val(resIdVal, marker);
Log.d("ADAS数据延时", "创建一个新 marker cost : " + TimeUnit.NANOSECONDS.toMillis((System.nanoTime() - start)));
return marker;
}

View File

@@ -15,18 +15,19 @@ import com.mogo.map.marker.IMogoMarker;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.R;
import com.mogo.module.common.constants.AdasRecognizedType;
import com.mogo.module.common.drawer.bean.SpeedData;
import com.mogo.module.common.uploadintime.SnapshotLocationController;
import com.mogo.utils.WorkThreadHandler;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import static com.mogo.cloud.socket.entity.SocketDownDataHelper.FROM_ADAS;
import static com.mogo.cloud.socket.entity.SocketDownDataHelper.FROM_MY_LOCATION;
import static com.mogo.cloud.socket.entity.SocketDownDataHelper.FROM_ROAD_UNIT;
import static com.mogo.module.common.constants.DataTypes.TYPE_MARKER_ADAS;
import static com.mogo.module.common.constants.DataTypes.TYPE_MARKER_CLOUD_DATA;
import static java.lang.Math.PI;
@@ -48,6 +49,11 @@ class BaseDrawer {
*/
public static final int MAP_RENDER_FRAME_FREQUENCY = 30;
/**
* 显示速度
*/
public static final int MSG_DISPLAY_SPEED = 11;
/**
* 移动点的时间间隔
*/
@@ -60,7 +66,7 @@ class BaseDrawer {
protected final Context mContext;
private TextView mSpeedView;
private static TextView mSpeedView;
public BaseDrawer() {
mContext = AbsMogoApplication.getApp();
@@ -79,6 +85,7 @@ class BaseDrawer {
}
private static Handler mWorkThreadHandler;
protected static Handler mRenderThreadHandler = null;
/**
* 处理 marker 移除的线程
@@ -107,6 +114,29 @@ class BaseDrawer {
}
};
}
if (mRenderThreadHandler == null) {
mRenderThreadHandler = new Handler(WorkThreadHandler.newInstance("render-thread-" + new Random().nextLong()).getLooper()) {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (msg.what == MSG_DISPLAY_SPEED) {
if (msg.obj instanceof SpeedData) {
showSpeed((SpeedData) msg.obj);
}
}
}
};
}
}
private static void showSpeed(SpeedData speedData) {
showSelfSpeed(speedData.getMarker()
, speedData.getSpeed()
, speedData.getUuid()
, speedData.getType()
, speedData.getHeading()
, speedData.getIsVrMode());
}
/**
@@ -179,7 +209,8 @@ class BaseDrawer {
public int getModelRes(int type) {
AdasRecognizedType recognizedType = AdasRecognizedType.valueFrom(type);
if (recognizedType == AdasRecognizedType.classIdCar) {
return R.raw.othercar;
// TODO 这里临时替换模型解决穿模现象
return R.raw.tachexiaoche;
} else if (recognizedType == AdasRecognizedType.classIdTrafficBus) {
return R.raw.bus;
} else if (recognizedType == AdasRecognizedType.classIdMoto) {
@@ -193,15 +224,16 @@ class BaseDrawer {
} else if (recognizedType == AdasRecognizedType.classIdBicycle) {
return R.raw.zixingche;
} else if (recognizedType == AdasRecognizedType.classIdTrafficTruck) {
return R.raw.kache;
// TODO 这里临时替换模型解决穿模现象
return R.raw.daba;
}
return R.raw.people;
}
/**
* 根据速度、经纬度计算距离判断车辆颜色
* 根据数据源判断车辆预警颜色
*
* @param speed 车速 TODO 这里很可能是adas的策略
* @param speed 车速
* @param lon 经度
* @param lat 纬度
* @return 实际车辆颜色
@@ -211,45 +243,8 @@ class BaseDrawer {
// AdasRecognizedType recognizedType = AdasRecognizedType.valueFrom(type);
// if (recognizedType == AdasRecognizedType.classIdUnKnow) {
// return Car3DModelColor.Normal.color;
// }
// 距离策略 todo 此处两种策略是临时方案
// double[] coordinates = getCurCoordinates();
// double distance = CoordinateUtils.calculateLineDistance(lon, lat, coordinates[0], coordinates[1]) * 100;
// if (distance < 15) {
// return Car3DModelColor.Dangerous.color; // todo 方案1
//// return Car3DTestModelColor.getTestModelColor(fromType, Waring_Dangerous); // todo 方案2
// } else if (distance < 50 && distance >= 15) {
// return Car3DModelColor.Warming.color; // todo 方案1
//// return Car3DTestModelColor.getTestModelColor(fromType, Waring_Close); // todo 方案2
// }
// 他车车速和自车车速对比速度策略
// 自车速度 >= 50% 危险
// 10% < 自车速度 < 50% 警告
// double curSpeed = getCurSpeed();
// if (curSpeed > 0 && speed > curSpeed) {
// double rate = ((speed - curSpeed) / curSpeed) * 100;
// if (rate >= 50) {
// return Car3DModelColor.Dangerous.color; // todo 方案1
//// return Car3DTestModelColor.getTestModelColor(fromType, Waring_Dangerous); // todo 方案2
// } else if (rate > 10 && rate < 50) {
// return Car3DModelColor.Warming.color; // todo 方案1
//// return Car3DTestModelColor.getTestModelColor(fromType, Waring_Close); // todo 方案2
// }
// }
// 默认颜色 // todo 方案1
// switch (fromType) {
// case FROM_ADAS:
// return Car3DModelColor.Normal_Visual.color;
// case FROM_ROAD_UNIT:
// return Car3DModelColor.Normal_Cloud.color;
// default:
// return Car3DModelColor.Normal.color;
// }
return Car3DModelColor.Normal.color;
// todo 方案2
// return Car3DTestModelColor.getTestModelColor(fromType, Waring_Normal);
}
/**
@@ -312,7 +307,6 @@ class BaseDrawer {
Dangerous_Visual("#FF91B7F1"),
Dangerous_Cloud("#FF260FEC");
private int fromType;
private final String color;
Car3DModelColor(String color) {
@@ -321,47 +315,6 @@ class BaseDrawer {
}
public static final int Waring_Normal = 0;
public static final int Waring_Close = 1;
public static final int Waring_Dangerous = 2;
/**
* 模型颜色
*/
public enum Car3DTestModelColor {
Normal_Type(FROM_MY_LOCATION, Waring_Normal, "#D8D8D8FF"),
Normal_Type_Visual(FROM_ADAS, Waring_Normal, "#D8CFF8BD"),
Normal_Type_Cloud(FROM_ROAD_UNIT, Waring_Normal, "#D8F83F94"),
Warming_Type(FROM_MY_LOCATION, Waring_Close, "#FFD53EFF"),
Warming_Type_Visual(FROM_ADAS, Waring_Close, "#FFC192F1"),
Warming_Type_Cloud(FROM_ROAD_UNIT, Waring_Close, "#FFEF09AD"),
Dangerous_Type(FROM_MY_LOCATION, Waring_Dangerous, "#FF3C45FF"),
Dangerous_Type_Visual(FROM_ADAS, Waring_Dangerous, "#FF91B7F1"),
Dangerous_Type_Cloud(FROM_ROAD_UNIT, Waring_Dangerous, "#FF260FEC");
private final int fromType;
private final int waringType;
private final String color;
Car3DTestModelColor(int fromType, int waringType, String color) {
this.fromType = fromType;
this.waringType = waringType;
this.color = color;
}
public static String getTestModelColor(int fromType, int waringType) {
for (Car3DTestModelColor value : Car3DTestModelColor.values()) {
if (value.fromType == fromType && value.waringType == waringType) {
return value.color;
}
}
return Normal_Type.color;
}
}
/**
* 展示车辆速度
*
@@ -369,7 +322,7 @@ class BaseDrawer {
* @param speed 是否显示速度
* @param isVrMode 是否是vrMode
*/
public void showSelfSpeed(IMogoMarker mogoMarker, double speed, String uuid, int type, double heading, boolean isVrMode) {
public static void showSelfSpeed(IMogoMarker mogoMarker, double speed, String uuid, int type, double heading, boolean isVrMode) {
Log.d("EmArrow", "showSelf uuid : " + uuid + " speed : " + speed);
if (mogoMarker == null || mogoMarker.isDestroyed()) {
return;
@@ -384,7 +337,8 @@ class BaseDrawer {
return;
}
mogoMarker.setInfoWindowOffset(0, 20);
String text = "speed : " + speedIntVal + "\n" + uuid + "\n" + "type : " + type + "\n" + "heading : " + heading;
// String text = "speed : " + speedIntVal + "\n" + uuid + "\n" + "type : " + type + "\n" + "heading : " + heading;
String text = uuid + " " + (int) heading;
mSpeedView.setText(text);
mogoMarker.updateInfoWindowView(mSpeedView);
}
@@ -461,16 +415,18 @@ class BaseDrawer {
/**
* 使用系统时间或卫星时间计算出动画的运动时间最小值45防止两个点距离过近设置的最小动画执行时间
*
* @param lastSystemTime 上一个点系统时间,误差值
* @param curSystemTime 当前点系统时间,误差值
* @param lastSatelliteTime 上一个点SNTP时间精确值
* @param curSatelliteTime 当前点SNTP时间精确值
* @return 动画运动时间
*/
public long computeAnimDuration(long lastSystemTime, long curSystemTime, long lastSatelliteTime, long curSatelliteTime) {
long systemTimeInterval = curSystemTime - lastSystemTime;
long satelliteTimeInterval = curSatelliteTime - lastSatelliteTime;
long interval = systemTimeInterval < satelliteTimeInterval || satelliteTimeInterval == 0 ? systemTimeInterval : satelliteTimeInterval;
public long computeAnimDuration(long lastSatelliteTime, long curSatelliteTime) {
if (lastSatelliteTime == 0 || curSatelliteTime == 0) {
Log.d("ADAS动画数据", "卫星时间存在错误");
return 45;
}
long interval = curSatelliteTime - lastSatelliteTime;
Log.d("ADAS动画数据", "lastSatelliteTime : " + lastSatelliteTime +
" ---- curSatelliteTime : " + curSatelliteTime + " ===== 插值 " + interval);
if (interval < 45) {
interval = 45;
}

View File

@@ -1,6 +1,7 @@
package com.mogo.module.common.drawer;
import android.os.Build;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
@@ -19,6 +20,7 @@ import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.R;
import com.mogo.module.common.api.CallChatApi;
import com.mogo.module.common.constants.DataTypes;
import com.mogo.module.common.drawer.bean.SpeedData;
import com.mogo.module.common.utils.Trigonometric;
import com.mogo.service.adas.IMogoADASController;
import com.mogo.service.statusmanager.IMogoStatusChangedListener;
@@ -263,7 +265,7 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
while (iterator.hasNext()) {
SocketDownData.CloudRoadDataProto result = iterator.next();
long internal = result.getSatelliteTime() - Long.parseLong(adasControllerApi.getSatelliteTime());
if (internal > 300) {
if (internal > 3000) {
iterator.remove();
}
}
@@ -318,7 +320,7 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
mLastPositions.put(uniqueKey, cloudRoadData);
if (useCache) {
long interval = computeAnimDuration(lastPosition.getSystemTime(), cloudRoadData.getSystemTime(), lastPosition.getSatelliteTime(), cloudRoadData.getSatelliteTime());
long interval = computeAnimDuration(lastPosition.getSatelliteTime(), cloudRoadData.getSatelliteTime());
final MogoLatLng point = new MogoLatLng(cloudRoadData.getWgslat(), cloudRoadData.getWgslon());
long cost = System.currentTimeMillis() - start;
@@ -328,12 +330,19 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
marker.setRotateAngle(((float) cloudRoadData.getHeading()));
marker.setPosition(cloudRoadData.getWgslat(), cloudRoadData.getWgslon());
}
marker.setAnchorColor(getModelRenderColor(cloudRoadData.getType(), cloudRoadData.getFromType(), cloudRoadData.getSpeed(), cloudRoadData.getWgslon(), cloudRoadData.getWgslat(), cloudRoadData.getHeading()));
newSnapshotCaches.put(uniqueKey, marker);
marker.setAnchorColor(getModelRenderColor(cloudRoadData.getType(), cloudRoadData.getFromType(), cloudRoadData.getSpeed(), cloudRoadData.getWgslon(), cloudRoadData.getWgslat(), cloudRoadData.getHeading()));
if (shouldShowSpeed(cloudRoadData.getType())) {
showSelfSpeed(marker, cloudRoadData.getSpeed(), cloudRoadData.getUuid(), cloudRoadData.getType(), cloudRoadData.getHeading(), MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode());
Message msg = mRenderThreadHandler.obtainMessage();
msg.obj = new SpeedData(marker
, cloudRoadData.getSpeed()
, cloudRoadData.getUuid()
, cloudRoadData.getType()
, cloudRoadData.getHeading()
, MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode());
msg.what = MSG_DISPLAY_SPEED;
msg.sendToTarget();
}
}

View File

@@ -80,17 +80,15 @@ public class V2XWarnDataDrawer extends BaseDrawer implements IMogoStatusChangedL
*/
public void renderWarnData(V2XWarningEntity data) {
MarkerLocation location = new MarkerLocation();
location.setLat(data.getDirection() == 1 ? data.getStopLines().get(0).lat : data.getLat());
location.setLon(data.getDirection() == 1 ? data.getStopLines().get(0).lon : data.getLon());
location.setLat(data.getLat());
location.setLon(data.getLon());
MarkerShowEntity markerShowEntity = new MarkerShowEntity();
markerShowEntity.setMarkerLocation(location);
markerShowEntity.setMarkerType(TYPE_MARKER_CLOUD_WARN_DATA);
IMogoMarker marker = drawMarker(markerShowEntity, modeResType(data.getType()));
//识别物
marker.addDynamicAnchorPosition(new MogoLatLng(
data.getDirection() == 1 ? data.getStopLines().get(1).lat : data.getCollisionLat(),
data.getDirection() == 1 ? data.getStopLines().get(1).lon : data.getCollisionLon()), (float) data.getHeading(), 5000);
marker.addDynamicAnchorPosition(new MogoLatLng(data.getCollisionLat(), data.getCollisionLon()), (float) data.getHeading(), 5000);
//移动完成以后3s后消失
UiThreadHandler.postDelayed(() -> {
marker.remove();
@@ -98,19 +96,16 @@ public class V2XWarnDataDrawer extends BaseDrawer implements IMogoStatusChangedL
}
//根据识别物类型 (行人0/自行车1/摩托车2/小汽车3/公交车4)获取3D模型(对应查看getModelRes)
//根据识别物类型 (行人1/自行车2/摩托车4/骑行车辆11)获取3D模型(对应查看getModelRes)
private int modeResType(int dataType) {
switch (dataType) {
case 0:
return 1;
case 1:
return 2;
case 11:
return 1;
case 2:
return 4;
case 3:
return 3;
return 2;
case 4:
return 6;
return 4;
}
return 1;
}

View File

@@ -0,0 +1,73 @@
package com.mogo.module.common.drawer.bean;
import com.mogo.map.marker.IMogoMarker;
/**
* 速度显示对象
*/
public class SpeedData {
public IMogoMarker marker;
public double speed;
public String uuid;
public int type;
public double heading;
public boolean isVrMode;
public SpeedData(IMogoMarker marker, double speed, String uuid, int type, double heading, boolean isVrMode) {
this.marker = marker;
this.speed = speed;
this.uuid = uuid;
this.type = type;
this.heading = heading;
this.isVrMode = isVrMode;
}
public IMogoMarker getMarker() {
return marker;
}
public void setMarker(IMogoMarker marker) {
this.marker = marker;
}
public double getSpeed() {
return speed;
}
public void setSpeed(double speed) {
this.speed = speed;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public double getHeading() {
return heading;
}
public void setHeading(double heading) {
this.heading = heading;
}
public boolean getIsVrMode() {
return isVrMode;
}
public void setIsVrMode(boolean isVrMode) {
this.isVrMode = isVrMode;
}
}

View File

@@ -12,7 +12,7 @@ import java.util.List;
*/
public class V2XWarningEntity implements Serializable {
//事件类型 行人0/自行车1/摩托车2/小汽车3/公交车4
//事件类型 行人1/自行车2/摩托车4/骑行车辆11
private int type;
//目标物位置
private double lat;

Binary file not shown.

View File

@@ -3,8 +3,8 @@
<dimen name="dp_32">42px</dimen>
<dimen name="module_v2n_tip_width">628px</dimen>
<dimen name="module_v2n_tip_height">188px</dimen>
<dimen name="module_v2n_tip_text_width">106px</dimen>
<dimen name="module_v2n_tip_text_margin_right">52px</dimen>
<dimen name="module_v2n_tip_text_width">120px</dimen>
<dimen name="module_v2n_tip_text_margin_right">26px</dimen>
<dimen name="module_v2n_image_margin_left">37px</dimen>
<dimen name="module_v2x_brake_tip_width">435px</dimen>
<dimen name="module_v2x_brake_tip_height">186px</dimen>

View File

@@ -49,6 +49,7 @@ import com.mogo.map.uicontroller.EnumMapUI;
import com.mogo.map.uicontroller.IMogoMapUIController;
import com.mogo.map.uicontroller.VisualAngleMode;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.constants.DataTypes;
import com.mogo.module.common.dialog.WMDialog;
import com.mogo.module.common.glide.SkinAbleBitmapTarget;
import com.mogo.module.common.map.CustomNaviInterrupter;
@@ -963,7 +964,7 @@ public class EntranceFragment extends MvpFragment<EntranceView, EntrancePresente
}
}
private int[] heights = new int[]{100, 200, 300};
private final int[] heights = new int[]{100, 200, 300};
private int currentHeight;
private void debugTopView() {
@@ -1363,7 +1364,7 @@ public class EntranceFragment extends MvpFragment<EntranceView, EntrancePresente
.getMapUIController().changeMapVisualAngle(VisualAngleMode.MODE_MEDIUM_SIGHT, null);
mSwitchText.setText(R.string.module_map_model_normal);
} else if (MogoApisHandler.getInstance().getApis().getMapServiceApi().getMapUIController().getCurrentMapVisualAngle().isMediumSight()) {
MogoApisHandler.getInstance().getApis().getMapServiceApi().getMarkerManager(AbsMogoApplication.getApp()).inVisibleAllMarkers();
MogoApisHandler.getInstance().getApis().getMapServiceApi().getMarkerManager(AbsMogoApplication.getApp()).inVisibleWithoutMarkers(DataTypes.TYPE_MARKER_ADAS);
MogoApisHandler.getInstance().getApis().getMapServiceApi()
.getMapUIController().changeMapVisualAngle(VisualAngleMode.MODE_LONG_SIGHT, null);
mSwitchText.setText(R.string.module_map_model_faster);

View File

@@ -341,7 +341,7 @@ public class MockIntentHandler implements IntentHandler {
MarkerServiceHandler.getApis().getRefreshStrategyControllerApi().restartAutoRefreshAtTime(duration);
IMogoMarker marker = MarkerServiceHandler.getMarkerManager().addMarker(TAG, options);
MarkerServiceHandler.getMogoStatusManager().setUserInteractionStatus(TAG, true, false);
if(!MarkerServiceHandler.getApis().getStatusManagerApi().isVrMode()){
if (!MarkerServiceHandler.getApis().getStatusManagerApi().isVrMode()) {
MarkerServiceHandler.getMapUIController().moveToCenter(mogoLatLngs.get(0));
}
WorkThreadHandler.getInstance().post(() -> marker.startSmooth(mogoLatLngs, duration));
@@ -652,7 +652,7 @@ public class MockIntentHandler implements IntentHandler {
String carsLine = roadSizeBr.readLine();
SocketDownData.LauncherSnapshotProto.Builder data = SocketDownData.LauncherSnapshotProto.newBuilder();
List<SocketDownData.CloudRoadDataProto> allList = GsonUtil.arrayFromJson(carsLine, SocketDownData.CloudRoadDataProto.class);
if(allList == null || allList.size() == 0){
if (allList == null || allList.size() == 0) {
return;
}
for (SocketDownData.CloudRoadDataProto cloudRoadData : allList) {
@@ -854,7 +854,7 @@ public class MockIntentHandler implements IntentHandler {
Log.i("mock-timer-loc-map", "cost " + (System.currentTimeMillis() - start) + "ms");
SnapshotLocationController.getInstance().syncAdasLocationInfo(jo);
Log.i("mock-timer-loc", "cost " + (System.currentTimeMillis() - start) + "ms");
Log.i("mock-timer-loc-info",jo.toString());
Log.i("mock-timer-loc-info", jo.toString());
return true;
}
@@ -917,10 +917,7 @@ public class MockIntentHandler implements IntentHandler {
}
}
AdasRec adasRec = new AdasRec();
adasRec.models = allList;
MogoApisHandler.getInstance().getApis().getAdasControllerApi().mockAdasRecognized(GsonUtil.jsonFromObject(adasRec));
MogoApisHandler.getInstance().getApis().getAdasControllerApi().mockAdasRecognized(allList);
Log.i("mock-timer-adas", "cost " + (System.currentTimeMillis() - start) + "ms");
return true;
}
@@ -947,16 +944,9 @@ public class MockIntentHandler implements IntentHandler {
}
}
AdasRec adasRec = new AdasRec();
adasRec.models = allList;
MogoApisHandler.getInstance().getApis().getAdasControllerApi().mockAdasRecognized(GsonUtil.jsonFromObject(adasRec));
MogoApisHandler.getInstance().getApis().getAdasControllerApi().mockAdasRecognized(allList);
Log.i("mock-timer-adas", "cost " + (System.currentTimeMillis() - start) + "ms");
return true;
}
public static class AdasRec {
public String action = "view";
public List<ADASRecognizedResult> models;
}
}

View File

@@ -1,46 +1,39 @@
package com.mogo.module.small.map;
import android.content.Context;
import android.graphics.Color;
import android.graphics.BitmapFactory;
import android.location.Location;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import androidx.annotation.Nullable;
import com.alibaba.android.arouter.thread.CancelableCountDownLatch;
import com.amap.api.maps.AMap;
import com.amap.api.maps.CameraUpdate;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.TextureMapView;
import com.amap.api.maps.UiSettings;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.CameraPosition;
import com.amap.api.maps.model.CustomMapStyleOptions;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.LatLngBounds;
import com.amap.api.maps.model.Marker;
import com.amap.api.maps.model.MarkerOptions;
import com.amap.api.maps.model.Polyline;
import com.amap.api.maps.model.PolylineOptions;
import com.mogo.cloud.commons.utils.CoordinateUtils;
import com.amap.api.navi.AMapNavi;
import com.amap.api.navi.AMapNaviView;
import com.amap.api.navi.AMapNaviViewOptions;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.commons.debug.DebugConfig;
import com.mogo.map.MogoLatLng;
import com.mogo.map.navi.IMogoCarLocationChangedListener2;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.view.RoundLayout;
import com.mogo.module.small.map.animation.DirectionRotateAnimation;
import com.mogo.module.small.map.utils.MapAssetStyleUtils;
import com.mogo.module.small.map.view.ISmallMapDirectionView;
import com.mogo.utils.logger.Logger;
import java.util.ArrayList;
import java.util.List;
import ch.hsr.geohash.GeoHash;
/**
* 小地图的方向View
*
@@ -55,17 +48,14 @@ public class SmallMapDirectionView
public static final String MODULE_NAME = "SmallMap";
private RoundLayout rlSmallMapBorder;
private TextureMapView mAMapNaviView;
private AMap mAMap;
private Marker mCarMarker;
private Marker mStartMarker;
private Marker mEndMarker;
private ImageView mIvMapBorder;
private DirectionRotateAnimation mRotateAnimation;
private int lastAngle = 0;
private int zoomLevel = 13;
private List<LatLng> mCoordinatesLatLng = new ArrayList<>();
private List<MogoLatLng> mCoordinatesLatLngCurrent = new ArrayList<>();
private Polyline mPolyline;
private CameraUpdate mCameraUpdate;
private AMapNaviView mAMapNaviView;
private AMap mAMap;
private AMapNavi mAMapNavi;
private int zoomLevel = 15;
public SmallMapDirectionView(Context context) {
this(context, null);
@@ -85,11 +75,15 @@ public class SmallMapDirectionView
}
private void initView(Context context) {
mRotateAnimation = new DirectionRotateAnimation(context, null);
LayoutInflater.from(context).inflate(R.layout.module_small_map_view, this);
mAMapNaviView = AbsMogoApplication.getMapNaviView();
rlSmallMapBorder = findViewById(R.id.rlSmallMapBorder);
rlSmallMapBorder.addView(mAMapNaviView);
mIvMapBorder = findViewById(R.id.ivMapBorder);
initAMapView();
@@ -122,7 +116,10 @@ public class SmallMapDirectionView
}
private void initAMapView() {
mCameraUpdate = CameraUpdateFactory.zoomTo(zoomLevel);
// 车头朝上
mAMapNaviView.setNaviMode(AMapNaviView.CAR_UP_MODE);
// 设置电子眼所在路线的可见性
mAMapNaviView.setRouteOverlayVisible(false);
mAMap = mAMapNaviView.getMap();
// 关闭地图文字标注
mAMap.showMapText(false);
@@ -130,15 +127,26 @@ public class SmallMapDirectionView
mAMap.setMapType(AMap.MAP_TYPE_NIGHT);
// 关闭显示实时路况图层aMap是地图控制器对象。
mAMap.setTrafficEnabled(false);
mAMap.setOnCameraChangeListener(new AMap.OnCameraChangeListener() {
@Override
public void onCameraChange(CameraPosition cameraPosition) {
if (cameraPosition != null) {
//Log.w("onCameraChange", "cameraPosition=" + cameraPosition.bearing);
changeAngle((int) cameraPosition.bearing);
}
}
@Override
public void onCameraChangeFinish(CameraPosition cameraPosition) {
}
});
mAMapNavi = AMapNavi.getInstance(getContext());
//使用外部GPS数据
mAMapNavi.setIsUseExtraGPSData(true);
// 设置 锚点 图标
mCarMarker = mAMap.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.module_small_map_view_my_location_logo))
.anchor(0.5f, 0.5f));
mStartMarker = mAMap.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.module_small_map_view_dir_start)));
mEndMarker = mAMap.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.module_small_map_view_dir_end)));
new Thread(() -> {
try {
@@ -154,7 +162,8 @@ public class SmallMapDirectionView
);
//设置希望展示的地图缩放级别
mAMap.moveCamera(mCameraUpdate);
CameraUpdate cameraUpdate = CameraUpdateFactory.zoomTo(zoomLevel);
mAMap.moveCamera(cameraUpdate);
}).start();
// 设置地图的样式
@@ -164,6 +173,70 @@ public class SmallMapDirectionView
uiSettings.setMyLocationButtonEnabled(false); // 显示默认的定位按钮
uiSettings.setLogoBottomMargin(-150); //设置Logo下边界距离屏幕底部的边距,设置为负值即可
// 导航地图
AMapNaviViewOptions options = mAMapNaviView.getViewOptions();
//设置导航界面UI是否显示。
if (options != null) {
// 设置是否开启自动黑夜模式切换默认为false不自动切换
options.setAutoNaviViewNightMode(false);
// 设置6秒后是否自动锁车
options.setAutoLockCar(true);
// 设置路线上的摄像头气泡是否显示
options.setCameraBubbleShow(false);
// 设置路线相关的配置属性,如:路线的路况颜色,路线上是否显示摄像头气泡等。
// options.setRouteOverlayOptions( MapStyleUtils.getRouteOverlayOptions() );
// 设置自车的图片对象
options.setCarBitmap(BitmapFactory.decodeResource(getContext().getResources(),
R.drawable.module_small_map_view_my_location_logo));
// 设置罗盘位图对象
options.setFourCornersBitmap(BitmapFactory.decodeResource(getContext().getResources(),
R.drawable.icon_module_small_map_four_corners));
// 设置指南针图标否在导航界面显示默认显示。true显示false隐藏。
options.setCompassEnabled(false);
//设置路况光柱条是否显示(只适用于驾车导航,需要联网)。
options.setTrafficBarEnabled(false);
// 设置[实时交通图层开关按钮]是否显示(只适用于驾车导航,需要联网)。
options.setTrafficLayerEnabled(false);
// 设置导航界面是否显示路线全览按钮。
options.setRouteListButtonShow(false);
// 设置屏幕是否常亮,默认开启
options.setScreenAlwaysBright(false);
// 设置交通播报是否打开(只适用于驾车导航,需要联网)。
options.setTrafficInfoUpdateEnabled(false);
// 设置摄像头播报是否打开(只适用于驾车导航)。
options.setCameraInfoUpdateEnabled(false);
// 设置菜单按钮是否在导航界面显示。
options.setSettingMenuEnabled(false);
// 设置是否绘制显示交通路况的线路(彩虹线),拥堵-红色,畅通-绿色,缓慢-黄色,未知-蓝色。默认不绘制彩虹线。
options.setTrafficLine(false);
// 设置是否绘制牵引线(当前位置到目的地的指引线)。默认不绘制牵引线。
options.setLeaderLineEnabled(-1);
// 设置导航界面UI是否显示。
options.setLayoutVisible(false);
// 设置是否自动画路
options.setAutoDrawRoute(false);
// 设置是否显示路口放大图(实景图)
options.setRealCrossDisplayShow(false);
// 设置是否显示路口放大图(路口模型图)
options.setModeCrossDisplayShow(false);
// 设置是否显示道路信息view
options.setLaneInfoShow(false);
// 设置是否自动改变缩放等级
options.setAutoChangeZoom(false);
// 设置是否自动全览模式,即在算路成功后自动进入全览模式
options.setAutoDisplayOverview(false);
// 设置路线转向箭头隐藏和显示
options.setNaviArrowVisible(false);
// 通过路线是否自动置灰,仅支持驾车导航
options.setAfterRouteAutoGray(false);
options.setZoom(((int) 10));
//options.setPointToCenter(0.7D, 0.5D);
// 2D模式
options.setTilt(0);
// 黑夜模式
options.setNaviNight(true);
mAMapNaviView.setViewOptions(options);
}
}
@@ -175,44 +248,8 @@ public class SmallMapDirectionView
@Override
public void onCarLocationChanged2(Location latLng) {
Logger.d(MODULE_NAME, "onCarLocationChanged2 latLng:" + latLng);
LatLng currentLatLng = new LatLng(latLng.getLatitude(), latLng.getLongitude());
if (mCarMarker != null) {
mCarMarker.setRotateAngle(360 - latLng.getBearing());
mCarMarker.setPosition(currentLatLng);
mCarMarker.setToTop();
}
if (mCoordinatesLatLng.size() > 1) {
mCoordinatesLatLngCurrent.clear();
for (LatLng lng : mCoordinatesLatLng) {
MogoLatLng mogoLatLng = new MogoLatLng(lng.latitude, lng.longitude);
mCoordinatesLatLngCurrent.add(mogoLatLng);
}
// 结束位置
LatLng endLatLng = mCoordinatesLatLng.get(mCoordinatesLatLng.size() - 1);
// 与结束位置进行 GeoHash 0-12
// GeoHash endGeoHash = GeoHash.withCharacterPrecision(endLatLng.latitude, endLatLng.longitude, 7);
// GeoHash currentGeoHash = GeoHash.withCharacterPrecision(currentLatLng.latitude, currentLatLng.longitude, 7);
// Log.d(MODULE_NAME, "currentGeoHash=" + currentGeoHash);
// Log.d(MODULE_NAME, "endGeoHash=" + endGeoHash);
float calculateDistance = CoordinateUtils.calculateLineDistance(
endLatLng.latitude, endLatLng.longitude,
currentLatLng.latitude, currentLatLng.longitude
);
Log.d(MODULE_NAME, "calculateDistance=" + calculateDistance);
if (calculateDistance <= 20) {
clearPolyline();
} else {
drawablePolyline(mCoordinatesLatLngCurrent);
}
} else {
//设置希望展示的地图缩放级别
mAMap.moveCamera(CameraUpdateFactory.newLatLngZoom(currentLatLng, zoomLevel));
if (mAMapNavi != null) {
mAMapNavi.setExtraGPSData(2, latLng);
}
}
@@ -223,57 +260,39 @@ public class SmallMapDirectionView
@Override
public void drawablePolyline(List<MogoLatLng> coordinates) {
clearPolyline();
mCoordinatesLatLng.clear();
for (MogoLatLng coordinate : coordinates) {
mCoordinatesLatLng.add(new LatLng(coordinate.getLat(), coordinate.getLon()));
}
if (mAMap != null) {
if (mCoordinatesLatLng.size() > 2) {
// 设置开始结束Marker位置
mStartMarker.setPosition(mCoordinatesLatLng.get(0));
mEndMarker.setPosition(mCoordinatesLatLng.get(mCoordinatesLatLng.size() - 1));
mStartMarker.setVisible(true);
mEndMarker.setVisible(true);
//存放所有点的经纬度
LatLngBounds.Builder boundsBuilder = new LatLngBounds.Builder();
for (int i = 0; i < mCoordinatesLatLng.size(); i++) {
//把所有点都include进去LatLng类型
boundsBuilder.include(mCoordinatesLatLng.get(i));
}
//第二个参数为四周留空宽度
mAMap.animateCamera(CameraUpdateFactory.newLatLngBoundsRect(boundsBuilder.build(), 65, 65, 65, 65));
// 绘制线
mPolyline = mAMap.addPolyline(
new PolylineOptions()
.addAll(mCoordinatesLatLng)
.color(Color.argb(255, 31, 127, 255))
.width(5));
} else {
//设置希望展示的地图缩放级别
mAMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mCoordinatesLatLng.get(0), zoomLevel));
}
}
}
@Override
public void clearPolyline() {
mCoordinatesLatLng.clear();
if (mPolyline != null) {
mPolyline.remove();
}
if (mStartMarker != null) {
mStartMarker.setVisible(false);
}
if (mEndMarker != null) {
mEndMarker.setVisible(false);
}
}
/**
* 修改角度
*
* @param angle 角度 0 - 359度旋转,相对于自身中心位置
*/
public void changeAngle(int angle) {
int tempAngle = 360 - angle;
// if (tempAngle <= 180) {
// tempAngle = tempAngle;
// } else {
// tempAngle = -(360 - tempAngle);
// }
mRotateAnimation.setFromDegrees(lastAngle);
mRotateAnimation.setToDegrees(tempAngle);
//设置线性插值,可以解决旋转一圈后卡顿问题
mRotateAnimation.setInterpolator(new LinearInterpolator());
//设置旋转一圈时间
mRotateAnimation.setDuration(300);
//控件动画结束时是否保持动画最后的状态
mRotateAnimation.setFillAfter(true);
mIvMapBorder.startAnimation(mRotateAnimation);
// 刷新最后一次角度
lastAngle = tempAngle;
}
}

View File

@@ -10,7 +10,7 @@
android:layout_width="@dimen/module_small_map_view_border_width"
android:layout_height="@dimen/module_small_map_view_border_width"
android:layout_centerInParent="true"
android:background="@drawable/module_small_map_view_border_north" />
android:background="@drawable/module_small_map_view_border" />
<com.mogo.module.common.view.RoundLayout
android:id="@+id/rlSmallMapBorder"
@@ -30,4 +30,11 @@
android:layout_height="match_parent" />-->
</com.mogo.module.common.view.RoundLayout>
<ImageView
android:id="@+id/ivMapBorder"
android:layout_width="@dimen/module_small_map_border_view_width"
android:layout_height="@dimen/module_small_map_border_view_width"
android:layout_centerInParent="true"
android:src="@drawable/module_small_map_view_border_north" />
</merge>

View File

@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="module_small_map_padding">40px</dimen>
<dimen name="module_small_map_view_border_width">550px</dimen>
<dimen name="module_small_map_view_border_width">400px</dimen>
<dimen name="module_small_map_border_view_width">550px</dimen>
<dimen name="module_small_map_view_width">360px</dimen>
</resources>

View File

@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="module_small_map_padding">30px</dimen>
<dimen name="module_small_map_view_border_width">450px</dimen>
<dimen name="module_small_map_view_border_width">288px</dimen>
<dimen name="module_small_map_border_view_width">450px</dimen>
<dimen name="module_small_map_view_width">260px</dimen>
</resources>

View File

@@ -11,7 +11,6 @@ import com.mogo.map.uicontroller.IMogoMapUIController;
import com.mogo.module.v2x.alarm.V2XCalculateServer;
import com.mogo.module.v2x.manager.IMoGoPersonWarnPolylineManager;
import com.mogo.module.v2x.manager.IMoGoStopPolylineManager;
import com.mogo.module.v2x.manager.IMoGoV2XCloundDataManager;
import com.mogo.module.v2x.manager.IMoGoV2XMarkerManager;
import com.mogo.module.v2x.manager.IMoGoV2XPolylineManager;
import com.mogo.module.v2x.manager.IMoGoV2XStatusManager;
@@ -45,9 +44,6 @@ import com.mogo.service.windowview.IMogoWindowManager;
import com.zhidao.carchattingprovider.CallChattingProviderConstant;
import com.zhidao.carchattingprovider.ICarsChattingProvider;
import java.util.ArrayList;
import java.util.List;
/**
* author : donghongyu
* e-mail : 1358506549@qq.com
@@ -109,7 +105,6 @@ public class V2XServiceManager {
private static IMoGoWarnPolylineManager moGoWarnPolylineManager;
private static IMoGoPersonWarnPolylineManager moGoPersonWarnPolylineManager;
private static IMoGoStopPolylineManager moGoStopPolylineManager;
private static IMoGoV2XCloundDataManager moGoV2XCloundDataManager;
private V2XServiceManager() {
@@ -165,7 +160,6 @@ public class V2XServiceManager {
moGoV2XMarkerManager = (IMoGoV2XMarkerManager) ARouter.getInstance().build(MoGoV2XServicePaths.PATH_V2X_MARKER_MANAGER).navigation(context);
moGoV2XPolylineManager = (IMoGoV2XPolylineManager) ARouter.getInstance().build(MoGoV2XServicePaths.PATH_V2X_POLYLINE_MANAGER).navigation(context);
moGoWarnPolylineManager = (IMoGoWarnPolylineManager) ARouter.getInstance().build(MoGoV2XServicePaths.PATH_V2X_WARN_POLYLINE_MANAGER).navigation(context);
moGoV2XCloundDataManager = (IMoGoV2XCloundDataManager) ARouter.getInstance().build(MoGoV2XServicePaths.PATH_V2X_WARN_CLOUND_DATA_MANAGER).navigation(context);
moGoPersonWarnPolylineManager = (IMoGoPersonWarnPolylineManager) ARouter.getInstance().build(MoGoV2XServicePaths.PATH_V2X_PERSON_WARN_POLYLINE_MANAGER).navigation(context);
moGoStopPolylineManager = (IMoGoStopPolylineManager) ARouter.getInstance().build(MoGoV2XServicePaths.PATH_V2X_STOP_POLYLINE_MANAGER).navigation(context);
@@ -337,14 +331,6 @@ public class V2XServiceManager {
V2XServiceManager.mIMogoADASController = mIMogoADASController;
}
public static IMoGoV2XCloundDataManager getMoGoV2XCloundDataManager() {
return moGoV2XCloundDataManager;
}
public static void setMoGoV2XCloundDataManager(IMoGoV2XCloundDataManager moGoV2XCloundDataManager) {
V2XServiceManager.moGoV2XCloundDataManager = moGoV2XCloundDataManager;
}
public static IMoGoPersonWarnPolylineManager getMoGoPersonWarnPolylineManager() {
return moGoPersonWarnPolylineManager;
}

View File

@@ -1,21 +0,0 @@
package com.mogo.module.v2x.listener;
import com.mogo.module.common.entity.V2XWarningEntity;
import com.mogo.service.connection.IMogoOnMessageListener;
/**
* @author liujing
* @description 车路云—场景预警-云下发数据监听 前车/行人/摩托车/盲区碰撞预警
* @since: 2021/3/31
*/
public class V2XMessageListener_401013 implements IMogoOnMessageListener<V2XWarningEntity> {
@Override
public Class target() {
return null;
}
@Override
public void onMsgReceived(V2XWarningEntity obj) {
}
}

View File

@@ -1,21 +0,0 @@
package com.mogo.module.v2x.manager;
import com.alibaba.android.arouter.facade.template.IProvider;
import com.mogo.module.common.entity.V2XWarningEntity;
/**
* desc: V2X 处理云端预警消息
*/
public interface IMoGoV2XCloundDataManager extends IProvider {
/**
* 处理下发数据
*/
void analysisV2XCloundDataEvent(V2XWarningEntity cloundWarningInfo);
/**
* 清除 所有的 POI
*/
void clearALLPOI();
}

View File

@@ -1,367 +0,0 @@
package com.mogo.module.v2x.manager.impl;
import android.content.Context;
import android.location.Location;
import android.util.Log;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.mogo.cloud.commons.utils.CoordinateUtils;
import com.mogo.map.MogoLatLng;
import com.mogo.map.navi.IMogoCarLocationChangedListener2;
import com.mogo.map.overlay.IMogoPolyline;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.drawer.V2XWarnDataDrawer;
import com.mogo.module.common.entity.V2XWarningEntity;
import com.mogo.module.common.utils.Trigonometric;
import com.mogo.module.service.MarkerServiceHandler;
import com.mogo.module.service.receiver.MogoReceiver;
import com.mogo.module.v2x.MoGoV2XServicePaths;
import com.mogo.module.v2x.V2XConst;
import com.mogo.module.v2x.V2XServiceManager;
import com.mogo.module.v2x.entity.model.DrawLineInfo;
import com.mogo.module.v2x.listener.V2XLocationListener;
import com.mogo.module.v2x.manager.IMoGoV2XCloundDataManager;
import com.mogo.module.v2x.scenario.scene.warning.V2XFrontWarningScenario;
import com.mogo.utils.UiThreadHandler;
import com.mogo.utils.WorkThreadHandler;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static com.mogo.module.common.constants.DataTypes.TYPE_MARKER_CLOUD_STOP_LINE_DATA;
import static com.mogo.module.common.constants.DataTypes.TYPE_MARKER_CLOUD_WARN_DATA;
import static com.mogo.module.common.entity.V2XMessageEntity.V2XTypeEnum.ALERT_THE_FRONT_CRASH_WARNING_TOP;
import static com.mogo.module.v2x.V2XServiceManager.getContext;
/**
* desc : V2X 服务端下发数据处理 点的绘制
*/
@Route(path = MoGoV2XServicePaths.PATH_V2X_WARN_CLOUND_DATA_MANAGER)
public class MoGoV2XCloundDataManager implements IMoGoV2XCloundDataManager, IMogoCarLocationChangedListener2 {
private static String WARNING_ARROWS = "WARNING_ARROWS";
private V2XWarningEntity mCloundWarningInfo;
private static String TAG = "MoGoV2XCloundDataManager";
private boolean isSelfLineClear = true;//绘制线是否已被清除
private List fillPoints = new ArrayList();//停止线经纬度合集
private boolean isFirstLocation = false;
private MogoLatLng carLocation = new MogoLatLng(
MogoApisHandler.getInstance().getApis().getAdasControllerApi().getLastLat(),
MogoApisHandler.getInstance().getApis().getAdasControllerApi().getLastLon()
);
/*
* 自车前方的点,在停止线上--通过自车位置与距离停止线之间的距离计算
* */
private MogoLatLng middleLocationInStopLine;
private V2XFrontWarningScenario mV2XScenario;
private static long showTime = 4000;
private float bearing;
@Override
public void init(Context context) {
MogoApisHandler.getInstance().getApis().getRegisterCenterApi()
.registerCarLocationChangedListener(TAG, this);
}
@Override
public void analysisV2XCloundDataEvent(V2XWarningEntity cloundWarningInfo) {
if (MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode()) {
mCloundWarningInfo = cloundWarningInfo;
showTime = mCloundWarningInfo.getShowTime();
pointsBetween();
bearing = V2XLocationListener.getInstance().getLastCarLocation().getBearing();
//顶部弹框
if (mV2XScenario == null) {
mV2XScenario = new V2XFrontWarningScenario();
}
// mV2XScenario.setWarningEntity(cloundWarningInfo);
mV2XScenario.init(null);
//预警蒙层
MarkerServiceHandler.getApis().getV2XListenerManager().warningChangedForListenerWithDirection(cloundWarningInfo.getDirection(), MogoReceiver.ACTION_V2X_FRONT_WARNING);
isSelfLineClear = false;
isFirstLocation = false;
V2XServiceManager.getMarkerManager().removeMarkers(WARNING_ARROWS);
if (cloundWarningInfo.getDirection() == ALERT_THE_FRONT_CRASH_WARNING_TOP) { //前方 TODO
middleLocationInStopLine = getMiddleLocationInStopLine();
//如果是正前方类型,红色绘制区域从停止线向前绘制50米
MogoLatLng warningLocation = Trigonometric.getNewLocation(middleLocationInStopLine, 50, cloundWarningInfo.getAngle());
//停止线前方画线
WorkThreadHandler.getInstance().postDelayed(() -> {
//二轮车和行人的渲染和移动
V2XServiceManager.getMarkerManager().removeMarkers(TYPE_MARKER_CLOUD_WARN_DATA);
V2XWarnDataDrawer.getInstance().renderWarnData(cloundWarningInfo);
//绘制识别物与交汇点连线,并且更新连线数据
drawRedWarningLineFrontOfStopLine(cloundWarningInfo, middleLocationInStopLine, warningLocation);
//添加停止线marker
handleStopLine();
//自车画线
drawSelfCarLine(carLocation.lon, carLocation.lat, bearing);
}, 500);
UiThreadHandler.postDelayed(() -> {
V2XServiceManager.getMoGoPersonWarnPolylineManager().clearLine();
V2XServiceManager.getMoGoWarnPolylineManager().clearLine();
V2XServiceManager.getMoGoStopPolylineManager().clearLine();
isSelfLineClear = true;
}, showTime);
} else { //左侧或者右侧
WorkThreadHandler.getInstance().postDelayed(() -> {
//绘制识别物与交汇点连线,并且更新连线数据
drawOtherObjectLine(cloundWarningInfo);
//二轮车和行人的渲染和移动
V2XServiceManager.getMarkerManager().removeMarkers(TYPE_MARKER_CLOUD_WARN_DATA);
V2XWarnDataDrawer.getInstance().renderWarnData(cloundWarningInfo);
//车辆静止的时候
drawSelfCarLine(carLocation.lon, carLocation.lat, bearing);
}, 500);
//延迟3秒清理线
UiThreadHandler.postDelayed(() -> {
V2XServiceManager.getMoGoPersonWarnPolylineManager().clearLine();
V2XServiceManager.getMoGoWarnPolylineManager().clearLine();
isSelfLineClear = true;
}, showTime);
}
}
}
/**
* 自车为起点绘制(根据设计,前方行人/弱势交通参与者预警 getDirection() == ALERT_THE_FRONT_CRASH_WARNING_TOP自车与停止线之间为蓝色预警;其他侧方预警自车与预碰撞点之间显示红色预警)
*/
private void drawSelfCarLine(double lon, double lat, float bearing) {
if (!isSelfLineClear) {
IMogoPolyline mogoPolyline = V2XServiceManager.getMoGoWarnPolylineManager().getMogoWarnPolyline();
if (mCloundWarningInfo != null) {
MogoLatLng startLatlng = null;
MogoLatLng endLatlng = null;
MogoLatLng addMiddleLoc = null;
if (!isFirstLocation) {
carLocation = getMogoLat(new MogoLatLng(lat, lon));
isFirstLocation = true;
}
//绘制线的终点(在停止线上或者预碰撞点上)
endLatlng = new MogoLatLng(mCloundWarningInfo.getDirection() == ALERT_THE_FRONT_CRASH_WARNING_TOP ? middleLocationInStopLine.lat : mCloundWarningInfo.getCollisionLat(),
mCloundWarningInfo.getDirection() == ALERT_THE_FRONT_CRASH_WARNING_TOP ? middleLocationInStopLine.lon : mCloundWarningInfo.getCollisionLon());
//自车位置
startLatlng = new MogoLatLng(lat, lon);
float distance = CoordinateUtils.calculateLineDistance(startLatlng.lon, startLatlng.lat, endLatlng.lon, endLatlng.lat);
//扩展点为了渐变色添加
addMiddleLoc = Trigonometric.getNewLocation(startLatlng, distance / 2, Trigonometric.getAngle(startLatlng.lon, startLatlng.lat, endLatlng.lon, endLatlng.lat));
Log.d(TAG, "自车为起点绘制 自车;" + startLatlng.lon + "," + startLatlng.lat +
"中间扩展点" + addMiddleLoc.lon + "," + addMiddleLoc.lat + "终点:" + endLatlng.lon + "," + endLatlng.lat);
if (mogoPolyline != null) {
mogoPolyline.setPoints(Arrays.asList(startLatlng, addMiddleLoc, endLatlng));
mogoPolyline.setTransparency(0.5f);
} else {
DrawLineInfo info = new DrawLineInfo(); // 对象
Log.d(TAG, "安全区域的画线点为" + "起点:" + startLatlng + "中间点:" + addMiddleLoc + "终点:" + endLatlng);
List locations = new ArrayList();
locations.add(startLatlng);
locations.add(addMiddleLoc);
locations.add(endLatlng);
info.setLocations(locations);
info.setHeading(bearing);
info.setWidth(mCloundWarningInfo.getRoadwidth() * 14 + 5);
info.setDirection(mCloundWarningInfo.getDirection());
V2XServiceManager.getMoGoWarnPolylineManager().drawWarnPolyline(getContext(), info);
}
} else {
V2XServiceManager.getMoGoWarnPolylineManager().clearLine();
}
}
}
/*
* 停止线绘制
* */
private void handleStopLine() {
try {
if (mCloundWarningInfo != null) {
V2XServiceManager.getMarkerManager().removeMarkers(TYPE_MARKER_CLOUD_STOP_LINE_DATA);
for (int i = 0; i < fillPoints.size(); i++) {
V2XWarningEntity entity = new V2XWarningEntity();
MogoLatLng latLng = (MogoLatLng) fillPoints.get(i);
entity.setLat(latLng.lat);
entity.setLon(latLng.lon);
entity.heading = mCloundWarningInfo.heading;
V2XWarnDataDrawer.getInstance().renderStopLineData(entity);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 场景如:车辆行驶正前方绘制红色区域(停止线继续前行的预警区域) TODO 需要实时给行人当前位置
*/
private void drawRedWarningLineFrontOfStopLine(V2XWarningEntity info, MogoLatLng
startLatLng, MogoLatLng mogoLatLng) {
if (info != null) {
IMogoPolyline polyLine = V2XServiceManager.getMoGoStopPolylineManager().getMogoStopPolyline();
MogoLatLng endLatlng = new MogoLatLng(mogoLatLng.lat, mogoLatLng.lon);
float distance = CoordinateUtils.calculateLineDistance(startLatLng.lon, startLatLng.lat, endLatlng.lon, endLatlng.lat);
MogoLatLng addMiddleLoc = Trigonometric.getNewLocation(startLatLng, distance / 2, mCloundWarningInfo.getAngle());
Log.d(TAG, "红色区域起始点 = " + startLatLng.lon + "," + startLatLng.lat +
"中间点坐标:" + addMiddleLoc.lon + "," + addMiddleLoc.lat
+ "终点" + endLatlng.lon + "," + endLatlng.lat);
if (polyLine != null) {
Log.d(V2XConst.LOG_NAME_WARN, "drawStopLine polyLine != null");
polyLine.setPoints(Arrays.asList(startLatLng, addMiddleLoc, endLatlng));
polyLine.setTransparency(0.5f);
} else {
DrawLineInfo lineInfo = new DrawLineInfo();
List locations = new ArrayList();
locations.add(startLatLng);
locations.add(addMiddleLoc);
locations.add(endLatlng);
lineInfo.setLocations(locations);
lineInfo.setHeading(info.heading);
Log.d(V2XConst.LOG_NAME_WARN, "drawStopLine width = " + info.getRoadwidth());
lineInfo.setWidth(info.getRoadwidth() * 14 + 5);
V2XServiceManager.getMoGoStopPolylineManager().drawStopPolyline(getContext(), lineInfo);
}
} else {
V2XServiceManager.getMoGoPersonWarnPolylineManager().clearLine();
V2XServiceManager.getMoGoStopPolylineManager().clearLine();
}
}
/**
* 侧方目标物与预碰撞点连线,并且更新数据 TODO 需要实时给行人当前位置
*/
private void drawOtherObjectLine(V2XWarningEntity info) {
if (info != null) {
IMogoPolyline polyLine = V2XServiceManager.getMoGoPersonWarnPolylineManager().getMogoPersonWarnPolyline();
MogoLatLng startLatlng = new MogoLatLng(info.getLat(), info.getLon());//识别物坐标
MogoLatLng endLatlng = new MogoLatLng(info.getCollisionLat(), info.getCollisionLon());//预碰撞点坐标
float distance = CoordinateUtils.calculateLineDistance(startLatlng.lon, startLatlng.lat, endLatlng.lon, endLatlng.lat);//识别物到碰撞点之间的距离
MogoLatLng addMiddleLoc = Trigonometric.getNewLocation(startLatlng, distance / 2,
Trigonometric.getAngle(startLatlng.lon, startLatlng.lat, endLatlng.lon, endLatlng.lat));//补点
if (polyLine != null) {
Log.d(V2XConst.LOG_NAME_WARN, "polyLine != null");
polyLine.setPoints(Arrays.asList(startLatlng, addMiddleLoc, endLatlng));
polyLine.setTransparency(0.5f);
} else {
DrawLineInfo lineInfo = new DrawLineInfo();
Log.d(TAG, "目标物与预碰撞点画线点为" + "起点:" + startLatlng + "中间点:" + addMiddleLoc + "终点:" + endLatlng);
List locations = new ArrayList();
locations.add(startLatlng);
locations.add(addMiddleLoc);
locations.add(endLatlng);
lineInfo.setLocations(locations);
lineInfo.setHeading(info.heading);
Log.d(V2XConst.LOG_NAME_WARN, "drawOtherObjectLine width = " + info.getRoadwidth());
lineInfo.setWidth(info.getRoadwidth() * 14 + 5);
V2XServiceManager.getMoGoPersonWarnPolylineManager().drawPersonWarnPolyline(getContext(), lineInfo);
//识别物到预碰撞点之间的箭头
addArrows(startLatlng, endLatlng);
}
} else {
Log.e(V2XConst.LOG_NAME_WARN, "info == null");
V2XServiceManager.getMoGoPersonWarnPolylineManager().clearLine();
}
}
//侧面目标物与碰撞点之间添加多个小箭头
private void addArrows(MogoLatLng startLatLng, MogoLatLng endLatLng) {
float distance = CoordinateUtils.calculateLineDistance(
startLatLng.lon, startLatLng.lat, endLatLng.lon, endLatLng.lat);
double rotate = Trigonometric.getAngle(startLatLng.lon, startLatLng.lat, endLatLng.lon, endLatLng.lat);
Log.d(TAG, "添加小箭头--目标物与预碰撞点之间的距离是" + String.valueOf(distance));
if (distance > 5) {
int count = (int) (distance / 5);
for (int i = 0; i < count; i++) {
MogoLatLng newLo = Trigonometric.getNewLocation(
startLatLng, 5 * (i + 1), Trigonometric.getAngle(startLatLng.lon, startLatLng.lat, endLatLng.lon, endLatLng.lat));
Log.d(TAG, "小箭头位置" + newLo);
V2XWarnDataDrawer.getInstance().drawerArrowsMarkerWithLocation(newLo, WARNING_ARROWS, 10, new Double(rotate).intValue());
}
}
//延迟3秒清理线
UiThreadHandler.postDelayed(() -> {
V2XServiceManager.getMarkerManager().removeMarkers(WARNING_ARROWS);
}, showTime);
}
@Override
public void clearALLPOI() {
}
/**
* 自车定位 移动完成需要 3s消失,这里何时清理,应该是没有数据的时候
* 地图侧回调回的定位Location为高德坐标
*/
@Override
public void onCarLocationChanged2(Location latLng) {
if (MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode() && isSelfLineClear == false) {
//当行人经纬度交点 开始画线,否则清理
if (mCloundWarningInfo != null) {
mCloundWarningInfo.setCarLocation(new MogoLatLng(latLng.getLatitude(), latLng.getLongitude()));
}
drawSelfCarLine(latLng.getLongitude(), latLng.getLatitude(), latLng.getBearing());
}
carLocation = new MogoLatLng(latLng.getLatitude(), latLng.getLongitude());
Log.d("车行驶的轨迹---", String.valueOf(latLng.getLongitude()) + "," + String.valueOf(latLng.getLatitude()));
}
@Override
public void onCarLocationChanged(MogoLatLng latLng) {
}
/**
* 补点后的停止线经纬度合集
*/
public void pointsBetween() {
try {
fillPoints.clear();
List stopLines = mCloundWarningInfo.getStopLines();
if (stopLines.size() > 1) {
MogoLatLng x = mCloundWarningInfo.getStopLines().get(0);
MogoLatLng y = mCloundWarningInfo.getStopLines().get(1);
//两点间的距离
float distance = CoordinateUtils.calculateLineDistance(x.lon, x.lat, y.lon, y.lat);
float average = distance / 3;
//两点间的角度
double angle = Trigonometric.getAngle(x.lon, x.lat, y.lon, y.lat);
//根据距离和角度获取下个点的经纬度
fillPoints.add(x);
for (int i = 1; i < 3; i++) {
MogoLatLng newLocation = Trigonometric.getNewLocation(x, average * i, angle);
fillPoints.add(newLocation);
}
fillPoints.add(y);
}
} catch (Exception e) {
e.printStackTrace();
}
}
private MogoLatLng getMogoLat(MogoLatLng latlng) {
MogoLatLng newLocation = Trigonometric.getNewLocation(latlng, mCloundWarningInfo.getStopLineDistance(), mCloundWarningInfo.getAngle());
return newLocation;
}
/*
* 自车前方的点,在停止线上--通过自车位置与距离停止线之间的距离计算
* */
private MogoLatLng getMiddleLocationInStopLine() {
MogoLatLng newLocation = Trigonometric.getNewLocation(carLocation, mCloundWarningInfo.getStopLineDistance(), mCloundWarningInfo.getAngle());
return newLocation;
}
}

View File

@@ -58,7 +58,7 @@ public class V2XWarningMarker implements IV2XMarker {
/*
* 自车前方的点,在停止线上--通过自车位置与距离停止线之间的距离计算
* */
private MogoLatLng middleLocationInStopLine;
private MogoLatLng middleLocationInStopLine = new MogoLatLng(0,0);
private static long showTime = 5000;
private float bearing;
@@ -75,8 +75,8 @@ public class V2XWarningMarker implements IV2XMarker {
}
public void drawLineWithEntity() {
showTime = mCloundWarningInfo.getShowTime() > 0 ? mCloundWarningInfo.getShowTime() : 5000;
Log.d(TAG, "显示时间为++" + String.valueOf(showTime));
showTime = mCloundWarningInfo.getShowTime() > 0 ? mCloundWarningInfo.getShowTime()*1000 : 5000;
Log.d(TAG, "显示时间为++" + String.valueOf(showTime)+"识别物类型:"+String.valueOf(mCloundWarningInfo.getType()));
pointsBetween();
bearing = V2XLocationListener.getInstance().getLastCarLocation().getBearing();
isSelfLineClear = false;
@@ -95,8 +95,12 @@ public class V2XWarningMarker implements IV2XMarker {
drawRedWarningLineFrontOfStopLine(mCloundWarningInfo, middleLocationInStopLine, warningLocation);
//添加停止线marker
handleStopLine();
//自车画线
drawSelfCarLine(carLocation.lon, carLocation.lat, bearing);
if (carLocation.lat != 0 && carLocation.lon != 0){
//自车画线
drawSelfCarLine(carLocation.lon, carLocation.lat, bearing);
}else {
Log.d(TAG,"自车定位数据为空carLocation == null");
}
}, 0);
UiThreadHandler.postDelayed(() -> {
@@ -114,7 +118,11 @@ public class V2XWarningMarker implements IV2XMarker {
V2XServiceManager.getMarkerManager().removeMarkers(TYPE_MARKER_CLOUD_WARN_DATA);
V2XWarnDataDrawer.getInstance().renderWarnData(mCloundWarningInfo);
//车辆静止的时候
drawSelfCarLine(carLocation.lon, carLocation.lat, bearing);
if (carLocation.lat != 0 && carLocation.lon != 0){
drawSelfCarLine(carLocation.lon, carLocation.lat, bearing);
}else {
Log.d(TAG,"数据为空carLocation == null");
}
}, 0);
@@ -242,16 +250,15 @@ public class V2XWarningMarker implements IV2XMarker {
if (!isSelfLineClear) {
IMogoPolyline mogoPolyline = V2XServiceManager.getMoGoWarnPolylineManager().getMogoWarnPolyline();
if (mCloundWarningInfo != null) {
MogoLatLng startLatlng = null;
MogoLatLng endLatlng = null;
MogoLatLng addMiddleLoc = null;
MogoLatLng startLatlng = new MogoLatLng(0,0);
MogoLatLng endLatlng = new MogoLatLng(0,0);
MogoLatLng addMiddleLoc = new MogoLatLng(0,0);
if (!isFirstLocation) {
carLocation = getMogoLat(new MogoLatLng(lat, lon));
isFirstLocation = true;
}
//绘制线的终点(在停止线上或者预碰撞点上)
endLatlng = new MogoLatLng(mCloundWarningInfo.getDirection() == ALERT_THE_FRONT_CRASH_WARNING_TOP ? middleLocationInStopLine.lat : mCloundWarningInfo.getCollisionLat(),
mCloundWarningInfo.getDirection() == ALERT_THE_FRONT_CRASH_WARNING_TOP ? middleLocationInStopLine.lon : mCloundWarningInfo.getCollisionLon());
//自车位置

View File

@@ -11,7 +11,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/module_v2n_image_margin_left"
android:layout_marginTop="@dimen/dp_20"
android:layout_centerVertical="true"
android:src="@drawable/v2x_road_front_car_warning" />
<TextView
@@ -22,7 +22,7 @@
android:layout_centerVertical="true"
android:layout_marginRight="@dimen/dp_28"
android:maxWidth="@dimen/module_v2n_tip_text_width"
android:text="1.2米"
android:text="112米"
android:textColor="@color/v2x_FF3036"
android:textSize="@dimen/dp_32" />
@@ -32,7 +32,7 @@
android:layout_height="wrap_content"
android:layout_alignEnd="@+id/warning_distance"
android:layout_centerVertical="true"
android:layout_marginLeft="@dimen/dp_20"
android:layout_marginLeft="@dimen/dp_30"
android:layout_marginRight="@dimen/module_v2n_tip_text_margin_right"
android:layout_toRightOf="@+id/warning_type_image"
android:text="前车碰撞预警"