diff --git a/OCH/common/common/src/main/java/com/mogo/och/common/module/manager/autopilot/line/LineManager.kt b/OCH/common/common/src/main/java/com/mogo/och/common/module/manager/autopilot/line/LineManager.kt index 95330857d3..536c385f53 100644 --- a/OCH/common/common/src/main/java/com/mogo/och/common/module/manager/autopilot/line/LineManager.kt +++ b/OCH/common/common/src/main/java/com/mogo/och/common/module/manager/autopilot/line/LineManager.kt @@ -15,6 +15,7 @@ import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListener import com.mogo.eagle.core.function.call.datacenter.CallerDataCenterBizListener import com.mogo.eagle.core.function.call.map.CallerMapGlobalTrajectoryDrawManager import com.mogo.eagle.core.function.call.och.CallerEagleBaseFunctionCall4OchManager +import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.d import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.e import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.Companion.M_BUS @@ -79,13 +80,14 @@ object LineManager : CallerBase() { private var autopilotId: String by Delegates.observable("") { _, oldValue, newValue -> if (oldValue != newValue) { CallerEagleBaseFunctionCall4OchManager.setOchAutopilotOrderId(newValue) - val (start, end) = getStations() - if(start!=null&&end!=null){ - CallerDataCenterBizListener.invokeOchInfo(OchInfo(0, mutableListOf(start.toMogoLocation(),end.toMogoLocation()))) - }else{ - CallerDataCenterBizListener.invokeOchInfo(OchInfo(0, mutableListOf())) + if(!AppIdentityModeUtils.isBus(FunctionBuildConfig.appIdentityMode)&&!AppIdentityModeUtils.isShuttle(FunctionBuildConfig.appIdentityMode)){ + val (start, end) = getStations() + if(start!=null&&end!=null){ + CallerDataCenterBizListener.invokeOchInfo(OchInfo(0, mutableListOf(start.toMogoLocation(),end.toMogoLocation()))) + }else{ + CallerDataCenterBizListener.invokeOchInfo(OchInfo(0, mutableListOf())) + } } - } } diff --git a/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/model/LineModel.kt b/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/model/LineModel.kt index 635b965e5b..15c40c8764 100644 --- a/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/model/LineModel.kt +++ b/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/model/LineModel.kt @@ -5,7 +5,11 @@ import android.content.Context import com.mogo.commons.AbsMogoApplication import com.mogo.commons.storage.SharedPrefsMgr import com.mogo.eagle.core.data.config.FunctionBuildConfig +import com.mogo.eagle.core.data.map.SiteMarkerBean +import com.mogo.eagle.core.data.och.OchInfo +import com.mogo.eagle.core.data.v2x.Point import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotControlManager +import com.mogo.eagle.core.function.call.datacenter.CallerDataCenterBizListener import com.mogo.eagle.core.network.utils.digest.DigestUtils import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.d @@ -327,6 +331,7 @@ object LineModel { currentTask = null LineManager.setLineInfo(null) LineManager.setStartAndEndStation(null, null) + LineModel.callEyeMap(true) stationList = mutableListOf() startStationIndex = 0 mBusLinesCallbackMap.forEach { @@ -360,6 +365,7 @@ object LineModel { currentTask = null LineManager.setLineInfo(null) LineManager.setStartAndEndStation(null, null) + LineModel.callEyeMap(true) stationList = mutableListOf() startStationIndex = 0 mBusLinesCallbackMap.forEach { @@ -404,4 +410,45 @@ object LineModel { } } + fun callEyeMap(isClear:Boolean){ + if(isClear) { + val ochInfo = OchInfo(1, mutableListOf()) + ochInfo.siteMarkerList = mutableListOf() + CallerDataCenterBizListener.invokeOchInfo(ochInfo) + }else{ + val siteList = mutableListOf() + var temp: SiteMarkerBean?=null + stationList?.let { + it.forEachIndexed { index, busStationBean -> + if(index==0){ + temp =SiteMarkerBean(Point(busStationBean.gcjLon,busStationBean.gcjLat),R.drawable.bus_station_start,0.5f,0.87f) + }else if(index==it.size-1){ + temp =SiteMarkerBean(Point(busStationBean.gcjLon,busStationBean.gcjLat),R.drawable.bus_station_end,0.5f,0.87f) + }else{ + if(busStationBean.drivingStatus==1){ + temp =SiteMarkerBean(Point(busStationBean.gcjLon,busStationBean.gcjLat),R.drawable.bus_station_pass,0.5f,0.478f) + }else if (busStationBean.drivingStatus==3){ + temp =SiteMarkerBean(Point(busStationBean.gcjLon,busStationBean.gcjLat),R.drawable.bus_station_notarrive,0.5f,0.478f) + }else if (busStationBean.drivingStatus==2){ + if(busStationBean.isLeaving){ + temp =SiteMarkerBean(Point(busStationBean.gcjLon,busStationBean.gcjLat),R.drawable.bus_station_pass,0.5f,0.478f) + }else{ + temp =SiteMarkerBean(Point(busStationBean.gcjLon,busStationBean.gcjLat),R.drawable.bus_station_notarrive,0.5f,0.478f) + } + } + } + temp?.let {temp-> + siteList.add(temp) + } + } + } + val (start, end) = LineManager.getStations() + if(start!=null&&end!=null){ + val ochInfo = OchInfo(1, mutableListOf(start.toMogoLocation(),end.toMogoLocation())) + ochInfo.siteMarkerList = siteList + CallerDataCenterBizListener.invokeOchInfo(ochInfo) + } + } + } + } diff --git a/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/model/OrderModel.kt b/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/model/OrderModel.kt index b78c7fff71..865c646471 100644 --- a/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/model/OrderModel.kt +++ b/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/model/OrderModel.kt @@ -416,6 +416,7 @@ object OrderModel { if(LineModel.startStationIndex +1< it.size){ val endStation = it[LineModel.startStationIndex +1] LineManager.setStartAndEndStation(startStation,endStation) + LineModel.callEyeMap(false) } } LineModel.arrivedStationSuccess() @@ -431,6 +432,7 @@ object OrderModel { if(LineModel.startStationIndex +1< it.size){ val endStation = it[LineModel.startStationIndex +1] LineManager.setStartAndEndStation(startStation,endStation) + LineModel.callEyeMap(false) } } LineModel.arrivedStationSuccess() diff --git a/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/repository/line/impl/NormalRepository.kt b/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/repository/line/impl/NormalRepository.kt index e1120f92e6..79a4836648 100644 --- a/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/repository/line/impl/NormalRepository.kt +++ b/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/repository/line/impl/NormalRepository.kt @@ -124,6 +124,7 @@ class NormalRepository: ILineRepository { if (LineModel.startStationIndex < stationlist.size-1) { val endStation = stationlist[LineModel.startStationIndex + 1] LineManager.setStartAndEndStation(startStation,endStation) + LineModel.callEyeMap(false) } } return@flatMap Observable.just(true) diff --git a/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/repository/line/impl/WeaknetRepository.kt b/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/repository/line/impl/WeaknetRepository.kt index 933ecf7b70..71c7fc1141 100644 --- a/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/repository/line/impl/WeaknetRepository.kt +++ b/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/repository/line/impl/WeaknetRepository.kt @@ -100,6 +100,7 @@ class WeaknetRepository : ILineRepository { if (LineModel.startStationIndex < stationlist.size-1) { val endStation = stationlist[LineModel.startStationIndex + 1] LineManager.setStartAndEndStation(startStation,endStation) + LineModel.callEyeMap(false) } } diff --git a/OCH/shuttle/driver_weaknet/src/main/res/drawable-nodpi/bus_station_end.png b/OCH/shuttle/driver_weaknet/src/main/res/drawable-nodpi/bus_station_end.png new file mode 100644 index 0000000000..45071228a2 Binary files /dev/null and b/OCH/shuttle/driver_weaknet/src/main/res/drawable-nodpi/bus_station_end.png differ diff --git a/OCH/shuttle/driver_weaknet/src/main/res/drawable-nodpi/bus_station_notarrive.png b/OCH/shuttle/driver_weaknet/src/main/res/drawable-nodpi/bus_station_notarrive.png new file mode 100644 index 0000000000..cbb2dda8b9 Binary files /dev/null and b/OCH/shuttle/driver_weaknet/src/main/res/drawable-nodpi/bus_station_notarrive.png differ diff --git a/OCH/shuttle/driver_weaknet/src/main/res/drawable-nodpi/bus_station_pass.png b/OCH/shuttle/driver_weaknet/src/main/res/drawable-nodpi/bus_station_pass.png new file mode 100644 index 0000000000..a411050a6e Binary files /dev/null and b/OCH/shuttle/driver_weaknet/src/main/res/drawable-nodpi/bus_station_pass.png differ diff --git a/OCH/shuttle/driver_weaknet/src/main/res/drawable-nodpi/bus_station_start.png b/OCH/shuttle/driver_weaknet/src/main/res/drawable-nodpi/bus_station_start.png new file mode 100644 index 0000000000..baca87f72f Binary files /dev/null and b/OCH/shuttle/driver_weaknet/src/main/res/drawable-nodpi/bus_station_start.png differ diff --git a/OCH/shuttle/passenger_weaknet/src/main/java/m2/com/mogo/och/shuttle/weaknet/passenger/ui/widget/M2StatusBarView.kt b/OCH/shuttle/passenger_weaknet/src/main/java/m2/com/mogo/och/shuttle/weaknet/passenger/ui/widget/M2StatusBarView.kt index 2d4be3d1d2..808ae4f02a 100644 --- a/OCH/shuttle/passenger_weaknet/src/main/java/m2/com/mogo/och/shuttle/weaknet/passenger/ui/widget/M2StatusBarView.kt +++ b/OCH/shuttle/passenger_weaknet/src/main/java/m2/com/mogo/och/shuttle/weaknet/passenger/ui/widget/M2StatusBarView.kt @@ -19,6 +19,7 @@ import com.mogo.eagle.core.utilcode.kotlin.* import com.mogo.eagle.core.utilcode.util.ClickUtils import com.mogo.eagle.core.utilcode.util.ThreadUtils import com.mogo.och.shuttle.weaknet.passenger.R +import kotlinx.android.synthetic.main.shuttle_p_m2_view_status_bar.view.aciv_wait_ele import kotlinx.android.synthetic.main.shuttle_p_m2_view_status_bar.view.progress import kotlinx.android.synthetic.main.shuttle_p_m2_view_status_bar.view.tv_power_cos import kotlinx.coroutines.* @@ -64,10 +65,11 @@ class M2StatusBarView @JvmOverloads constructor( CallerChassisStatesListenerManager.addListener(TAG,this) progress?.also { - it.progress = 50 + it.progress = 0 + aciv_wait_ele.visibility = VISIBLE } tv_power_cos?.also { - it.text = "50%" + it.text = "检测中" } } @@ -104,6 +106,7 @@ class M2StatusBarView @JvmOverloads constructor( progress?.also { it.progress = power } tv_power_cos?.also {it.text = "$power%" } } + aciv_wait_ele.visibility = GONE } } } finally { diff --git a/OCH/shuttle/passenger_weaknet/src/main/res/m2/drawable-nodpi/shuttle_p_m2_electricity.png b/OCH/shuttle/passenger_weaknet/src/main/res/m2/drawable-nodpi/shuttle_p_m2_electricity.png new file mode 100644 index 0000000000..4a27ff437f Binary files /dev/null and b/OCH/shuttle/passenger_weaknet/src/main/res/m2/drawable-nodpi/shuttle_p_m2_electricity.png differ diff --git a/OCH/shuttle/passenger_weaknet/src/main/res/m2/layout/shuttle_p_m2_view_status_bar.xml b/OCH/shuttle/passenger_weaknet/src/main/res/m2/layout/shuttle_p_m2_view_status_bar.xml index 8d106b4337..0cf568ac02 100644 --- a/OCH/shuttle/passenger_weaknet/src/main/res/m2/layout/shuttle_p_m2_view_status_bar.xml +++ b/OCH/shuttle/passenger_weaknet/src/main/res/m2/layout/shuttle_p_m2_view_status_bar.xml @@ -58,6 +58,16 @@ app:layout_constraintRight_toLeftOf="@+id/tv_power_cos" app:layout_constraintTop_toTopOf="@+id/iv_logon" /> + + () + params["time"] = sdf.format(Date()) + params["title"] = title + params["info"] = info + MogoAnalyticUtils.track(EVENT_KEY_HARDWARE_DEVICES, params) + + } catch (e: Exception) { + e.printStackTrace() + } + } +} \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/setting/DebugSettingView.kt b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/setting/DebugSettingView.kt index 6dadffc3f0..db4218888f 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/setting/DebugSettingView.kt +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/setting/DebugSettingView.kt @@ -9,7 +9,6 @@ import android.content.Intent import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.os.Build -import android.os.Environment import android.os.Environment.* import android.os.Process import android.text.Html @@ -135,9 +134,9 @@ import com.mogo.map.uicontroller.VisualAngleMode.MAP_STYLE_VR_ANGLE_300 import com.mogo.map.uicontroller.VisualAngleMode.MAP_STYLE_VR_ANGLE_CROSS import com.mogo.map.uicontroller.VisualAngleMode.MAP_STYLE_VR_ANGLE_TOP import com.mogo.map.uicontroller.VisualAngleMode.MODE_LONG_SIGHT -import com.mogo.tts.base.IMogoTTSCallback import com.mogo.support.device.DevicesManager import com.mogo.support.device.IBindStateChangeListener +import com.mogo.tts.base.IMogoTTSCallback import com.zhjt.mogo.adas.data.AdasConstants import com.zhjt.service.chain.ChainLog import kotlinx.android.synthetic.main.view_debug_setting.view.appVersionInfoLayout @@ -337,6 +336,7 @@ import kotlin.collections.component4 import kotlin.collections.set import kotlin.math.abs import kotlin.system.exitProcess +import com.mogo.eagle.core.function.hmi.ui.tools.ShowVersionDialog /** @@ -1336,37 +1336,16 @@ internal class DebugSettingView @JvmOverloads constructor( } //硬件服务绑定状态以及版本 + tvHardwareDeviceBindState.text = + getBindDeviceServiceState(DevicesManager.getServiceBindState()) tvHardwareDeviceBindState.setOnClickListener { - val state = when (DevicesManager.getServiceBindState()) { - 0 -> { - "绑定成功" - } - - 1 -> { - "绑定失败:未安装“硬件服务”APP" - } - - 2 -> { - "绑定失败:没有绑定权限或找不到服务" - } - - 3 -> { - "服务被异常销毁" - } - - else -> { - "未知" - } - } - var msg = "客户端SDK版本:${DevicesManager.getSDKVersion() ?: "未知"}\n" + var msg = + "${getBindDeviceServiceState(DevicesManager.getServiceBindState(), false)}\n" + msg += "客户端SDK版本:${DevicesManager.getSDKVersion() ?: "未知"}\n" msg += "客户端SDK AIDL版本:${DevicesManager.getSDKAIDLVersion() ?: "未知"}\n" msg += "硬件服务端APP版本:${DevicesManager.getServerVersion() ?: "未知"}\n" - msg += "硬件服务端APP AIDL版本:${DevicesManager.getServerAIDLVersion() ?: ""}" - AlertDialog.Builder(context) - .setTitle("硬件服务绑定状态: $state") - .setMessage(msg) - .setPositiveButton("确定", null) - .create().show() + msg += "硬件服务端APP AIDL版本:${DevicesManager.getServerAIDLVersion() ?: "未知"}" + ShowVersionDialog(context, "硬件服务绑定", msg).show() } } @@ -2766,29 +2745,42 @@ internal class DebugSettingView @JvmOverloads constructor( } override fun onServiceState(state: Int) { - val stateMsg = when (state) { + UiThreadHandler.post { + tvHardwareDeviceBindState.text = getBindDeviceServiceState(state) + } + } + + private fun getBindDeviceServiceState(state: Int, isUseTitle: Boolean = true): CharSequence { + val msg = when (state) { 0 -> { - "绑定成功" + "绑定成功" } 1 -> { - "绑定失败:未安装“硬件服务”APP" + "绑定失败,未安装“硬件服务”APP" } 2 -> { - "绑定失败:没有绑定权限或找不到服务" + "绑定失败,没有绑定权限或找不到服务" } 3 -> { - "服务被异常销毁" + "绑定失败,服务被异常销毁" } else -> { - "未知" + "未知" } } - UiThreadHandler.post { - tvHardwareDeviceBindState.text = "硬件服务绑定状态: $stateMsg" + val title = if (isUseTitle) { + "硬件服务绑定" + } else { + "" + } + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + Html.fromHtml("${title}状态:${msg}", Html.FROM_HTML_MODE_LEGACY) + } else { + Html.fromHtml("${title}状态:${msg}") } } } \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/tools/ShowVersionDialog.kt b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/tools/ShowVersionDialog.kt new file mode 100644 index 0000000000..54baff053f --- /dev/null +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/tools/ShowVersionDialog.kt @@ -0,0 +1,49 @@ +package com.mogo.eagle.core.function.hmi.ui.tools + +import android.content.Context +import android.widget.TextView +import com.mogo.eagle.core.function.hmi.R +import com.mogo.eagle.core.function.hmi.dialog.BaseFloatDialog +import com.mogo.support.device.DevicesManager + + +/** + * 离线地图缓存 + */ +class ShowVersionDialog(context: Context, val title: String, val msg: String) : + BaseFloatDialog(context, TAG) { + + companion object { + private const val TAG = "ShowVersionDialog" + } + + private var tvTitle: TextView? = null + private var tvMsg: TextView? = null + private var okView: TextView? = null + + + init { + setContentView(R.layout.dialog_show_version) + setCanceledOnTouchOutside(true) + setCancelable(true) + initView() + } + + private fun initView() { + tvTitle = findViewById(R.id.tv_title) + tvMsg = findViewById(R.id.tv_msg) + okView = findViewById(R.id.tv_ok) + tvTitle?.text = title + tvMsg?.text = msg + + okView?.setOnClickListener { + dismiss() + } + } + + + override fun dismiss() { + super.dismiss() + + } +} \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/layout/dialog_show_version.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/dialog_show_version.xml new file mode 100644 index 0000000000..ba3103c97e --- /dev/null +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/dialog_show_version.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/deva/chain/ChainConstant.kt b/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/deva/chain/ChainConstant.kt index 60714df309..4f1081368b 100644 --- a/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/deva/chain/ChainConstant.kt +++ b/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/deva/chain/ChainConstant.kt @@ -152,5 +152,10 @@ class ChainConstant { // Biz const val CHAIN_CODE_MAP_ROAD_CROSS_ERROR = "CHAIN_CODE_MAP_ROAD_CROSS_ERROR" + //硬件设备相关 + const val CHAIN_CODE_HARDWARE_DEVICES = "CHAIN_CODE_HARDWARE_DEVICES" + + // + } } \ No newline at end of file diff --git a/libraries/mogo-hardware-devices/src/main/java/com/mogo/support/device/DevicesManager.kt b/libraries/mogo-hardware-devices/src/main/java/com/mogo/support/device/DevicesManager.kt index bd2ec77ccf..bcc15a9468 100644 --- a/libraries/mogo-hardware-devices/src/main/java/com/mogo/support/device/DevicesManager.kt +++ b/libraries/mogo-hardware-devices/src/main/java/com/mogo/support/device/DevicesManager.kt @@ -15,12 +15,24 @@ import com.mogo.support.serialport.common.core.Device import com.mogo.support.serialport.common.devices.speech.cx830se.data.SwitchingValueData import java.util.concurrent.ConcurrentHashMap +data class OpenState( + var path: String?, + var deviceType: Byte, + var isOpen: Boolean, + var message: String? +) + object DevicesManager { private const val TAG = "DevicesManager" - private var serviceBindState = -1//-1:未知 + private val serialPortManager: SerialPortManager by lazy { SerialPortManager() // 初始化 SerialPortManager } + private var serviceBindState = -1//-1:未知 + private val verificationOpenState = + OpenState(path = null, deviceType = -1, isOpen = false, message = "未初始化") + private val speechCx830seOpenState = + OpenState(path = null, deviceType = -1, isOpen = false, message = "未初始化") private val bindStateChangeListeners: ConcurrentHashMap = ConcurrentHashMap() @@ -28,11 +40,28 @@ object DevicesManager { ConcurrentHashMap() private val speechCx830seListeners: ConcurrentHashMap = ConcurrentHashMap() + private val physicalButtonListeners: ConcurrentHashMap = + ConcurrentHashMap() + private var writeChainLogListener: IWriteChainLogListener? = null fun init(context: Context, sn: String) { serialPortManager.bindService(context, sn, bindStateChangeListener) } + fun destroy() { + serialPortManager.close(DefaultDevices.VERIFICATION.path) + serialPortManager.close(DefaultDevices.SPEECH_CX830SE.path) + serialPortManager.unbindService() + } + + fun registerWriteChainLogListener(writeChainLogListener: IWriteChainLogListener) { + this.writeChainLogListener = writeChainLogListener + } + + fun unregisterWriteChainLogListener() { + this.writeChainLogListener = null + } + /** * 注册服务端APP绑定状态 */ @@ -41,6 +70,7 @@ object DevicesManager { return } bindStateChangeListeners[tag] = listener + listener.onServiceState(serviceBindState)//注册时回调一次当前状态 } /** @@ -53,15 +83,19 @@ object DevicesManager { } /** - * 注册核销设备回调接口 注册时自动连接核销设备 + * 注册核销设备回调接口 注册时如果未连接将进行自动连接 */ fun addVerificationListener(tag: String, listener: IVerificationAutoListener) { if (verificationAutoListeners.containsKey(tag)) { return } verificationAutoListeners[tag] = listener - if (verificationAutoListeners.isNotEmpty()) { - if (serviceBindState == SERVICE_STATE.BIND_SUCCEED) { + listener.onDeviceState( + verificationOpenState.path, verificationOpenState.deviceType, + verificationOpenState.isOpen, verificationOpenState.message + )//注册时回调一次当前状态 + if (serviceBindState == SERVICE_STATE.BIND_SUCCEED) { + if (!serialPortManager.isOpen(DefaultDevices.VERIFICATION.path)) { serialPortManager.open(DefaultDevices.VERIFICATION, verificationListener) } } @@ -75,20 +109,27 @@ object DevicesManager { verificationAutoListeners.remove(tag) } if (verificationAutoListeners.isEmpty()) { - + if (serviceBindState == SERVICE_STATE.BIND_SUCCEED) { + serialPortManager.close(DefaultDevices.VERIFICATION.path) + } } } /** - * 注册语音设备回调接口 注册时自动连接语音设备 + * 注册语音设备回调接口 注册时如果未连接将进行自动连接 */ fun addSpeechCx830seListener(tag: String, listener: ISpeechCx830seListener) { if (speechCx830seListeners.containsKey(tag)) { return } + listener.onOpenState( + speechCx830seOpenState.path ?: "", + speechCx830seOpenState.isOpen, + speechCx830seOpenState.message + )//注册时回调一次当前状态 speechCx830seListeners[tag] = listener - if (speechCx830seListeners.isNotEmpty()) { - if (serviceBindState == SERVICE_STATE.BIND_SUCCEED) { + if (serviceBindState == SERVICE_STATE.BIND_SUCCEED) { + if (!serialPortManager.isOpen(DefaultDevices.SPEECH_CX830SE.path)) { serialPortManager.open(DefaultDevices.SPEECH_CX830SE, speechCx830seListener) } } @@ -101,6 +142,41 @@ object DevicesManager { if (speechCx830seListeners.containsKey(tag)) { speechCx830seListeners.remove(tag) } + if (speechCx830seListeners.isEmpty() && physicalButtonListeners.isEmpty()) { + if (serviceBindState == SERVICE_STATE.BIND_SUCCEED) { + serialPortManager.close(DefaultDevices.SPEECH_CX830SE.path) + } + } + } + + + /** + * 注册语音设备物理按键回调接口 注册时如果未连接将进行自动连接 + */ + fun addPhysicalButtonListener(tag: String, listener: IPhysicalButtonListener) { + if (physicalButtonListeners.containsKey(tag)) { + return + } + physicalButtonListeners[tag] = listener + if (serviceBindState == SERVICE_STATE.BIND_SUCCEED) { + if (!serialPortManager.isOpen(DefaultDevices.SPEECH_CX830SE.path)) { + serialPortManager.open(DefaultDevices.SPEECH_CX830SE, speechCx830seListener) + } + } + } + + /** + * 取消注册语音设备回调接口 + */ + fun removePhysicalButtonListener(tag: String) { + if (physicalButtonListeners.containsKey(tag)) { + physicalButtonListeners.remove(tag) + } + if (physicalButtonListeners.isEmpty() && speechCx830seListeners.isEmpty()) { + if (serviceBindState == SERVICE_STATE.BIND_SUCCEED) { + serialPortManager.close(DefaultDevices.SPEECH_CX830SE.path) + } + } } @@ -108,44 +184,39 @@ object DevicesManager { override fun onServiceState(serviceState: Int) { serviceBindState = serviceState - if (bindStateChangeListeners.isNotEmpty()) { - bindStateChangeListeners.forEach { - it.value.onServiceState(serviceState) - } - } - //TODO 链路日志和埋点 -// OchChainLogManager.writeChainLogScanner( -// TAG + "bindStatus", -// "绑定服务结果:serviceState:${serviceState}" -// ) + var msg = "" when (serviceState) { SERVICE_STATE.BIND_SUCCEED -> { - Log.d(TAG, "服务绑定成功") - if (verificationAutoListeners.isNotEmpty()) { + msg = "服务绑定成功" + if (!serialPortManager.isOpen(DefaultDevices.VERIFICATION.path)) { serialPortManager.open(DefaultDevices.VERIFICATION, verificationListener) } - if (speechCx830seListeners.isNotEmpty()) { + if (!serialPortManager.isOpen(DefaultDevices.SPEECH_CX830SE.path)) { serialPortManager.open(DefaultDevices.SPEECH_CX830SE, speechCx830seListener) } } SERVICE_STATE.BIND_FAILURE_UNINSTALLED -> { - Log.d(TAG, "服务绑定失败:未安装串口服务端APP") + msg = "服务绑定失败:未安装串口服务端APP" } SERVICE_STATE.BIND_FAILURE_NO_PERMISSION_NOT_FOUND -> { - Log.d( - TAG, + msg = "服务绑定失败:没有绑定权限或找不到服务(如果是此状态,基本上安装后就可以找到,主要就是权限问题)" - ) } SERVICE_STATE.EXCEPTION -> { - Log.d(TAG, "服务被异常销毁") + msg = "服务被异常销毁" } else -> {} } + if (bindStateChangeListeners.isNotEmpty()) { + bindStateChangeListeners.forEach { + it.value.onServiceState(serviceState) + } + } + writeChainLogListener?.onWriteChainLog("硬件服务", "绑定状态=${msg}") } } @@ -157,11 +228,19 @@ object DevicesManager { isOpen: Boolean, message: String? ) { + verificationOpenState.path = path + verificationOpenState.deviceType = deviceType + verificationOpenState.isOpen = isOpen + verificationOpenState.message = message if (verificationAutoListeners.isNotEmpty()) { verificationAutoListeners.forEach { it.value.onDeviceState(path, deviceType, isOpen, message) } } + writeChainLogListener?.onWriteChainLog( + "核销设备", + "状态=地址:${path} 设备类型:${deviceType} 是否打开:${isOpen} 消息:${message}" + ) } override fun onReceive(data: VerificationData) { @@ -170,6 +249,7 @@ object DevicesManager { it.value.onReceive(data) } } + writeChainLogListener?.onWriteChainLog("核销设备", "核销数据接收=$data") } } @@ -181,29 +261,18 @@ object DevicesManager { isOpen: Boolean, throwableMessage: String? ) { + speechCx830seOpenState.path = path + speechCx830seOpenState.isOpen = isOpen + speechCx830seOpenState.message = throwableMessage if (speechCx830seListeners.isNotEmpty()) { speechCx830seListeners.forEach { it.value.onOpenState(path, isOpen, throwableMessage) } } - -// if (isOpen) { -// openBtnEnable(!serialPortManager.isOpen(selectDevice.path)) -// updateUi(path, true) -// if (serialPortManager.getDeviceType(path) == DeviceType.SPEECH_CX830SE) { -// val device = serialPortManager.getOpenedSerialPort(path) -// serialPortManager.speechCx830seSendCommand( -// device, -// SpeechCommand.READ_DEVICE_ADDRESS -// ) -// serialPortManager.speechCx830seSendCommand( -// device, -// SpeechCommand.READ_SWITCHING_VALUE_STATE -// ) -// } -// } else { -// showOpenFailed(path) -// } + writeChainLogListener?.onWriteChainLog( + "车外语音设备", + "状态=地址:${path} 是否打开:${isOpen} 消息:${throwableMessage}" + ) } override fun onSpeechState(path: String, state: Int) { @@ -232,13 +301,13 @@ object DevicesManager { else -> "" } - Log.d(TAG, msg) + writeChainLogListener?.onWriteChainLog("车外语音设备", "播报状态=${msg}") } override fun onSwitchingValue(path: String, state: Int, data: SwitchingValueData?) { super.onSwitchingValue(path, state, data) - if (speechCx830seListeners.isNotEmpty()) { - speechCx830seListeners.forEach { + if (physicalButtonListeners.isNotEmpty()) { + physicalButtonListeners.forEach { it.value.onSwitchingValue(path, state, data) } } @@ -258,8 +327,11 @@ object DevicesManager { else -> null } - if (!msg.isNullOrEmpty()) { - Log.d(TAG, msg) + if (!msg.isNullOrEmpty() && data != null) { + writeChainLogListener?.onWriteChainLog( + "车外语音设备", + "物理按钮状态=$msg $data" + ) } } @@ -283,7 +355,10 @@ object DevicesManager { else -> null } if (!msg.isNullOrEmpty()) { - Log.d(TAG, msg) + writeChainLogListener?.onWriteChainLog( + "车外语音设备", + "设备地址读取状态=$msg 设备地址$address" + ) } } @@ -321,18 +396,21 @@ object DevicesManager { */ @Define.Code fun speechCx830seBroadcast(content: String?): Int { - return serialPortManager.speechCx830seBroadcastSpeech( + val code = serialPortManager.speechCx830seBroadcastSpeech( DefaultDevices.SPEECH_CX830SE, content ) + writeChainLogListener?.onWriteChainLog( + "车外语音设备", + "播报内容=${content ?: " 调用结果=${code}"}" + ) + return code + } /** * 设备是否打开 - * @param device {@link DefaultDevices#SPEECH_CX830SE} - * {@link DefaultDevices#VERIFICATION} - * {@link DefaultDevices#VERIFICATION_SK87R} - * {@link DefaultDevices#VERIFICATION_Q350} + * @param device [DefaultDevices.SPEECH_CX830SE] [DefaultDevices.VERIFICATION] [DefaultDevices.VERIFICATION_SK87R] [DefaultDevices.VERIFICATION_Q350] */ fun isDeviceOpen(device: Device): Boolean { if (DefaultDevices.VERIFICATION.equals(device)) { diff --git a/libraries/mogo-hardware-devices/src/main/java/com/mogo/support/device/IPhysicalButtonListener.kt b/libraries/mogo-hardware-devices/src/main/java/com/mogo/support/device/IPhysicalButtonListener.kt new file mode 100644 index 0000000000..bf801870f8 --- /dev/null +++ b/libraries/mogo-hardware-devices/src/main/java/com/mogo/support/device/IPhysicalButtonListener.kt @@ -0,0 +1,19 @@ +package com.mogo.support.device + +import com.mogo.support.serialport.common.core.Define +import com.mogo.support.serialport.common.devices.speech.cx830se.data.SwitchingValueData + +/** + * 语音设备(科星互联 CX-830S-E)物理按钮状态监听 + */ +interface IPhysicalButtonListener { + /** + * 开关量状态 + * 设备主动触发开关量时 state = Code.PASSIVITY_RECEIVE + * + * @param path 串口 + * @param state 状态 查询成功:{@link Code#SUCCESS};查询命令下发失败:{@link Code#FAILED};查询超时:{@link Code#TIMEOUT};设备主动触发开关量:{@link Code#PASSIVITY_RECEIVE}; + * @param data 开关量数据 + */ + fun onSwitchingValue(path: String, @Define.Code state: Int, data: SwitchingValueData?) +} \ No newline at end of file diff --git a/libraries/mogo-hardware-devices/src/main/java/com/mogo/support/device/ISpeechCx830seListener.kt b/libraries/mogo-hardware-devices/src/main/java/com/mogo/support/device/ISpeechCx830seListener.kt index 710c4040d1..74ad08eb96 100644 --- a/libraries/mogo-hardware-devices/src/main/java/com/mogo/support/device/ISpeechCx830seListener.kt +++ b/libraries/mogo-hardware-devices/src/main/java/com/mogo/support/device/ISpeechCx830seListener.kt @@ -1,7 +1,6 @@ package com.mogo.support.device; import com.mogo.support.serialport.common.core.Define -import com.mogo.support.serialport.common.devices.speech.cx830se.data.SwitchingValueData /** * 语音设备(科星互联 CX-830S-E)监听 @@ -25,16 +24,6 @@ interface ISpeechCx830seListener { */ fun onSpeechState(path: String, @Define.Code state: Int) {} - /** - * 开关量状态 - * 设备主动触发开关量时 state = Code.PASSIVITY_RECEIVE - * - * @param path 串口 - * @param state 状态 查询成功:{@link Code#SUCCESS};查询命令下发失败:{@link Code#FAILED};查询超时:{@link Code#TIMEOUT};设备主动触发开关量:{@link Code#PASSIVITY_RECEIVE}; - * @param data 开关量数据 - */ - fun onSwitchingValue(path: String, @Define.Code state: Int, data: SwitchingValueData?) {} - /** * 设备地址 * diff --git a/libraries/mogo-hardware-devices/src/main/java/com/mogo/support/device/IWriteChainLogListener.kt b/libraries/mogo-hardware-devices/src/main/java/com/mogo/support/device/IWriteChainLogListener.kt new file mode 100644 index 0000000000..227dc01b60 --- /dev/null +++ b/libraries/mogo-hardware-devices/src/main/java/com/mogo/support/device/IWriteChainLogListener.kt @@ -0,0 +1,9 @@ +package com.mogo.support.device + +/** + * 日志 + */ +interface IWriteChainLogListener { + + fun onWriteChainLog(title: String, info: String) +} \ No newline at end of file