[672][device] 注册硬件服务状态与设备回调接口时,回调一次设备状态信息
This commit is contained in:
@@ -28,7 +28,7 @@ class ShowVersionDialog(context: Context, val title: String, val msg: String) :
|
||||
setCancelable(true)
|
||||
initView()
|
||||
}
|
||||
var i=3;
|
||||
|
||||
private fun initView() {
|
||||
tvTitle = findViewById(R.id.tv_title)
|
||||
tvMsg = findViewById(R.id.tv_msg)
|
||||
@@ -37,7 +37,6 @@ class ShowVersionDialog(context: Context, val title: String, val msg: String) :
|
||||
tvMsg?.text = msg
|
||||
|
||||
okView?.setOnClickListener {
|
||||
DevicesManager.speechCx830seBroadcast("你好${i++}")
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<String, IBindStateChangeListener> =
|
||||
ConcurrentHashMap()
|
||||
@@ -30,7 +42,6 @@ object DevicesManager {
|
||||
ConcurrentHashMap()
|
||||
private val physicalButtonListeners: ConcurrentHashMap<String, IPhysicalButtonListener> =
|
||||
ConcurrentHashMap()
|
||||
|
||||
private var writeChainLogListener: IWriteChainLogListener? = null
|
||||
|
||||
fun init(context: Context, sn: String) {
|
||||
@@ -59,6 +70,7 @@ object DevicesManager {
|
||||
return
|
||||
}
|
||||
bindStateChangeListeners[tag] = listener
|
||||
listener.onServiceState(serviceBindState)//注册时回调一次当前状态
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,6 +90,10 @@ object DevicesManager {
|
||||
return
|
||||
}
|
||||
verificationAutoListeners[tag] = listener
|
||||
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)
|
||||
@@ -106,6 +122,11 @@ object DevicesManager {
|
||||
if (speechCx830seListeners.containsKey(tag)) {
|
||||
return
|
||||
}
|
||||
listener.onOpenState(
|
||||
speechCx830seOpenState.path ?: "",
|
||||
speechCx830seOpenState.isOpen,
|
||||
speechCx830seOpenState.message
|
||||
)//注册时回调一次当前状态
|
||||
speechCx830seListeners[tag] = listener
|
||||
if (serviceBindState == SERVICE_STATE.BIND_SUCCEED) {
|
||||
if (!serialPortManager.isOpen(DefaultDevices.SPEECH_CX830SE.path)) {
|
||||
@@ -207,6 +228,10 @@ 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)
|
||||
@@ -219,7 +244,6 @@ object DevicesManager {
|
||||
}
|
||||
|
||||
override fun onReceive(data: VerificationData) {
|
||||
Log.i(TAG, "核销数据=${data.toString()}")
|
||||
if (verificationAutoListeners.isNotEmpty()) {
|
||||
verificationAutoListeners.forEach {
|
||||
it.value.onReceive(data)
|
||||
@@ -237,6 +261,9 @@ 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)
|
||||
@@ -275,7 +302,6 @@ object DevicesManager {
|
||||
else -> ""
|
||||
}
|
||||
writeChainLogListener?.onWriteChainLog("车外语音设备", "播报状态=${msg}")
|
||||
Log.d(TAG, msg)
|
||||
}
|
||||
|
||||
override fun onSwitchingValue(path: String, state: Int, data: SwitchingValueData?) {
|
||||
@@ -329,7 +355,10 @@ object DevicesManager {
|
||||
else -> null
|
||||
}
|
||||
if (!msg.isNullOrEmpty()) {
|
||||
Log.d(TAG, msg)
|
||||
writeChainLogListener?.onWriteChainLog(
|
||||
"车外语音设备",
|
||||
"设备地址读取状态=$msg 设备地址$address"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -381,10 +410,7 @@ object DevicesManager {
|
||||
|
||||
/**
|
||||
* 设备是否打开
|
||||
* @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)) {
|
||||
|
||||
Reference in New Issue
Block a user