@@ -2,9 +2,11 @@ package com.mogo.eagle.core.function.obu.mogo
|
||||
|
||||
import android.content.Context
|
||||
import com.alibaba.android.arouter.facade.annotation.Route
|
||||
import com.mogo.eagle.core.data.constants.MoGoOBUConfig
|
||||
import com.mogo.eagle.core.function.api.obu.IMoGoObuProvider
|
||||
import com.mogo.eagle.core.utilcode.util.LogUtils
|
||||
import com.mogo.service.MogoServicePaths
|
||||
import com.mogo.utils.storage.SharedPrefsMgr
|
||||
|
||||
/**
|
||||
* @author xiaoyuzhou
|
||||
@@ -14,9 +16,22 @@ import com.mogo.service.MogoServicePaths
|
||||
class MoGoObuProvider : IMoGoObuProvider {
|
||||
private val TAG = "MoGoObuProvider"
|
||||
|
||||
private var mContext: Context? = null
|
||||
|
||||
override fun init(context: Context) {
|
||||
LogUtils.dTag(TAG, "初始化蘑菇自研OBU……")
|
||||
|
||||
MogoPrivateObuManager.INSTANCE.init(context)
|
||||
mContext = context
|
||||
val ipAddress =
|
||||
SharedPrefsMgr.getInstance(context).getString(MoGoOBUConfig.OBU_IP, "192.168.1.199")
|
||||
MogoPrivateObuManager.INSTANCE.init(context, ipAddress)
|
||||
}
|
||||
|
||||
override fun connect(ipAddress: String) {
|
||||
mContext?.let {
|
||||
// 保存本地OBU IP地址
|
||||
SharedPrefsMgr.getInstance(it).putString(MoGoOBUConfig.OBU_IP, ipAddress)
|
||||
MogoPrivateObuManager.INSTANCE.connectObu(it, ipAddress)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -41,18 +41,33 @@ class MogoPrivateObuManager private constructor() {
|
||||
private var mContext: Context? = null
|
||||
private var mObuStatusInfo = ObuStatusInfo()
|
||||
|
||||
fun init(context: Context?) {
|
||||
fun init(context: Context, ipAddress: String) {
|
||||
Logger.d(MogoObuConst.TAG_MOGO_OBU, "obuManager初始化--")
|
||||
mMogoServiceApis = ARouter.getInstance().build(MogoServicePaths.PATH_SERVICE_APIS)
|
||||
.navigation(context) as IMogoServiceApis
|
||||
mContext = context
|
||||
mIMogoMapService = mMogoServiceApis!!.mapServiceApi
|
||||
|
||||
//自研obu
|
||||
MogoObuManager.getInstance().connect(context, mObuStatusInfo.connectIP)
|
||||
connectObu(context, ipAddress)
|
||||
MogoObuManager.getInstance().registerListener(mogoObuListener)
|
||||
}
|
||||
|
||||
fun connectObu(context: Context, ipAddress: String) {
|
||||
//自研obu初始化
|
||||
mObuStatusInfo.connectIP = ipAddress
|
||||
if (!MogoObuManager.getInstance().isConnected) {
|
||||
MogoObuManager.getInstance().connect(context, mObuStatusInfo.connectIP)
|
||||
} else {
|
||||
MogoObuManager.getInstance().disConnect()
|
||||
try {
|
||||
Thread.sleep(500)
|
||||
MogoObuManager.getInstance().connect(context, mObuStatusInfo.connectIP)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val mogoObuListener: OnMogoObuListener = object : OnMogoObuListener() {
|
||||
// OBU连接成功
|
||||
override fun onConnected() {
|
||||
|
||||
Reference in New Issue
Block a user