opt traffic light
This commit is contained in:
@@ -1,28 +1,22 @@
|
||||
package com.zhidao.mogo.module.obu
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Handler
|
||||
import android.os.Message
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
import com.alibaba.android.arouter.launcher.ARouter
|
||||
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.*
|
||||
import com.zhidao.mogo.module.obu.obu.BaseObu
|
||||
import com.zhidao.mogo.module.obu.obu.IObuCallback
|
||||
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
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.Scheduler
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.Disposable
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import io.reactivex.schedulers.Schedulers.io
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlin.random.Random
|
||||
@@ -56,22 +50,25 @@ class MockUtil:Handler.Callback {
|
||||
return false
|
||||
}
|
||||
|
||||
private var cLightStatus: String = "G"
|
||||
private var cSurplusTime: String = "10"
|
||||
|
||||
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 = MogoObuEventInfo()
|
||||
carEventInfo.type = "vip变灯提醒"
|
||||
carEventInfo.typeCode = "vip变灯提醒"
|
||||
val r = Random.nextInt(0, 2)
|
||||
carEventInfo.describe = when (r) {
|
||||
0 -> "已更改前方红绿灯状态,可优先通行"
|
||||
else -> "已增加前方绿灯时间,可优先通行"
|
||||
}
|
||||
dataCallback?.onEventInfoCallback(carEventInfo)
|
||||
}
|
||||
// view.findViewById<Button>(R.id.btnVip).setOnClickListener {
|
||||
// val carEventInfo = MogoObuEventInfo()
|
||||
// carEventInfo.type = "vip变灯提醒"
|
||||
// carEventInfo.typeCode = "vip变灯提醒"
|
||||
// val r = Random.nextInt(0, 2)
|
||||
// carEventInfo.describe = when (r) {
|
||||
// 0 -> "已更改前方红绿灯状态,可优先通行"
|
||||
// else -> "已增加前方绿灯时间,可优先通行"
|
||||
// }
|
||||
// dataCallback?.onEventInfoCallback(carEventInfo)
|
||||
// }
|
||||
|
||||
// view.findViewById<Button>(R.id.btnPersonCrash).setOnClickListener {
|
||||
// obu.onMessageReceived("{\"pedestrain_information\": {\"pedestrian_crash_alarm\": 1}}".toByteArray())
|
||||
@@ -89,14 +86,44 @@ class MockUtil:Handler.Callback {
|
||||
// obu.onMessageReceived("{\"rush_redlight\": {\"glosa_info\": [{\"rush_redlight_alarm\": 0}]}}".toByteArray())
|
||||
// }
|
||||
|
||||
view.findViewById<Button>(R.id.btnStartTrafficLight).setOnClickListener {
|
||||
intervalMockData()
|
||||
// view.findViewById<Button>(R.id.btnStartTrafficLight).setOnClickListener {
|
||||
// intervalMockData()
|
||||
// }
|
||||
//
|
||||
// view.findViewById<Button>(R.id.btnStopTrafficLight).setOnClickListener {
|
||||
// if (intervalObs != null&&!intervalObs.isDisposed) {
|
||||
// intervalObs.dispose()
|
||||
// }
|
||||
// }
|
||||
|
||||
view.findViewById<Button>(R.id.btnGreen).setOnClickListener {
|
||||
Logger.d(TAG,"准备发送绿灯信号")
|
||||
cLightStatus = "G"
|
||||
sendTrafficEvent()
|
||||
}
|
||||
view.findViewById<Button>(R.id.btnRed).setOnClickListener {
|
||||
Logger.d(TAG,"准备发送红灯信号")
|
||||
cLightStatus = "R"
|
||||
sendTrafficEvent()
|
||||
}
|
||||
view.findViewById<Button>(R.id.btnYello).setOnClickListener {
|
||||
Logger.d(TAG,"准备发送黄灯信号")
|
||||
cLightStatus = "Y"
|
||||
sendTrafficEvent()
|
||||
}
|
||||
view.findViewById<Button>(R.id.btnChangeTime).setOnClickListener {
|
||||
val random = Random.nextInt(100)
|
||||
Logger.d(TAG,"准备修改时间信息: $random")
|
||||
cSurplusTime = random.toString()
|
||||
sendTrafficEvent()
|
||||
}
|
||||
|
||||
view.findViewById<Button>(R.id.btnStopTrafficLight).setOnClickListener {
|
||||
if (intervalObs != null&&!intervalObs.isDisposed) {
|
||||
intervalObs.dispose()
|
||||
}
|
||||
view.findViewById<Button>(R.id.btnShowLimitSpeed).setOnClickListener{
|
||||
val random = Random.nextInt(200)
|
||||
// 发送当前限速到 adas
|
||||
val intent = Intent("com.mogo.launcher.adas")
|
||||
intent.putExtra("adas_speed_limit", random)
|
||||
context.sendBroadcast(intent)
|
||||
}
|
||||
handler.sendEmptyMessageDelayed(1001, 10000)
|
||||
|
||||
@@ -148,6 +175,16 @@ class MockUtil:Handler.Callback {
|
||||
intervalObs2.dispose()
|
||||
}
|
||||
|
||||
private fun sendTrafficEvent() {
|
||||
val trafficLightInfo = MogoObuTrafficLightInfo()
|
||||
trafficLightInfo.id = "12"
|
||||
trafficLightInfo.lightStatus = cLightStatus
|
||||
trafficLightInfo.surplusTime = cSurplusTime
|
||||
dataCallback?.onTrafficLightInfoCallback(trafficLightInfo)
|
||||
Logger.d(TAG, "发送红绿灯数据: $trafficLightInfo")
|
||||
|
||||
}
|
||||
|
||||
private fun debugCarEvent() {
|
||||
val random = Random.nextInt(0, 4)
|
||||
Logger.d(TAG, "random====$random")
|
||||
|
||||
@@ -5,45 +5,92 @@
|
||||
android:columnCount="4">
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnVip"
|
||||
android:id="@+id/btnGreen"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="vip同行" />
|
||||
android:text="绿灯"
|
||||
android:textSize="30sp"
|
||||
android:padding="10dp"
|
||||
android:background="#0f0" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnRushRedLight"
|
||||
android:id="@+id/btnRed"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="闯红灯" />
|
||||
android:text="红灯"
|
||||
android:textSize="30sp"
|
||||
android:padding="10dp"
|
||||
android:background="#f00" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnOptimizeSpeed"
|
||||
android:id="@+id/btnYello"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="绿波车速" />
|
||||
android:text="黄灯"
|
||||
android:textSize="30sp"
|
||||
android:padding="10dp"
|
||||
android:background="#F7F709" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnCrossCrash"
|
||||
android:id="@+id/btnChangeTime"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="交叉口碰撞" />
|
||||
android:text="改变时间"
|
||||
android:textSize="30sp"
|
||||
android:padding="10dp"
|
||||
android:background="#FF00FF" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnPersonCrash"
|
||||
android:id="@+id/btnShowLimitSpeed"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="行人碰撞" />
|
||||
android:text="修改限速"
|
||||
android:textSize="30sp"
|
||||
android:padding="10dp"
|
||||
android:background="#FF00FF" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnStartTrafficLight"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="开始红绿灯倒计时" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnStopTrafficLight"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="停止红绿灯倒计时" />
|
||||
|
||||
<!-- <Button-->
|
||||
<!-- android:id="@+id/btnVip"-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:text="vip同行" />-->
|
||||
|
||||
<!-- <Button-->
|
||||
<!-- android:id="@+id/btnRushRedLight"-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:text="闯红灯" />-->
|
||||
|
||||
<!-- <Button-->
|
||||
<!-- android:id="@+id/btnOptimizeSpeed"-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:text="绿波车速" />-->
|
||||
|
||||
<!-- <Button-->
|
||||
<!-- android:id="@+id/btnCrossCrash"-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:text="交叉口碰撞" />-->
|
||||
|
||||
<!-- <Button-->
|
||||
<!-- android:id="@+id/btnPersonCrash"-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:text="行人碰撞" />-->
|
||||
|
||||
<!-- <Button-->
|
||||
<!-- android:id="@+id/btnStartTrafficLight"-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:text="开始红绿灯倒计时" />-->
|
||||
|
||||
<!-- <Button-->
|
||||
<!-- android:id="@+id/btnStopTrafficLight"-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:text="停止红绿灯倒计时" />-->
|
||||
|
||||
</GridLayout>
|
||||
Reference in New Issue
Block a user