1. 接入obu sdk
2. 进行数据转发功能开发
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package com.zhidao.mogo.module.obu
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class ExampleInstrumentedTest {
|
||||
@Test
|
||||
fun useAppContext() {
|
||||
// Context of the app under test.
|
||||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
assertEquals("com.zhidao.mogo.module.obu.test", appContext.packageName)
|
||||
}
|
||||
}
|
||||
5
modules/mogo-module-obu/src/main/AndroidManifest.xml
Normal file
5
modules/mogo-module-obu/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.zhidao.mogo.module.obu">
|
||||
|
||||
/
|
||||
</manifest>
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.zhidao.mogo.module.obu
|
||||
|
||||
import com.mogo.service.obu.IMogoObuDataChangedListener
|
||||
import com.mogo.utils.logger.Logger
|
||||
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.disposables.Disposable
|
||||
import io.reactivex.internal.operators.single.SingleSubscribeOn
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
/**
|
||||
* 模拟相关操作及数据的单例类
|
||||
*
|
||||
* @author tongchenfei
|
||||
*/
|
||||
object MockUtil {
|
||||
const val TAG = "MockUtil"
|
||||
private lateinit var dataCallback : IMogoObuDataChangedListener
|
||||
|
||||
private lateinit var intervalObs:Disposable
|
||||
|
||||
fun init(callback: IMogoObuDataChangedListener){
|
||||
Logger.d(TAG, "使用模拟obu数据===")
|
||||
dataCallback = callback
|
||||
intervalMockData()
|
||||
}
|
||||
|
||||
private fun intervalMockData(){
|
||||
intervalObs = Observable.interval(1000,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)
|
||||
}
|
||||
}
|
||||
|
||||
fun destroy(){
|
||||
intervalObs.dispose()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
package com.zhidao.mogo.module.obu
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.alibaba.android.arouter.facade.annotation.Route
|
||||
import com.mogo.commons.debug.DebugConfig
|
||||
import com.mogo.map.listener.IMogoMapListener
|
||||
import com.mogo.map.location.IMogoLocationListener
|
||||
import com.mogo.map.marker.IMogoMarkerClickListener
|
||||
import com.mogo.map.navi.IMogoNaviListener
|
||||
import com.mogo.service.MogoServicePaths
|
||||
import com.mogo.service.module.IMogoModuleLifecycle
|
||||
import com.mogo.service.obu.IMogoObuDataChangedListener
|
||||
import com.mogo.service.obu.IMogoObuManager
|
||||
import com.mogo.utils.logger.Logger
|
||||
import com.zhidao.smartv2x.api.V2xController
|
||||
import com.zhidao.smartv2x.model.obu.CarEventInfo
|
||||
import com.zhidao.smartv2x.model.obu.CarLocationInfo
|
||||
import com.zhidao.smartv2x.model.obu.TrafficLightInfo
|
||||
|
||||
/**
|
||||
* obu provider
|
||||
*
|
||||
* @author tongchenfei
|
||||
*/
|
||||
@Route(path = MogoServicePaths.PATH_OBU)
|
||||
class ObuManager: IMogoObuManager {
|
||||
companion object{
|
||||
const val TAG = "ObuProvider"
|
||||
}
|
||||
private var dataChangedListener: IMogoObuDataChangedListener? = null
|
||||
|
||||
override fun getNaviListener(): IMogoNaviListener? {
|
||||
return null
|
||||
}
|
||||
|
||||
override fun getLocationListener(): IMogoLocationListener? {
|
||||
return null
|
||||
}
|
||||
|
||||
override fun getType(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun getMarkerClickListener(): IMogoMarkerClickListener? {
|
||||
return null
|
||||
}
|
||||
|
||||
override fun init(context: Context) {
|
||||
Logger.d(TAG,"init=======")
|
||||
if (DebugConfig.isUseMockObuData()) {
|
||||
MockUtil.init {
|
||||
Logger.d(TAG, "obu mock callback===$it")
|
||||
|
||||
}
|
||||
} else {
|
||||
// 初始化sdk,注册数据回调等信息
|
||||
V2xController.getInstance().setMessageReceiveListener(this@ObuManager)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getMapListener(): IMogoMapListener? {
|
||||
return null
|
||||
}
|
||||
|
||||
override fun getAppPackage(): String {
|
||||
return ""
|
||||
}
|
||||
|
||||
override fun createView(context: Context?): View? {
|
||||
return null
|
||||
}
|
||||
|
||||
override fun createFragment(context: Context?, data: Bundle?): Fragment? {
|
||||
return null
|
||||
}
|
||||
|
||||
override fun getModuleName(): String {
|
||||
return "moduleObu"
|
||||
}
|
||||
|
||||
override fun getAppName(): String {
|
||||
return ""
|
||||
}
|
||||
|
||||
override fun getCardLifecycle(): IMogoModuleLifecycle? {
|
||||
return null
|
||||
}
|
||||
|
||||
override fun registerObuDataChangedListener(listener: IMogoObuDataChangedListener?) {
|
||||
this.dataChangedListener = listener
|
||||
}
|
||||
|
||||
/**
|
||||
* 车辆位置信息回调接口
|
||||
*/
|
||||
override fun showCarLocationInfo(info: CarLocationInfo?) {
|
||||
Logger.d(TAG,"showCarLocationInfo: ${info?.carId}")
|
||||
dataChangedListener?.showCarLocationInfo(info)
|
||||
}
|
||||
|
||||
/**
|
||||
* UDP 收发消息回调接口
|
||||
*/
|
||||
override fun showOtherInfo(info: String?) {
|
||||
Logger.d(TAG, "showOtherInfo: $info")
|
||||
dataChangedListener?.showOtherInfo(info)
|
||||
}
|
||||
|
||||
/**
|
||||
* 交通信号灯信息回调接口
|
||||
*/
|
||||
override fun showTrafficLightInfo(info: TrafficLightInfo?) {
|
||||
Logger.d(TAG, "showTrafficLightInfo: ${info?.id}")
|
||||
dataChangedListener?.showTrafficLightInfo(info)
|
||||
}
|
||||
|
||||
/**
|
||||
* 场景触发事件信息回调接口
|
||||
*/
|
||||
override fun showCarEventInfo(info: CarEventInfo?) {
|
||||
Logger.d(TAG, "showCarEventInfo: ${info?.type}")
|
||||
dataChangedListener?.showCarEventInfo(info)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.zhidao.mogo.module.obu
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
class ExampleUnitTest {
|
||||
@Test
|
||||
fun addition_isCorrect() {
|
||||
assertEquals(4, 2 + 2)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user