完成了自动驾驶状态信息回传

Signed-off-by: 董宏宇 <martindhy@gmail.com>
This commit is contained in:
董宏宇
2021-10-12 21:24:58 +08:00
parent 870af04059
commit 9802124169
15 changed files with 309 additions and 37 deletions

View File

@@ -0,0 +1,127 @@
package com.mogo.eagle.core.function.call.autopilot
import androidx.annotation.Nullable
import com.mogo.eagle.core.data.autopilot.AdasOCHData
import com.mogo.eagle.core.data.autopilot.AutopilotStatusInfo
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutoPilotStatusListener
import com.mogo.eagle.core.function.api.obu.IMoGoObuStatusListener
import com.mogo.eagle.core.function.call.base.CallerBase
import com.mogo.eagle.core.utilcode.util.GsonUtils
import com.mogo.eagle.core.utilcode.util.LogUtils
/**
* @author xiaoyuzhou
* @date 2021/9/30 5:48 下午
* 域控制器相关的回调监听
*/
object CallerAutoPilotStatusListenerManager : CallerBase() {
private val TAG = "CallerAutopilotListenerManager"
// 存储最后一次回调的数据,当有新当位置注册了监听将此数据回调过去,防止有些模块注册顺序问题导致无法获取最新状态
private var mAutopilotStatusInfo: AutopilotStatusInfo = AutopilotStatusInfo()
// 存储所有注册了监听的对象invokeXXXX进行遍历回调将信息同步
private val mAutoPilotStatusListeners: HashMap<String, IMoGoAutoPilotStatusListener> = HashMap()
/**
* 查询AutoPilot状态
*/
fun getAutoPilotStatusInfo(): AutopilotStatusInfo {
return mAutopilotStatusInfo
}
/**
* 查询AutoPilot状态
*/
fun getAutoPilotStatusInfoJsonString(): String {
return GsonUtils.toJson(mAutopilotStatusInfo)
}
/**
* 添加监听
* @param tag 标记,用来注销监听使用
* @param listener 监听回调
*/
fun addListener(
@Nullable tag: String,
@Nullable listener: IMoGoAutoPilotStatusListener
) {
mAutoPilotStatusListeners[tag] = listener
listener.onAutoPilotStatusResponse(mAutopilotStatusInfo)
}
/**
* 删除监听
* @param tag 标记,用来注销监听使用
*/
fun removeListener(@Nullable tag: String) {
mAutoPilotStatusListeners.remove(tag)
}
/**
* 删除自动驾驶按钮选中监听
* @param listener 要删除的监听对象
*/
fun removeListener(@Nullable listener: IMoGoObuStatusListener) {
mAutoPilotStatusListeners.forEach {
if (it.value == listener) {
mAutoPilotStatusListeners.remove(it.key)
}
}
}
/**
* 自动驾驶状态信息回调
*/
@Synchronized
fun invokeAutoPilotStatusListener() {
LogUtils.dTag(TAG, "$mAutopilotStatusInfo")
invokeAutoPilotStatusListener(mAutopilotStatusInfo)
}
/**
* 自动驾驶状态信息回调
* @param autopilotStatusInfo 自动驾驶状态信息
*/
@Synchronized
fun invokeAutoPilotStatusListener(autopilotStatusInfo: AutopilotStatusInfo) {
LogUtils.dTag(TAG, "$autopilotStatusInfo")
mAutopilotStatusInfo = autopilotStatusInfo
mAutoPilotStatusListeners.forEach {
val tag = it.key
val listener = it.value
LogUtils.dTag(TAG, "tag:$tag listener:$listener")
listener.onAutoPilotStatusResponse(mAutopilotStatusInfo)
}
}
/**
* 自动驾驶网约车回调数据 回调
* @param adasOCHData 自动驾驶网约车回调数据
*/
fun invokeArriveAtStationListener(adasOCHData: AdasOCHData) {
LogUtils.dTag(TAG, "$adasOCHData")
mAutoPilotStatusListeners.forEach {
val tag = it.key
val listener = it.value
LogUtils.dTag(TAG, "tag:$tag listener:$listener")
listener.onAutoPilotArriveAtStation(adasOCHData)
}
}
/**
* 自动驾驶状态回调
* @param state
* @param reason
*/
fun invokeStateChangedListener(state: Int, reason: String) {
LogUtils.dTag(TAG, "$state $reason")
mAutoPilotStatusListeners.forEach {
val tag = it.key
val listener = it.value
LogUtils.dTag(TAG, "tag:$tag listener:$listener")
listener.onAutoPilotStateChanged(state, reason)
}
}
}

View File

@@ -24,7 +24,14 @@ object CallerObuListenerManager : CallerBase() {
/**
* 查询OBU状态
*/
fun getObuStatusInfo(): String {
fun getObuStatusInfo(): ObuStatusInfo {
return mObuStatusInfo
}
/**
* 查询OBU状态
*/
fun getObuStatusInfoJsonString(): String {
return GsonUtils.toJson(mObuStatusInfo)
}
@@ -61,6 +68,14 @@ object CallerObuListenerManager : CallerBase() {
}
}
/**
* 触发自动驾驶按钮选中监听
*/
fun invokeListener() {
LogUtils.dTag(TAG, "isChecked:$mObuStatusInfo")
invokeListener(mObuStatusInfo)
}
/**
* 触发自动驾驶按钮选中监听
* @param obuStatusInfo 选中状态