[3.4.0-map-sdk] remove unuse thread to call mapdata api and fix bug of invoke suspend func which call

This commit is contained in:
zhongchao
2023-09-22 17:29:41 +08:00
parent 34f11edb96
commit cf747fc289
13 changed files with 138 additions and 234 deletions

View File

@@ -43,7 +43,7 @@ object OverViewDataManager {
null
}
data?.let { infStructures ->
withContext(Dispatchers.Default) {
`withContext(Dispatchers.Default) {`
val map = HashMap<String, ArrayList<Infrastructure>>()
infStructures.forEach {
val geoHash = it.geoHash

View File

@@ -20,10 +20,11 @@ import com.mogo.eagle.function.biz.v2x.v2n.remove.MarkerWrapper
import com.mogo.eagle.function.biz.v2x.v2n.scenario.scene.road.V2XAiRoadEventMarker
import com.mogo.map.MogoData.Companion.mogoMapData
import com.mogo.map.overlay.core.Level.ROAD_CENTER_LINE
import com.mogo.map.overlay.line.*
import com.mogo.map.overlay.line.Polyline
import com.zhidaoauto.map.data.road.CenterLine
import java.util.*
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.AtomicInteger
import java.util.concurrent.atomic.AtomicReference
/**
@@ -34,9 +35,9 @@ class AiRoadMarker {
companion object {
@JvmField
val aiMakers = ConcurrentHashMap<String, AiRoadMarker>()
}
private val TAG = "AiRoadMarker"
private const val TAG = "AiRoadMarker"
}
private val marker by lazy { AtomicReference<Marker>() }
@@ -50,6 +51,7 @@ class AiRoadMarker {
private val roadMarker by lazy { V2XAiRoadEventMarker() }
private val line = AtomicReference<Polyline>()
private val countDown = AtomicInteger(0)
private val handler by lazy {
Handler(Looper.getMainLooper())
@@ -91,6 +93,7 @@ class AiRoadMarker {
if (drawRoadLine) {
//施工中心点前方的自车行驶方向上300米距离
var l1: CenterLine? = null
var l2: CenterLine? = null
mogoMapData.get()?.getCenterLineRangeInfo(
marker.poi_lon,
marker.poi_lat,
@@ -101,100 +104,116 @@ class AiRoadMarker {
V2XBizTrace.onAck("$TAG --- marker --- 3 --- l1:", it)
l1 = result
}
countDown.incrementAndGet()
realMark(marker, wrapper, l1, l2, location.heading)
})
var l2: CenterLine? = null
mogoMapData.get()?.getCenterLineRangeInfo(
marker.poi_lon,
marker.poi_lat,
location.heading.toFloat(),
-300f, call = { result ->
result?.let {
V2XBizTrace.onAck("$TAG --- marker --- 3 --- l2:", it)
l2 = result
}
countDown.incrementAndGet()
realMark(marker, wrapper, l1, l2, location.heading)
})
if (l1 == null || l2 == null) {
V2XBizTrace.onAck("$TAG --- marker --- 3 --- return ----", "")
return@post
}
if(l1!!.points.isEmpty() || l2!!.points.isEmpty()){
V2XBizTrace.onAck("$TAG --- marker --- 3 --- return ----", "")
return@post
}
V2XBizTrace.onAck("$TAG --- marker --- 4 --- l2:", l2!!)
val points = LinkedList<MogoLatLng>()
if (l2 != null && l2!!.points.isNotEmpty()) {
points.addAll(l2!!.points.reversed().map {
MogoLatLng(it.latitude, it.longitude)
})
}
val centerX = marker.poi_lon
val centerY = marker.poi_lat
V2XBizTrace.onAck("$TAG --- marker --- 5 --- marker:", marker)
val farthestPoint = marker.polygon?.let {
var find: Pair<Double, Double> = Pair(centerX, centerY)
var min = Long.MAX_VALUE
for (p in it) {
val angle = DrivingDirectionUtils.getDegreeOfCar2Poi2(
centerX,
centerY,
p.first,
p.second,
location.heading
)
if (angle < min) {
min = angle
find = p
}
}
MogoLatLng(find.second, find.first)
} ?: MogoLatLng(centerY, centerX)
marker.farthestPoint = Pair(farthestPoint.lon, farthestPoint.lat)
V2XBizTrace.onAck("$TAG --- marker --- 6 --- marker:", marker)
if (l1 != null && l1!!.points.isNotEmpty()) {
for (l in l1!!.points) {
if (DrivingDirectionUtils.getDegreeOfCar2Poi2(
farthestPoint.lon,
farthestPoint.lat,
l.longitude,
l.latitude,
(location.heading + 180)
) < 90L
) {
points.add(l.let { MogoLatLng(it.latitude, it.longitude) })
}
}
}
if (points.size <= 1) {
return@post
}
val evaluator = ArgbEvaluator()
val interceptor = DecelerateInterpolator(1.5f)
val total = points.size
val colors = ArrayList<Int>()
(0..total).forEach { i ->
colors += evaluator.evaluate(
interceptor.getInterpolation(i * 1f / total),
START_COLOR,
END_COLOR
) as Int
}
builder.points(points)
builder.colors(colors)
builder.setVisible(true)
V2XBizTrace.onAck("$TAG --- marker --- 7 --- points:", "${points.size}")
val line = overlayManager?.showOrUpdateLine(builder.build())
if (line != null) {
this.line.set(line)
wrapper.addLine(line)
}
}
wrapper.onRemoved = { id ->
aiMakers.remove(id)
}
MarkerRemoveManager.addMarker(wrapper)
}
}
private fun realMark(
marker: Marker,
wrapper: MarkerWrapper,
l1: CenterLine?,
l2: CenterLine?,
heading: Double
) {
if (countDown.get() != 2) {
return
}
if (l1 == null || l2 == null) {
V2XBizTrace.onAck("$TAG --- marker --- 3 --- line null return ----", "")
return
}
if (l1.points.isEmpty() || l2.points.isEmpty()) {
V2XBizTrace.onAck("$TAG --- marker --- 3 --- line points null return ----", "")
return
}
V2XBizTrace.onAck("$TAG --- marker --- 4 --- l2:", l2)
val points = LinkedList<MogoLatLng>()
if (l2.points.isNotEmpty()) {
points.addAll(l2.points.reversed().map {
MogoLatLng(it.latitude, it.longitude)
})
}
val centerX = marker.poi_lon
val centerY = marker.poi_lat
V2XBizTrace.onAck("$TAG --- marker --- 5 --- marker:", marker)
val farthestPoint = marker.polygon?.let {
var find: Pair<Double, Double> = Pair(centerX, centerY)
var min = Long.MAX_VALUE
for (p in it) {
val angle = DrivingDirectionUtils.getDegreeOfCar2Poi2(
centerX,
centerY,
p.first,
p.second,
heading
)
if (angle < min) {
min = angle
find = p
}
}
MogoLatLng(find.second, find.first)
} ?: MogoLatLng(centerY, centerX)
marker.farthestPoint = Pair(farthestPoint.lon, farthestPoint.lat)
V2XBizTrace.onAck("$TAG --- marker --- 6 --- marker:", marker)
if (l1.points.isNotEmpty()) {
for (l in l1.points) {
if (DrivingDirectionUtils.getDegreeOfCar2Poi2(
farthestPoint.lon,
farthestPoint.lat,
l.longitude,
l.latitude,
(heading + 180)
) < 90L
) {
points.add(l.let { MogoLatLng(it.latitude, it.longitude) })
}
}
}
if (points.size <= 1) {
return
}
val evaluator = ArgbEvaluator()
val interceptor = DecelerateInterpolator(1.5f)
val total = points.size
val colors = ArrayList<Int>()
(0..total).forEach { i ->
colors += evaluator.evaluate(
interceptor.getInterpolation(i * 1f / total),
START_COLOR,
END_COLOR
) as Int
}
builder.points(points)
builder.colors(colors)
builder.setVisible(true)
V2XBizTrace.onAck("$TAG --- marker --- 7 --- points:", "${points.size}")
val line = overlayManager?.showOrUpdateLine(builder.build())
if (line != null) {
this.line.set(line)
wrapper.addLine(line)
}
wrapper.onRemoved = { id ->
aiMakers.remove(id)
}
MarkerRemoveManager.addMarker(wrapper)
}
private fun removeLine() {
val old = line.get()
V2XBizTrace.onAck("$TAG --- removeRedLine --- 1", "")

View File

@@ -95,24 +95,10 @@ class OfflineMapDialog(context: Context) : BaseFloatDialog(context) {
private fun cacheHDDataByCityByLonLat() {
mogoMapData.get()?.cacheHDDataByCityByLonLat(location!!, { _, progress ->
if (Thread.currentThread() != Looper.getMainLooper().thread) {
ThreadUtils.runOnUiThread({
updateProgress(progress.toInt())
}, ThreadUtils.MODE.QUEUE)
} else {
updateProgress(progress.toInt())
}
}, { _, state ->
if (Thread.currentThread() != Looper.getMainLooper().thread) {
ThreadUtils.runOnUiThread({
if (state == 0) {// 失败
showNewContent(isLoading = false, false)
}
}, ThreadUtils.MODE.QUEUE)
} else {
if (state == 0) {// 失败
showNewContent(isLoading = false, false)
}
if (state == 0) {// 失败
showNewContent(isLoading = false, false)
}
})
}
@@ -120,24 +106,10 @@ class OfflineMapDialog(context: Context) : BaseFloatDialog(context) {
private fun cacheHDOfflineData() {
if (location == null) {// 拿到了高德地图的cityCode
mogoMapData.get()?.cacheHDDataByCity({ _, progress ->
if (Thread.currentThread() != Looper.getMainLooper().thread) {
ThreadUtils.runOnUiThread({
updateProgress(progress.toInt())
}, ThreadUtils.MODE.QUEUE)
} else {
updateProgress(progress.toInt())
}
updateProgress(progress.toInt())
}, { _, state ->
if (Thread.currentThread() != Looper.getMainLooper().thread) {
ThreadUtils.runOnUiThread({
if (state == 0) {// 失败
showNewContent(isLoading = false, false)
}
}, ThreadUtils.MODE.QUEUE)
} else {
if (state == 0) {// 失败
showNewContent(isLoading = false, false)
}
if (state == 0) {// 失败
showNewContent(isLoading = false, false)
}
})
} else {// 只拿到了高精的经纬度

View File

@@ -8,7 +8,6 @@ import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.os.Build
import android.os.Looper
import android.os.Process
import android.text.Html
import android.util.AttributeSet
@@ -18,7 +17,6 @@ import androidx.annotation.RequiresApi
import androidx.appcompat.widget.PopupMenu
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat
import androidx.core.content.FileProvider
import androidx.core.view.MenuCompat
import androidx.core.view.isVisible
import androidx.lifecycle.lifecycleScope
@@ -50,9 +48,9 @@ import com.mogo.eagle.core.data.obu.ObuStatusInfo
import com.mogo.eagle.core.function.api.autopilot.*
import com.mogo.eagle.core.function.api.datacenter.obu.IMoGoObuConnectListener
import com.mogo.eagle.core.function.api.datacenter.obu.IMoGoObuInfoListener
import com.mogo.eagle.core.function.api.setting.ISopSettingListener
import com.mogo.eagle.core.function.api.devatools.IMoGoDevaToolsFuncConfigListener
import com.mogo.eagle.core.function.api.devatools.IMoGoDevaToolsListener
import com.mogo.eagle.core.function.api.setting.ISopSettingListener
import com.mogo.eagle.core.function.call.autopilot.*
import com.mogo.eagle.core.function.call.devatools.CallerDevaToolsFuncConfigListenerManager
import com.mogo.eagle.core.function.call.devatools.CallerDevaToolsListenerManager
@@ -234,7 +232,7 @@ internal class DebugSettingView @JvmOverloads constructor(
//添加 底盘灯光数据 监听
CallerChassisLamplightListenerManager.addListener(TAG, this)
//雨天、美化、点云设置同步
CallerSopSettingManager.addListener(TAG,this)
CallerSopSettingManager.addListener(TAG, this)
//添加 业务配置监听
CallerDevaToolsFuncConfigListenerManager.registerDevaToolsFuncConfigListener(
@@ -597,13 +595,9 @@ internal class DebugSettingView @JvmOverloads constructor(
}
if (AppIdentityModeUtils.isPassenger(FunctionBuildConfig.appIdentityMode)) {
ThreadUtils.getIoPool().execute {
mogoMapData.get()?.isCityDataCached {
isHDCached = it
UiThreadHandler.post {
btn_cache_hd_map.text = "缓存高精离线地图(${if (it) "已是最新版" else "待更新"}!)"
}
}
mogoMapData.get()?.isCityDataCached {
isHDCached = it
btn_cache_hd_map.text = "缓存高精离线地图(${if (it) "已是最新版" else "待更新"}!)"
}
btn_cache_hd_map.visibility = View.VISIBLE
}
@@ -706,7 +700,7 @@ internal class DebugSettingView @JvmOverloads constructor(
tbIsDemoMode.isChecked = FunctionBuildConfig.isDemoMode
// 演示模式
tbIsDemoMode.setOnCheckedChangeListener { compoundButton, isChecked ->
if(!compoundButton.isPressed){
if (!compoundButton.isPressed) {
return@setOnCheckedChangeListener
}
FunctionBuildConfig.isDemoMode = !FunctionBuildConfig.isDemoMode
@@ -745,7 +739,7 @@ internal class DebugSettingView @JvmOverloads constructor(
tbIsRainMode.isChecked = FunctionBuildConfig.isRainMode
//雨天模式
tbIsRainMode.setOnCheckedChangeListener { compoundButton, isChecked ->
if(!compoundButton.isPressed){
if (!compoundButton.isPressed) {
return@setOnCheckedChangeListener
}
CallerAutoPilotControlManager.setRainMode(isChecked)
@@ -869,7 +863,7 @@ internal class DebugSettingView @JvmOverloads constructor(
tbDrawPointCloudData.isChecked = FunctionBuildConfig.isDrawPointCloudData
//是否渲染点云数据
tbDrawPointCloudData.setOnCheckedChangeListener { compoundButton, isChecked ->
if(!compoundButton.isPressed){
if (!compoundButton.isPressed) {
return@setOnCheckedChangeListener
}
CallerAutoPilotControlManager.setIsDrawPointCloud(isChecked)
@@ -2174,40 +2168,16 @@ internal class DebugSettingView @JvmOverloads constructor(
private fun cacheHDOfflineData(isGaoDe: Boolean) {
if (isGaoDe) {// 拿到了高德地图的cityCode
mogoMapData.get()?.cacheHDDataByCity({ _, progress ->
if (Thread.currentThread() != Looper.getMainLooper().thread) {
ThreadUtils.runOnUiThread(Runnable {
cacheHDCityProgressUpdate(progress)
}, ThreadUtils.MODE.QUEUE)
} else {
cacheHDCityProgressUpdate(progress)
}
cacheHDCityProgressUpdate(progress)
}, { _, state ->
if (Thread.currentThread() != Looper.getMainLooper().thread) {
ThreadUtils.runOnUiThread(Runnable {
cacheHDCityResult(state)
}, ThreadUtils.MODE.QUEUE)
} else {
cacheHDCityResult(state)
}
cacheHDCityResult(state)
})
} else {// 只拿到了高精的经纬度
mGnssInfo?.let { loc ->
mogoMapData.get()?.cacheHDDataByCityByLonLat(loc, { _, progress ->
if (Thread.currentThread() != Looper.getMainLooper().thread) {
ThreadUtils.runOnUiThread(Runnable {
cacheHDCityProgressUpdate(progress)
}, ThreadUtils.MODE.QUEUE)
} else {
cacheHDCityProgressUpdate(progress)
}
cacheHDCityProgressUpdate(progress)
}, { _, state ->
if (Thread.currentThread() != Looper.getMainLooper().thread) {
ThreadUtils.runOnUiThread(Runnable {
cacheHDCityResult(state)
}, ThreadUtils.MODE.QUEUE)
} else {
cacheHDCityResult(state)
}
cacheHDCityResult(state)
})
}
}

View File

@@ -157,12 +157,8 @@ class SystemVersionView @JvmOverloads constructor(
}
}
ThreadUtils.getIoPool().execute {
mogoMapData.get()?.isCityDataCached {
UiThreadHandler.post {
updateHDDataCacheStatus(it)
}
}
mogoMapData.get()?.isCityDataCached {
updateHDDataCacheStatus(it)
}
if (AdUpgradeStateHelper.isConfirmUpgrade()) {
@@ -369,12 +365,12 @@ class SystemVersionView @JvmOverloads constructor(
* HQ、M1 MAP350开始弃用其他车型MAP360开始弃用
*/
override fun onAutopilotStatusRespByQuery(status: SystemStatusInfo.StatusInfo) {
Log.i(TAG,"hdMapVer="+status.hdMapVer)
Log.i(TAG, "hdMapVer=" + status.hdMapVer)
//hdMapVer返回示例/home/mogo/autopilot/share/hadmap_engine/data/hadmap_data/db.sqlite|bj|2.2.7|对bus路线上的junction进行修改对原609场景修改为6091、6092、6201、 6202四种细分场景并对通往园区路口改为619
if(status.hdMapVer!= null && status.hdMapVer.isNotEmpty()){
if (status.hdMapVer != null && status.hdMapVer.isNotEmpty()) {
//对地图版本进行截取
val city = status.hdMapVer.substringAfter(".sqlite|").substringBefore("|")
val version =status.hdMapVer.substringAfter("$city|").substringBefore("|")
val version = status.hdMapVer.substringAfter("$city|").substringBefore("|")
AppConfigInfo.adHdMapVersion = "${city}_${version}"
updateAdHdMapVersion()
}
@@ -388,12 +384,12 @@ class SystemVersionView @JvmOverloads constructor(
* @param statusInf 数据
*/
override fun onSystemStatus(statusInf: SsmInfo.SsmStatusInf) {
Log.i(TAG,"hdMapVer="+statusInf.hdMapVer)
Log.i(TAG, "hdMapVer=" + statusInf.hdMapVer)
//hdMapVer返回示例/home/mogo/autopilot/share/hadmap_engine/data/hadmap_data/db.sqlite|bj|2.2.7|对bus路线上的junction进行修改对原609场景修改为6091、6092、6201、 6202四种细分场景并对通往园区路口改为619
if(statusInf.hdMapVer!= null && statusInf.hdMapVer.isNotEmpty()){
if (statusInf.hdMapVer != null && statusInf.hdMapVer.isNotEmpty()) {
//对地图版本进行截取
val city = statusInf.hdMapVer.substringAfter(".sqlite|").substringBefore("|")
val version =statusInf.hdMapVer.substringAfter("$city|").substringBefore("|")
val version = statusInf.hdMapVer.substringAfter("$city|").substringBefore("|")
AppConfigInfo.adHdMapVersion = "${city}_${version}"
updateAdHdMapVersion()
}
@@ -402,8 +398,8 @@ class SystemVersionView @JvmOverloads constructor(
/**
* 更新工控机高精地图版本
*/
private fun updateAdHdMapVersion(){
if(tvAdHdMapVersionContent.text.isNullOrEmpty() && AppConfigInfo.adHdMapVersion.isNotEmpty() || tvAdHdMapVersionContent.text != AppConfigInfo.adHdMapVersion){
private fun updateAdHdMapVersion() {
if (tvAdHdMapVersionContent.text.isNullOrEmpty() && AppConfigInfo.adHdMapVersion.isNotEmpty() || tvAdHdMapVersionContent.text != AppConfigInfo.adHdMapVersion) {
ThreadUtils.runOnUiThread {
tvAdHdMapVersionContent.text = AppConfigInfo.adHdMapVersion
}