增加红绿灯时长mock数据

This commit is contained in:
yangjingjing
2020-07-19 20:00:40 +08:00
parent 0e4852e691
commit 9bfca836ee
3 changed files with 86 additions and 47 deletions

2
.idea/gradle.xml generated
View File

@@ -4,9 +4,11 @@
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="delegatedBuild" value="true" />
<option name="testRunner" value="PLATFORM" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="1.8" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />

2
.idea/misc.xml generated
View File

@@ -4,7 +4,7 @@
<asm skipDebug="false" skipFrames="false" skipCode="false" expandFrames="false" />
<groovy codeStyle="LEGACY" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="JDK" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
</project>

View File

@@ -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)
}
}
}