opt
This commit is contained in:
@@ -11,8 +11,10 @@ import com.mogo.commons.debug.DebugConfig
|
||||
import com.mogo.service.IMogoServiceApis
|
||||
import com.mogo.service.MogoServicePaths
|
||||
import com.mogo.utils.logger.Logger
|
||||
import com.zhidao.mogo.module.obu.obu.HualiObu
|
||||
import com.zhidao.mogo.module.obu.obu.IObu
|
||||
import com.zhidao.mogo.module.obu.obu.*
|
||||
import com.zhidao.mogo.module.obu.obu.bean.MogoObuEventInfo
|
||||
import com.zhidao.mogo.module.obu.obu.bean.MogoObuTrafficLightInfo
|
||||
import com.zhidao.mogo.module.obu.socket.IUdpSocketCallback
|
||||
import com.zhidao.smartv2x.listener.OnMessageReceiveListener
|
||||
import com.zhidao.smartv2x.model.obu.CarEventInfo
|
||||
import com.zhidao.smartv2x.model.obu.TrafficLightInfo
|
||||
@@ -35,7 +37,7 @@ class MockUtil:Handler.Callback {
|
||||
const val TAG = "MockUtil"
|
||||
}
|
||||
|
||||
private var dataCallback: OnMessageReceiveListener? = null
|
||||
private var dataCallback: IObuCallback? = null
|
||||
|
||||
private lateinit var intervalObs: Disposable
|
||||
private lateinit var intervalObs2: Disposable
|
||||
@@ -54,12 +56,13 @@ class MockUtil:Handler.Callback {
|
||||
return false
|
||||
}
|
||||
|
||||
fun init(context: Context,obu:HualiObu){
|
||||
fun init(context: Context,obu:BaseObu){
|
||||
Logger.d(TAG, "使用模拟obu数据===")
|
||||
this.context = context
|
||||
dataCallback = obu.callback
|
||||
view = LayoutInflater.from(context).inflate(R.layout.mock_obu, null)
|
||||
view.findViewById<Button>(R.id.btnVip).setOnClickListener {
|
||||
val carEventInfo = CarEventInfo()
|
||||
val carEventInfo = MogoObuEventInfo()
|
||||
carEventInfo.type = "vip变灯提醒"
|
||||
carEventInfo.typeCode = "vip变灯提醒"
|
||||
val r = Random.nextInt(0, 2)
|
||||
@@ -67,24 +70,24 @@ class MockUtil:Handler.Callback {
|
||||
0 -> "已更改前方红绿灯状态,可优先通行"
|
||||
else -> "已增加前方绿灯时间,可优先通行"
|
||||
}
|
||||
dataCallback?.showCarEventInfo(carEventInfo)
|
||||
dataCallback?.onEventInfoCallback(carEventInfo)
|
||||
}
|
||||
|
||||
view.findViewById<Button>(R.id.btnPersonCrash).setOnClickListener {
|
||||
obu.onMessageReceived("{\"pedestrain_information\": {\"pedestrian_crash_alarm\": 1}}".toByteArray())
|
||||
}
|
||||
|
||||
view.findViewById<Button>(R.id.btnCrossCrash).setOnClickListener {
|
||||
obu.onMessageReceived("{\"intersection_crash\":{\"intersection_crash_alarm\":1}}".toByteArray())
|
||||
}
|
||||
|
||||
view.findViewById<Button>(R.id.btnOptimizeSpeed).setOnClickListener {
|
||||
obu.onMessageReceived("{\"rush_redlight\": {\"glosa_info\": [{\"rush_redlight_alarm\": 1,\"advisory_speed\":40.0}]}}".toByteArray())
|
||||
}
|
||||
|
||||
view.findViewById<Button>(R.id.btnRushRedLight).setOnClickListener {
|
||||
obu.onMessageReceived("{\"rush_redlight\": {\"glosa_info\": [{\"rush_redlight_alarm\": 0}]}}".toByteArray())
|
||||
}
|
||||
// view.findViewById<Button>(R.id.btnPersonCrash).setOnClickListener {
|
||||
// obu.onMessageReceived("{\"pedestrain_information\": {\"pedestrian_crash_alarm\": 1}}".toByteArray())
|
||||
// }
|
||||
//
|
||||
// view.findViewById<Button>(R.id.btnCrossCrash).setOnClickListener {
|
||||
// obu.onMessageReceived("{\"intersection_crash\":{\"intersection_crash_alarm\":1}}".toByteArray())
|
||||
// }
|
||||
//
|
||||
// view.findViewById<Button>(R.id.btnOptimizeSpeed).setOnClickListener {
|
||||
// obu.onMessageReceived("{\"rush_redlight\": {\"glosa_info\": [{\"rush_redlight_alarm\": 1,\"advisory_speed\":40.0}]}}".toByteArray())
|
||||
// }
|
||||
//
|
||||
// view.findViewById<Button>(R.id.btnRushRedLight).setOnClickListener {
|
||||
// obu.onMessageReceived("{\"rush_redlight\": {\"glosa_info\": [{\"rush_redlight_alarm\": 0}]}}".toByteArray())
|
||||
// }
|
||||
|
||||
view.findViewById<Button>(R.id.btnStartTrafficLight).setOnClickListener {
|
||||
intervalMockData()
|
||||
@@ -148,7 +151,7 @@ class MockUtil:Handler.Callback {
|
||||
private fun debugCarEvent() {
|
||||
val random = Random.nextInt(0, 4)
|
||||
Logger.d(TAG, "random====$random")
|
||||
val carEventInfo = CarEventInfo()
|
||||
val carEventInfo = MogoObuEventInfo()
|
||||
when (random) {
|
||||
0 -> {
|
||||
// 绿波引导
|
||||
@@ -160,21 +163,21 @@ class MockUtil:Handler.Callback {
|
||||
1 -> "建议50km/h车速行驶"
|
||||
else -> "建议30km/h ~ 50km/h 车速行驶"
|
||||
}
|
||||
dataCallback?.showCarEventInfo(carEventInfo)
|
||||
dataCallback?.onEventInfoCallback(carEventInfo)
|
||||
}
|
||||
1 -> {
|
||||
// 前方急刹预警
|
||||
carEventInfo.type = "紧急制动预警"
|
||||
carEventInfo.typeCode = "06"
|
||||
carEventInfo.describe = "这个应该是随便写,反正也不用"
|
||||
dataCallback?.showCarEventInfo(carEventInfo)
|
||||
dataCallback?.onEventInfoCallback(carEventInfo)
|
||||
}
|
||||
2 -> {
|
||||
// 行人碰撞预警
|
||||
carEventInfo.type = "行人碰撞预警"
|
||||
carEventInfo.typeCode = "39"
|
||||
carEventInfo.describe = "这个应该是随便写,反正也不用"
|
||||
dataCallback?.showCarEventInfo(carEventInfo)
|
||||
dataCallback?.onEventInfoCallback(carEventInfo)
|
||||
}
|
||||
3 -> {
|
||||
// vip变灯提醒
|
||||
@@ -185,7 +188,7 @@ class MockUtil:Handler.Callback {
|
||||
0 -> "已更改前方红绿灯状态,可优先通行"
|
||||
else -> "已增加前方绿灯时间,可优先通行"
|
||||
}
|
||||
dataCallback?.showCarEventInfo(carEventInfo)
|
||||
dataCallback?.onEventInfoCallback(carEventInfo)
|
||||
}
|
||||
else -> {
|
||||
// 其他,不处理
|
||||
@@ -197,13 +200,13 @@ class MockUtil:Handler.Callback {
|
||||
Logger.d(TAG, "准备开始红绿灯模拟数据发送===")
|
||||
Thread.sleep(20_000)
|
||||
Logger.d(TAG, "开始红绿灯模拟数据发送===")
|
||||
val trafficLightInfo = TrafficLightInfo()
|
||||
val trafficLightInfo = MogoObuTrafficLightInfo()
|
||||
trafficLightInfo.id = "12"
|
||||
// 先来6秒红灯
|
||||
trafficLightInfo.lightStatus = "R"
|
||||
for (i in 0..5) {
|
||||
trafficLightInfo.surplusTime = (5 - i).toString()
|
||||
dataCallback?.showTrafficLightInfo(trafficLightInfo)
|
||||
dataCallback?.onTrafficLightInfoCallback(trafficLightInfo)
|
||||
Thread.sleep(1000)
|
||||
}
|
||||
// 停5秒
|
||||
@@ -212,7 +215,7 @@ class MockUtil:Handler.Callback {
|
||||
trafficLightInfo.lightStatus = "Y"
|
||||
for (i in 0..5) {
|
||||
trafficLightInfo.surplusTime = (5 - i).toString()
|
||||
dataCallback?.showTrafficLightInfo(trafficLightInfo)
|
||||
dataCallback?.onTrafficLightInfoCallback(trafficLightInfo)
|
||||
Thread.sleep(1000)
|
||||
}
|
||||
// 停5秒
|
||||
@@ -221,7 +224,7 @@ class MockUtil:Handler.Callback {
|
||||
trafficLightInfo.lightStatus = "G"
|
||||
for (i in 0..5) {
|
||||
trafficLightInfo.surplusTime = (5 - i).toString()
|
||||
dataCallback?.showTrafficLightInfo(trafficLightInfo)
|
||||
dataCallback?.onTrafficLightInfoCallback(trafficLightInfo)
|
||||
Thread.sleep(1000)
|
||||
}
|
||||
Logger.d(TAG, "红绿灯模拟数据发送结束====")
|
||||
|
||||
@@ -3,10 +3,8 @@ package com.zhidao.mogo.module.obu
|
||||
import android.content.Context
|
||||
import com.mogo.commons.debug.DebugConfig
|
||||
import com.mogo.utils.logger.Logger
|
||||
import com.zhidao.mogo.module.obu.obu.CidiObu
|
||||
import com.zhidao.mogo.module.obu.obu.HualiObu
|
||||
import com.zhidao.mogo.module.obu.obu.IObu
|
||||
import com.zhidao.mogo.module.obu.obu.IObuCallback
|
||||
import com.zhidao.mogo.module.obu.obu.*
|
||||
import com.zhidao.mogo.module.obu.socket.IUdpSocketCallback
|
||||
|
||||
/**
|
||||
* obu provider
|
||||
@@ -21,9 +19,10 @@ class ObuManager {
|
||||
// private var handler = Handler(Looper.getMainLooper(), this)
|
||||
|
||||
private lateinit var obu: IObu
|
||||
|
||||
private lateinit var context: Context
|
||||
fun init(context: Context) {
|
||||
Logger.d(TAG, "init=======")
|
||||
this.context = context
|
||||
obu = if (DebugConfig.getObuType() == DebugConfig.OBU_TYPE_CIDI) {
|
||||
CidiObu()
|
||||
} else {
|
||||
@@ -35,6 +34,10 @@ class ObuManager {
|
||||
fun registerObuDataChangedListener(listener: IObuCallback?) {
|
||||
if (listener != null) {
|
||||
obu.registerObuCallback(listener)
|
||||
if(DebugConfig.isUseMockObuData() ) {
|
||||
val mockUtil = MockUtil()
|
||||
mockUtil.init(context, obu as BaseObu)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.zhidao.mogo.module.obu.obu
|
||||
|
||||
abstract class BaseObu : IObu {
|
||||
protected var callback: IObuCallback? = null
|
||||
var callback: IObuCallback? = null
|
||||
override fun init() {
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ class HualiObu : BaseObu(), IUdpSocketCallback {
|
||||
}
|
||||
|
||||
override fun onMessageReceived(msg: ByteArray) {
|
||||
// 处理数据
|
||||
// 接收到obu原始数据,处理数据
|
||||
// val m = String(msg)
|
||||
// Logger.d(TAG, "onMessageReceived: $m")
|
||||
// printByteArray(msg)
|
||||
@@ -277,6 +277,9 @@ class HualiObu : BaseObu(), IUdpSocketCallback {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据末位校验数据可用性
|
||||
*/
|
||||
private fun isAvailable(msg: ByteArray): Boolean {
|
||||
val checkSum = msg.last()
|
||||
var check = msg[0].xor(0xff.toByte())
|
||||
@@ -299,6 +302,9 @@ class HualiObu : BaseObu(), IUdpSocketCallback {
|
||||
Logger.d(TAG, arrayBuilder.toString())
|
||||
}
|
||||
|
||||
/**
|
||||
* byte数组转int
|
||||
*/
|
||||
private fun convertTwoUnSignInt(byteArray: ByteArray): Int =
|
||||
(byteArray[0].toInt() shl 24) or (byteArray[1].toInt() and 0xFF) or (byteArray[2].toInt() shl 8) or (byteArray[3].toInt() and 0xFF)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user