重构obu模块,新增udp通信
This commit is contained in:
@@ -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