[MapDataCollect]高精车采逻辑优化

This commit is contained in:
renwj
2022-03-24 11:10:44 +08:00
parent e1ccfc755c
commit 31e4ee1681
11 changed files with 378 additions and 8 deletions

View File

@@ -51,6 +51,8 @@ dependencies {
kapt rootProject.ext.dependencies.aroutercompiler
//implementation rootProject.ext.dependencies.adasHigh
implementation rootProject.ext.dependencies.mogocustommapoperational
implementation rootProject.ext.dependencies.amapnavi3dmap
implementation rootProject.ext.dependencies.amaplocation

View File

@@ -0,0 +1,193 @@
package com.mogo.eagle.core.function.impl.collect
import android.content.Context
import android.text.TextUtils
import com.alibaba.android.arouter.facade.annotation.Route
import com.mogo.cloud.passport.IMoGoTokenCallback
import com.mogo.cloud.passport.MoGoAiCloudClient
import com.mogo.cloud.passport.MoGoAiCloudClientConfig
import com.mogo.commons.debug.DebugConfig
import com.mogo.eagle.core.data.constants.MogoServicePaths
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.Companion.M_MAP
import com.mogo.eagle.core.data.map.MogoLocation
import com.mogo.eagle.core.function.api.map.collect.IMoGoMapDataCollectProvider
import com.mogo.eagle.core.function.api.map.listener.IMoGoMapLocationListener
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
import com.mogo.eagle.core.function.call.map.CallerMapLocationListenerManager
import com.zhidaoauto.map.operational.open.GatherApi
import com.zhidaoauto.map.operational.open.GatherParams
import com.zhidaoauto.map.operational.open.abs.OnTaskListener
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.CopyOnWriteArrayList
import java.util.concurrent.atomic.AtomicReference
@Route(path = MogoServicePaths.PATH_MAP_DATA_COLLECT_PROVIDER)
class MoGoMapDataCollectProvider : IMoGoMapDataCollectProvider, OnTaskListener, IMoGoMapLocationListener, IMoGoTokenCallback {
companion object {
const val TAG = "MoGoMapDataCollect"
}
private val executor by lazy {
AtomicReference<GatherApi>(null)
}
private val listeners by lazy {
CopyOnWriteArrayList<IMoGoMapDataCollectProvider.OnMapCollectCmdListener>()
}
private val map: MutableMap<Int, Status> by lazy {
ConcurrentHashMap()
}
override val functionName: String = "$M_MAP$TAG"
@Volatile
private var hasInit = false
override fun init(context: Context?) {
CallerMapLocationListenerManager.addListener(functionName, this)
executor.set(context?.let {
GatherApi.also { itx ->
itx.init(it,
GatherParams.init()
.setDebugMode(DebugConfig.isDebug())
.setCoordinateType(GatherParams.COORDINATETYPE_GCJ02))
} })
executor.get()?.setOnTaskListener(this)
val carSn = MoGoAiCloudClientConfig.getInstance().sn
if (!TextUtils.isEmpty(carSn)) {
executor.get()?.setCarSn(carSn)
}
MoGoAiCloudClient.getInstance().addTokenCallbacks(this)
CallerLogger.d("$M_MAP$TAG", "--------- init --------")
CallerLogger.d("$M_MAP$TAG", "executor: ${ executor.get()?.hashCode() ?: 0 }")
}
override fun onDestroy() {
CallerMapLocationListenerManager.removeListener("$M_MAP$TAG")
CallerLogger.d("$M_MAP$TAG", "--------- onDestroy --------")
executor.get()?.setOnTaskListener(null)
listeners.clear()
map.clear()
}
override fun registerOnMapCollectTaskListener(listener: IMoGoMapDataCollectProvider.OnMapCollectCmdListener?) {
CallerLogger.d("$M_MAP$TAG", "--------- registerOnMapCollectTaskListener --------")
listener ?: return
if (listeners.contains(listener)) {
return
}
listeners += listener
}
override fun unRegisterOnMapCollectTaskListener(listener: IMoGoMapDataCollectProvider.OnMapCollectCmdListener?) {
CallerLogger.d("$M_MAP$TAG", "--------- unRegisterOnMapCollectTaskListener --------")
listener ?: return
if (!listeners.contains(listener)) {
return
}
listeners.remove(listener)
}
override fun finish(
id: Int,
state: Int,
gpsPath: String,
videoPath: String,
reason: String
) {
CallerLogger.d("$M_MAP$TAG", "-- finish:[$id, $state, $gpsPath, $videoPath, $reason]")
try {
if (isInValidStatus()) {
CallerLogger.w("$M_MAP$TAG", "-- finish: 状态无效")
return
}
if (!map.containsKey(id)) {
CallerLogger.w("$M_MAP$TAG", "-- finish: 无相关指令")
return
}
CallerLogger.d("$M_MAP$TAG", "-- finish: 结束任务[$id]")
executor.get()?.finishTask(id, state, gpsPath, videoPath, reason)
} catch (e : Throwable) {
e.printStackTrace()
CallerLogger.e("$M_MAP$TAG", "-- finish:\n$e")
} finally {
map[id] = Status.FINISH
}
}
override fun onTaskFinish(id: Int, time: Long) {
CallerLogger.d("$M_MAP$TAG", "地图模块下发结束采集指令 -> [$id, $time]")
if (!map.containsKey(id) || map[id] == Status.FINISH) {
CallerLogger.w("$M_MAP$TAG", "地图模块下发结束采集指令 -> 任务[$id]已经提前完成,无需再次请求自动驾驶模块结束采集")
return
}
CallerLogger.d("$M_MAP$TAG", "地图模块下发结束采集指令 -> [$id, $time] -> 调用自动驾驶模块,结束数据采集")
listeners.forEach {
it.onMapCollectEnd(id, time)
}
}
override fun onTaskStart(id: Int, time: Long) {
CallerLogger.d("$M_MAP$TAG", "地图模块下发开始采集指令 -> [$id, $time]")
map[id] = Status.INIT
listeners.forEach {
it.onMapCollectStart(id, time)
}
map[id] = Status.START
}
override fun setIsInit() {
if (!hasInit) {
executor.get()?.also {
hasInit = true
CallerLogger.d("$M_MAP$TAG", "告之地图sdk定义数据可以用了")
it.setIsInit()
}
}
}
override fun onLocationChanged(location: MogoLocation?) {
location ?: return
executor.get()?.updateLocation(
location.longitude,
location.latitude,
location.bearing,
location.speed,
location.provider == "GPS_SELF")
}
private fun isInValidStatus(): Boolean {
if (map.isEmpty()) {
return true
}
val iterator = map.iterator()
while (iterator.hasNext()) {
val next = iterator.next()
if (next.value == Status.FINISH) {
iterator.remove()
}
}
if (map.filter { it.value == Status.START }.isEmpty()) {
return true
}
return false
}
override fun onTokenGot(token: String?, sn: String?) {
CallerLogger.d("$M_MAP$TAG", "-- onTokenGot --> $sn")
sn?.let {
executor.get()?.setCarSn(it)
}
}
override fun onError(code: Int, msg: String?) = Unit
private sealed class Status {
object INIT : Status() //初始状态
object START : Status() //开始状态
object FINISH : Status() //完成状态
}
}