This commit is contained in:
tongchenfei
2020-06-28 10:00:32 +08:00
parent 02452f0549
commit 2cf3bc8463
5 changed files with 47 additions and 27 deletions

View File

@@ -1,18 +1,16 @@
package com.zhidao.mogo.module.obu
import com.mogo.service.obu.IMogoObuDataChangedListener
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.CarLocationInfo
import com.zhidao.smartv2x.model.obu.TrafficLightInfo
import io.reactivex.Observable
import io.reactivex.Scheduler
import io.reactivex.Single
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.internal.operators.single.SingleSubscribeOn
import io.reactivex.schedulers.Schedulers
import io.reactivex.schedulers.Schedulers.io
import java.util.concurrent.TimeUnit
import kotlin.random.Random
/**
* 模拟相关操作及数据的单例类
@@ -32,21 +30,44 @@ object MockUtil {
}
private fun intervalMockData(){
intervalObs = Observable.interval(1000,TimeUnit.MILLISECONDS).map {
intervalObs = Observable.interval(5000,TimeUnit.MILLISECONDS).map {
it.toString()
}.subscribe {
val carLocationInfo = CarLocationInfo()
carLocationInfo.carId = "carLocation$it"
dataCallback.showCarLocationInfo(carLocationInfo)
val other = "other$it"
dataCallback.showOtherInfo(other)
val eventInfo = CarEventInfo()
eventInfo.describe = "event des $it"
eventInfo.type = "event type $it"
dataCallback.showCarEventInfo(eventInfo)
val traffic = TrafficLightInfo()
traffic.id = "traffic $it"
dataCallback.showTrafficLightInfo(traffic)
}.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 = ObuConstant.TYPE_OPTIMAL_SPEED_ADVISORY.toString()
carEventInfo.typeCode = ObuConstant.TYPE_OPTIMAL_SPEED_ADVISORY.toString()
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 = ObuConstant.TYPE_URGENCY_COLLISION_WARNING.toString()
carEventInfo.typeCode = ObuConstant.TYPE_URGENCY_COLLISION_WARNING.toString()
carEventInfo.describe = "这个应该是随便写,反正也不用"
dataCallback.showCarEventInfo(carEventInfo)
}
2->{
// 行人碰撞预警
carEventInfo.type = ObuConstant.TYPE_ROAD_USER_COLLISION_WARNING.toString()
carEventInfo.typeCode = ObuConstant.TYPE_ROAD_USER_COLLISION_WARNING.toString()
carEventInfo.describe = "这个应该是随便写,反正也不用"
dataCallback.showCarEventInfo(carEventInfo)
}
else->{
// 其他,不处理
}
}
}
}