[V2X]道路施工(AI云)事件代码逻辑优化

This commit is contained in:
renwj
2022-08-29 16:39:32 +08:00
parent 39e9c14885
commit 08c752c849
5 changed files with 212 additions and 31 deletions

View File

@@ -269,6 +269,7 @@ dependencies {
androidTestImplementation rootProject.ext.dependencies.androidx_runner
androidTestImplementation rootProject.ext.dependencies.androidx_espresso_core
androidTestImplementation rootProject.ext.dependencies.localbroadcastmanager
androidTestImplementation rootProject.ext.dependencies.mogo_v2x
}
if (!isAndroidTestBuild()) {

View File

@@ -0,0 +1,160 @@
package com.mogo.functions.test
import android.os.*
import androidx.test.core.app.*
import androidx.test.ext.junit.runners.*
import androidx.test.filters.*
import com.mogo.eagle.core.function.hmi.ui.*
import com.mogo.eagle.core.function.main.*
import com.mogo.eagle.core.function.v2x.events.*
import com.mogo.v2x.event.V2XEvent.RoadAI
import kotlinx.coroutines.*
import org.junit.*
import org.junit.runner.*
import roadwork.Road.*
import java.util.concurrent.*
import java.util.concurrent.TimeUnit.MILLISECONDS
import java.util.concurrent.TimeUnit.SECONDS
import kotlin.Result
@RunWith(AndroidJUnit4::class)
@LargeTest
class RoadAITest {
lateinit var launch: ActivityScenario<MainLauncherActivity>
@Before
fun before() {
launch = ActivityScenario.launch(MainLauncherActivity::class.java)
}
@Test
fun test() = runBlocking(Dispatchers.Default) {
ensureMoGoHmiFragmentShow()
val nanos = System.nanoTime()
val child =
RW_PB
.newBuilder()
.setHeader(
Header
.newBuilder()
.setFrameId("rw")
.setModuleName("ai_cloud")
.setStamp(Time.newBuilder()
.setSec(TimeUnit.NANOSECONDS.convert(nanos, SECONDS).toInt())
.setNsec(180000000)
.build())
.build())
.setRoadwork(
Roadwork_PB
.newBuilder()
.setId("4e47e17d-4950-4c80-9b02-29a450e54b50")
.setScore(95)
.setDetectTime(nanos)
.setPoiType(100061)
.setType(1006)
.setCenter(
Center_PB
.newBuilder()
.setRoad(Road_PB
.newBuilder()
.setRoadId("200091")
.setLaneNo("-2")
.setTileId("556834853")
.setBearing(156)
.build())
.setPoint(GPSPoint_PB
.newBuilder()
.setLat(26.819533419884188)
.setLon(112.57506466334905)
.build())
.build())
.addPolygon(0, GPSPoint_PB
.newBuilder()
.setLat(26.819544927961125)
.setLon(112.57503948748804)
.build())
.addPolygon(1, GPSPoint_PB
.newBuilder()
.setLat(26.81953162903423)
.setLon(112.57503758421541)
.build())
.addPolygon(2, GPSPoint_PB
.newBuilder()
.setLat(26.81952255026517)
.setLon(112.5750496963295)
.build())
.addPolygon(3, GPSPoint_PB
.newBuilder()
.setLat(26.819517691652617)
.setLon(112.57507582382465)
.build())
.addPolygon(4, GPSPoint_PB
.newBuilder()
.setLat(26.819521911807858)
.setLon(112.57508983920647)
.build())
.addPolygon(5, GPSPoint_PB
.newBuilder()
.setLat(26.819535210732194)
.setLon(112.57509174248064)
.build())
.addPolygon(6, GPSPoint_PB
.newBuilder()
.setLat(26.81954428950259)
.setLon(112.5750796303722)
.build())
.addPolygon(7, GPSPoint_PB
.newBuilder()
.setLat(26.819549148117684)
.setLon(112.57505350287552)
.build())
.addRoad(0, Road_PB
.newBuilder()
.setRoadId("200090")
.setLaneNo("-2")
.setTileId("556834853")
.setBearing(154)
.build())
.addRoad(1, Road_PB
.newBuilder()
.setRoadId("200091")
.setLaneNo("-2")
.setTileId("556834853")
.setBearing(156)
.build())
.build())
.build()
val event = RoadAI(data = child)
while (true) {
delay(1000)
V2XEventManager.onAck(event)
}
}
private suspend fun ensureMoGoHmiFragmentShow(): MoGoHmiFragment = suspendCancellableCoroutine {
launch.onActivity { itx ->
val executor = Executors.newSingleThreadScheduledExecutor()
executor.scheduleAtFixedRate({
var find =
itx.supportFragmentManager.fragments.find { it is MoGoHmiFragment } as? MoGoHmiFragment
while (find == null) {
find =
itx.supportFragmentManager.fragments.find { it is MoGoHmiFragment } as? MoGoHmiFragment
}
while (!find.isResumed) {
Thread.sleep(500)
}
it.resumeWith(Result.success(find))
try {
Thread.sleep(500)
executor.shutdownNow()
} catch (e: Throwable) {
e.printStackTrace()
}
}, 50, 500, MILLISECONDS)
}
}
}

View File

@@ -3,13 +3,12 @@ package com.mogo.eagle.core.function.v2x.events.scenario.scene.road;
import android.graphics.Color;
import androidx.core.util.Pair;
import com.google.protobuf.FieldOrBuilder;
import com.mogo.eagle.core.data.map.MogoLatLng;
import com.mogo.eagle.core.function.v2x.R;
import com.mogo.eagle.core.function.v2x.events.bridge.BridgeApi;
import com.mogo.eagle.core.function.v2x.events.manager.IMoGoV2XMarkerManager;
import com.mogo.eagle.core.function.v2x.events.manager.IMoGoV2XPolylineManager;
import com.mogo.eagle.core.function.v2x.events.manager.IMoGoV2XStatusManager;
import com.mogo.eagle.core.function.v2x.events.scenario.view.IV2XMarker;
import com.mogo.map.MogoMarkerManager;
import com.mogo.map.MogoOverlayManager;
@@ -20,7 +19,6 @@ import com.mogo.map.overlay.IMogoPolyline;
import com.mogo.map.overlay.MogoPolylineOptions;
import com.mogo.module.common.entity.MarkerExploreWay;
import com.mogo.module.common.entity.V2XRoadEventEntity;
import java.util.ArrayList;
import java.util.List;
@@ -48,9 +46,18 @@ public class V2XRoadEventMarker implements IV2XMarker<V2XRoadEventEntity> {
MarkerExploreWay noveltyInfo = entity.getNoveltyInfo();
if (noveltyInfo != null && noveltyInfo.extras != null && noveltyInfo.extras.containsKey("polygon")) {
Object extra = noveltyInfo.extras.get("polygon");
if (pyramids.size() > 0) {
for (IMogoMarker m : pyramids) {
m.remove();
}
pyramids.clear();
}
if (polyline != null && polyline.isVisible()) {
polyline.remove();
}
if (extra instanceof List) {
List l = (List) extra;
if (l.size() >= 3) {
if (l.size() > 0) {
List<Pair<Double, Double>> polygons = new ArrayList<>();
for (int i = 0; i < l.size(); i++) {
Object o = l.get(i);
@@ -88,24 +95,25 @@ public class V2XRoadEventMarker implements IV2XMarker<V2XRoadEventEntity> {
if (polygons.size() > 1) {
if (overlayManager == null) {
overlayManager = MogoOverlayManager.getInstance();
MogoPolylineOptions options = new MogoPolylineOptions();
List<Integer> colors = new ArrayList<>();
colors.add(Color.argb(100, 255, 0, 0));
colors.add(Color.argb(100, 0, 255, 0));
options.colorValues(colors);
List<MogoLatLng> points = new ArrayList<>();
for (int i = 0; i < polygons.size(); i++) {
Pair<Double, Double> p = polygons.get(i);
points.add(new MogoLatLng(p.second, p.first));
}
options.points(points);
options.useGradient(true);
options.useFacade(true);
options.setGps(true);
options.width(5f);
polyline = overlayManager.addPolyline(options);
}
MogoPolylineOptions options = new MogoPolylineOptions();
List<Integer> colors = new ArrayList<>();
colors.add(Color.argb(100, 255, 0, 0));
colors.add(Color.argb(100, 0, 255, 0));
options.colorValues(colors);
List<MogoLatLng> points = new ArrayList<>();
for (int i = 0; i < polygons.size(); i++) {
Pair<Double, Double> p = polygons.get(i);
points.add(new MogoLatLng(p.second, p.first));
}
options.points(points);
options.useGradient(true);
options.useFacade(true);
options.setGps(true);
options.width(5f);
options.maxIndex(2000000f);
polyline = overlayManager.addPolyline(options);
polyline.setVisible(true);
}
}
}
@@ -125,6 +133,19 @@ public class V2XRoadEventMarker implements IV2XMarker<V2XRoadEventEntity> {
if (polyLineManager != null) {
polyLineManager.clearLine();
}
IMoGoV2XStatusManager v2xStatus = BridgeApi.INSTANCE.v2xStatus();
if (v2xStatus != null && v2xStatus.isRoadEventPOIShow()) {
if (polyline != null) {
polyline.remove();
}
if (pyramids.size() > 0) {
for (IMogoMarker marker : pyramids) {
marker.remove();
}
pyramids.clear();
}
}
IMoGoV2XMarkerManager v2xMarker = BridgeApi.INSTANCE.v2xMarker();
if (v2xMarker != null) {
// 移除事件POI
@@ -132,15 +153,5 @@ public class V2XRoadEventMarker implements IV2XMarker<V2XRoadEventEntity> {
// 绘制上次的数据
v2xMarker.drawableLastAllPOI();
}
if (polyline != null) {
polyline.remove();
}
if (pyramids.size() > 0) {
for (IMogoMarker marker : pyramids) {
marker.remove();
}
pyramids.clear();
}
}
}

View File

@@ -20,6 +20,7 @@ import java.util.List;
public class MogoPolylineOptions {
public boolean useFacade = false;
public float maxIndex = Float.MIN_VALUE;
private List<MogoLatLng> mPoints;
private float mWidth = 10.0F;
private int mColor = Color.BLACK;
@@ -157,6 +158,11 @@ public class MogoPolylineOptions {
return this;
}
public MogoPolylineOptions maxIndex(float maxIndex) {
this.maxIndex = maxIndex;
return this;
}
/**
* 设置透明度
*

View File

@@ -480,6 +480,9 @@ public class ObjectUtils {
target.setColor(options.getColor());
target.useGradient(options.isGradient());
target.useFacade(options.useFacade);
if (options.maxIndex >= 0f) {
target.maxIndex = options.maxIndex;
}
if (options.getColorValues() != null) {
target.colorValues(options.getColorValues());
}