1. 增加site维度,用来区分顺义还是苏州,主要是为了区分obu

2. 调试接收obu数据后的流程,基本调通
This commit is contained in:
tongchenfei
2020-09-22 10:59:38 +08:00
parent 156586d63e
commit c63c5ea87b
8 changed files with 189 additions and 73 deletions

View File

@@ -70,12 +70,13 @@ android {
em4 {
manifest.srcFile 'src/em4/AndroidManifest.xml'
}
f8xxLauncherOnlineRelease {
manifest.srcFile 'src/f8xxLauncherOnlineRelease/AndroidManifest.xml'
}
// 演示分支,暂时不需要这一项
// f8xxLauncherOnlineRelease {
// manifest.srcFile 'src/f8xxLauncherOnlineRelease/AndroidManifest.xml'
// }
}
flavorDimensions "product", "basic", "env"
flavorDimensions "site","product", "basic", "env"
productFlavors {
//独立app
@@ -276,6 +277,18 @@ android {
// 是否支持换肤
buildConfigField 'boolean', 'IS_SKIN_SUPPORTED', 'false'
}
// 演示地点-顺义
shunyi{
dimension "site"
// 西迪obu
buildConfigField 'int', "OBU_TYPE", '1'
}
// 演示地点-苏州
suzhou{
dimension "site"
// 华砺智行obu
buildConfigField 'int', "OBU_TYPE", '2'
}
qa {
dimension "env"
buildConfigField 'int', 'NET_ENV', '2'

View File

@@ -128,7 +128,7 @@ public class MogoApplication extends AbsMogoApplication {
DebugConfig.setUseCustomNavi( BuildConfig.USE_CUSTOM_NAVI );
DebugConfig.setLauncher( BuildConfig.IS_LAUNCHER );
DebugConfig.setActiveAIAssistFlag( BuildConfig.AI_ASSIST_ACTIVE_STAUTS );
DebugConfig.setUseMockObuData(false);
DebugConfig.setUseMockObuData(true);
ObuConfig.useObuLocation = false;
DebugConfig.setCarMachineType( BuildConfig.CAR_MACHINE_TYPE );
DebugConfig.setProductFlavor( BuildConfig.FLAVOR_product );
@@ -136,6 +136,7 @@ public class MogoApplication extends AbsMogoApplication {
DebugConfig.setRoadEventAnimated( BuildConfig.ROAD_EVENT_ANIMATED );
DebugConfig.setLoadGuideModule( BuildConfig.LOAD_GUIDE_MODULE );
DebugConfig.setSkinSupported( BuildConfig.IS_SKIN_SUPPORTED );
DebugConfig.setObuType(BuildConfig.OBU_TYPE);
}
@Override

View File

@@ -1,12 +1,18 @@
package com.zhidao.mogo.module.obu
import android.content.Context
import android.os.Handler
import android.os.Message
import android.view.LayoutInflater
import android.view.View
import android.widget.Button
import com.alibaba.android.arouter.launcher.ARouter
import com.mogo.commons.debug.DebugConfig
import com.mogo.service.IMogoServiceApis
import com.mogo.service.MogoServicePaths
import com.mogo.utils.logger.Logger
import com.zhidao.mogo.module.obu.obu.HualiObu
import com.zhidao.mogo.module.obu.obu.IObu
import com.zhidao.smartv2x.listener.OnMessageReceiveListener
import com.zhidao.smartv2x.model.obu.CarEventInfo
import com.zhidao.smartv2x.model.obu.TrafficLightInfo
@@ -24,18 +30,34 @@ import kotlin.random.Random
*
* @author tongchenfei
*/
object MockUtil {
const val TAG = "MockUtil"
private var dataCallback : OnMessageReceiveListener?=null
class MockUtil:Handler.Callback {
companion object {
const val TAG = "MockUtil"
}
private lateinit var intervalObs:Disposable
private lateinit var intervalObs2:Disposable
private var dataCallback: OnMessageReceiveListener? = null
fun init(context: Context, callback: OnMessageReceiveListener? = null){
private lateinit var intervalObs: Disposable
private lateinit var intervalObs2: Disposable
private lateinit var context: Context
private lateinit var view:View
private val handler = Handler(this)
override fun handleMessage(msg: Message): Boolean {
if (msg.what == 1001) {
Logger.d(TAG,"准备添加调试view")
val api = ARouter.getInstance().build(MogoServicePaths.PATH_SERVICE_APIS).navigation(context) as IMogoServiceApis
api.windowManagerApi.addView(view, 1000, 600, false)
}
return false
}
fun init(context: Context,obu:HualiObu){
Logger.d(TAG, "使用模拟obu数据===")
dataCallback = callback
val api = ARouter.getInstance().build(MogoServicePaths.PATH_SERVICE_APIS).navigation(context) as IMogoServiceApis
val view = LayoutInflater.from(context).inflate(R.layout.mock_obu, null)
this.context = context
view = LayoutInflater.from(context).inflate(R.layout.mock_obu, null)
view.findViewById<Button>(R.id.btnVip).setOnClickListener {
val carEventInfo = CarEventInfo()
carEventInfo.type = "vip变灯提醒"
@@ -48,19 +70,55 @@ object MockUtil {
dataCallback?.showCarEventInfo(carEventInfo)
}
view.findViewById<Button>(R.id.btnRoadCondition).setOnClickListener {
val carEventInfo = CarEventInfo()
carEventInfo.type = "行人碰撞预警"
carEventInfo.typeCode = "39"
carEventInfo.describe = "这个应该是随便写,反正也不用"
dataCallback?.showCarEventInfo(carEventInfo)
view.findViewById<Button>(R.id.btnPersonCrash).setOnClickListener {
obu.onMessageReceived("{\"pedestrain_information\": {\"pedestrian_crash_alarm\": 1}}".toByteArray())
}
api.windowManagerApi.addView(view, 500, 300, false)
intervalMockData()
view.findViewById<Button>(R.id.btnCrossCrash).setOnClickListener {
obu.onMessageReceived("{\"intersection_crash\":{\"intersection_crash_alarm\":1}}".toByteArray())
}
view.findViewById<Button>(R.id.btnOptimizeSpeed).setOnClickListener {
obu.onMessageReceived("{\"rush_redlight\": {\"glosa_info\": [{\"rush_redlight_alarm\": 1,\"advisory_speed\":40.0}]}}".toByteArray())
}
view.findViewById<Button>(R.id.btnRushRedLight).setOnClickListener {
obu.onMessageReceived("{\"rush_redlight\": {\"glosa_info\": [{\"rush_redlight_alarm\": 0}]}}".toByteArray())
}
handler.sendEmptyMessageDelayed(1001, 10000)
}
private fun intervalMockData(){
intervalObs = Observable.interval(5000,TimeUnit.MILLISECONDS).map {
// fun init(context: Context, obuType: Int, callback: OnMessageReceiveListener? = null) {
// Logger.d(TAG, "使用模拟obu数据===")
// dataCallback = callback
// val api = ARouter.getInstance().build(MogoServicePaths.PATH_SERVICE_APIS).navigation(context) as IMogoServiceApis
// val view = LayoutInflater.from(context).inflate(R.layout.mock_obu, null)
// view.findViewById<Button>(R.id.btnVip).setOnClickListener {
// val carEventInfo = CarEventInfo()
// carEventInfo.type = "vip变灯提醒"
// carEventInfo.typeCode = "vip变灯提醒"
// val r = Random.nextInt(0, 2)
// carEventInfo.describe = when (r) {
// 0 -> "已更改前方红绿灯状态,可优先通行"
// else -> "已增加前方绿灯时间,可优先通行"
// }
// dataCallback?.showCarEventInfo(carEventInfo)
// }
//
// view.findViewById<Button>(R.id.btnPersonCrash).setOnClickListener {
// val carEventInfo = CarEventInfo()
// carEventInfo.type = "行人碰撞预警"
// carEventInfo.typeCode = "39"
// carEventInfo.describe = "这个应该是随便写,反正也不用"
// dataCallback?.showCarEventInfo(carEventInfo)
// }
// api.windowManagerApi.addView(view, 500, 300, false)
// intervalMockData()
// }
private fun intervalMockData() {
intervalObs = Observable.interval(5000, TimeUnit.MILLISECONDS).map {
it.toString()
}.subscribeOn(io()).observeOn(io()).subscribe {
debugTrafficLight()
@@ -72,17 +130,17 @@ object MockUtil {
// }
}
fun destroy(){
fun destroy() {
intervalObs.dispose()
intervalObs2.dispose()
}
private fun debugCarEvent(){
private fun debugCarEvent() {
val random = Random.nextInt(0, 4)
Logger.d(TAG, "random====$random")
val carEventInfo = CarEventInfo()
when (random) {
0->{
0 -> {
// 绿波引导
carEventInfo.type = "绿波车速引导"
carEventInfo.typeCode = "13"
@@ -94,14 +152,14 @@ object MockUtil {
}
dataCallback?.showCarEventInfo(carEventInfo)
}
1->{
1 -> {
// 前方急刹预警
carEventInfo.type = "紧急制动预警"
carEventInfo.typeCode = "06"
carEventInfo.describe = "这个应该是随便写,反正也不用"
dataCallback?.showCarEventInfo(carEventInfo)
}
2->{
2 -> {
// 行人碰撞预警
carEventInfo.type = "行人碰撞预警"
carEventInfo.typeCode = "39"
@@ -119,22 +177,22 @@ object MockUtil {
}
dataCallback?.showCarEventInfo(carEventInfo)
}
else->{
else -> {
// 其他,不处理
}
}
}
private fun debugTrafficLight(){
Logger.d(TAG,"准备开始红绿灯模拟数据发送===")
private fun debugTrafficLight() {
Logger.d(TAG, "准备开始红绿灯模拟数据发送===")
Thread.sleep(20_000)
Logger.d(TAG,"开始红绿灯模拟数据发送===")
Logger.d(TAG, "开始红绿灯模拟数据发送===")
val trafficLightInfo = TrafficLightInfo()
trafficLightInfo.id = "12"
// 先来6秒红灯
trafficLightInfo.lightStatus = "R"
for (i in 0..5) {
trafficLightInfo.surplusTime = (5-i).toString()
trafficLightInfo.surplusTime = (5 - i).toString()
dataCallback?.showTrafficLightInfo(trafficLightInfo)
Thread.sleep(1000)
}
@@ -143,7 +201,7 @@ object MockUtil {
// 再来5秒黄灯
trafficLightInfo.lightStatus = "Y"
for (i in 0..5) {
trafficLightInfo.surplusTime = (5-i).toString()
trafficLightInfo.surplusTime = (5 - i).toString()
dataCallback?.showTrafficLightInfo(trafficLightInfo)
Thread.sleep(1000)
}
@@ -152,7 +210,7 @@ object MockUtil {
// 再来5秒绿灯
trafficLightInfo.lightStatus = "G"
for (i in 0..5) {
trafficLightInfo.surplusTime = (5-i).toString()
trafficLightInfo.surplusTime = (5 - i).toString()
dataCallback?.showTrafficLightInfo(trafficLightInfo)
Thread.sleep(1000)
}

View File

@@ -7,7 +7,6 @@ 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
/**
* obu provider
@@ -15,26 +14,22 @@ import com.zhidao.smartv2x.api.V2xController
* @author tongchenfei
*/
class ObuManager {
companion object{
companion object {
const val TAG = "ObuManger"
}
// private var handler = Handler(Looper.getMainLooper(), this)
private lateinit var obu:IObu
private lateinit var obu: IObu
fun init(context: Context) {
Logger.d(TAG,"init=======")
if (DebugConfig.isUseMockObuData()) {
MockUtil.init(context)
Logger.d(TAG, "init=======")
obu = if (DebugConfig.getObuType() == DebugConfig.OBU_TYPE_CIDI) {
CidiObu()
} else {
obu = if(DebugConfig.getObuType() == DebugConfig.OBU_TYPE_CIDI){
CidiObu()
}else{
HualiObu()
}
obu.init()
HualiObu()
}
obu.init()
}
fun registerObuDataChangedListener(listener: IObuCallback?) {

View File

@@ -1,5 +1,7 @@
package com.zhidao.mogo.module.obu.obu
import android.os.Handler
import com.mogo.commons.debug.DebugConfig
import com.mogo.utils.logger.Logger
import com.zhidao.mogo.module.obu.ObuConstant
import com.zhidao.mogo.module.obu.obu.bean.MogoObuEventInfo
@@ -25,6 +27,8 @@ class HualiObu : BaseObu(), IUdpSocketCallback {
const val PORT = 10005
}
private val handler = Handler()
override fun init() {
super.init()
socketManager.receiveMsgFrom(IP_ADDRESS, PORT)
@@ -44,7 +48,11 @@ class HualiObu : BaseObu(), IUdpSocketCallback {
* @param ori 原始数据
*/
private fun parseObuProtocol(ori: ByteArray) {
val effectiveData = getEffectiveData(ori)
val effectiveData = if (DebugConfig.isUseMockObuData()) {
ori
} else {
getEffectiveData(ori)
}
if (effectiveData != null) {
val msg = String(effectiveData)
Logger.d(TAG, "收到obu数据: \n $msg")
@@ -62,21 +70,29 @@ class HualiObu : BaseObu(), IUdpSocketCallback {
when (alert) {
0 -> {
// 有闯红灯风险
Logger.d(TAG,"准备预警--闯红灯")
Logger.d(TAG, "准备预警--闯红灯")
eventInfo.mogoEventId = ObuConstant.TYPE_RUSH_RED_LIGHT
eventInfo.describe = "当前车速经过路口会闯红灯,请减速!"
callback?.onEventInfoCallback(eventInfo)
callback?.let {
handler.post {
it.onEventInfoCallback(eventInfo)
}
}
}
1 -> {
// 没有风险,给出建议车速,绿波车速
Logger.d(TAG,"准备预警--绿波车速")
Logger.d(TAG, "准备预警--绿波车速")
eventInfo.mogoEventId = ObuConstant.TYPE_OPTIMAL_SPEED_ADVISORY
val optSpeed = lastInfo.optInt("advisory_speed")
eventInfo.describe = "前方路口,建议车速 $optSpeed km/h"
callback?.onEventInfoCallback(eventInfo)
callback?.let {
handler.post {
it.onEventInfoCallback(eventInfo)
}
}
}
else -> {
Logger.e(TAG,"没有有效红绿灯预警信息")
Logger.e(TAG, "没有有效红绿灯预警信息")
}
}
}
@@ -88,10 +104,14 @@ class HualiObu : BaseObu(), IUdpSocketCallback {
val alert = it.optInt("intersection_crash_alarm", 0)
if (alert == 1) {
// 有碰撞预警
Logger.d(TAG,"准备预警--交叉口碰撞")
Logger.d(TAG, "准备预警--交叉口碰撞")
val eventInfo = MogoObuEventInfo()
eventInfo.mogoEventId = ObuConstant.TYPE_CROSS_COLLISION_WARNING
callback?.onEventInfoCallback(eventInfo)
callback?.let {
handler.post {
it.onEventInfoCallback(eventInfo)
}
}
}
}
@@ -102,9 +122,14 @@ class HualiObu : BaseObu(), IUdpSocketCallback {
val alert = it.optInt("pedestrian_crash_alarm", 0)
if (alert == 1) {
// 有人车冲突
Logger.d(TAG,"准备预警--行人碰撞")
Logger.d(TAG, "准备预警--行人碰撞")
val eventInfo = MogoObuEventInfo()
eventInfo.mogoEventId = ObuConstant.TYPE_ROAD_USER_COLLISION_WARNING
callback?.let {
handler.post {
it.onEventInfoCallback(eventInfo)
}
}
}
}

View File

@@ -1,21 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="wrap_content"
android:layout_height="wrap_content">
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:columnCount="4">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnVip"
android:text="vip"/>
<Space
android:layout_width="10dp"
android:layout_height="wrap_content" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnRoadCondition"
android:text="行人" />
android:text="vip同行" />
</LinearLayout>
<Button
android:id="@+id/btnRushRedLight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="闯红灯" />
<Button
android:id="@+id/btnOptimizeSpeed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="绿波车速" />
<Button
android:id="@+id/btnCrossCrash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="交叉口碰撞" />
<Button
android:id="@+id/btnPersonCrash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="行人碰撞" />
</GridLayout>

View File

@@ -9,6 +9,7 @@ import android.util.ArrayMap;
import com.amap.api.maps.CoordinateConverter;
import com.amap.api.maps.model.LatLng;
import com.mogo.commons.debug.DebugConfig;
import com.mogo.map.location.MogoLocation;
import com.mogo.module.common.entity.V2XMessageEntity;
import com.mogo.module.common.entity.V2XObuEventEntity;
@@ -172,7 +173,7 @@ public class V2XObuManager implements IObuCallback, Handler.Callback {
}
// int eventType = parseObuEvent(info.getTypeCode());
int eventType = info.getMogoEventId();
if (eventType == ObuConstant.TYPE_OPTIMAL_SPEED_ADVISORY) {
if (eventType == ObuConstant.TYPE_OPTIMAL_SPEED_ADVISORY&& DebugConfig.getObuType() == DebugConfig.OBU_TYPE_CIDI) {
// 加一个容错机制如果已经驶过绿波车速路口那么再收到绿波车速obu事件就不再上报
MogoLocation currentLocation = V2XLocationListener.getInstance().getLastCarLocation();
double eventAngle = DrivingDirectionUtils.getDegreeOfCar2Poi(
@@ -248,6 +249,8 @@ public class V2XObuManager implements IObuCallback, Handler.Callback {
default:
break;
}
}else{
Logger.d(TAG,"未超过时限,不展示事件");
}
}

View File

@@ -6,6 +6,7 @@ import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import com.mogo.commons.debug.DebugConfig;
import com.mogo.commons.voice.AIAssist;
import com.mogo.map.MogoLatLng;
import com.mogo.map.location.MogoLocation;
@@ -88,7 +89,7 @@ public class V2XObuEventScenario extends AbsV2XScenario<V2XObuEventEntity> imple
public void init(@Nullable V2XMessageEntity<V2XObuEventEntity> v2XMessageEntity) {
Logger.d(MODULE_NAME, "obu场景初始化: " + v2XMessageEntity);
setV2XMessageEntity(v2XMessageEntity);
if (v2XMessageEntity.getContent().getType() == ObuConstant.TYPE_OPTIMAL_SPEED_ADVISORY) {
if (v2XMessageEntity.getContent().getType() == ObuConstant.TYPE_OPTIMAL_SPEED_ADVISORY&& DebugConfig.getObuType() == DebugConfig.OBU_TYPE_CIDI) {
// 如果需要区分路口,就在这里做一下判断,给默认目标点赋值
defaultTarget = optimalCrossing;
if (optimalSpeedMarker == null) {