重构obu模块,新增udp通信
This commit is contained in:
@@ -21,14 +21,10 @@ import com.mogo.map.navi.MogoTraffic;
|
||||
import com.mogo.map.uicontroller.EnumMapUI;
|
||||
import com.mogo.module.main.registercenter.MogoRegisterCenterHandler;
|
||||
import com.mogo.service.adas.IMogoADASControlStatusChangedListener;
|
||||
import com.mogo.service.obu.IMogoObuDataChangedListener;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.zhidao.adasconfig.common.config.EnumCarChatIncognitoMode;
|
||||
import com.zhidao.adasconfig.listener.IAdasSettingUIListener;
|
||||
import com.zhidao.adasconfig.listener.IAdasSkinStyleListener;
|
||||
import com.zhidao.smartv2x.model.obu.CarEventInfo;
|
||||
import com.zhidao.smartv2x.model.obu.CarLocationInfo;
|
||||
import com.zhidao.smartv2x.model.obu.TrafficLightInfo;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
@@ -46,7 +42,6 @@ public class EventDispatchCenter implements
|
||||
IMogoMapListener,
|
||||
IMogoNaviListener2,
|
||||
IMogoLocationListener,
|
||||
IMogoObuDataChangedListener,
|
||||
IAdasSettingUIListener,
|
||||
IAdasSkinStyleListener {
|
||||
|
||||
@@ -486,50 +481,6 @@ public class EventDispatchCenter implements
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showCarLocationInfo( CarLocationInfo info ) {
|
||||
Iterator< IMogoObuDataChangedListener > iterator = MogoRegisterCenterHandler.getInstance().getObuDataChangedListeners();
|
||||
if ( iterator == null ) {
|
||||
return;
|
||||
}
|
||||
while ( iterator.hasNext() ) {
|
||||
iterator.next().showCarLocationInfo( info );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showOtherInfo( String info ) {
|
||||
Iterator< IMogoObuDataChangedListener > iterator = MogoRegisterCenterHandler.getInstance().getObuDataChangedListeners();
|
||||
if ( iterator == null ) {
|
||||
return;
|
||||
}
|
||||
while ( iterator.hasNext() ) {
|
||||
iterator.next().showOtherInfo( info );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showTrafficLightInfo( TrafficLightInfo info ) {
|
||||
Iterator< IMogoObuDataChangedListener > iterator = MogoRegisterCenterHandler.getInstance().getObuDataChangedListeners();
|
||||
if ( iterator == null ) {
|
||||
return;
|
||||
}
|
||||
while ( iterator.hasNext() ) {
|
||||
iterator.next().showTrafficLightInfo( info );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showCarEventInfo( CarEventInfo info ) {
|
||||
Iterator< IMogoObuDataChangedListener > iterator = MogoRegisterCenterHandler.getInstance().getObuDataChangedListeners();
|
||||
if ( iterator == null ) {
|
||||
return;
|
||||
}
|
||||
while ( iterator.hasNext() ) {
|
||||
iterator.next().showCarEventInfo( info );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void northModel() {
|
||||
Iterator< IMogoADASControlStatusChangedListener > iterator = MogoRegisterCenterHandler.getInstance().getAdasControlStatusChangedListeners();
|
||||
|
||||
@@ -6,9 +6,6 @@ import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.mogo.commons.debug.DebugConfig;
|
||||
import com.mogo.commons.mvp.MvpActivity;
|
||||
@@ -30,7 +27,6 @@ import com.mogo.service.adas.IMogoADASControlStatusChangedListener;
|
||||
import com.mogo.service.fragmentmanager.IMogoFragmentManager;
|
||||
import com.mogo.service.map.IMogoMapService;
|
||||
import com.mogo.service.module.IMogoModuleProvider;
|
||||
import com.mogo.service.obu.IMogoObuManager;
|
||||
import com.mogo.service.statusmanager.IMogoStatusManager;
|
||||
import com.mogo.skin.support.SkinMode;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
@@ -40,6 +36,9 @@ import com.zhidao.autopilot.support.api.AutopilotServiceManage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-23
|
||||
@@ -159,11 +158,6 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
mMogoMapService.getHostListenerRegister().registerMarkerClickListener( this );
|
||||
}
|
||||
|
||||
IMogoObuManager obuManager = mServiceApis.getObuManager();
|
||||
if(obuManager!=null) {
|
||||
obuManager.registerObuDataChangedListener(EventDispatchCenter.getInstance());
|
||||
}
|
||||
|
||||
if ( DebugConfig.isSkinSupported() ) {
|
||||
initAdasControlStatusListener();
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.adas.IMogoADASControlStatusChangedListener;
|
||||
import com.mogo.service.module.IMogoModuleLifecycle;
|
||||
import com.mogo.service.module.IMogoRegisterCenter;
|
||||
import com.mogo.service.obu.IMogoObuDataChangedListener;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
@@ -101,16 +100,6 @@ public class MogoRegisterCenter implements IMogoRegisterCenter {
|
||||
MogoRegisterCenterHandler.getInstance().unregisterCarLocationChangedListener( tag, listener );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerObuDataListener( String tag, IMogoObuDataChangedListener listener ) {
|
||||
MogoRegisterCenterHandler.getInstance().registerObuDataListener( tag, listener );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterObuDataListener( String tag ) {
|
||||
MogoRegisterCenterHandler.getInstance().unregisterObuDataListener( tag );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerADASControlStatusChangedListener( String tag, IMogoADASControlStatusChangedListener listener ) {
|
||||
MogoRegisterCenterHandler.getInstance().registerADASControlStatusChangedListener( tag, listener );
|
||||
|
||||
@@ -11,7 +11,6 @@ import com.mogo.map.navi.IMogoNaviListener;
|
||||
import com.mogo.service.adas.IMogoADASControlStatusChangedListener;
|
||||
import com.mogo.service.module.IMogoModuleLifecycle;
|
||||
import com.mogo.service.module.IMogoRegisterCenter;
|
||||
import com.mogo.service.obu.IMogoObuDataChangedListener;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
@@ -34,7 +33,6 @@ public class MogoRegisterCenterHandler implements IMogoRegisterCenter {
|
||||
private Map< String, IMogoMarkerClickListener > mMarker = new HashMap<>();
|
||||
private Map< String, IMogoAimlessModeListener > mAimless = new HashMap<>();
|
||||
private Map< String, IMogoCarLocationChangedListener > mCarLocations = new HashMap<>();
|
||||
private Map< String, IMogoObuDataChangedListener > mObus = new HashMap<>();
|
||||
private Map< String, IMogoADASControlStatusChangedListener > mADAS = new HashMap<>();
|
||||
|
||||
private MogoRegisterCenterHandler() {
|
||||
@@ -126,16 +124,6 @@ public class MogoRegisterCenterHandler implements IMogoRegisterCenter {
|
||||
mCarLocations.remove( tag );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerObuDataListener( String tag, IMogoObuDataChangedListener listener ) {
|
||||
mObus.put( tag, listener );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterObuDataListener( String tag ) {
|
||||
mObus.remove( tag );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerADASControlStatusChangedListener( String tag, IMogoADASControlStatusChangedListener listener ) {
|
||||
mADAS.put( tag, listener );
|
||||
@@ -182,10 +170,6 @@ public class MogoRegisterCenterHandler implements IMogoRegisterCenter {
|
||||
return mNavi.values().iterator();
|
||||
}
|
||||
|
||||
public Iterator< IMogoObuDataChangedListener > getObuDataChangedListeners() {
|
||||
return mObus.values().iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator< IMogoLocationListener > getLocationListeners() {
|
||||
return mLocation.values().iterator();
|
||||
|
||||
@@ -39,6 +39,9 @@ dependencies {
|
||||
kapt rootProject.ext.dependencies.aroutercompiler
|
||||
implementation rootProject.ext.dependencies.rxjava
|
||||
implementation rootProject.ext.dependencies.rxandroid
|
||||
|
||||
implementation rootProject.ext.dependencies.obusdk
|
||||
implementation 'com.mogo.module:module-crash-warning:1.1.0'
|
||||
if (Boolean.valueOf(RELEASE)) {
|
||||
implementation rootProject.ext.dependencies.modulecommon
|
||||
} else {
|
||||
|
||||
@@ -26,12 +26,12 @@ import kotlin.random.Random
|
||||
*/
|
||||
object MockUtil {
|
||||
const val TAG = "MockUtil"
|
||||
private lateinit var dataCallback : OnMessageReceiveListener
|
||||
private var dataCallback : OnMessageReceiveListener?=null
|
||||
|
||||
private lateinit var intervalObs:Disposable
|
||||
private lateinit var intervalObs2:Disposable
|
||||
|
||||
fun init(context: Context, callback: OnMessageReceiveListener){
|
||||
fun init(context: Context, callback: OnMessageReceiveListener? = null){
|
||||
Logger.d(TAG, "使用模拟obu数据===")
|
||||
dataCallback = callback
|
||||
val api = ARouter.getInstance().build(MogoServicePaths.PATH_SERVICE_APIS).navigation(context) as IMogoServiceApis
|
||||
@@ -45,7 +45,7 @@ object MockUtil {
|
||||
0 -> "已更改前方红绿灯状态,可优先通行"
|
||||
else -> "已增加前方绿灯时间,可优先通行"
|
||||
}
|
||||
dataCallback.showCarEventInfo(carEventInfo)
|
||||
dataCallback?.showCarEventInfo(carEventInfo)
|
||||
}
|
||||
|
||||
view.findViewById<Button>(R.id.btnRoadCondition).setOnClickListener {
|
||||
@@ -53,7 +53,7 @@ object MockUtil {
|
||||
carEventInfo.type = "行人碰撞预警"
|
||||
carEventInfo.typeCode = "39"
|
||||
carEventInfo.describe = "这个应该是随便写,反正也不用"
|
||||
dataCallback.showCarEventInfo(carEventInfo)
|
||||
dataCallback?.showCarEventInfo(carEventInfo)
|
||||
}
|
||||
api.windowManagerApi.addView(view, 500, 300, false)
|
||||
intervalMockData()
|
||||
@@ -92,21 +92,21 @@ object MockUtil {
|
||||
1 -> "建议50km/h车速行驶"
|
||||
else -> "建议30km/h ~ 50km/h 车速行驶"
|
||||
}
|
||||
dataCallback.showCarEventInfo(carEventInfo)
|
||||
dataCallback?.showCarEventInfo(carEventInfo)
|
||||
}
|
||||
1->{
|
||||
// 前方急刹预警
|
||||
carEventInfo.type = "紧急制动预警"
|
||||
carEventInfo.typeCode = "06"
|
||||
carEventInfo.describe = "这个应该是随便写,反正也不用"
|
||||
dataCallback.showCarEventInfo(carEventInfo)
|
||||
dataCallback?.showCarEventInfo(carEventInfo)
|
||||
}
|
||||
2->{
|
||||
// 行人碰撞预警
|
||||
carEventInfo.type = "行人碰撞预警"
|
||||
carEventInfo.typeCode = "39"
|
||||
carEventInfo.describe = "这个应该是随便写,反正也不用"
|
||||
dataCallback.showCarEventInfo(carEventInfo)
|
||||
dataCallback?.showCarEventInfo(carEventInfo)
|
||||
}
|
||||
3 -> {
|
||||
// vip变灯提醒
|
||||
@@ -117,7 +117,7 @@ object MockUtil {
|
||||
0 -> "已更改前方红绿灯状态,可优先通行"
|
||||
else -> "已增加前方绿灯时间,可优先通行"
|
||||
}
|
||||
dataCallback.showCarEventInfo(carEventInfo)
|
||||
dataCallback?.showCarEventInfo(carEventInfo)
|
||||
}
|
||||
else->{
|
||||
// 其他,不处理
|
||||
@@ -135,7 +135,7 @@ object MockUtil {
|
||||
trafficLightInfo.lightStatus = "R"
|
||||
for (i in 0..5) {
|
||||
trafficLightInfo.surplusTime = (5-i).toString()
|
||||
dataCallback.showTrafficLightInfo(trafficLightInfo)
|
||||
dataCallback?.showTrafficLightInfo(trafficLightInfo)
|
||||
Thread.sleep(1000)
|
||||
}
|
||||
// 停5秒
|
||||
@@ -144,7 +144,7 @@ object MockUtil {
|
||||
trafficLightInfo.lightStatus = "Y"
|
||||
for (i in 0..5) {
|
||||
trafficLightInfo.surplusTime = (5-i).toString()
|
||||
dataCallback.showTrafficLightInfo(trafficLightInfo)
|
||||
dataCallback?.showTrafficLightInfo(trafficLightInfo)
|
||||
Thread.sleep(1000)
|
||||
}
|
||||
// 停5秒
|
||||
@@ -153,7 +153,7 @@ object MockUtil {
|
||||
trafficLightInfo.lightStatus = "G"
|
||||
for (i in 0..5) {
|
||||
trafficLightInfo.surplusTime = (5-i).toString()
|
||||
dataCallback.showTrafficLightInfo(trafficLightInfo)
|
||||
dataCallback?.showTrafficLightInfo(trafficLightInfo)
|
||||
Thread.sleep(1000)
|
||||
}
|
||||
Logger.d(TAG, "红绿灯模拟数据发送结束====")
|
||||
|
||||
@@ -1,136 +1,47 @@
|
||||
package com.zhidao.mogo.module.obu
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.os.Message
|
||||
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.mogo.module.obu.obu.CidiObu
|
||||
import com.zhidao.mogo.module.obu.obu.HualiObu
|
||||
import com.zhidao.mogo.module.obu.obu.IObu
|
||||
import com.zhidao.mogo.module.obu.obu.IObuCallback
|
||||
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,Handler.Callback {
|
||||
class ObuManager {
|
||||
companion object{
|
||||
const val TAG = "ObuManger"
|
||||
const val MSG_MONITOR_OBU_STATUS = 1001
|
||||
const val DEFAULT_MONITOR_TIME = 10_000L
|
||||
}
|
||||
private var dataChangedListener: IMogoObuDataChangedListener? = null
|
||||
|
||||
private var handler = Handler(Looper.getMainLooper(), this)
|
||||
// private var handler = Handler(Looper.getMainLooper(), this)
|
||||
|
||||
override fun init(context: Context) {
|
||||
private lateinit var obu:IObu
|
||||
|
||||
fun init(context: Context) {
|
||||
Logger.d(TAG,"init=======")
|
||||
if (DebugConfig.isUseMockObuData()) {
|
||||
MockUtil.init(context,this)
|
||||
MockUtil.init(context)
|
||||
} else {
|
||||
// 初始化sdk,注册数据回调等信息
|
||||
V2xController.getInstance().setMessageReceiveListener(this)
|
||||
V2xController.getInstance().init()
|
||||
// V2xController.getInstance().setMessageReceiveListener(this@ObuManager)
|
||||
handler.sendEmptyMessageDelayed(MSG_MONITOR_OBU_STATUS, DEFAULT_MONITOR_TIME)
|
||||
}
|
||||
}
|
||||
|
||||
override fun registerObuDataChangedListener(listener: IMogoObuDataChangedListener?) {
|
||||
this.dataChangedListener = listener
|
||||
}
|
||||
|
||||
/**
|
||||
* 车辆位置信息回调接口
|
||||
*/
|
||||
override fun showCarLocationInfo(info: CarLocationInfo?) {
|
||||
Logger.v(TAG, "thread: ${Thread.currentThread()} showCarLocationInfo: ${info?.carId}")
|
||||
if(!DebugConfig.isUseMockObuData()) {
|
||||
// 不使用模拟数据时候不做此处理
|
||||
// 由于obu会频繁回调此接口,故10秒收不到此数据,则认为obu连接不正常,就断开重连一下
|
||||
handler.removeMessages(MSG_MONITOR_OBU_STATUS)
|
||||
handler.sendEmptyMessageDelayed(MSG_MONITOR_OBU_STATUS, DEFAULT_MONITOR_TIME)
|
||||
}
|
||||
|
||||
handler.post{
|
||||
dataChangedListener?.showCarLocationInfo(info)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* UDP 收发消息回调接口
|
||||
*/
|
||||
override fun showOtherInfo(info: String?) {
|
||||
Logger.d(TAG, "thread: ${Thread.currentThread()} showOtherInfo: $info")
|
||||
handler.post{
|
||||
dataChangedListener?.showOtherInfo(info)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 交通信号灯信息回调接口
|
||||
* 17号路口红绿灯倒计时出现了,如果[TrafficLightInfo.lightStatus]为0,或者说,不为G/Y/R时,此条红绿灯数据无效
|
||||
*/
|
||||
override fun showTrafficLightInfo(info: TrafficLightInfo?) {
|
||||
Logger.d(TAG, "thread: ${Thread.currentThread()} showTrafficLightInfo: $info")
|
||||
Logger.d(TAG, "isTrafficLightInfoValid: ${isTrafficLightInfoValid(info)}")
|
||||
if(isTrafficLightInfoValid(info)) {
|
||||
handler.post {
|
||||
dataChangedListener?.showTrafficLightInfo(info)
|
||||
obu = if(DebugConfig.getObuType() == DebugConfig.OBU_TYPE_CIDI){
|
||||
CidiObu()
|
||||
}else{
|
||||
HualiObu()
|
||||
}
|
||||
obu.init()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断红绿灯信息是否有效
|
||||
*
|
||||
* @return true 有效
|
||||
*/
|
||||
private fun isTrafficLightInfoValid(info:TrafficLightInfo?):Boolean{
|
||||
return info == null||(info.lightStatus=="G"||info.lightStatus=="Y"||info.lightStatus=="R")
|
||||
}
|
||||
|
||||
/**
|
||||
* 场景触发事件信息回调接口
|
||||
*/
|
||||
override fun showCarEventInfo(info: CarEventInfo?) {
|
||||
Logger.d(TAG, "thread: ${Thread.currentThread()} showCarEventInfo: ${info?.type}")
|
||||
handler.post {
|
||||
dataChangedListener?.showCarEventInfo(info)
|
||||
fun registerObuDataChangedListener(listener: IObuCallback?) {
|
||||
if (listener != null) {
|
||||
obu.registerObuCallback(listener)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param msg A [Message][android.os.Message] object
|
||||
* @return True if no further handling is desired
|
||||
*/
|
||||
override fun handleMessage(msg: Message?): Boolean {
|
||||
if (msg?.what == MSG_MONITOR_OBU_STATUS) {
|
||||
// obu未正常连接,需要重新连接
|
||||
Logger.d(TAG,"obu未正常连接,需要重新连接")
|
||||
V2xController.getInstance().release()
|
||||
V2xController.getInstance().setMessageReceiveListener(this)
|
||||
V2xController.getInstance().init()
|
||||
handler.sendEmptyMessageDelayed(MSG_MONITOR_OBU_STATUS, DEFAULT_MONITOR_TIME)
|
||||
// V2xController.getInstance().release()
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.zhidao.mogo.module.obu.obu
|
||||
|
||||
open class BaseObu : IObu {
|
||||
protected var callback: IObuCallback? = null
|
||||
override fun init() {
|
||||
}
|
||||
|
||||
override fun registerObuCallback(callback: IObuCallback) {
|
||||
this.callback = callback
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package com.zhidao.mogo.module.obu.obu
|
||||
|
||||
import android.os.Handler
|
||||
import android.os.Message
|
||||
import com.mogo.commons.debug.DebugConfig
|
||||
import com.mogo.utils.logger.Logger
|
||||
import com.zhidao.mogo.module.obu.obu.bean.MogoObuEventInfo
|
||||
import com.zhidao.mogo.module.obu.obu.bean.MogoObuLocationInfo
|
||||
import com.zhidao.mogo.module.obu.obu.bean.MogoObuTrafficLightInfo
|
||||
import com.zhidao.smartv2x.api.V2xController
|
||||
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
|
||||
|
||||
/**
|
||||
* 西迪obu
|
||||
*
|
||||
* @author tongchenfei
|
||||
*/
|
||||
class CidiObu : BaseObu(), Handler.Callback, OnMessageReceiveListener {
|
||||
companion object {
|
||||
const val TAG = "CidiObu"
|
||||
const val MSG_MONITOR_OBU_STATUS = 1001
|
||||
const val DEFAULT_MONITOR_TIME = 10_000L
|
||||
}
|
||||
|
||||
private val handler = Handler(this)
|
||||
override fun init() {
|
||||
super.init()
|
||||
// 初始化sdk,注册数据回调等信息
|
||||
V2xController.getInstance().setMessageReceiveListener(this)
|
||||
V2xController.getInstance().init()
|
||||
handler.sendEmptyMessageDelayed(MSG_MONITOR_OBU_STATUS, DEFAULT_MONITOR_TIME)
|
||||
}
|
||||
|
||||
/**
|
||||
* 车辆位置信息回调接口
|
||||
*/
|
||||
override fun showCarLocationInfo(info: CarLocationInfo?) {
|
||||
Logger.v(TAG, "thread: ${Thread.currentThread()} showCarLocationInfo: ${info?.carId}")
|
||||
if (!DebugConfig.isUseMockObuData()) {
|
||||
// 不使用模拟数据时候不做此处理
|
||||
// 由于obu会频繁回调此接口,故10秒收不到此数据,则认为obu连接不正常,就断开重连一下
|
||||
handler.removeMessages(MSG_MONITOR_OBU_STATUS)
|
||||
handler.sendEmptyMessageDelayed(MSG_MONITOR_OBU_STATUS, DEFAULT_MONITOR_TIME)
|
||||
}
|
||||
|
||||
handler.post {
|
||||
if (info == null) {
|
||||
callback?.onLocationInfoCallback(null)
|
||||
}else {
|
||||
callback?.onLocationInfoCallback(MogoObuLocationInfo(info))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* UDP 收发消息回调接口
|
||||
*/
|
||||
override fun showOtherInfo(info: String?) {
|
||||
Logger.d(TAG, "thread: ${Thread.currentThread()} showOtherInfo: $info")
|
||||
}
|
||||
|
||||
/**
|
||||
* 交通信号灯信息回调接口
|
||||
* 17号路口红绿灯倒计时出现了,如果[TrafficLightInfo.lightStatus]为0,或者说,不为G/Y/R时,此条红绿灯数据无效
|
||||
*/
|
||||
override fun showTrafficLightInfo(info: TrafficLightInfo?) {
|
||||
Logger.d(TAG, "thread: ${Thread.currentThread()} showTrafficLightInfo: $info")
|
||||
Logger.d(TAG, "isTrafficLightInfoValid: ${isTrafficLightInfoValid(info)}")
|
||||
if (isTrafficLightInfoValid(info)) {
|
||||
handler.post {
|
||||
if (info == null) {
|
||||
callback?.onTrafficLightInfoCallback(null)
|
||||
}else{
|
||||
callback?.onTrafficLightInfoCallback(MogoObuTrafficLightInfo(info))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断红绿灯信息是否有效
|
||||
*
|
||||
* @return true 有效
|
||||
*/
|
||||
private fun isTrafficLightInfoValid(info: TrafficLightInfo?): Boolean {
|
||||
return info == null || (info.lightStatus == "G" || info.lightStatus == "Y" || info.lightStatus == "R")
|
||||
}
|
||||
|
||||
/**
|
||||
* 场景触发事件信息回调接口
|
||||
*/
|
||||
override fun showCarEventInfo(info: CarEventInfo?) {
|
||||
Logger.d(TAG, "thread: ${Thread.currentThread()} showCarEventInfo: ${info?.type}")
|
||||
handler.post {
|
||||
if (info == null) {
|
||||
callback?.onEventInfoCallback(null)
|
||||
}else{
|
||||
callback?.onEventInfoCallback(MogoObuEventInfo(info))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param msg A [Message][android.os.Message] object
|
||||
* @return True if no further handling is desired
|
||||
*/
|
||||
override fun handleMessage(msg: Message?): Boolean {
|
||||
if (msg?.what == MSG_MONITOR_OBU_STATUS) {
|
||||
// obu未正常连接,需要重新连接
|
||||
Logger.d(TAG, "obu未正常连接,需要重新连接")
|
||||
V2xController.getInstance().release()
|
||||
V2xController.getInstance().setMessageReceiveListener(this)
|
||||
V2xController.getInstance().init()
|
||||
handler.sendEmptyMessageDelayed(MSG_MONITOR_OBU_STATUS, DEFAULT_MONITOR_TIME)
|
||||
// V2xController.getInstance().release()
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.zhidao.mogo.module.obu.obu
|
||||
|
||||
import com.mogo.utils.logger.Logger
|
||||
import com.zhidao.mogo.module.obu.socket.IUdpSocketCallback
|
||||
import com.zhidao.mogo.module.obu.socket.UdpSocketManager
|
||||
import kotlin.concurrent.thread
|
||||
|
||||
/**
|
||||
* 华砺智行obu 苏州演示项目用到的
|
||||
*
|
||||
* @author tongchenfei
|
||||
*/
|
||||
class HualiObu : BaseObu(),IUdpSocketCallback {
|
||||
private val socketManager = UdpSocketManager(this)
|
||||
companion object{
|
||||
const val TAG = "HualiObu"
|
||||
const val IP_ADDRESS = "172.30.33.38"
|
||||
const val PORT = 10005
|
||||
}
|
||||
override fun init() {
|
||||
super.init()
|
||||
socketManager.receiveMsgFrom(IP_ADDRESS, PORT)
|
||||
socketManager.sendMsgTo("Hello ssokit", IP_ADDRESS, PORT)
|
||||
Logger.d(TAG, "init")
|
||||
thread {
|
||||
var count = 0
|
||||
while (true) {
|
||||
Logger.d(TAG,"准备发送测试数据===")
|
||||
socketManager.sendMsgTo("Hello ssokit===$count", IP_ADDRESS, PORT)
|
||||
count++
|
||||
Thread.sleep(1000)
|
||||
if (count == 1000) {
|
||||
Logger.d(TAG, "测试数据结束")
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onMessageReceived(msg: ByteArray) {
|
||||
// todo 处理数据
|
||||
val m = String(msg)
|
||||
Logger.d(TAG, "onMessageReceived: $msg")
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.zhidao.mogo.module.obu.obu
|
||||
|
||||
/**
|
||||
* Obu基本方法
|
||||
* @author tongchenfei
|
||||
*/
|
||||
interface IObu {
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
fun init()
|
||||
|
||||
/**
|
||||
* 注册数据回调
|
||||
*/
|
||||
fun registerObuCallback(callback: IObuCallback)
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.zhidao.mogo.module.obu.obu
|
||||
|
||||
import com.zhidao.mogo.module.obu.obu.bean.MogoObuEventInfo
|
||||
import com.zhidao.mogo.module.obu.obu.bean.MogoObuLocationInfo
|
||||
import com.zhidao.mogo.module.obu.obu.bean.MogoObuTrafficLightInfo
|
||||
|
||||
/**
|
||||
* obu数据回调,目前是根据西迪的数据进行的封装
|
||||
*
|
||||
* @author tongchenfei
|
||||
*/
|
||||
interface IObuCallback {
|
||||
/**
|
||||
* obu事件回调
|
||||
* @param eventInfo 事件信息
|
||||
*/
|
||||
fun onEventInfoCallback(eventInfo:MogoObuEventInfo?)
|
||||
|
||||
/**
|
||||
* obu定位信息回调
|
||||
* @param locationInfo 定位信息
|
||||
*/
|
||||
fun onLocationInfoCallback(locationInfo: MogoObuLocationInfo?)
|
||||
|
||||
/**
|
||||
* obu红绿灯信息回调
|
||||
* @param trafficLightInfo 红绿灯信息
|
||||
*/
|
||||
fun onTrafficLightInfoCallback(trafficLightInfo: MogoObuTrafficLightInfo?)
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.zhidao.mogo.module.obu.obu.bean
|
||||
|
||||
import com.zhidao.smartv2x.model.obu.CarEventInfo
|
||||
|
||||
/**
|
||||
* obu事件数据封装,根据西迪obu数据进行整理
|
||||
*
|
||||
* {"typeCode":"01","type":"前碰撞预警","describe":"等级:1"}
|
||||
*/
|
||||
class MogoObuEventInfo(){
|
||||
var typeCode:String? = null
|
||||
var type:String? = null
|
||||
var describe:String? = null
|
||||
override fun toString(): String {
|
||||
return "MogoObuEventInfo(typeCode=$typeCode, type=$type, describe=$describe)"
|
||||
}
|
||||
|
||||
constructor(info:CarEventInfo):this(){
|
||||
this.typeCode = info.typeCode
|
||||
this.type = info.type
|
||||
this.describe = info.describe
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.zhidao.mogo.module.obu.obu.bean
|
||||
|
||||
import com.zhidao.smartv2x.model.obu.CarLocationInfo
|
||||
|
||||
/**
|
||||
* obu定位信息,根据西迪obu进行封装
|
||||
* {"carId":"1952999795","lat":28.089524299999997,"lng":112.9908293,"speed":"14"," direction":"10112","sateNum":"24","signal":"0"}
|
||||
* @author tongchenfei
|
||||
*/
|
||||
class MogoObuLocationInfo() {
|
||||
var carId: String? = null
|
||||
var lat: Double? = 0.0
|
||||
var lon: Double? = 0.0
|
||||
var speed: String? = null
|
||||
var direction: String? = null
|
||||
var sateNum: String? = null
|
||||
var signal: String? = null
|
||||
override fun toString(): String {
|
||||
return "MogoObuLocationInfo(lat=$lat)"
|
||||
}
|
||||
|
||||
constructor(info:CarLocationInfo?) : this() {
|
||||
this.carId = info?.carId
|
||||
this.lat = info?.lat
|
||||
this.lon = info?.lng
|
||||
this.speed = info?.speed
|
||||
this.direction = info?.direction
|
||||
this.sateNum = info?.sateNum
|
||||
this.signal = info?.signal
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.zhidao.mogo.module.obu.obu.bean
|
||||
|
||||
import com.zhidao.smartv2x.model.obu.TrafficLightInfo
|
||||
|
||||
/**
|
||||
* obu信号灯数据,根据西迪obu进行封装
|
||||
* lightStatus:信号灯的当前状态 G/R/Y 分别对应 绿/红/黄
|
||||
* surplusTime:当前信号灯剩余时间 十进制 单位:秒
|
||||
* lightPriority:保留字段,暂无说明
|
||||
*
|
||||
* @author tongchenfei
|
||||
*/
|
||||
class MogoObuTrafficLightInfo(){
|
||||
var id:String? =null
|
||||
var lightStatus:String? =null
|
||||
var surplusTime:String? =null
|
||||
var lightPriority:String? =null
|
||||
override fun toString(): String {
|
||||
return "MogoObuTrafficLightInfo(id=$id, lightStatus=$lightStatus, surplusTime=$surplusTime, lightPriority=$lightPriority)"
|
||||
}
|
||||
|
||||
constructor(info:TrafficLightInfo):this(){
|
||||
this.id = info.id
|
||||
this.lightStatus = info.lightStatus
|
||||
this.surplusTime = info.surplusTime
|
||||
this.lightPriority = info.lightPriority
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.zhidao.mogo.module.obu.socket
|
||||
|
||||
/**
|
||||
* udp 数据回调
|
||||
*/
|
||||
interface IUdpSocketCallback {
|
||||
/**
|
||||
* udp过来的字节码数据,目前已知数据类型就是ByteArray
|
||||
*
|
||||
* @param msg udp发过来的数据
|
||||
*/
|
||||
fun onMessageReceived(msg: ByteArray)
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.zhidao.mogo.module.obu.socket
|
||||
|
||||
class SimpleAddress(val ip: String, val port: Int) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
return when (other) {
|
||||
is SimpleAddress -> other.ip == ip && port == port
|
||||
null -> false
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return ip.hashCode() + port.hashCode()
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return "SimpleAddress(ip='$ip', port=$port)"
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.zhidao.mogo.module.obu.socket
|
||||
|
||||
import android.util.ArrayMap
|
||||
import com.mogo.utils.logger.Logger
|
||||
import java.net.DatagramPacket
|
||||
import java.net.DatagramSocket
|
||||
import java.net.InetAddress
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
/**
|
||||
* udp socket 管理类,统一管理udp socket数据接收和发送
|
||||
*/
|
||||
class UdpSocketManager(private val callback: IUdpSocketCallback? = null) {
|
||||
companion object{
|
||||
const val TAG = "Mogo-UdpSocketManager"
|
||||
}
|
||||
private val socketMap = ArrayMap<SimpleAddress, DatagramSocket>()
|
||||
private val socketExecutor = Executors.newCachedThreadPool()
|
||||
|
||||
@Volatile private var isConnected = false
|
||||
|
||||
fun sendMsgTo(msg:String,ip: String, port: Int) {
|
||||
isConnected = true
|
||||
val address = SimpleAddress(ip, port)
|
||||
socketExecutor.execute(UdpSenderRunnable(address, msg))
|
||||
}
|
||||
|
||||
fun receiveMsgFrom(ip: String, port: Int) {
|
||||
isConnected = true
|
||||
val address = SimpleAddress(ip, port)
|
||||
socketExecutor.execute(UdpReceiverRunnable(address))
|
||||
}
|
||||
|
||||
fun release(){
|
||||
isConnected = false
|
||||
socketMap.forEach {
|
||||
it.value.close()
|
||||
}
|
||||
}
|
||||
|
||||
inner class UdpSenderRunnable(private val address: SimpleAddress,private val msg:String):Runnable{
|
||||
override fun run() {
|
||||
Logger.d(TAG, "${address}准备发送消息: $msg")
|
||||
var socket = socketMap[address]
|
||||
val netAddress = InetAddress.getByName(address.ip)
|
||||
if (socket == null) {
|
||||
socket = DatagramSocket(address.port)
|
||||
socketMap[address] = socket
|
||||
}
|
||||
socket.send(DatagramPacket(msg.toByteArray(), msg.toByteArray().size, netAddress, address.port))
|
||||
}
|
||||
}
|
||||
inner class UdpReceiverRunnable(private val address:SimpleAddress):Runnable{
|
||||
override fun run() {
|
||||
var socket = socketMap[address]
|
||||
Logger.d(TAG, "init receiver: $address")
|
||||
|
||||
if (socket == null) {
|
||||
socket = DatagramSocket(address.port)
|
||||
socketMap[address] = socket
|
||||
}
|
||||
val buffer = ByteArray(1024)
|
||||
val packet = DatagramPacket(buffer, buffer.size)
|
||||
while (isConnected){
|
||||
if(socket.isClosed){
|
||||
break
|
||||
}
|
||||
Logger.d(TAG,"准备接受消息====$address")
|
||||
socket.receive(packet)
|
||||
val msg = ByteArray(buffer.size)
|
||||
System.arraycopy(buffer, 0, msg, 0, buffer.size)
|
||||
callback?.onMessageReceived(msg)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -90,8 +90,7 @@ dependencies {
|
||||
testImplementation 'junit:junit:4.13'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||
|
||||
compileOnly project(':modules:mogo-module-obu')
|
||||
implementation project(':modules:mogo-module-obu')
|
||||
}
|
||||
|
||||
apply from: new File(rootProject.rootDir, "gradle/upload.gradle").toString()
|
||||
|
||||
@@ -136,7 +136,7 @@ public class V2XModuleProvider implements
|
||||
localBroadcastManager.registerReceiver(localReceiver, intentFilter);
|
||||
|
||||
// obu数据转发初始化
|
||||
V2XObuManager.getInstance().init();
|
||||
V2XObuManager.getInstance().init(context);
|
||||
}
|
||||
|
||||
private void initBiz(Context context) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.mogo.module.v2x;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
@@ -17,13 +18,15 @@ import com.mogo.module.v2x.scenario.scene.obu.V2XObuEventScenario;
|
||||
import com.mogo.module.v2x.utils.ADASUtils;
|
||||
import com.mogo.module.v2x.utils.DrivingDirectionUtils;
|
||||
import com.mogo.module.v2x.utils.ObuConfig;
|
||||
import com.mogo.service.obu.IMogoObuDataChangedListener;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.zhidao.mogo.module.obu.ObuConstant;
|
||||
import com.zhidao.smartv2x.model.obu.CarEventInfo;
|
||||
import com.zhidao.smartv2x.model.obu.CarLocationInfo;
|
||||
import com.zhidao.smartv2x.model.obu.TrafficLightInfo;
|
||||
import com.zhidao.mogo.module.obu.ObuManager;
|
||||
import com.zhidao.mogo.module.obu.obu.IObuCallback;
|
||||
import com.zhidao.mogo.module.obu.obu.bean.MogoObuEventInfo;
|
||||
import com.zhidao.mogo.module.obu.obu.bean.MogoObuLocationInfo;
|
||||
import com.zhidao.mogo.module.obu.obu.bean.MogoObuTrafficLightInfo;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -36,7 +39,7 @@ import static com.mogo.module.v2x.scenario.scene.obu.V2XObuEventScenario.ACTION_
|
||||
*
|
||||
* @author tongchenfei
|
||||
*/
|
||||
public class V2XObuManager implements IMogoObuDataChangedListener, Handler.Callback {
|
||||
public class V2XObuManager implements IObuCallback, Handler.Callback {
|
||||
private static final String TAG = V2XObuManager.class.getSimpleName();
|
||||
|
||||
private static final long DEFAULT_INTERVAL_TIME = 30_000L;
|
||||
@@ -61,9 +64,11 @@ public class V2XObuManager implements IMogoObuDataChangedListener, Handler.Callb
|
||||
private static final long DEFAULT_HIDE_TRAFFIC_LIGHT_DELAY = 1500L;
|
||||
private Handler handler = new Handler(this);
|
||||
|
||||
public void init() {
|
||||
public void init(Context context) {
|
||||
Logger.d(MODULE_NAME, "obuManager初始化--");
|
||||
V2XServiceManager.getMogoRegisterCenter().registerObuDataListener(MODULE_NAME, this);
|
||||
ObuManager obuManager = new ObuManager();
|
||||
obuManager.init(context);
|
||||
obuManager.registerObuDataChangedListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,133 +76,6 @@ public class V2XObuManager implements IMogoObuDataChangedListener, Handler.Callb
|
||||
*/
|
||||
private Map<String, Long> intervalMap = new ArrayMap<>();
|
||||
|
||||
/**
|
||||
* 车辆位置信息回调接口
|
||||
*
|
||||
* @param info 位置信息
|
||||
*/
|
||||
@Override
|
||||
public void showCarLocationInfo(CarLocationInfo info) {
|
||||
if (ObuConfig.useObuLocation) {
|
||||
MogoLocation currentLocation = new MogoLocation();
|
||||
|
||||
CoordinateConverter converter = new CoordinateConverter(V2XServiceManager.getContext());
|
||||
converter.from(CoordinateConverter.CoordType.GPS);
|
||||
LatLng latLng = new LatLng(info.lat, info.lng);
|
||||
converter.coord(latLng);
|
||||
LatLng convert = converter.convert();
|
||||
|
||||
currentLocation.setLatitude(convert.latitude);
|
||||
currentLocation.setLongitude(convert.longitude);
|
||||
currentLocation.setBearing(computeCarAngle(currentLocation));
|
||||
|
||||
V2XObuEventScenario.getInstance().updateLocation(currentLocation);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* UDP 收发消息回调接口
|
||||
*
|
||||
* @param info 消息回调
|
||||
*/
|
||||
@Override
|
||||
public void showOtherInfo(String info) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 交通信号灯信息回调接口
|
||||
*
|
||||
* @param info 信号灯信息
|
||||
*/
|
||||
@Override
|
||||
public void showTrafficLightInfo(TrafficLightInfo info) {
|
||||
handler.removeMessages(MSG_HIDE_TRAFFIC_LIGHT);
|
||||
if (info == null) {
|
||||
Logger.d("V2X_OBU_EVENT", "红绿灯数据为空===");
|
||||
sendTrafficLightStatusToAdas(CALL_ADAS_HIDE_TRAFFIC_LIGHT, null);
|
||||
} else {
|
||||
Logger.d("V2X_OBU_EVENT", "红绿灯数据==" + info);
|
||||
handler.sendEmptyMessageDelayed(MSG_HIDE_TRAFFIC_LIGHT, DEFAULT_HIDE_TRAFFIC_LIGHT_DELAY);
|
||||
sendTrafficLightStatusToAdas(CALL_ADAS_SHOW_TRAFFIC_LIGHT, info);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 场景触发事件信息回调接口
|
||||
*
|
||||
* @param info 场景触发事件信息
|
||||
*/
|
||||
@Override
|
||||
public void showCarEventInfo(CarEventInfo info) {
|
||||
Logger.d("V2X_OBU_EVENT", "carEventInfo==" + info);
|
||||
Long last = intervalMap.get(info.typeCode);
|
||||
if (last == null) {
|
||||
last = 0L;
|
||||
}
|
||||
int eventType = parseObuEvent(info.typeCode);
|
||||
if (eventType == ObuConstant.TYPE_OPTIMAL_SPEED_ADVISORY) {
|
||||
// 加一个容错机制,如果已经驶过绿波车速路口,那么再收到绿波车速obu事件,就不再上报
|
||||
MogoLocation currentLocation = V2XLocationListener.getInstance().getLastCarLocation();
|
||||
double eventAngle = DrivingDirectionUtils.getDegreeOfCar2Poi(
|
||||
currentLocation.getLongitude(),
|
||||
currentLocation.getLatitude(),
|
||||
V2XObuEventScenario.getInstance().getOptimalCrossing().getLon(),
|
||||
V2XObuEventScenario.getInstance().getOptimalCrossing().getLat(),
|
||||
(int) currentLocation.getBearing()
|
||||
);
|
||||
if (0 > eventAngle || eventAngle > 20) {
|
||||
Logger.e(MODULE_NAME, "超出绿波引导点范围,不处理此次事件===" + eventAngle);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (SystemClock.elapsedRealtime() - last > DEFAULT_INTERVAL_TIME) {
|
||||
// 距离上次记录超过三十秒,继续相关逻辑,如果不超过三十秒,忽略此次事件
|
||||
intervalMap.put(info.typeCode, SystemClock.elapsedRealtime());
|
||||
V2XMessageEntity<V2XObuEventEntity> messageEntity = new V2XMessageEntity<>();
|
||||
messageEntity.setType(V2XMessageEntity.V2XTypeEnum.ALERT_OBU_EVENT);
|
||||
switch (eventType) {
|
||||
case ObuConstant
|
||||
.TYPE_OPTIMAL_SPEED_ADVISORY:
|
||||
// 绿波车速引导
|
||||
V2XObuEventEntity optimalEvent = new V2XObuEventEntity();
|
||||
optimalEvent.setType(ObuConstant.TYPE_OPTIMAL_SPEED_ADVISORY);
|
||||
optimalEvent.setDesc(info.describe);
|
||||
messageEntity.setContent(optimalEvent);
|
||||
V2XObuEventScenario.getInstance().init(messageEntity);
|
||||
break;
|
||||
case ObuConstant.TYPE_URGENCY_COLLISION_WARNING:
|
||||
// 前车紧急制动预警
|
||||
V2XObuEventEntity urgencyEvent = new V2XObuEventEntity();
|
||||
urgencyEvent.setType(ObuConstant.TYPE_URGENCY_COLLISION_WARNING);
|
||||
urgencyEvent.setDesc(V2XObuEventScenario.URGENCY_COLLISION_WARN_TEXT);
|
||||
messageEntity.setContent(urgencyEvent);
|
||||
V2XObuEventScenario.getInstance().init(messageEntity);
|
||||
break;
|
||||
case ObuConstant.TYPE_ROAD_USER_COLLISION_WARNING:
|
||||
// 行人预警,给adas发送广播即可
|
||||
V2XPushMessageEntity entity = new V2XPushMessageEntity();
|
||||
// 盲区行人预警的sceneId-100003
|
||||
entity.setSceneId("100003");
|
||||
entity.setTts("前方行人,注意减速");
|
||||
entity.setExpireTime(30_000);
|
||||
entity.setAlarmContent("前方行人,注意减速");
|
||||
ADASUtils.broadcastToADAS(V2XServiceManager.getContext(), entity);
|
||||
break;
|
||||
case ObuConstant.TYPE_CHANGE_LIGHT_FOR_VIP:
|
||||
// vip变灯提醒
|
||||
V2XObuEventEntity changeLightEvent = new V2XObuEventEntity();
|
||||
changeLightEvent.setType(ObuConstant.TYPE_CHANGE_LIGHT_FOR_VIP);
|
||||
changeLightEvent.setDesc(info.describe);
|
||||
messageEntity.setContent(changeLightEvent);
|
||||
V2XObuEventScenario.getInstance().init(messageEntity);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int parseObuEvent(String type) {
|
||||
switch (type) {
|
||||
case "06":
|
||||
@@ -240,7 +118,7 @@ public class V2XObuManager implements IMogoObuDataChangedListener, Handler.Callb
|
||||
private static final String CALL_ADAS_SHOW_TRAFFIC_LIGHT = "2";
|
||||
private static final String CALL_ADAS_HIDE_TRAFFIC_LIGHT = "1";
|
||||
|
||||
private void sendTrafficLightStatusToAdas(String status, TrafficLightInfo trafficLightInfo) {
|
||||
private void sendTrafficLightStatusToAdas(String status, MogoObuTrafficLightInfo trafficLightInfo) {
|
||||
if (V2XObuEventScenario.getInstance().isInChangeLightForVip()) {
|
||||
status = CALL_ADAS_HIDE_TRAFFIC_LIGHT;
|
||||
}
|
||||
@@ -250,15 +128,15 @@ public class V2XObuManager implements IMogoObuDataChangedListener, Handler.Callb
|
||||
// String action "1" - 隐藏 "2" - 显示
|
||||
json.put("action", status);
|
||||
if (trafficLightInfo != null) {
|
||||
if (trafficLightInfo.lightStatus == null) {
|
||||
if (trafficLightInfo.getLightStatus() == null) {
|
||||
json.put("lightStatus", "G");
|
||||
} else {
|
||||
json.put("lightStatus", trafficLightInfo.lightStatus);
|
||||
json.put("lightStatus", trafficLightInfo.getLightStatus());
|
||||
}
|
||||
if (trafficLightInfo.surplusTime == null) {
|
||||
if (trafficLightInfo.getSurplusTime() == null) {
|
||||
json.put("surplusTime", "0");
|
||||
} else {
|
||||
json.put("surplusTime", trafficLightInfo.surplusTime);
|
||||
json.put("surplusTime", trafficLightInfo.getSurplusTime());
|
||||
}
|
||||
}
|
||||
String data = json.toString();
|
||||
@@ -280,4 +158,107 @@ public class V2XObuManager implements IMogoObuDataChangedListener, Handler.Callb
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEventInfoCallback(MogoObuEventInfo info) {
|
||||
Logger.d("V2X_OBU_EVENT", "carEventInfo==" + info);
|
||||
Long last = intervalMap.get(info.getTypeCode());
|
||||
if (last == null) {
|
||||
last = 0L;
|
||||
}
|
||||
int eventType = parseObuEvent(info.getTypeCode());
|
||||
if (eventType == ObuConstant.TYPE_OPTIMAL_SPEED_ADVISORY) {
|
||||
// 加一个容错机制,如果已经驶过绿波车速路口,那么再收到绿波车速obu事件,就不再上报
|
||||
MogoLocation currentLocation = V2XLocationListener.getInstance().getLastCarLocation();
|
||||
double eventAngle = DrivingDirectionUtils.getDegreeOfCar2Poi(
|
||||
currentLocation.getLongitude(),
|
||||
currentLocation.getLatitude(),
|
||||
V2XObuEventScenario.getInstance().getOptimalCrossing().getLon(),
|
||||
V2XObuEventScenario.getInstance().getOptimalCrossing().getLat(),
|
||||
(int) currentLocation.getBearing()
|
||||
);
|
||||
if (0 > eventAngle || eventAngle > 20) {
|
||||
Logger.e(MODULE_NAME, "超出绿波引导点范围,不处理此次事件===" + eventAngle);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (SystemClock.elapsedRealtime() - last > DEFAULT_INTERVAL_TIME) {
|
||||
// 距离上次记录超过三十秒,继续相关逻辑,如果不超过三十秒,忽略此次事件
|
||||
intervalMap.put(info.getTypeCode(), SystemClock.elapsedRealtime());
|
||||
V2XMessageEntity<V2XObuEventEntity> messageEntity = new V2XMessageEntity<>();
|
||||
messageEntity.setType(V2XMessageEntity.V2XTypeEnum.ALERT_OBU_EVENT);
|
||||
switch (eventType) {
|
||||
case ObuConstant
|
||||
.TYPE_OPTIMAL_SPEED_ADVISORY:
|
||||
// 绿波车速引导
|
||||
V2XObuEventEntity optimalEvent = new V2XObuEventEntity();
|
||||
optimalEvent.setType(ObuConstant.TYPE_OPTIMAL_SPEED_ADVISORY);
|
||||
optimalEvent.setDesc(info.getDescribe());
|
||||
messageEntity.setContent(optimalEvent);
|
||||
V2XObuEventScenario.getInstance().init(messageEntity);
|
||||
break;
|
||||
case ObuConstant.TYPE_URGENCY_COLLISION_WARNING:
|
||||
// 前车紧急制动预警
|
||||
V2XObuEventEntity urgencyEvent = new V2XObuEventEntity();
|
||||
urgencyEvent.setType(ObuConstant.TYPE_URGENCY_COLLISION_WARNING);
|
||||
urgencyEvent.setDesc(V2XObuEventScenario.URGENCY_COLLISION_WARN_TEXT);
|
||||
messageEntity.setContent(urgencyEvent);
|
||||
V2XObuEventScenario.getInstance().init(messageEntity);
|
||||
break;
|
||||
case ObuConstant.TYPE_ROAD_USER_COLLISION_WARNING:
|
||||
// 行人预警,给adas发送广播即可
|
||||
V2XPushMessageEntity entity = new V2XPushMessageEntity();
|
||||
// 盲区行人预警的sceneId-100003
|
||||
entity.setSceneId("100003");
|
||||
entity.setTts("前方行人,注意减速");
|
||||
entity.setExpireTime(30_000);
|
||||
entity.setAlarmContent("前方行人,注意减速");
|
||||
ADASUtils.broadcastToADAS(V2XServiceManager.getContext(), entity);
|
||||
break;
|
||||
case ObuConstant.TYPE_CHANGE_LIGHT_FOR_VIP:
|
||||
// vip变灯提醒
|
||||
V2XObuEventEntity changeLightEvent = new V2XObuEventEntity();
|
||||
changeLightEvent.setType(ObuConstant.TYPE_CHANGE_LIGHT_FOR_VIP);
|
||||
changeLightEvent.setDesc(info.getDescribe());
|
||||
messageEntity.setContent(changeLightEvent);
|
||||
V2XObuEventScenario.getInstance().init(messageEntity);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocationInfoCallback( MogoObuLocationInfo locationInfo) {
|
||||
if (ObuConfig.useObuLocation) {
|
||||
MogoLocation currentLocation = new MogoLocation();
|
||||
|
||||
CoordinateConverter converter = new CoordinateConverter(V2XServiceManager.getContext());
|
||||
converter.from(CoordinateConverter.CoordType.GPS);
|
||||
LatLng latLng = new LatLng(locationInfo.getLat(), locationInfo.getLon());
|
||||
converter.coord(latLng);
|
||||
LatLng convert = converter.convert();
|
||||
|
||||
currentLocation.setLatitude(convert.latitude);
|
||||
currentLocation.setLongitude(convert.longitude);
|
||||
currentLocation.setBearing(computeCarAngle(currentLocation));
|
||||
|
||||
V2XObuEventScenario.getInstance().updateLocation(currentLocation);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTrafficLightInfoCallback(MogoObuTrafficLightInfo trafficLightInfo) {
|
||||
handler.removeMessages(MSG_HIDE_TRAFFIC_LIGHT);
|
||||
if (trafficLightInfo == null) {
|
||||
Logger.d("V2X_OBU_EVENT", "红绿灯数据为空===");
|
||||
sendTrafficLightStatusToAdas(CALL_ADAS_HIDE_TRAFFIC_LIGHT, null);
|
||||
} else {
|
||||
Logger.d("V2X_OBU_EVENT", "红绿灯数据==" + trafficLightInfo);
|
||||
handler.sendEmptyMessageDelayed(MSG_HIDE_TRAFFIC_LIGHT,
|
||||
DEFAULT_HIDE_TRAFFIC_LIGHT_DELAY);
|
||||
sendTrafficLightStatusToAdas(CALL_ADAS_SHOW_TRAFFIC_LIGHT, trafficLightInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,6 @@ import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.mogo.commons.voice.AIAssist;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.map.location.MogoLocation;
|
||||
@@ -23,13 +21,15 @@ import com.mogo.module.v2x.scenario.impl.AbsV2XScenario;
|
||||
import com.mogo.module.v2x.utils.DrivingDirectionUtils;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.zhidao.mogo.module.obu.ObuConstant;
|
||||
import com.zhidao.smartv2x.model.obu.CarEventInfo;
|
||||
import com.zhidao.mogo.module.obu.obu.bean.MogoObuEventInfo;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import static com.mogo.module.v2x.V2XConst.MODULE_NAME;
|
||||
|
||||
/**
|
||||
@@ -99,7 +99,7 @@ public class V2XObuEventScenario extends AbsV2XScenario<V2XObuEventEntity> imple
|
||||
} else if (v2XMessageEntity.getContent().getType() == ObuConstant.TYPE_CHANGE_LIGHT_FOR_VIP) {
|
||||
// vip变灯提醒
|
||||
isInChangeLightForVip = true;
|
||||
V2XObuManager.getInstance().showTrafficLightInfo(null);
|
||||
V2XObuManager.getInstance().onTrafficLightInfoCallback(null);
|
||||
|
||||
if (optimalSpeedMarker == null) {
|
||||
optimalSpeedMarker = new OptimalSpeedMarker();
|
||||
@@ -267,11 +267,11 @@ public class V2XObuEventScenario extends AbsV2XScenario<V2XObuEventEntity> imple
|
||||
//距离小于DEFAULT_VIP_CROSSING_DISTANCE,且夹角在0~20(说明在前方),则触发vip通行
|
||||
defaultTarget = crossing;
|
||||
handler.post(() -> {
|
||||
CarEventInfo eventInfo = new CarEventInfo();
|
||||
eventInfo.type = "vip变灯提醒";
|
||||
eventInfo.typeCode = "vip变灯提醒";
|
||||
eventInfo.describe = "将为您变灯,vip车辆可优先通行";
|
||||
V2XObuManager.getInstance().showCarEventInfo(eventInfo);
|
||||
MogoObuEventInfo eventInfo = new MogoObuEventInfo();
|
||||
eventInfo.setType("vip变灯提醒");
|
||||
eventInfo.setTypeCode("vip变灯提醒");
|
||||
eventInfo.setDescribe("将为您变灯,vip车辆可优先通行");
|
||||
V2XObuManager.getInstance().onEventInfoCallback(eventInfo);
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user