[3.3.0][魔方] 添加链路日志
This commit is contained in:
@@ -11,23 +11,33 @@ internal class MoFangCommandExecutor {
|
||||
companion object {
|
||||
private const val TAG = "MoFangCommandExecutor"
|
||||
private const val MSG_WHAT_KEY_CODE_A = 0x01
|
||||
private const val MSG_WHAT_KEY_CODE_BL = 0x02
|
||||
private const val MSG_WHAT_KEY_CODE_C = 0x03
|
||||
private const val MSG_WHAT_KEY_CODE_D = 0x04
|
||||
private const val MSG_WHAT_KEY_CODE_E = 0x05
|
||||
private const val MSG_WHAT_KEY_CODE_EL = 0x06
|
||||
private const val MSG_WHAT_KEY_CODE_AB = 0x07
|
||||
private const val MSG_WHAT_KEY_CODE_B = 0x02
|
||||
private const val MSG_WHAT_KEY_CODE_BL = 0x03
|
||||
private const val MSG_WHAT_KEY_CODE_C = 0x04
|
||||
private const val MSG_WHAT_KEY_CODE_D = 0x05
|
||||
private const val MSG_WHAT_KEY_CODE_E = 0x06
|
||||
private const val MSG_WHAT_KEY_CODE_EL = 0x07
|
||||
private const val MSG_WHAT_KEY_CODE_AB = 0x08
|
||||
}
|
||||
|
||||
@Volatile
|
||||
private var linkedLog: MoFangLinkedLog? = null
|
||||
|
||||
fun setLinkedLog(log: MoFangLinkedLog) {
|
||||
this.linkedLog = log
|
||||
}
|
||||
|
||||
private val handlerCallback = Handler.Callback { msg ->
|
||||
val message = whatToString(msg.what, ", msg_info:[obj:${msg.obj}, arg1: ${msg.arg1}, arg2: ${msg.arg2}]")
|
||||
linkedLog?.record(mapOf("收到:${System.currentTimeMillis()}" to "$message"))
|
||||
when(msg.what) {
|
||||
MSG_WHAT_KEY_CODE_A, MSG_WHAT_KEY_CODE_AB, MSG_WHAT_KEY_CODE_BL -> {
|
||||
Log.d(TAG, "--- msg: $msg ---")
|
||||
MSG_WHAT_KEY_CODE_A, MSG_WHAT_KEY_CODE_B, MSG_WHAT_KEY_CODE_AB, MSG_WHAT_KEY_CODE_BL -> {
|
||||
var send = false
|
||||
try {
|
||||
val acc = msg.obj as? Double
|
||||
if (acc != null && acc != 0.0) {
|
||||
send = true
|
||||
if (acc != null) {
|
||||
send = acc != 0.0
|
||||
linkedLog?.record(mapOf("执行:${System.currentTimeMillis()}" to "$message, $acc"))
|
||||
CallerAutoPilotControlManager.sendOperatorSetAcceleratedSpeed(acc)
|
||||
}
|
||||
} catch (t: Throwable) {
|
||||
@@ -46,10 +56,12 @@ internal class MoFangCommandExecutor {
|
||||
}
|
||||
val isLeft = msg.arg1 == -1
|
||||
if (isLeft) {
|
||||
linkedLog?.record(mapOf("执行:${System.currentTimeMillis()}" to "$message"))
|
||||
Log.d(TAG, "--- 左变道执行了 ----")
|
||||
CallerAutoPilotControlManager.sendOperatorChangeLaneLeft()
|
||||
} else {
|
||||
Log.d(TAG, "--- 右变道执行了 ----")
|
||||
linkedLog?.record(mapOf("执行:${System.currentTimeMillis()}" to "$message"))
|
||||
CallerAutoPilotControlManager.sendOperatorChangeLaneRight()
|
||||
}
|
||||
} catch (t: Throwable) {
|
||||
@@ -61,7 +73,9 @@ internal class MoFangCommandExecutor {
|
||||
try {
|
||||
val autoPilotStatusInfo = CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo()
|
||||
val parameters = autoPilotStatusInfo.autopilotControlParameters
|
||||
Log.d(TAG, "--- 启动自驾 ----入参:${GsonUtil.jsonFromObject(parameters)}")
|
||||
val json = GsonUtil.jsonFromObject(parameters)
|
||||
linkedLog?.record(mapOf("执行:${System.currentTimeMillis()}" to "$message, $json"))
|
||||
Log.d(TAG, "--- 启动自驾 ----入参:$json")
|
||||
CallerAutoPilotControlManager.startAutoPilot(parameters)
|
||||
} catch (t: Throwable) {
|
||||
t.printStackTrace()
|
||||
@@ -75,6 +89,7 @@ internal class MoFangCommandExecutor {
|
||||
if (value != null && value != 0.0) {
|
||||
send = value != 2.0
|
||||
Log.d(TAG, "--- 长按鸣笛 ---入参:$value")
|
||||
linkedLog?.record(mapOf("执行:${System.currentTimeMillis()}" to "$message, $value"))
|
||||
CallerAutoPilotControlManager.sendOperatorSetHorn(value)
|
||||
}
|
||||
} catch (t: Throwable) {
|
||||
@@ -97,28 +112,61 @@ internal class MoFangCommandExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
private fun whatToString(what: Int, extra: String = ""): String? {
|
||||
return when(what) {
|
||||
MSG_WHAT_KEY_CODE_A -> {
|
||||
"单击键A->加速度每隔500ms,减少1$extra"
|
||||
}
|
||||
MSG_WHAT_KEY_CODE_AB -> {
|
||||
"组合键AB->加速度每隔500毫秒,减小2$extra"
|
||||
}
|
||||
MSG_WHAT_KEY_CODE_B -> {
|
||||
"单击键B->复原$extra"
|
||||
}
|
||||
MSG_WHAT_KEY_CODE_BL -> {
|
||||
"长按键B->加速度每隔500ms,增加1$extra"
|
||||
}
|
||||
MSG_WHAT_KEY_CODE_C -> {
|
||||
"单击键C->左变道$extra"
|
||||
}
|
||||
MSG_WHAT_KEY_CODE_D -> {
|
||||
"单击键D->右变道$extra"
|
||||
}
|
||||
MSG_WHAT_KEY_CODE_E -> {
|
||||
"单击键E->开启自驾$extra"
|
||||
}
|
||||
MSG_WHAT_KEY_CODE_EL -> {
|
||||
"长按键E->鸣笛$extra"
|
||||
}
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun handleSingleClick(keycode: Int) {
|
||||
if (keycode == KeyEvent.KEYCODE_A) {
|
||||
Log.d(TAG, "--- 单机键A --- 加速度每隔500ms减少1 ----")
|
||||
handler.removeMessages(MSG_WHAT_KEY_CODE_BL)
|
||||
handler.removeMessages(MSG_WHAT_KEY_CODE_A)
|
||||
handler.removeMessages(MSG_WHAT_KEY_CODE_B)
|
||||
handler.removeMessages(MSG_WHAT_KEY_CODE_AB)
|
||||
handler.removeMessages(MSG_WHAT_KEY_CODE_BL)
|
||||
handler.sendMessage(Message.obtain().also {
|
||||
it.what = MSG_WHAT_KEY_CODE_A
|
||||
it.obj = -1.0
|
||||
})
|
||||
linkedLog?.record(mapOf("发送[A]:${System.currentTimeMillis()}" to "${whatToString(MSG_WHAT_KEY_CODE_A)}"))
|
||||
}
|
||||
if (keycode == KeyEvent.KEYCODE_B) {
|
||||
Log.d(TAG, "--- 单机键B --- 复原 ----")
|
||||
handler.removeMessages(MSG_WHAT_KEY_CODE_BL)
|
||||
handler.removeMessages(MSG_WHAT_KEY_CODE_A)
|
||||
handler.removeMessages(MSG_WHAT_KEY_CODE_B)
|
||||
handler.removeMessages(MSG_WHAT_KEY_CODE_AB)
|
||||
try {
|
||||
CallerAutoPilotControlManager.sendOperatorSetAcceleratedSpeed(0.0)
|
||||
} catch (t: Throwable) {
|
||||
t.printStackTrace()
|
||||
}
|
||||
handler.removeMessages(MSG_WHAT_KEY_CODE_BL)
|
||||
handler.sendMessage(Message.obtain().also {
|
||||
it.what = MSG_WHAT_KEY_CODE_B
|
||||
it.obj = 0.0
|
||||
})
|
||||
linkedLog?.record(mapOf("发送[B]:${System.currentTimeMillis()}" to "${whatToString(MSG_WHAT_KEY_CODE_B)}"))
|
||||
}
|
||||
|
||||
if (keycode == KeyEvent.KEYCODE_C) {
|
||||
@@ -128,6 +176,7 @@ internal class MoFangCommandExecutor {
|
||||
it.what = MSG_WHAT_KEY_CODE_C
|
||||
it.arg1 = -1
|
||||
})
|
||||
linkedLog?.record(mapOf("发送[C]:${System.currentTimeMillis()}" to "${whatToString(MSG_WHAT_KEY_CODE_C)}"))
|
||||
}
|
||||
|
||||
if (keycode == KeyEvent.KEYCODE_D) {
|
||||
@@ -137,6 +186,7 @@ internal class MoFangCommandExecutor {
|
||||
it.what = MSG_WHAT_KEY_CODE_D
|
||||
it.arg1 = 1
|
||||
})
|
||||
linkedLog?.record(mapOf("发送[D]:${System.currentTimeMillis()}" to "${whatToString(MSG_WHAT_KEY_CODE_D)}"))
|
||||
}
|
||||
|
||||
if (keycode == KeyEvent.KEYCODE_E) {
|
||||
@@ -145,6 +195,7 @@ internal class MoFangCommandExecutor {
|
||||
handler.sendMessage(Message.obtain().also {
|
||||
it.what = MSG_WHAT_KEY_CODE_E
|
||||
})
|
||||
linkedLog?.record(mapOf("发送[E]:${System.currentTimeMillis()}" to "${whatToString(MSG_WHAT_KEY_CODE_E)}"))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -157,16 +208,19 @@ internal class MoFangCommandExecutor {
|
||||
it.what = MSG_WHAT_KEY_CODE_EL
|
||||
it.obj = 1.0
|
||||
})
|
||||
linkedLog?.record(mapOf("发送[EL]:${System.currentTimeMillis()}" to "${whatToString(MSG_WHAT_KEY_CODE_EL)}"))
|
||||
}
|
||||
if (keyCode == KeyEvent.KEYCODE_B) {
|
||||
Log.d(TAG, "--- 长按键B --- 加速度加1 ----")
|
||||
handler.removeMessages(MSG_WHAT_KEY_CODE_BL)
|
||||
handler.removeMessages(MSG_WHAT_KEY_CODE_A)
|
||||
handler.removeMessages(MSG_WHAT_KEY_CODE_B)
|
||||
handler.removeMessages(MSG_WHAT_KEY_CODE_AB)
|
||||
handler.removeMessages(MSG_WHAT_KEY_CODE_BL)
|
||||
handler.sendMessage(Message.obtain().also {
|
||||
it.what = MSG_WHAT_KEY_CODE_BL
|
||||
it.obj = 1.0
|
||||
})
|
||||
linkedLog?.record(mapOf("发送[BL]:${System.currentTimeMillis()}" to "${whatToString(MSG_WHAT_KEY_CODE_BL)}"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,12 +228,15 @@ internal class MoFangCommandExecutor {
|
||||
if (isCombineEqual(KeyEvent.KEYCODE_A, KeyEvent.KEYCODE_B, *keyCodes)) {
|
||||
//AB组合键,加速度每隔500毫秒,减小2
|
||||
Log.d(TAG, "---- 组合键AB ---- 按下,加速度每隔500毫秒,减小2 ---")
|
||||
handler.removeCallbacksAndMessages(null)
|
||||
handler.removeMessages(MSG_WHAT_KEY_CODE_A)
|
||||
handler.removeMessages(MSG_WHAT_KEY_CODE_B)
|
||||
handler.removeMessages(MSG_WHAT_KEY_CODE_AB)
|
||||
handler.removeMessages(MSG_WHAT_KEY_CODE_BL)
|
||||
handler.sendMessage(Message.obtain().also {
|
||||
it.what = MSG_WHAT_KEY_CODE_AB
|
||||
it.obj = -2.0
|
||||
})
|
||||
|
||||
linkedLog?.record(mapOf("发送[AB]:${System.currentTimeMillis()}" to "${whatToString(MSG_WHAT_KEY_CODE_AB)}"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.zhjt.mogo_core_function_devatools.mofang
|
||||
|
||||
import com.mogo.eagle.core.data.deva.chain.*
|
||||
import com.zhjt.service.chain.*
|
||||
|
||||
internal class MoFangLinkedLog {
|
||||
|
||||
fun record(extra: Map<String, String>) {
|
||||
try {
|
||||
recordInternal(extra)
|
||||
} catch (t: Throwable) {
|
||||
t.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
@ChainLog(
|
||||
linkChainLog = ChainConstant.CHAIN_TYPE_HMI,
|
||||
linkCode = ChainConstant.CHAIN_SOURCE_CLOUD,
|
||||
nodeAliasCode = ChainConstant.CHAIN_CODE_MO_FANG_CONNECT,
|
||||
paramIndexes = [0]
|
||||
)
|
||||
private fun recordInternal(extra: Map<String, String>) {}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.zhjt.mogo_core_function_devatools.mofang
|
||||
|
||||
import android.annotation.*
|
||||
import android.app.*
|
||||
import android.bluetooth.*
|
||||
import android.util.*
|
||||
@@ -28,20 +29,55 @@ internal class MoGoMoFangProviderImpl: IMoGoMoFangProvider, OnMoFangDeviceListen
|
||||
|
||||
private val executor by lazy { MoFangCommandExecutor() }
|
||||
|
||||
private val linkedLog by lazy { MoFangLinkedLog().also { executor.setLinkedLog(it) } }
|
||||
|
||||
override fun init(app: Application) {
|
||||
MoFangManager.init(MoFangDevice.Builder().application(app).listener(this))
|
||||
try {
|
||||
linkedLog.record(mapOf("init" to "start"))
|
||||
MoFangManager.init(MoFangDevice.Builder().application(app).listener(this))
|
||||
linkedLog.record(mapOf("init" to "success"))
|
||||
} catch (t: Throwable) {
|
||||
t.printStackTrace()
|
||||
linkedLog.record(mapOf("init" to "error: ${t.message}"))
|
||||
throw t
|
||||
}
|
||||
}
|
||||
|
||||
override fun connect() {
|
||||
MoFangManager.connect()
|
||||
try {
|
||||
linkedLog.record(mapOf("connect" to "start"))
|
||||
MoFangManager.connect()
|
||||
linkedLog.record(mapOf("connect" to "success"))
|
||||
} catch (t: Throwable) {
|
||||
t.printStackTrace()
|
||||
linkedLog.record(mapOf("connect" to "error: ${t.message}"))
|
||||
throw t
|
||||
}
|
||||
}
|
||||
|
||||
override fun disconnect() {
|
||||
MoFangManager.disconnect()
|
||||
try {
|
||||
linkedLog.record(mapOf("disconnect" to "start"))
|
||||
MoFangManager.disconnect()
|
||||
linkedLog.record(mapOf("disconnect" to "success"))
|
||||
} catch (t: Throwable) {
|
||||
t.printStackTrace()
|
||||
linkedLog.record(mapOf("disconnect" to "error:${t.message}"))
|
||||
throw t
|
||||
}
|
||||
}
|
||||
|
||||
override fun isConnected(): Boolean {
|
||||
return MoFangManager.isConnected()
|
||||
return try {
|
||||
linkedLog.record(mapOf("isConnected" to "start"))
|
||||
val ret = MoFangManager.isConnected()
|
||||
linkedLog.record(mapOf("isConnected" to "success: $ret"))
|
||||
ret
|
||||
} catch (t: Throwable) {
|
||||
t.printStackTrace()
|
||||
linkedLog.record(mapOf("isConnected" to "error: ${t.message}"))
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
override fun provideWindowCallback(delegate: Callback?): Callback {
|
||||
@@ -59,6 +95,7 @@ internal class MoGoMoFangProviderImpl: IMoGoMoFangProvider, OnMoFangDeviceListen
|
||||
}
|
||||
|
||||
override fun onBluetoothBatteryChanged(battery: Int) {
|
||||
linkedLog.record(mapOf("callback" to "onBluetoothBatteryChanged:$battery"))
|
||||
if (this.battery.get() != battery) {
|
||||
UiThreadHandler.post {
|
||||
listeners.values.forEach {
|
||||
@@ -69,7 +106,13 @@ internal class MoGoMoFangProviderImpl: IMoGoMoFangProvider, OnMoFangDeviceListen
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
override fun onBluetoothConnected(device: BluetoothDevice?) {
|
||||
try {
|
||||
linkedLog.record(mapOf("callback" to "onBluetoothConnected:${device?.name}"))
|
||||
} catch (t: Throwable) {
|
||||
t.printStackTrace()
|
||||
}
|
||||
UiThreadHandler.post {
|
||||
listeners.values.forEach {
|
||||
it.onMoFangConnected()
|
||||
@@ -77,7 +120,13 @@ internal class MoGoMoFangProviderImpl: IMoGoMoFangProvider, OnMoFangDeviceListen
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
override fun onBluetoothDisconnected(device: BluetoothDevice?, systemOff: Boolean) {
|
||||
try {
|
||||
linkedLog.record(mapOf("callback" to "onBluetoothDisconnected:name -> ${device?.name}, systemOff: $systemOff"))
|
||||
} catch (t: Throwable) {
|
||||
t.printStackTrace()
|
||||
}
|
||||
UiThreadHandler.post {
|
||||
listeners.values.forEach {
|
||||
it.onMoFangDisconnected()
|
||||
@@ -87,18 +136,18 @@ internal class MoGoMoFangProviderImpl: IMoGoMoFangProvider, OnMoFangDeviceListen
|
||||
|
||||
override fun onBluetoothKeyBoardCombineClicked(vararg keyCodes: Int) {
|
||||
try {
|
||||
linkedLog.record(mapOf("command" to "combine_clicked: ${keyCodes.joinToString(",") { KeyEvent.keyCodeToString(it) } }"))
|
||||
executor.handleCombineClick(*keyCodes)
|
||||
} finally {
|
||||
UiThreadHandler.post { listeners.values.forEach {
|
||||
it.onMoFangCombineClicked(*keyCodes)
|
||||
} }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun onBluetoothKeyBoardLongClicked(keyCode: Int) {
|
||||
try {
|
||||
linkedLog.record(mapOf("command" to "long_clicked: ${ KeyEvent.keyCodeToString(keyCode) }"))
|
||||
executor.handleLongClick(keyCode)
|
||||
} finally {
|
||||
UiThreadHandler.post {
|
||||
@@ -111,6 +160,7 @@ internal class MoGoMoFangProviderImpl: IMoGoMoFangProvider, OnMoFangDeviceListen
|
||||
|
||||
override fun onBluetoothKeyboardClicked(keyCode: Int) {
|
||||
try {
|
||||
linkedLog.record(mapOf("command" to "clicked: ${ KeyEvent.keyCodeToString(keyCode) }"))
|
||||
executor.handleSingleClick(keyCode)
|
||||
} finally {
|
||||
UiThreadHandler.post {
|
||||
@@ -125,6 +175,7 @@ internal class MoGoMoFangProviderImpl: IMoGoMoFangProvider, OnMoFangDeviceListen
|
||||
|
||||
override fun onBluetoothKeyboardInputInvalid() {
|
||||
Log.d(TAG, "--- onBluetoothKeyboardInputInvalid ---")
|
||||
linkedLog.record(mapOf("callback" to "onBluetoothKeyboardInputInvalid"))
|
||||
UiThreadHandler.post {
|
||||
listeners.values.forEach {
|
||||
it.onMoFangStatusError("检测到鹰眼未处于前台, 魔方指令暂不能使用, 请将鹰眼切换到前台运行...")
|
||||
@@ -134,18 +185,22 @@ internal class MoGoMoFangProviderImpl: IMoGoMoFangProvider, OnMoFangDeviceListen
|
||||
|
||||
override fun onBluetoothKeyboardInputValid() {
|
||||
Log.d(TAG, "--- onBluetoothKeyboardInputValid ---")
|
||||
linkedLog.record(mapOf("callback" to "onBluetoothKeyboardInputValid"))
|
||||
}
|
||||
|
||||
override fun onBluetoothOpenAgreed() {
|
||||
Log.d(TAG, "--- onBluetoothOpenAgreed ---")
|
||||
linkedLog.record(mapOf("callback" to "onBluetoothOpenAgreed"))
|
||||
}
|
||||
|
||||
override fun onBluetoothOpenDenied() {
|
||||
Log.d(TAG, "--- onBluetoothOpenDenied ---")
|
||||
linkedLog.record(mapOf("callback" to "onBluetoothOpenDenied"))
|
||||
}
|
||||
|
||||
override fun onBluetoothSettingRequest() {
|
||||
Log.d(TAG, "--- onBluetoothSettingRequest ---")
|
||||
linkedLog.record(mapOf("callback" to "onBluetoothSettingRequest"))
|
||||
UiThreadHandler.post {
|
||||
Toast.makeText(Utils.getApp(), "检测到魔方未正确连接,请在系统蓝牙设置页面,找到魔方并配对连接...", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user