[6.5.0][道路事件] 统一处理上车数据的坐标类型判断逻辑;添加道路施工和道路事故的单元测试

This commit is contained in:
renwj
2024-07-10 16:52:11 +08:00
parent 2f6d38211f
commit d79866b554
7 changed files with 148 additions and 33 deletions

View File

@@ -232,6 +232,7 @@ dependencies {
androidTestImplementation rootProject.ext.dependencies.localbroadcastmanager
androidTestImplementation rootProject.ext.dependencies.downloader
androidTestImplementation project(":libraries:mogo-map")
androidTestImplementation rootProject.ext.dependencies.jts_core
}

View File

@@ -9,6 +9,7 @@ import androidx.test.platform.app.InstrumentationRegistry
import com.google.protobuf.ByteString
import com.mogo.eagle.core.data.config.FunctionBuildConfig
import com.mogo.eagle.core.data.multidisplay.TelematicConstant
import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotIdentifyListenerManager
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationWGS84ListenerManager
import com.mogo.eagle.core.function.call.autopilot.CallerV2nNioEventListenerManager
import com.mogo.eagle.core.function.call.telematic.CallerTelematicManager
@@ -20,12 +21,16 @@ import com.mogo.map.MapDataWrapper
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import mogo.telematics.pad.MessagePad
import mogo.telematics.pad.MessagePad.Location
import mogo.telematics.pad.MessagePad.TrackedObject
import mogo.telematics.pad.MessagePad.V2nCrossSpeed
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import java.util.HashMap
import java.util.Collections
import java.util.concurrent.TimeUnit
import kotlin.math.cos
import kotlin.math.sin
@RunWith(AndroidJUnit4::class)
@@ -43,6 +48,100 @@ class V2NTest {
launch = ActivityScenario.launch(MainLauncherActivity::class.java)
}
@Test
fun testRoadShiGong(): Unit = runBlocking {
val arguments = InstrumentationRegistry.getArguments()
val millis = arguments.getString("delay", "0").toLong()
if (millis > 0) {
delay(millis)
}
FunctionBuildConfig.isNewV2NData = true
FunctionBuildConfig.v2nMainSwitch = true
runCatching {
val map = HashMap<String, Boolean>().also {
it["f1"] = FunctionBuildConfig.v2nMainSwitch
it["f2"] = FunctionBuildConfig.isNewV2NData
}
CallerTelematicManager.sendMsgToAllClients(TelematicConstant.V2N_NEW_LINK_SWITCH, GsonUtils.toJson(map).toByteArray())
}
delay(2000)
val targetX = arguments.getString("lon", "0").toDouble()
val targetY = arguments.getString("lat", "0").toDouble()
val targetDistance = arguments.getString("distance", "0").toDouble()
val eventDistance = arguments.getString("event_distance", "50").toDouble()
val r = arguments.getString("r", "1").toDouble()
var car = CallerChassisLocationWGS84ListenerManager.getChassisLocationWGS84()
var distance = CoordinateUtils.calculateLineDistance(car.longitude, car.latitude, targetX, targetY)
Log.d(TAG, "target_distance: $targetDistance, current distance: $distance, event_distance: $eventDistance")
while (distance > targetDistance) {
delay(2000)
car = CallerChassisLocationWGS84ListenerManager.getChassisLocationWGS84()
distance = CoordinateUtils.calculateLineDistance(car.longitude, car.latitude, targetX, targetY)
Log.d(TAG, "target_distance: $targetDistance, current distance: $distance")
}
car = CallerChassisLocationWGS84ListenerManager.getChassisLocationWGS84()
val point = DrivingDirectionUtils.calculateNewPoint(car.longitude, car.latitude, car.heading , eventDistance)
val polygon = generateTriangle(point.first, point.second, car.heading, r * 1e-5)
val data = TrackedObject.getDefaultInstance().toBuilder().setType(501).setLongitude(point.first).setLatitude(point.second).setAltitude(0.0).setSystemTime(System.currentTimeMillis() * 1.0 / 1000).setSatelliteTime(1.0).setUuid(10).setCarID("1").setColor("#ffffff").setHeading(car.heading).setSpeed(0.0).setDrawLevel(1).setDriverTime(1.0).setCameraIp("172.18.7.40").setVideoUrl("").addAllImageUrl(Collections.singletonList("http://www.baidu.com")).addAllPolygon(polygon.map { Location.getDefaultInstance().toBuilder().setLongitude(it.first).setLatitude(it.second).setAltitude(0.0).setHeading(0.0).setStation(false).build() }).setDetectStartTime(System.currentTimeMillis()).setV2XUuid("xxxxx1").setStrUuid("xxxxx2").build()
val trafficData = Collections.singletonList(data)
CallerTelematicManager.sendMsgToAllClients(TelematicConstant.V2N_AI_ROAD_SHI_GONG, data.toByteArray())
CallerAutopilotIdentifyListenerManager.invokeAutopilotIdentifyDataUpdate(trafficData)
delay(TimeUnit.MINUTES.toMillis(10))
}
@Test
fun testRoadShiGu(): Unit = runBlocking {
val arguments = InstrumentationRegistry.getArguments()
val millis = arguments.getString("delay", "0").toLong()
if (millis > 0) {
delay(millis)
}
FunctionBuildConfig.isNewV2NData = true
FunctionBuildConfig.v2nMainSwitch = true
runCatching {
val map = HashMap<String, Boolean>().also {
it["f1"] = FunctionBuildConfig.v2nMainSwitch
it["f2"] = FunctionBuildConfig.isNewV2NData
}
CallerTelematicManager.sendMsgToAllClients(TelematicConstant.V2N_NEW_LINK_SWITCH, GsonUtils.toJson(map).toByteArray())
}
delay(2000)
val targetX = arguments.getString("lon", "0").toDouble()
val targetY = arguments.getString("lat", "0").toDouble()
val targetDistance = arguments.getString("distance", "0").toDouble()
val eventDistance = arguments.getString("event_distance", "0").toDouble()
val r = arguments.getString("r", "1").toDouble()
var car = CallerChassisLocationWGS84ListenerManager.getChassisLocationWGS84()
var distance = CoordinateUtils.calculateLineDistance(car.longitude, car.latitude, targetX, targetY)
Log.d(TAG, "target_distance: $targetDistance, current distance: $distance, event_distance: $eventDistance")
while (distance > targetDistance) {
delay(2000)
car = CallerChassisLocationWGS84ListenerManager.getChassisLocationWGS84()
distance = CoordinateUtils.calculateLineDistance(car.longitude, car.latitude, targetX, targetY)
Log.d(TAG, "target_distance: $targetDistance, current distance: $distance")
}
car = CallerChassisLocationWGS84ListenerManager.getChassisLocationWGS84()
val point = DrivingDirectionUtils.calculateNewPoint(car.longitude, car.latitude, car.heading , eventDistance)
val polygon = generateTriangle(point.first, point.second, car.heading, r * 1e-5)
val data = TrackedObject.getDefaultInstance().toBuilder().setType(13).setLongitude(point.first).setLatitude(point.second).setAltitude(0.0).setSystemTime(System.currentTimeMillis() * 1.0 / 1000).setSatelliteTime(1.0).setUuid(10).setCarID("1").setColor("#ffffff").setHeading(car.heading).setSpeed(0.0).setDrawLevel(1).setDriverTime(1.0).setCameraIp("172.18.7.40").setVideoUrl("").addAllImageUrl(Collections.singletonList("http://www.baidu.com")).addAllPolygon(polygon.map { Location.getDefaultInstance().toBuilder().setLongitude(it.first).setLatitude(it.second).setAltitude(0.0).setHeading(0.0).setStation(false).build() }).setDetectStartTime(System.currentTimeMillis()).setV2XUuid("xxxxx1").setStrUuid("xxxxx2").build()
val trafficData = Collections.singletonList(data)
CallerTelematicManager.sendMsgToAllClients(TelematicConstant.V2N_AI_ROAD_SHI_GU, data.toByteArray())
CallerAutopilotIdentifyListenerManager.invokeAutopilotIdentifyDataUpdate(trafficData)
delay(TimeUnit.MINUTES.toMillis(10))
}
private fun generateTriangle(x: Double, y: Double, angle: Double, r: Double): List<Pair<Double, Double>> {
val angles = arrayOf(0, 120, 240)
val coordinates = ArrayList<Pair<Double, Double>>()
for(i in 0 until 3) {
val radian = Math.toRadians(angles[i] + angle)
val x1 = x + (r * cos(radian))
val y1 = y + (r * sin(radian))
coordinates += Pair(x1, y1)
}
coordinates.add(coordinates[0])
return coordinates
}
@Test
fun testGreenWave(): Unit = runBlocking {
@@ -164,8 +263,6 @@ class V2NTest {
Log.d(TAG, "location:[x:${targetX}, y:${targetY}, new_location:[x:${newPoint.first}, y:${newPoint.second}]")
FunctionBuildConfig.isNewV2NData = true
FunctionBuildConfig.v2nMainSwitch = true
FunctionBuildConfig.isNewV2NData = true
FunctionBuildConfig.v2nMainSwitch = true
runCatching {
val map = HashMap<String, Boolean>().also {
it["f1"] = FunctionBuildConfig.v2nMainSwitch

View File

@@ -6,36 +6,26 @@ import android.os.Message
import android.text.TextUtils
import android.util.Log
import androidx.core.util.Pair
import com.google.gson.JsonArray
import com.google.gson.JsonObject
import com.mogo.commons.voice.AIAssist
import com.mogo.eagle.core.data.config.FunctionBuildConfig
import com.mogo.eagle.core.data.enums.CommunicationType
import com.mogo.eagle.core.data.enums.DataSourceType
import com.mogo.eagle.core.data.enums.EventTypeEnumNew
import com.mogo.eagle.core.data.enums.TrafficTypeEnum
import com.mogo.eagle.core.data.enums.WarningDirectionEnum.ALERT_WARNING_TOP
import com.mogo.eagle.core.data.map.entity.MarkerExploreWay
import com.mogo.eagle.core.data.map.entity.MarkerLocation
import com.mogo.eagle.core.data.map.entity.V2XRoadEventEntity
import com.mogo.eagle.core.data.msgbox.MsgBoxBean
import com.mogo.eagle.core.data.msgbox.MsgBoxType.V2X
import com.mogo.eagle.core.data.msgbox.V2XMsg
import com.mogo.eagle.core.function.angle.scenes.Default
import com.mogo.eagle.core.function.angle.scenes.RoadEvent
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotIdentifyListener
import com.mogo.eagle.core.function.api.autopilot.IMoGoV2nNioEventListener
import com.mogo.eagle.core.function.api.hmi.warning.IMoGoWarningStatusListener
import com.mogo.eagle.core.function.api.hmi.xiaozhi.event.V2N
import com.mogo.eagle.core.function.api.hmi.xiaozhi.state.State
import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotIdentifyListenerManager
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationGCJ02ListenerManager
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationWGS84ListenerManager
import com.mogo.eagle.core.function.call.autopilot.CallerV2XListenerManager.V2NCarTypeCheck
import com.mogo.eagle.core.function.call.autopilot.CallerV2nNioEventListenerManager
import com.mogo.eagle.core.function.call.hmi.CallerHmiManager
import com.mogo.eagle.core.function.call.hmi.CallerRoadV2NEventWindowListenerManager
import com.mogo.eagle.core.function.call.map.CallerMapUIServiceManager
import com.mogo.eagle.core.function.call.map.CallerVisualAngleManager
import com.mogo.eagle.core.function.call.msgbox.CallerMsgBoxManager.saveMsgBox
import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
@@ -144,7 +134,7 @@ internal object V2NIdentifyDrawer: IEventDismissListener {
it.location = e.location
it.polygon = polygon
}
}), true, isDrawRoadLine(poiType)
}, isUseGps = true), true, isDrawRoadLine(poiType)
)
val distance = CoordinateUtils.calculateLineDistance(
@@ -168,6 +158,7 @@ internal object V2NIdentifyDrawer: IEventDismissListener {
)
)
if (polygon.isNotEmpty()) {
val decision = V2NUtils.computeOccupyLanesInfo(Triple(car.longitude, car.latitude, car.heading.toFloat()), Triple(itx.longitude, itx.latitude, itx.heading.toFloat()), polygon.map { kotlin.Pair(it.first, it.second) })
if (decision != null) {
val isDriver = AppIdentityModeUtils.isDriver(FunctionBuildConfig.appIdentityMode)
@@ -330,12 +321,10 @@ internal object V2NIdentifyDrawer: IEventDismissListener {
}
Logger.d(TAG, "cameraIp: $cameraIp, heading:$heading, uuid: $uuid")
val newEventId = "other_retrograde_vehicle_${event.eventId}"
val isUseGps = event.gnssType != 0
val eventLocation = if (isUseGps) arrayOf(event.longitude, event.latitude) else CoordinateTransform.GCJ02ToWGS84(event.longitude, event.latitude)
val carLocation = if (isUseGps) CallerChassisLocationWGS84ListenerManager.getChassisLocationWGS84() else CallerChassisLocationGCJ02ListenerManager.getChassisLocationGCJ02()
AiRoadMarker.aiMakers.getOrPut(newEventId) {
val eventLocation = when (event.gnssType) {
0 -> CoordinateTransform.GCJ02ToWGS84(event.longitude, event.latitude)
else -> arrayOf(event.longitude, event.latitude)
}
val carLocation = CallerChassisLocationWGS84ListenerManager.getChassisLocationWGS84()
val distance = CoordinateUtils.calculateLineDistance(carLocation.longitude, carLocation.latitude, eventLocation[0], eventLocation[1])
if (distance > 150) {
Logger.i(TAG, "other_retrograde_vehicle --> distance > 150")
@@ -352,11 +341,11 @@ internal object V2NIdentifyDrawer: IEventDismissListener {
isDriver,
String.format(EventTypeEnumNew.getWarningTts(EventTypeEnumNew.TYPE_SOCKET_ROAD_OTHER_RETROGRADE_VEHICLE.poiType), distance.toInt()),
cameraIp.toString(),
event.longitude,
event.latitude)
eventLocation[0],
eventLocation[1])
AiRoadMarker()
}.also {
it.marker(Marker(newEventId, EventTypeEnumNew.TYPE_SOCKET_ROAD_OTHER_RETROGRADE_VEHICLE.poiType, event.longitude, event.latitude, 0.0), drawMarker = true, false, isHighFrequency = true)
it.marker(Marker(newEventId, EventTypeEnumNew.TYPE_SOCKET_ROAD_OTHER_RETROGRADE_VEHICLE.poiType, eventLocation[0], eventLocation[1], heading, isUseGps = isUseGps), drawMarker = true, false, isHighFrequency = true)
}.receive()
} else if (msg.what == MSG_WHAT_DRAW_GREEN_WAVE) {
val data = msg.obj as? V2nCrossSpeed ?: return@Callback true
@@ -406,17 +395,19 @@ internal object V2NIdentifyDrawer: IEventDismissListener {
}
}
Logger.d(TAG, "cameraIp: $cameraIp, heading:$heading, uuid: $uuid")
val isUseGps = data.gnssType != 0
val eventLocation = if (isUseGps) arrayOf(data.longitude, data.latitude) else CoordinateTransform.GCJ02ToWGS84(data.longitude, data.latitude)
val carLocation = if (isUseGps) CallerChassisLocationWGS84ListenerManager.getChassisLocationWGS84() else CallerChassisLocationGCJ02ListenerManager.getChassisLocationGCJ02()
val distance = CoordinateUtils.calculateLineDistance(carLocation.longitude, carLocation.latitude, eventLocation[0], eventLocation[1])
AiRoadMarker.aiMakers.getOrPut(data.eventId) {
Logger.i(TAG, "people cross -- 2 --")
val isDriver = AppIdentityModeUtils.isDriver(FunctionBuildConfig.appIdentityMode)
val carLocation = CallerChassisLocationWGS84ListenerManager.getChassisLocationWGS84()
val distance = CoordinateUtils.calculateLineDistance(carLocation.longitude, carLocation.latitude, data.longitude, data.latitude)
if (distance > 150) {
Logger.i(TAG, "people cross --> distance > 150")
V2XBizTrace.onAck(TAG, mapOf("people cross" to "distance > 150"), true)
return@Callback true
}
Logger.i(TAG, "people cross -- 3 --")
val isDriver = AppIdentityModeUtils.isDriver(FunctionBuildConfig.appIdentityMode)
// 弹事件框
CallerRoadV2NEventWindowListenerManager.showLiveVideo(
data.eventId,
@@ -426,12 +417,12 @@ internal object V2NIdentifyDrawer: IEventDismissListener {
isDriver,
String.format(EventTypeEnumNew.getWarningTts(EventTypeEnumNew.TYPE_SOCKET_ROAD_PEOPLE_CROSS.poiType), distance.toInt()),
cameraIp.toString(),
data.longitude,
data.latitude)
eventLocation[0],
eventLocation[1])
AiRoadMarker()
}.also {
Logger.i(TAG, "people cross -- 4 --")
it.marker(Marker(data.eventId, EventTypeEnumNew.TYPE_SOCKET_ROAD_PEOPLE_CROSS.poiType, data.longitude, data.latitude, heading), drawMarker = true, false, isHighFrequency = true)
it.marker(Marker(data.eventId, EventTypeEnumNew.TYPE_SOCKET_ROAD_PEOPLE_CROSS.poiType, eventLocation[0], eventLocation[1], heading, isUseGps = isUseGps), drawMarker = true, false, isHighFrequency = true)
}.receive()
}
true

View File

@@ -107,7 +107,7 @@ class AiRoadMarker {
val builder = getOrPutPointOptionBuilder(markerId, V2XConst.V2X_MARKER_OWNER, MAP_MARKER)
builder
.set3DMode(true)
.isUseGps(true)
.isUseGps(marker.isUseGps)
.icon3DRes(EventTypeEnumNew.getMarker3DRes(marker.poiType))
.anchorColor("#D65D5AFF")
.controlAngle(true)
@@ -122,7 +122,7 @@ class AiRoadMarker {
if (marker.poiType == EventTypeEnumNew.TYPE_SOCKET_ROAD_OTHER_RETROGRADE_VEHICLE.poiType) {
distance = 100
}
val wrapper = MarkerWrapper(markerId, marker.poi_lon, marker.poi_lat, 1, elapsedDistance = distance)
val wrapper = MarkerWrapper(markerId, marker.poi_lon, marker.poi_lat, if (marker.isUseGps) 1 else 0, elapsedDistance = distance)
wrapper.onRemoved = {
builders.remove(markerId)
markerIds.remove(p.id)
@@ -153,7 +153,7 @@ class AiRoadMarker {
if (marker.poiType == EventTypeEnumNew.TYPE_SOCKET_ROAD_GREE_WAVE.poiType) {
elapsedDuration = TimeUnit.SECONDS.toMillis(3)
}
val wrapper = MarkerWrapper(markerId, marker.poi_lon, marker.poi_lat, 1, elapsedDistance = elapsedDistance, elapsedDuration = elapsedDuration)
val wrapper = MarkerWrapper(markerId, marker.poi_lon, marker.poi_lat, if (marker.isUseGps) 1 else 0, elapsedDistance = elapsedDistance, elapsedDuration = elapsedDuration)
if (drawMarker) {
marker.entity?.apply { roadMarker.drawMarkers(this, wrapper) }
}
@@ -371,6 +371,7 @@ class AiRoadMarker {
val polygon: List<Pair<Double, Double>>? = null,
var farthestPoint: Pair<Double, Double>? = null,
var entity: V2XRoadEventEntity? = null,
var isUseGps: Boolean = false
) {
override fun equals(other: Any?): Boolean {

View File

@@ -47,7 +47,7 @@ public class V2XRoadEventMarker implements IV2XMarker<V2XRoadEventEntity> {
List<Pair<Double, Double>> polygons = noveltyInfo.getPolygon();
if (gpsLocation != null && polygons != null) {
MarkerLocation location = noveltyInfo.getLocation();
AiRoadMarker.Marker m = new AiRoadMarker.Marker(noveltyInfo.getInfoId(), noveltyInfo.getPoiType(), gpsLocation.second, gpsLocation.first, location.getAngle(), polygons, null, entity);
AiRoadMarker.Marker m = new AiRoadMarker.Marker(noveltyInfo.getInfoId(), noveltyInfo.getPoiType(), gpsLocation.second, gpsLocation.first, location.getAngle(), polygons, null, entity, false);
AiRoadMarker aiMarker = new AiRoadMarker();
aiMarker.marker(m, true, isDrawRoadLine(m.getPoiType()), false);
AiRoadMarker.aiMakers.put(noveltyInfo.getInfoId(), aiMarker);

View File

@@ -16,6 +16,7 @@ import com.mogo.eagle.core.data.v2x.V2XEvent.RoadEventX
import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotControlManager
import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotControlManager.setDemoMode
import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotControlManager.setIgnoreConditionDraw
import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotIdentifyListenerManager
import com.mogo.eagle.core.function.call.autopilot.CallerV2nNioEventListenerManager
import com.mogo.eagle.core.function.call.cloud.CallerCloudListenerManager
import com.mogo.eagle.core.function.call.devatools.CallerDevaToolsManager
@@ -37,7 +38,9 @@ import io.netty.channel.Channel
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import mogo.telematics.pad.MessagePad
import mogo.telematics.pad.MessagePad.TrackedObject
import java.nio.charset.Charset
import java.util.Collections
class TeleMsgHandler : IMsgHandler {
@@ -103,6 +106,22 @@ class TeleMsgHandler : IMsgHandler {
}
return
}
if (it.protocolType == TelematicConstant.V2N_AI_ROAD_SHI_GONG) {
runCatching {
Log.d(TAG, "乘客屏收到司机屏转发云端下发的道路施工 --- 1 ---")
CallerAutopilotIdentifyListenerManager.invokeAutopilotIdentifyDataUpdate(Collections.singletonList(TrackedObject.parseFrom(msg.body)))
Log.d(TAG, "乘客屏收到司机屏转发云端下发的道路施工 --- 2 ---")
}
return
}
if (it.protocolType == TelematicConstant.V2N_AI_ROAD_SHI_GU) {
runCatching {
Log.d(TAG, "乘客屏收到司机屏转发云端下发的道路事故 --- 1 ---")
CallerAutopilotIdentifyListenerManager.invokeAutopilotIdentifyDataUpdate(Collections.singletonList(TrackedObject.parseFrom(msg.body)))
Log.d(TAG, "乘客屏收到司机屏转发云端下发的道路事故 --- 2 ---")
}
return
}
if (it.protocolType == TelematicConstant.V2N_NEW_LINK_SWITCH) {
try {
Log.d(TAG, "乘客屏收到司机屏转发的新链路开关 --- 1 ---")

View File

@@ -19,10 +19,16 @@ class TelematicConstant {
const val V2N_NEW_LINK_SWITCH = 202 // FunctionBuildConfig#v2nMainSwitch & FunctionBuildConfig#isNewV2NData
// -------------------- For Android Unit Test -----BEGIN------------
const val V2N_AI_ROAD_PEOPLE_CROSS = 203
const val V2N_AI_ROAD_GREEN_WAVE = 204
const val V2N_AI_ROAD_OTHER_RETROGRADE_VEHICLE = 205
const val V2N_AI_ROAD_SHI_GONG = 206
const val V2N_AI_ROAD_SHI_GU = 207
// -------------------- For Android Unit Test ------ END ------------
}
}