diff --git a/.idea/misc.xml b/.idea/misc.xml index 74aa6f6b47..9375f3dd35 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -8,7 +8,7 @@ - + \ No newline at end of file diff --git a/libraries/map-custom/build.gradle b/libraries/map-custom/build.gradle index 69779ad144..611bfa6974 100644 --- a/libraries/map-custom/build.gradle +++ b/libraries/map-custom/build.gradle @@ -67,7 +67,7 @@ dependencies { implementation project(':foudations:mogo-commons') } - implementation 'com.zhidaoauto.machine:map:1.0.0-vr-8.4.6' + implementation 'com.zhidaoauto.machine:map:1.0.0-vr-8.4.7' // implementation 'com.zhidaoauto.machine:map:1.0.0-vr-test-3.4' } diff --git a/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/AMapViewWrapper.java b/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/AMapViewWrapper.java index ff1f5099d7..6b93b87225 100644 --- a/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/AMapViewWrapper.java +++ b/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/AMapViewWrapper.java @@ -1044,7 +1044,7 @@ public class AMapViewWrapper implements IMogoMapView, } Map roadCacheMap = new ConcurrentHashMap<>(); - private RoadCacheWrapper noCache = new RoadCacheWrapper(null); + private final RoadCacheWrapper noCache = new RoadCacheWrapper(null); @Override public void clearRoadCacheById(String id) { @@ -1056,21 +1056,32 @@ public class AMapViewWrapper implements IMogoMapView, return matchRoad(id, lon, lat, angle, isGpsLocation, isRTK, true); } - int[] colors = new int[]{Color.RED, Color.GREEN, Color.BLUE}; - int colorIndex = 0; + /** + * 带缓存的道路匹配算法 + * + * 使用{@link MapDataApi#INSTANCE#getSinglePointMatchRoad()}这个方法获取道路数据会存在一定耗时,目前是4-10ms,因为请求频繁,为了 + * 减小这部分耗时,使用一个ConcurrentHashMap{@link #roadCacheMap}缓存道路数据,此缓存是以目标车id为key,道路数据为value,以此减少 + * 道路数据获取次数。 + * + * 当出现道路改变的情况,需要重新获取道路数据,采用递归的方式重获道路数据以及添加缓存,为了避免一直获取不到道路数据,一直递归,增加useCache参数跳出递归。 + * + * 道路改变的情况主要分为: + * 1. 目标车距离道路中心线距离超过阈值 matchThreshold(取路宽的1/4为阈值); + * 2. 目标车到道路中心线的映射点不在道路上(此判断在{@link PointInterpolatorUtil#mergeToRoad(double, double, List)}),也就是说已经驶出了这条道路 + * + * @param id 目标车唯一标识 + * @param lon 目标车经度 + * @param lat 目标车纬度 + * @param angle 目标车角度 + * @param isGpsLocation true-使用gps定位数据 + * @param isRTK true-使用rtk数据 + * @param usdCache true-使用道路缓存 false-不使用道路缓存 + * @return double[]{匹配后经度,匹配后纬度,目标车距离车道中心线距离},若匹配后经纬度值为-1,则没有匹配成功 + */ private double[] matchRoad(String id, double lon, double lat, double angle, boolean isGpsLocation, boolean isRTK, boolean usdCache) { - double wgs[] = new double[]{lon, lat}; + double[] wgs = new double[]{lon, lat}; long start = System.currentTimeMillis(); -// - -// SinglePointRoadInfo singlePointRoadInfo = MapDataApi.INSTANCE.getSinglePointMatchRoad(((float) wgs[0]), ((float) wgs[1]), ((float) angle), isGpsLocation, isRTK); -// if ( singlePointRoadInfo == null || singlePointRoadInfo.getCoords() == null || singlePointRoadInfo.getCoords().isEmpty() ) { -// return null; -// } -// double matchedPoint[] = PointInterpolatorUtil.mergeToRoad(wgs[0], wgs[1], singlePointRoadInfo.getCoords()); -// return matchedPoint; - RoadCacheWrapper roadCache = roadCacheMap.get(id); double matchThreshold = -1; if (roadCache == null||roadCache == noCache) { @@ -1079,6 +1090,7 @@ public class AMapViewWrapper implements IMogoMapView, Log.i("timer-matchRoad-4", "cost " + (System.currentTimeMillis() - start) + "ms roadId: " + singlePointRoadInfo.getRoadId()); roadCache = new RoadCacheWrapper(singlePointRoadInfo.getCoords()); roadCache.setLaneWidth(singlePointRoadInfo.getLaneWidth()); + // 在地图上画点的测试方法 // try { // PolylineOptions options = new PolylineOptions( ); // options.setColor( colors[colorIndex++] ); @@ -1105,22 +1117,22 @@ public class AMapViewWrapper implements IMogoMapView, if (roadCache != null && roadCache.getRoad() != null && !roadCache.getRoad().isEmpty()) { + // 未获取到道路中心线数据 start = System.currentTimeMillis(); matchThreshold = roadCache.getLaneWidth() / 4; - double matchedPoint[] = PointInterpolatorUtil.mergeToRoad(wgs[0], wgs[1], roadCache.getRoad()); + double[] matchedPoint = PointInterpolatorUtil.mergeToRoad(wgs[0], wgs[1], roadCache.getRoad()); if (matchThreshold>0&&matchedPoint[2] > 0 && matchedPoint[2] <= matchThreshold) { -// if (roadCache.inCache(matchedPoint[0], matchedPoint[1])) { + // 目标车在阈值范围内 roadCacheMap.put(id, roadCache); Log.i("timer-matchRoad-3", "cost " + (System.currentTimeMillis() - start) + "ms"); return matchedPoint; -// } -// roadCacheMap.put(id, null); // Log.i("timer-matchRoad-2", "cost " + (System.currentTimeMillis() - start) + "ms roadId: "+roadCache.getLastLat()); -// return matchRoad(id, lon, lat, angle, isGpsLocation, isRTK,false); } else if (matchedPoint[2] > matchThreshold && matchedPoint[2] < 1.5) { + // 目标车在阈值范围外,也就是说距离道路中心线太远了,就不吸附了 return null; } else { + // 目标车到道路中心线的映射点不在道路上,也就是已经使出了缓存的那条道路,需要重新获取一条道路,用useCache这个参数来避免重复递归 roadCacheMap.put(id, noCache); Log.i("timer-matchRoad-2", "cost " + (System.currentTimeMillis() - start) + "ms roadId: " + roadCache.getLastLat()); if (usdCache) { @@ -1128,7 +1140,6 @@ public class AMapViewWrapper implements IMogoMapView, } else { return null; } -// return null; } } roadCacheMap.put(id, noCache); diff --git a/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/utils/PointInterpolatorUtil.java b/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/utils/PointInterpolatorUtil.java index c4bbcd4e1f..ccd8dc5321 100644 --- a/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/utils/PointInterpolatorUtil.java +++ b/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/utils/PointInterpolatorUtil.java @@ -1,14 +1,10 @@ package com.mogo.map.impl.custom.utils; -import android.util.Log; - import com.mogo.cloud.commons.utils.CoordinateUtils; import com.mogo.map.MogoLatLng; import com.mogo.utils.logger.Logger; import com.zhidaoauto.map.sdk.open.query.LonLatPoint; -import java.text.NumberFormat; -import java.util.ArrayList; import java.util.List; /** @@ -35,22 +31,22 @@ public class PointInterpolatorUtil { * @deprecated 这个方法有问题,并不能算出来想要的值 */ @Deprecated - public static void interpolate( List< MogoLatLng > points ) { - if ( points.size() >= 2 ) { + public static void interpolate(List points) { + if (points.size() >= 2) { // 插值 - for ( int i = 0; i < points.size() - 1; i++ ) { - MogoLatLng current = points.get( i ); - MogoLatLng next = points.get( i + 1 ); - float distance = CoordinateUtils.calculateLineDistance( current.lon, current.lat, next.lon, next.lat ); - Logger.d( TAG, i + ": " + distance ); - if ( distance > DISTANCE_THRESHOLD ) { - int inter = ( int ) ( distance / DISTANCE_THRESHOLD ) + 1; - for ( int j = 1; j < inter; j++ ) { - double newLat = current.lat + ( next.lat - current.lat ) * j / inter; - double newLon = current.lon + ( next.lon - current.lon ) * j / inter; - Logger.d( TAG, "distance: " + distance + ", j: " + j + ", nextLat: " + next.lat + ", nextLon: " + next.lon + ", newLat: " + newLat + ", newLon: " + newLon ); - points.add( i + 1, new MogoLatLng( newLat, newLon ) ); - current = points.get( ++i ); + for (int i = 0; i < points.size() - 1; i++) { + MogoLatLng current = points.get(i); + MogoLatLng next = points.get(i + 1); + float distance = CoordinateUtils.calculateLineDistance(current.lon, current.lat, next.lon, next.lat); + Logger.d(TAG, i + ": " + distance); + if (distance > DISTANCE_THRESHOLD) { + int inter = (int) (distance / DISTANCE_THRESHOLD) + 1; + for (int j = 1; j < inter; j++) { + double newLat = current.lat + (next.lat - current.lat) * j / inter; + double newLon = current.lon + (next.lon - current.lon) * j / inter; + Logger.d(TAG, "distance: " + distance + ", j: " + j + ", nextLat: " + next.lat + ", nextLon: " + next.lon + ", newLat: " + newLat + ", newLon: " + newLon); + points.add(i + 1, new MogoLatLng(newLat, newLon)); + current = points.get(++i); } } } @@ -58,77 +54,67 @@ public class PointInterpolatorUtil { } } - public static double[] mergeToRoad( double lon, double lat, List< LonLatPoint > road ) { + /** + * 道路吸附算法 + *

+ * 所谓的道路数据,实际就是道路对应的点集,每两个点之间是直线,但是两点间距并不固定,点集内点的数量也不固定,点集是有序的,按道路方向排序,road[0]是起点。 + * 为了避免拐弯道路的问题,先使用{@link #getCloseTwoPoint(int, int, double, double, List)}从道路数据里面找出距离目标点最近的两个点,记为A、B,最近的两个点就在目标点一前一后排列, + * 这样的话,求一下目标点到AB的垂直映射以及距离{@link #getFootAndMinDistance(double, double, double, double, double, double)},就是吸附后的经纬度和距离 + * + * @param lon 目标经度 + * @param lat 目标纬度 + * @param road 目标道路数据 + * @return double[]{吸附后的经度,吸附后的纬度,目标经纬度距离道路的垂直距离} + */ + public static double[] mergeToRoad(double lon, double lat, List road) { int closeStart = 0; int closeEnd = road.size() - 1; - int[] result = getCloseTwoPoint(closeStart,closeEnd, lon, lat, road ); - LonLatPoint start = road.get( result[0] ); - LonLatPoint end = road.get( result[1] ); -// Logger.d( TAG, "mergeToRoad start: " + closeStart + " end: " + closeEnd ); -// return getMid(start, end); -// double[] foot = getFoot( lon, lat, start, end ); - -// float d = CoordinateUtils.calculateLineDistance( foot[0], foot[1], lon, lat ); -// Logger.d( TAG, "distance to mid line==" + d ); -// return new double[]{foot[0], foot[1], d}; - + int[] result = getCloseTwoPoint(closeStart, closeEnd, lon, lat, road); + LonLatPoint start = road.get(result[0]); + LonLatPoint end = road.get(result[1]); return getFootAndMinDistance(lon, lat, start.getLongitude(), start.getLatitude(), end.getLongitude(), end.getLatitude()); } - private static int[] getCloseTwoPoint(int closeStart,int closeEnd, double lon, double lat, List< LonLatPoint > road ) { - if ( closeEnd - closeStart == 1 ) { - return new int[]{closeStart,closeEnd}; + /** + * 获取距离目标点经纬度最近的道路点index + *

+ * 采用二分查找思想,先用道路数据的起点和终点分别计算距离目标点的距离: + * 若起点距离较远,则说明目标点在整条道路的后半段,则将起点后移至原起点和终点的中间,继续递归计算; + * 同理,若终点距离较远,则目标点在前半段,则终点前移,继续递归计算; + * 递归结束条件是起点index和终点index间隔是1; + * + * @param closeStart 距离目标点最近的起始点index + * @param closeEnd 距离目标点最近的终点index + * @param lon 目标点经度 + * @param lat 目标点纬度 + * @param road 目标道路 + * @return int[]{距离目标点最近的起始点index,距离目标点最近的终点index} + */ + private static int[] getCloseTwoPoint(int closeStart, int closeEnd, double lon, double lat, List road) { + if (closeEnd - closeStart == 1) { + return new int[]{closeStart, closeEnd}; } - LonLatPoint start = road.get( closeStart ); - LonLatPoint end = road.get( closeEnd ); - float startDistance = CoordinateUtils.calculateLineDistance( start.getLongitude(), start.getLatitude(), lon, lat ); - float endDistance = CoordinateUtils.calculateLineDistance( end.getLongitude(), end.getLatitude(), lon, lat ); - if ( startDistance > endDistance ) { - closeStart += ( closeEnd - closeStart ) / 2; + LonLatPoint start = road.get(closeStart); + LonLatPoint end = road.get(closeEnd); + float startDistance = CoordinateUtils.calculateLineDistance(start.getLongitude(), start.getLatitude(), lon, lat); + float endDistance = CoordinateUtils.calculateLineDistance(end.getLongitude(), end.getLatitude(), lon, lat); + if (startDistance > endDistance) { + closeStart += (closeEnd - closeStart) / 2; } else { - closeEnd -= ( closeEnd - closeStart ) / 2; + closeEnd -= (closeEnd - closeStart) / 2; } - return getCloseTwoPoint(closeStart,closeEnd, lon, lat, road ); + return getCloseTwoPoint(closeStart, closeEnd, lon, lat, road); } - private static double[] getFoot( double lon, double lat, LonLatPoint beginPt, LonLatPoint endPt ) { - double dx = beginPt.getLatitude() - endPt.getLatitude(); - double dy = beginPt.getLongitude() - endPt.getLongitude(); - - double u = ( lat - beginPt.getLatitude() ) * ( beginPt.getLatitude() - endPt.getLatitude() ) + - ( lon - beginPt.getLongitude() ) * ( beginPt.getLongitude() - endPt.getLongitude() ); - u = u / ( dx * dx + dy * dy ); - return new double[]{beginPt.getLongitude() + u * dy, beginPt.getLatitude() + u * dx}; - } - - -// un minDistance(x: Double, y: Double, x1: Double, y1: Double, x2: Double, y2: Double): Double { -// val cross = (x2 - x1) * (x - x1) + (y2 - y1) * (y - y1) -// println("1.cross:$cross") -// if (cross <= 0) { -// return Math.sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1)) -// } -// val d2 = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) -// println("2.d2:$cross") -// if (cross > d2) { -// return Math.sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2)) -// } -// val r = cross / d2 -// val px = x1 + (x2 - x1) * r -// val py = y1 + (y2 - y1) * r -// println("3.r:$r,px:$px,py:$py") -// return Math.sqrt((x - px) * (x - px) + (py - y) * (py - y)) -// } - /** * 计算垂足以及最短距离 * - * @param x target point lon - * @param y target point lat - * @param x1 start point lon - * @param y1 start point lat - * @param x2 end point lon - * @param y2 end point lat + * @param x target point lon + * @param y target point lat + * @param x1 线段起点 lon + * @param y1 起点起点 lat + * @param x2 线段终点 lon + * @param y2 线段终点 lat * @return double[]{footLon,footLat,minDistance} if(footLon == -1) => no foot or foot not in line */ private static double[] getFootAndMinDistance(double x, double y, double x1, double y1, double x2, double y2) { @@ -136,30 +122,17 @@ public class PointInterpolatorUtil { double cross = (x2 - x1) * (x - x1) + (y2 - y1) * (y - y1); if (cross < 0) { // 垂足没有在线段内,所以也无需计算最短距离 - // result[2] = Math.sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1)); -// Log.d("getFootAndMinDistance", "垂足不在线段内--1"); return result; } double d2 = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1); if (cross > d2) { // 垂足没有在线段内,所以也无需计算最短距离 - // result[2] = Math.sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2)); -// Log.d("getFootAndMinDistance", "垂足不在线段内--2"); return result; } double r = cross / d2; result[0] = x1 + (x2 - x1) * r; result[1] = y1 + (y2 - y1) * r; -// NumberFormat numberFormat = NumberFormat.getInstance(); -// numberFormat.setMaximumFractionDigits(4); -// String formatNum = numberFormat.format(Math.sqrt((x - result[0]) * (x - result[0]) + (result[1] - y) * (result[1] - y))); -// result[2] = Double.parseDouble(formatNum); result[2] = CoordinateUtils.calculateLineDistance(result[0], result[1], x, y); -// Log.d("getFootAndMinDistance", "计算距离--lon: "+result[0]+" lat: "+result[1]+" dis: "+result[2]); return result; } - - private static double[] getMid( LonLatPoint start, LonLatPoint end ) { - return new double[]{( start.getLongitude() + end.getLongitude() ) / 2, ( start.getLatitude() + end.getLatitude() ) / 2}; - } } diff --git a/modules/mogo-module-v2x/src/main/AndroidManifest.xml b/modules/mogo-module-v2x/src/main/AndroidManifest.xml index 55a8c743c5..8be51ea5bf 100644 --- a/modules/mogo-module-v2x/src/main/AndroidManifest.xml +++ b/modules/mogo-module-v2x/src/main/AndroidManifest.xml @@ -9,6 +9,14 @@ + + + + + + + + @@ -25,13 +33,6 @@ - - - - - - - diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/V2XModuleProvider.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/V2XModuleProvider.java index 497923eb0d..417e971ee9 100644 --- a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/V2XModuleProvider.java +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/V2XModuleProvider.java @@ -34,6 +34,7 @@ import com.mogo.module.common.utils.Const; import com.mogo.module.v2x.entity.net.V2XSeekHelpRes; import com.mogo.module.v2x.entity.net.V2XStrategyPushRes; import com.mogo.module.v2x.network.V2XRefreshCallback; +import com.mogo.module.v2x.receiver.AdasDataBroadcastReceiver; import com.mogo.module.v2x.receiver.SceneBroadcastReceiver; import com.mogo.module.v2x.scenario.impl.V2XScenarioManager; import com.mogo.module.v2x.scenario.scene.livecar.V2XVoiceCallLiveBiz; @@ -302,6 +303,9 @@ public class V2XModuleProvider implements V2XServiceManager.getV2XMarkerService().startAutoRefresh(); // 锁车就是将地图视图移植中心点,因为行驶中的车和地图要相对的跟随 V2XServiceManager.getMapUIController().recoverLockMode(); + Log.d("liyz", "V2XModuleProvider ------> "); + //注册adas数据通道 + V2XWaringManager.getInstance().registerAdasSocketMessage(mContext); } /** diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/V2XServiceManager.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/V2XServiceManager.java index 5151de383b..3d791a6d2d 100644 --- a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/V2XServiceManager.java +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/V2XServiceManager.java @@ -1,6 +1,7 @@ package com.mogo.module.v2x; import android.content.Context; +import android.util.Log; import com.alibaba.android.arouter.launcher.ARouter; import com.mogo.map.MogoLatLng; @@ -108,8 +109,6 @@ public class V2XServiceManager { private static IMoGoV2XStatusManager moGoV2XStatusManager; private static IMoGoWarnPolylineManager moGoWarnPolylineManager; - List resultList = new ArrayList<>(); - private V2XServiceManager() { @@ -164,34 +163,6 @@ public class V2XServiceManager { moGoWarnPolylineManager = (IMoGoWarnPolylineManager) ARouter.getInstance().build(MoGoV2XServicePaths.PATH_V2X_WARN_POLYLINE_MANAGER).navigation(context); moGoV2XStatusManager = (IMoGoV2XStatusManager) ARouter.getInstance().build(MoGoV2XServicePaths.PATH_V2X_STATUS_MANAGER).navigation(context); - - List lonLats = new ArrayList<>(); - - // adas 每隔一秒传递的他车或行人数据 - mIMogoADASController.addAdasRecognizedDataCallback(resultList -> { - // 绘制近景识别到的车辆,行人和二轮车 TODO - AdasRecognizedResultDrawer.getInstance().renderAdasRecognizedResult( resultList ); - - //清理 - V2XServiceManager.getMoGoWarnPolylineManager().clearLine(); - - // 绘制连接线 TODO 来的是列表数据 -// V2XServiceManager.getMoGoWarnPolylineManager().drawableWarnPolyline(context, roadEventEntity); - - //更新数据 - for (ADASRecognizedResult result : resultList) { - MogoLatLng latLng = new MogoLatLng(result.lat, result.lon); - lonLats.add(latLng); - } - - IMogoPolyline mMogoPolyline = V2XServiceManager.getMoGoWarnPolylineManager().getMogoWarnPolyline(); - mMogoPolyline.setPoints(lonLats); - - } ); - - //绘制自车数据 liyz - - } } @@ -342,4 +313,12 @@ public class V2XServiceManager { public static IEventPanelProvider getEventPanelProvider() { return mIEventPanelProvider; } + + public static IMogoADASController getmIMogoADASController() { + return mIMogoADASController; + } + + public static void setmIMogoADASController(IMogoADASController mIMogoADASController) { + V2XServiceManager.mIMogoADASController = mIMogoADASController; + } } diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/V2XWaringManager.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/V2XWaringManager.java new file mode 100644 index 0000000000..33cb208b48 --- /dev/null +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/V2XWaringManager.java @@ -0,0 +1,151 @@ +package com.mogo.module.v2x; + +import android.content.Context; +import android.util.Log; + +import com.mogo.map.MogoLatLng; +import com.mogo.map.overlay.IMogoPolyline; +import com.mogo.module.common.MogoApisHandler; +import com.mogo.module.common.drawer.AdasRecognizedResultDrawer; +import com.mogo.module.v2x.entity.model.DrawLineInfo; +import com.mogo.module.v2x.listener.V2XMessageListener_401011; +import com.mogo.realtime.entity.ADASRecognizedResult; +import com.mogo.utils.logger.Logger; + +import java.util.ArrayList; +import java.util.List; + +import static com.mogo.module.v2x.V2XServiceManager.getContext; + +/** + * desc : V2X报警事件管理,这里进行报警事件的分发处理,包括了adas数据 + */ +public class V2XWaringManager { + + List lonLats = new ArrayList<>(); + List resultList = new ArrayList<>(); + private Context mContext; + + private static V2XWaringManager mV2XWaringManager; + //TODO 需要修改 + private V2XMessageListener_401011 v2XMessageListener_401011; + + + private V2XWaringManager() { + } + + /** + * 获取操作实体 + */ + public static synchronized V2XWaringManager getInstance() { + synchronized (V2XWaringManager.class) { + if (mV2XWaringManager == null) { + mV2XWaringManager = new V2XWaringManager(); + } + } + return mV2XWaringManager; + } + + /** + * 注册长链接消息处理 + */ + public void registerAdasSocketMessage(Context context) { + Logger.d("liyz", "开始注册Socket通道...."); + mContext = context; + + register401011(); + handleAdasData(); + } + + /** + * 反注册消息通道,不再进行接受 + */ + public void unregisterAdasSocketMessage() { + Logger.w("liyz", "反注册Socket通道...."); + if (v2XMessageListener_401011 != null) { + V2XServiceManager + .getMoGoSocketManager() + .unregisterOnMessageListener(401011, v2XMessageListener_401011); + } + } + + /** + * 道路事件,行人 + */ + private void register401011() { + v2XMessageListener_401011 = new V2XMessageListener_401011(); + // 道路事件,在线车辆绘制 + V2XServiceManager + .getMoGoSocketManager() + .registerOnMessageListener( + 401011, + v2XMessageListener_401011 + ); + } + + public V2XMessageListener_401011 getV2XMessageListener_401011() { + return v2XMessageListener_401011; + } + + + /** + * 处理adas返回的数据 + */ + private void handleAdasData() { + Log.d("liyz", "V2XWaringManager ---- handleAdasData ---0-- "); + //清理 + V2XServiceManager.getMoGoWarnPolylineManager().clearLine(); + + // 绘制连接线 TODO 来的是列表数据 + DrawLineInfo info1 = new DrawLineInfo(); + MogoLatLng startLatlng1 = new MogoLatLng(39.968919,116.407642); + MogoLatLng endLatlng1 = new MogoLatLng(39.977173,116.417555); + info1.setStartLocation(startLatlng1); + info1.setEndLocation(endLatlng1); + V2XServiceManager.getMoGoWarnPolylineManager().drawableWarnPolyline(getContext(), info1); + + + // adas 每隔一秒传递的他车或行人数据 + V2XServiceManager.getmIMogoADASController().addAdasRecognizedDataCallback(resultList -> { + // 绘制近景识别到的车辆,行人和二轮车 TODO + AdasRecognizedResultDrawer.getInstance().renderAdasRecognizedResult( resultList ); + Log.d("liyz", "V2XWaringManager ---- handleAdasData ----- "); + + //清理 + V2XServiceManager.getMoGoWarnPolylineManager().clearLine(); + + // 绘制连接线 TODO 来的是列表数据 + DrawLineInfo info = new DrawLineInfo(); + MogoLatLng startLatlng = new MogoLatLng(39.969247,116.407299); + MogoLatLng endLatlng = new MogoLatLng(39.971089,116.407384); + info.setStartLocation(startLatlng); + info.setEndLocation(endLatlng); + V2XServiceManager.getMoGoWarnPolylineManager().drawableWarnPolyline(mContext, info); + + //更新数据 + for (ADASRecognizedResult result : resultList) { + MogoLatLng latLng = new MogoLatLng(result.lat, result.lon); + lonLats.add(latLng); + } + IMogoPolyline mMogoPolyline = V2XServiceManager.getMoGoWarnPolylineManager().getMogoWarnPolyline(); + mMogoPolyline.setPoints(lonLats); + + } ); + + double lon = MogoApisHandler.getInstance().getApis().getAdasControllerApi().getLastLon(); + double lat = MogoApisHandler.getInstance().getApis().getAdasControllerApi().getLastLat(); + Log.d("liyz", "lon = " + lon + "----lat = " + lat); + + //绘制自车数据 liyz +// DrawLineInfo info = new DrawLineInfo(); +// MogoLatLng startLatlng = new MogoLatLng(lat,lon); //我的位置 +// MogoLatLng endLatlng = new MogoLatLng(39.971089,); //交点位置 +// info.setStartLocation(startLatlng); +// info.setEndLocation(endLatlng); +// V2XServiceManager.getMoGoWarnPolylineManager().drawableWarnPolyline(mContext, info); + + + } + + +} diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/manager/impl/MoGoWarnPolylineManager.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/manager/impl/MoGoWarnPolylineManager.java index fed112a454..67d9db85a5 100644 --- a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/manager/impl/MoGoWarnPolylineManager.java +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/manager/impl/MoGoWarnPolylineManager.java @@ -1,6 +1,7 @@ package com.mogo.module.v2x.manager.impl; import android.content.Context; +import android.util.Log; import com.alibaba.android.arouter.facade.annotation.Route; import com.mogo.map.MogoLatLng; @@ -22,7 +23,6 @@ import java.util.List; */ @Route(path = MoGoV2XServicePaths.PATH_V2X_WARN_POLYLINE_MANAGER) public class MoGoWarnPolylineManager implements IMoGoWarnPolylineManager { - private static final String TAG = "MoGoWarnPolylineManager"; private static IMogoPolyline mMogoPolyline; @@ -39,25 +39,27 @@ public class MoGoWarnPolylineManager implements IMoGoWarnPolylineManager { // 渐变色 List colors = new ArrayList<>(); - if (info.getType().equals("1")) { //预警 TODO - colors.add(0xFFFFA31A); - colors.add(0xFFFFA31A); - } else { - colors.add(0xFFE32F46); - colors.add(0xFFE32F46); - } +// if (info.getType().equals("1")) { //预警 TODO +// colors.add(0xFFFFA31A); +// colors.add(0xFFFFA31A); +// } else { +// colors.add(0xFFE32F46); +// colors.add(0xFFE32F46); +// } + + colors.add(0xFF3036); + colors.add(0xFF3036); // 线条粗细,渐变,渐变色值 - options.width(30).useGradient(true).colorValues(colors); - + options.width(60).useGradient(true).colorValues(colors); // 当前车辆位置 options.add(info.getStartLocation()); - // 目标车辆位置 - options.add(info.getStartLocation()); + options.add(info.getEndLocation()); // 绘制线的对象 mMogoPolyline = V2XServiceManager.getMogoOverlayManager().addPolyline(options); + Log.d("liyz", "MoGoWarnPolylineManager drawableWarnPolyline -----> "); } catch (Exception e) { e.printStackTrace(); diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/receiver/AdasDataBroadcastReceiver.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/receiver/AdasDataBroadcastReceiver.java index 80325f76df..df75b1e5aa 100644 --- a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/receiver/AdasDataBroadcastReceiver.java +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/receiver/AdasDataBroadcastReceiver.java @@ -3,8 +3,10 @@ package com.mogo.module.v2x.receiver; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.util.Log; import com.mogo.module.v2x.V2XConst; +import com.mogo.module.v2x.V2XWaringManager; import com.mogo.realtime.entity.ADASRecognizedResult; import com.mogo.utils.logger.Logger; import com.mogo.utils.network.utils.GsonUtil; @@ -17,10 +19,11 @@ public class AdasDataBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { try { - ADASRecognizedResult adasResult = (ADASRecognizedResult) intent.getSerializableExtra(V2XConst.BROADCAST_ADAS_EXTRA_KEY); - Logger.d("AdasDataBroadcastReceiver", "adasResult:" + GsonUtil.jsonFromObject(adasResult)); - -// V2XScenarioManager.getInstance().handlerMessage(adasResult); +// ADASRecognizedResult adasResult = (ADASRecognizedResult) intent.getSerializableExtra(V2XConst.BROADCAST_ADAS_EXTRA_KEY); +// Logger.d("liyz", "AdasDataBroadcastReceiver -->" + GsonUtil.jsonFromObject(adasResult)); + String adasResult = (String) intent.getSerializableExtra(V2XConst.BROADCAST_ADAS_EXTRA_KEY); + Log.d("liyz", "AdasDataBroadcastReceiver -----> "); + V2XWaringManager.getInstance().registerAdasSocketMessage(context); } catch (Exception e) { e.printStackTrace(); diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/receiver/SceneBroadcastReceiver.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/receiver/SceneBroadcastReceiver.java index dd3773819e..d4cd59f9a7 100644 --- a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/receiver/SceneBroadcastReceiver.java +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/receiver/SceneBroadcastReceiver.java @@ -3,6 +3,7 @@ package com.mogo.module.v2x.receiver; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.util.Log; import com.mogo.module.v2x.V2XConst; import com.mogo.module.common.entity.V2XMessageEntity; @@ -24,6 +25,7 @@ public class SceneBroadcastReceiver extends BroadcastReceiver { try { V2XMessageEntity v2XMessageEntity = (V2XMessageEntity) intent.getSerializableExtra(V2XConst.BROADCAST_SCENE_EXTRA_KEY); //Logger.d(TAG, "v2XMessageEntity:" + GsonUtil.jsonFromObject(v2XMessageEntity)); + Log.d("liyz", "SceneBroadcastReceiver ------->"); V2XScenarioManager.getInstance().handlerMessage(v2XMessageEntity); } catch (Exception e) { e.printStackTrace(); diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/test/V2XTestConsoleWindow.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/test/V2XTestConsoleWindow.java index bae631d719..14b426c956 100644 --- a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/test/V2XTestConsoleWindow.java +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/test/V2XTestConsoleWindow.java @@ -66,6 +66,7 @@ public class V2XTestConsoleWindow extends ConstraintLayout { private Button mBtnTriggerTrafficSearch; private Button mBtnTriggerRecommendRouteEvent; private ToggleButton nBtnTriggerVR; + private Button mBtnAdasDataWarn; private Button btnTriggerRearVIPCarTip, btnTriggerVehicleBrakes, @@ -129,6 +130,7 @@ public class V2XTestConsoleWindow extends ConstraintLayout { mBtnTriggerTrafficSearch = findViewById(R.id.btnTriggerTrafficSearch); mBtnTriggerRecommendRouteEvent = findViewById(R.id.btnTriggerRecommendRouteEvent); nBtnTriggerVR = findViewById(R.id.btnTriggerVR); + mBtnAdasDataWarn = findViewById(R.id.btnAdasDataWarn); switch (showType) { case 0: @@ -301,6 +303,12 @@ public class V2XTestConsoleWindow extends ConstraintLayout { LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent); }); + mBtnAdasDataWarn.setOnClickListener(v -> { + Intent intent = new Intent(V2XConst.BROADCAST_ADAS_SCENE_HANDLER_ACTION); + intent.putExtra(V2XConst.BROADCAST_ADAS_EXTRA_KEY, "23"); + getContext().sendBroadcast(intent); + }); + mBtnTriggerTrafficSearch.setOnClickListener(v -> V2XServiceManager.getIMogoTrafficUploadProvider().verifyCurrentTrafficStatus()); mBtnTriggerRecommendRouteEvent.setOnClickListener(view -> { diff --git a/modules/mogo-module-v2x/src/main/res/layout/window_test_console.xml b/modules/mogo-module-v2x/src/main/res/layout/window_test_console.xml index e19d12dce3..c7bcf65f0c 100644 --- a/modules/mogo-module-v2x/src/main/res/layout/window_test_console.xml +++ b/modules/mogo-module-v2x/src/main/res/layout/window_test_console.xml @@ -461,7 +461,22 @@ app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" /> +