增加红绿灯时长mock数据
This commit is contained in:
@@ -3,6 +3,7 @@ package com.zhidao.mogo.module.obu
|
||||
import com.mogo.utils.logger.Logger
|
||||
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
|
||||
@@ -33,56 +34,92 @@ object MockUtil {
|
||||
intervalObs = Observable.interval(5000,TimeUnit.MILLISECONDS).map {
|
||||
it.toString()
|
||||
}.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe {
|
||||
val random = Random.nextInt(0, 3)
|
||||
Logger.d(TAG, "random====$random")
|
||||
val carEventInfo = CarEventInfo()
|
||||
when (random) {
|
||||
0->{
|
||||
// 绿波引导
|
||||
carEventInfo.type = "绿波车速引导"
|
||||
carEventInfo.typeCode = "13"
|
||||
val r = Random.nextInt(0, 3)
|
||||
carEventInfo.describe = when (r) {
|
||||
0 -> "保持当前车速行驶!"
|
||||
1 -> "建议50km/h车速行驶"
|
||||
else -> "建议30km/h ~ 50km/h 车速行驶"
|
||||
}
|
||||
dataCallback.showCarEventInfo(carEventInfo)
|
||||
}
|
||||
1->{
|
||||
// 前方急刹预警
|
||||
carEventInfo.type = "紧急制动预警"
|
||||
carEventInfo.typeCode = "06"
|
||||
carEventInfo.describe = "这个应该是随便写,反正也不用"
|
||||
dataCallback.showCarEventInfo(carEventInfo)
|
||||
}
|
||||
2->{
|
||||
// 行人碰撞预警
|
||||
carEventInfo.type = "行人碰撞预警"
|
||||
carEventInfo.typeCode = "39"
|
||||
carEventInfo.describe = "这个应该是随便写,反正也不用"
|
||||
dataCallback.showCarEventInfo(carEventInfo)
|
||||
}
|
||||
3 -> {
|
||||
// vip变灯提醒
|
||||
carEventInfo.type = "vip变灯提醒"
|
||||
carEventInfo.typeCode = "vip变灯提醒"
|
||||
val r = Random.nextInt(0, 2)
|
||||
carEventInfo.describe = when (r) {
|
||||
0 -> "已更改前方红绿灯状态,可优先通行"
|
||||
else -> "已增加前方绿灯时间,可优先通行"
|
||||
}
|
||||
dataCallback.showCarEventInfo(carEventInfo)
|
||||
}
|
||||
else->{
|
||||
// 其他,不处理
|
||||
}
|
||||
}
|
||||
|
||||
// debugCarEvent()
|
||||
debugTrafficLight()
|
||||
}
|
||||
}
|
||||
|
||||
fun destroy(){
|
||||
intervalObs.dispose()
|
||||
}
|
||||
|
||||
private fun debugCarEvent(){
|
||||
val random = Random.nextInt(0, 3)
|
||||
Logger.d(TAG, "random====$random")
|
||||
val carEventInfo = CarEventInfo()
|
||||
when (random) {
|
||||
0->{
|
||||
// 绿波引导
|
||||
carEventInfo.type = "绿波车速引导"
|
||||
carEventInfo.typeCode = "13"
|
||||
val r = Random.nextInt(0, 3)
|
||||
carEventInfo.describe = when (r) {
|
||||
0 -> "保持当前车速行驶!"
|
||||
1 -> "建议50km/h车速行驶"
|
||||
else -> "建议30km/h ~ 50km/h 车速行驶"
|
||||
}
|
||||
dataCallback.showCarEventInfo(carEventInfo)
|
||||
}
|
||||
1->{
|
||||
// 前方急刹预警
|
||||
carEventInfo.type = "紧急制动预警"
|
||||
carEventInfo.typeCode = "06"
|
||||
carEventInfo.describe = "这个应该是随便写,反正也不用"
|
||||
dataCallback.showCarEventInfo(carEventInfo)
|
||||
}
|
||||
2->{
|
||||
// 行人碰撞预警
|
||||
carEventInfo.type = "行人碰撞预警"
|
||||
carEventInfo.typeCode = "39"
|
||||
carEventInfo.describe = "这个应该是随便写,反正也不用"
|
||||
dataCallback.showCarEventInfo(carEventInfo)
|
||||
}
|
||||
3 -> {
|
||||
// vip变灯提醒
|
||||
carEventInfo.type = "vip变灯提醒"
|
||||
carEventInfo.typeCode = "vip变灯提醒"
|
||||
val r = Random.nextInt(0, 2)
|
||||
carEventInfo.describe = when (r) {
|
||||
0 -> "已更改前方红绿灯状态,可优先通行"
|
||||
else -> "已增加前方绿灯时间,可优先通行"
|
||||
}
|
||||
dataCallback.showCarEventInfo(carEventInfo)
|
||||
}
|
||||
else->{
|
||||
// 其他,不处理
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun debugTrafficLight(){
|
||||
val trafficLightInfo = TrafficLightInfo()
|
||||
trafficLightInfo.id = "12"
|
||||
// 先来6秒红灯
|
||||
trafficLightInfo.lightStatus = "R"
|
||||
for (i in 0..5) {
|
||||
trafficLightInfo.surplusTime = (5-i).toString()
|
||||
dataCallback.showTrafficLightInfo(trafficLightInfo)
|
||||
Thread.sleep(1000)
|
||||
}
|
||||
// 停5秒
|
||||
Thread.sleep(4000)
|
||||
// 再来5秒黄灯
|
||||
trafficLightInfo.lightStatus = "Y"
|
||||
for (i in 0..5) {
|
||||
trafficLightInfo.surplusTime = (5-i).toString()
|
||||
dataCallback.showTrafficLightInfo(trafficLightInfo)
|
||||
Thread.sleep(1000)
|
||||
}
|
||||
// 停5秒
|
||||
Thread.sleep(4000)
|
||||
// 再来5秒绿灯
|
||||
trafficLightInfo.lightStatus = "G"
|
||||
for (i in 0..5) {
|
||||
trafficLightInfo.surplusTime = (5-i).toString()
|
||||
dataCallback.showTrafficLightInfo(trafficLightInfo)
|
||||
Thread.sleep(1000)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user