This commit is contained in:
tongchenfei
2020-10-28 15:40:26 +08:00
parent 175f018832
commit 3fb3fe93fd
10 changed files with 240 additions and 101 deletions

2
.idea/misc.xml generated
View File

@@ -4,7 +4,7 @@
<asm skipDebug="false" skipFrames="false" skipCode="false" expandFrames="false" />
<groovy codeStyle="LEGACY" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="JDK" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="SuppressionsComponent">

View File

@@ -40,6 +40,7 @@ dependencies {
implementation project(":foudations:mogo-utils")
implementation project(":foudations:mogo-commons")
implementation project(":services:mogo-service-api")
implementation project(':modules:mogo-module-common')
}
}

View File

@@ -6,11 +6,13 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import com.mogo.map.location.IMogoLocationListener;
import com.mogo.map.location.MogoLocation;
import com.mogo.map.navi.MogoTraffic;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.entity.CloudRoadData;
import com.mogo.module.common.entity.MogoSnapshotSetData;
@@ -31,54 +33,79 @@ import org.json.JSONObject;
* @author tongchenfei
*/
public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLocationListener,
Handler.Callback , IMogoOnWebSocketMessageListener<MogoSnapshotSetData> {
Handler.Callback, IMogoOnWebSocketMessageListener<MogoSnapshotSetData> {
private static final String TAG = "AdasNoticeHelper";
private static final int MSG_HIDE_TRAFFIC_LIGHT_BY_OBU = 1001;
private static final int MSG_HIDE_TRAFFIC_LIGHT_BY_CLOUD = 1002;
private static final int MSG_HIDE_LIMIT_SPEED = 1003;
private static final int MSG_REFRESH_CAR_STRATEGY = 1004;
private static final long HIDE_TRAFFIC_LIGHT_DELAY = 2_000L;
private static final long HIDE_LIMIT_SPEED_DELAY = 10_000L;
private static final long STRATEGY_DELAY = 1000L;
private Context context;
private AdasNoticeReceiver adasReceiver = new AdasNoticeReceiver();
private boolean isVrMode = false;
private volatile boolean isVrMode = false;
private TextView tvSelfSpeed, tvTrafficLight, tvLimitSpeed;
private int limitSpeed;
private int currentSpeed = 0;
private String lightStatus = "G";
private String surplusTime;
private Handler handler = new Handler(this);
private View selfCar;
private boolean lightCenter = false;
public void init(Context context) {
this.context = context;
if(!lightCenter) {
selfCar = LayoutInflater.from(context).inflate(R.layout.module_ext_item_self_car, null);
tvSelfSpeed = selfCar.findViewById(R.id.tvSelfSpeed);
tvTrafficLight = selfCar.findViewById(R.id.tvTrafficLight);
tvLimitSpeed = selfCar.findViewById(R.id.tvLimitSpeed);
}
Logger.d(TAG, "init====");
}
public void initView(View root) {
tvSelfSpeed = root.findViewById(R.id.tvSelfSpeed);
tvTrafficLight = root.findViewById(R.id.tvTrafficLight);
tvLimitSpeed = root.findViewById(R.id.tvLimitSpeed);
if(lightCenter) {
tvSelfSpeed = root.findViewById(R.id.tvSelfSpeed);
tvTrafficLight = root.findViewById(R.id.tvTrafficLight);
tvLimitSpeed = root.findViewById(R.id.tvLimitSpeed);
}
}
public void enterVrMode() {
isVrMode = true;
IntentFilter filter = new IntentFilter("com.mogo.launcher.adas.app.biz");
context.registerReceiver(adasReceiver, filter);
MogoApisHandler.getInstance().getApis().getAdasControllerApi().addAdasWarnMessageCallback(this);
MogoApisHandler.getInstance().getApis().getRegisterCenterApi().registerMogoLocationListener(TAG, this);
MogoApisHandler.getInstance().getApis().getWebSocketManagerApi(context).registerOnWebSocketMessageListener(this);
// debug code
tvSelfSpeed.setVisibility(View.VISIBLE);
tvTrafficLight.setVisibility(View.VISIBLE);
tvLimitSpeed.setVisibility(View.VISIBLE);
Logger.d(TAG, "enterVrMode===" + isVrMode);
if (!isVrMode) {
isVrMode = true;
IntentFilter filter = new IntentFilter("com.mogo.launcher.adas.app.biz");
context.registerReceiver(adasReceiver, filter);
MogoApisHandler.getInstance().getApis().getAdasControllerApi().addAdasWarnMessageCallback(this);
MogoApisHandler.getInstance().getApis().getRegisterCenterApi().registerMogoLocationListener(TAG, this);
MogoApisHandler.getInstance().getApis().getWebSocketManagerApi(context).registerOnWebSocketMessageListener(this);
if(!lightCenter) {
handler.sendEmptyMessageDelayed(MSG_REFRESH_CAR_STRATEGY, STRATEGY_DELAY);
}
// debug code
// tvSelfSpeed.setVisibility(View.VISIBLE);
// tvTrafficLight.setVisibility(View.VISIBLE);
// tvLimitSpeed.setVisibility(View.VISIBLE);
}
}
public void exitVrMode() {
if(isVrMode) {
Logger.d(TAG, "退出vr模式===" + isVrMode);
if (isVrMode) {
isVrMode = false;
handler.removeMessages(MSG_REFRESH_CAR_STRATEGY);
tvSelfSpeed.setVisibility(View.GONE);
tvTrafficLight.setVisibility(View.GONE);
tvLimitSpeed.setVisibility(View.GONE);
@@ -91,7 +118,7 @@ public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLoca
@Override
public void onReceiveData(ADASWarnMessage msg) {
Logger.d(TAG, "收到adas warn message, isVrMode: "+isVrMode+" msg: " + msg);
Logger.d(TAG, "收到adas warn message, isVrMode: " + isVrMode + " msg: " + msg);
if (!isVrMode) {
return;
}
@@ -119,20 +146,49 @@ public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLoca
if (!isVrMode) {
return;
}
int speed = (int) (location.getSpeed() * 3.6F);
if (tvSelfSpeed != null) {
tvSelfSpeed.post(() -> {
if (tvSelfSpeed.getVisibility() == View.GONE) {
tvSelfSpeed.setVisibility(View.VISIBLE);
}
tvSelfSpeed.setText("" + speed);
});
currentSpeed = (int) (location.getSpeed() * 3.6F);
if(lightCenter) {
if (tvSelfSpeed != null) {
tvSelfSpeed.post(() -> {
if (tvSelfSpeed.getVisibility() == View.GONE) {
tvSelfSpeed.setVisibility(View.VISIBLE);
}
tvSelfSpeed.setText("" + currentSpeed);
Logger.d(TAG, "onLocationChange: " + currentSpeed);
});
}
}
}
@Override
public boolean handleMessage(Message msg) {
switch (msg.what) {
case MSG_REFRESH_CAR_STRATEGY:
// 自车速度
tvSelfSpeed.setText("" + currentSpeed);
// 红绿灯
if (tvTrafficLight.getVisibility() == View.GONE) {
tvTrafficLight.setVisibility(View.VISIBLE);
}
// todo 设置字体颜色、背景颜色、leftDrawable
switch (lightStatus) {
case "Y":
// 黄灯
break;
case "R":
// 红灯
break;
default:
// 默认绿灯
break;
}
tvTrafficLight.setText(surplusTime + "S");
MogoApisHandler.getInstance().getApis().getMapServiceApi().getMapUIController().showMyLocation(selfCar);
if (isVrMode) {
handler.sendEmptyMessageDelayed(MSG_REFRESH_CAR_STRATEGY, STRATEGY_DELAY);
}
return true;
case MSG_HIDE_LIMIT_SPEED:
tvLimitSpeed.setVisibility(View.GONE);
return true;
@@ -191,11 +247,12 @@ public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLoca
handler.removeMessages(MSG_HIDE_TRAFFIC_LIGHT_BY_OBU);
handler.removeMessages(MSG_HIDE_TRAFFIC_LIGHT_BY_CLOUD);
drawTrafficLight(lightStatus, surplusTime);
handler.sendEmptyMessageDelayed(MSG_HIDE_TRAFFIC_LIGHT_BY_OBU, HIDE_TRAFFIC_LIGHT_DELAY);
handler.sendEmptyMessageDelayed(MSG_HIDE_TRAFFIC_LIGHT_BY_OBU,
HIDE_TRAFFIC_LIGHT_DELAY);
}
}
private void handleCloudTrafficLight(CloudRoadData roadData){
private void handleCloudTrafficLight(CloudRoadData roadData) {
if (tvTrafficLight != null && !handler.hasMessages(MSG_HIDE_TRAFFIC_LIGHT_BY_OBU)) {
handler.removeMessages(MSG_HIDE_TRAFFIC_LIGHT_BY_CLOUD);
// todo drawTrafficLight
@@ -214,7 +271,7 @@ public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLoca
lightStatus = "G";
break;
}
int diff = (int) ((System.currentTimeMillis() - roadData.getSystemTime())/1000);
int diff = (int) ((System.currentTimeMillis() - roadData.getSystemTime()) / 1000);
int leftTime = roadData.getLightLeftTime() - diff;
drawTrafficLight(lightStatus, "" + leftTime);
handler.sendEmptyMessageDelayed(MSG_HIDE_TRAFFIC_LIGHT_BY_CLOUD,
@@ -223,25 +280,29 @@ public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLoca
}
private void drawTrafficLight(String lightStatus, String surplusTime) {
tvTrafficLight.post(() -> {
if (tvTrafficLight.getVisibility() == View.GONE) {
tvTrafficLight.setVisibility(View.VISIBLE);
}
// todo 设置字体颜色、背景颜色、leftDrawable
switch (lightStatus) {
case "Y":
// 黄灯
break;
case "R":
//
break;
default:
// 默认绿
break;
}
tvTrafficLight.setText(surplusTime + "S");
Logger.d(TAG, "展示红绿灯信息: " + lightStatus + " time: " + surplusTime);
});
this.lightStatus = lightStatus;
this.surplusTime = surplusTime;
if(lightCenter) {
tvTrafficLight.post(() -> {
if (tvTrafficLight.getVisibility() == View.GONE) {
tvTrafficLight.setVisibility(View.VISIBLE);
}
// todo 设置字体颜色、背景颜色、leftDrawable
switch (lightStatus) {
case "Y":
//
break;
case "R":
//
break;
default:
// 默认绿灯
break;
}
tvTrafficLight.setText(surplusTime + "S");
Logger.d(TAG, "展示红绿灯信息: " + lightStatus + " time: " + surplusTime);
});
}
}
@Override
@@ -261,7 +322,7 @@ public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLoca
if (roadData != null) {
Logger.d(TAG, "收到红绿灯数据");
handleCloudTrafficLight(roadData);
}else{
} else {
handler.sendEmptyMessage(MSG_HIDE_TRAFFIC_LIGHT_BY_CLOUD);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

View File

@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tvSelfSpeed"
tools:visibility="visible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/module_ext_vr_mode_self_speed_margin_end"
android:background="@drawable/module_ext_vr_mode_speed_red_bg"
android:gravity="center"
android:text="72"
android:textColor="@color/module_ext_vr_mode_left_traffic_light_red"
android:textSize="@dimen/module_ext_vr_mode_traffic_light_text_size"
android:visibility="gone"
app:layout_constraintRight_toLeftOf="@+id/tvTrafficLight"
app:layout_constraintTop_toTopOf="@+id/tvTrafficLight"/>
<TextView
android:id="@+id/tvTrafficLight"
tools:visibility="visible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/module_ext_vr_mode_traffic_light_green_bg"
android:gravity="center"
android:text="26S"
android:textColor="@color/module_ext_vr_mode_left_traffic_light_green"
android:textSize="@dimen/module_ext_vr_mode_traffic_light_text_size"
android:visibility="gone"
app:layout_constraintLeft_toLeftOf="@+id/ivSelfCar"
app:layout_constraintRight_toRightOf="@+id/ivSelfCar"
app:layout_constraintBottom_toTopOf="@+id/ivSelfCar"/>
<TextView
android:id="@+id/tvLimitSpeed"
tools:visibility="visible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/module_ext_vr_mode_self_speed_margin_end"
android:background="@drawable/module_ext_vr_mode_speed_white_bg"
android:gravity="center"
android:text="160"
android:textColor="@color/module_ext_vr_mode_left_traffic_light_white"
android:textSize="@dimen/module_ext_vr_mode_traffic_light_text_size"
android:visibility="gone"
app:layout_constraintLeft_toRightOf="@+id/tvTrafficLight"
app:layout_constraintTop_toTopOf="@+id/tvTrafficLight"/>
<ImageView
android:id="@+id/ivSelfCar"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/module_ext_self_car" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -232,45 +232,46 @@
android:id="@+id/tvSelfSpeed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/module_ext_vr_mode_self_speed_margin_end"
android:background="@drawable/module_ext_vr_mode_speed_red_bg"
android:gravity="center"
android:text="72"
android:textColor="@color/module_ext_vr_mode_left_traffic_light_red"
android:textSize="@dimen/module_ext_vr_mode_traffic_light_text_size"
android:visibility="gone"
android:gravity="center"
tools:visibility="visible"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintRight_toLeftOf="@+id/tvTrafficLight"
app:layout_constraintTop_toTopOf="@+id/tvTrafficLight"
tools:visibility="visible" />
<TextView
android:id="@+id/tvTrafficLight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/module_ext_vr_mode_self_speed_margin_end"
android:background="@drawable/module_ext_vr_mode_traffic_light_green_bg"
android:text="26S"
android:gravity="center"
android:layout_marginStart="@dimen/module_ext_vr_mode_self_speed_margin_end"
android:text="26S"
android:textColor="@color/module_ext_vr_mode_left_traffic_light_green"
android:textSize="@dimen/module_ext_vr_mode_traffic_light_text_size"
android:visibility="gone"
tools:visibility="visible"
app:layout_constraintLeft_toRightOf="@+id/tvSelfSpeed"
app:layout_constraintTop_toTopOf="@+id/tvSelfSpeed" />
app:layout_constraintRight_toLeftOf="@+id/tvLimitSpeed"
app:layout_constraintTop_toTopOf="@+id/tvLimitSpeed"
tools:visibility="visible" />
<TextView
android:id="@+id/tvLimitSpeed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/module_ext_vr_mode_self_speed_margin_end"
android:layout_marginTop="@dimen/module_ext_vr_mode_self_speed_margin_end"
android:background="@drawable/module_ext_vr_mode_speed_white_bg"
android:text="160"
tools:visibility="visible"
android:gravity="center"
android:text="160"
android:textColor="@color/module_ext_vr_mode_left_traffic_light_white"
android:textSize="@dimen/module_ext_vr_mode_traffic_light_text_size"
android:visibility="gone"
app:layout_constraintLeft_toRightOf="@+id/tvTrafficLight"
app:layout_constraintTop_toTopOf="@+id/tvTrafficLight" />
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/ivUserHeadImg"
tools:visibility="visible" />
<Button
android:id="@+id/btnDebugCtrlTopView"

View File

@@ -11,8 +11,10 @@ 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.mogo.module.obu.obu.*
import com.zhidao.mogo.module.obu.obu.bean.MogoObuEventInfo
import com.zhidao.mogo.module.obu.obu.bean.MogoObuTrafficLightInfo
import com.zhidao.mogo.module.obu.socket.IUdpSocketCallback
import com.zhidao.smartv2x.listener.OnMessageReceiveListener
import com.zhidao.smartv2x.model.obu.CarEventInfo
import com.zhidao.smartv2x.model.obu.TrafficLightInfo
@@ -35,7 +37,7 @@ class MockUtil:Handler.Callback {
const val TAG = "MockUtil"
}
private var dataCallback: OnMessageReceiveListener? = null
private var dataCallback: IObuCallback? = null
private lateinit var intervalObs: Disposable
private lateinit var intervalObs2: Disposable
@@ -54,12 +56,13 @@ class MockUtil:Handler.Callback {
return false
}
fun init(context: Context,obu:HualiObu){
fun init(context: Context,obu:BaseObu){
Logger.d(TAG, "使用模拟obu数据===")
this.context = context
dataCallback = obu.callback
view = LayoutInflater.from(context).inflate(R.layout.mock_obu, null)
view.findViewById<Button>(R.id.btnVip).setOnClickListener {
val carEventInfo = CarEventInfo()
val carEventInfo = MogoObuEventInfo()
carEventInfo.type = "vip变灯提醒"
carEventInfo.typeCode = "vip变灯提醒"
val r = Random.nextInt(0, 2)
@@ -67,24 +70,24 @@ class MockUtil:Handler.Callback {
0 -> "已更改前方红绿灯状态,可优先通行"
else -> "已增加前方绿灯时间,可优先通行"
}
dataCallback?.showCarEventInfo(carEventInfo)
dataCallback?.onEventInfoCallback(carEventInfo)
}
view.findViewById<Button>(R.id.btnPersonCrash).setOnClickListener {
obu.onMessageReceived("{\"pedestrain_information\": {\"pedestrian_crash_alarm\": 1}}".toByteArray())
}
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())
}
// view.findViewById<Button>(R.id.btnPersonCrash).setOnClickListener {
// obu.onMessageReceived("{\"pedestrain_information\": {\"pedestrian_crash_alarm\": 1}}".toByteArray())
// }
//
// 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())
// }
view.findViewById<Button>(R.id.btnStartTrafficLight).setOnClickListener {
intervalMockData()
@@ -148,7 +151,7 @@ class MockUtil:Handler.Callback {
private fun debugCarEvent() {
val random = Random.nextInt(0, 4)
Logger.d(TAG, "random====$random")
val carEventInfo = CarEventInfo()
val carEventInfo = MogoObuEventInfo()
when (random) {
0 -> {
// 绿波引导
@@ -160,21 +163,21 @@ class MockUtil:Handler.Callback {
1 -> "建议50km/h车速行驶"
else -> "建议30km/h ~ 50km/h 车速行驶"
}
dataCallback?.showCarEventInfo(carEventInfo)
dataCallback?.onEventInfoCallback(carEventInfo)
}
1 -> {
// 前方急刹预警
carEventInfo.type = "紧急制动预警"
carEventInfo.typeCode = "06"
carEventInfo.describe = "这个应该是随便写,反正也不用"
dataCallback?.showCarEventInfo(carEventInfo)
dataCallback?.onEventInfoCallback(carEventInfo)
}
2 -> {
// 行人碰撞预警
carEventInfo.type = "行人碰撞预警"
carEventInfo.typeCode = "39"
carEventInfo.describe = "这个应该是随便写,反正也不用"
dataCallback?.showCarEventInfo(carEventInfo)
dataCallback?.onEventInfoCallback(carEventInfo)
}
3 -> {
// vip变灯提醒
@@ -185,7 +188,7 @@ class MockUtil:Handler.Callback {
0 -> "已更改前方红绿灯状态,可优先通行"
else -> "已增加前方绿灯时间,可优先通行"
}
dataCallback?.showCarEventInfo(carEventInfo)
dataCallback?.onEventInfoCallback(carEventInfo)
}
else -> {
// 其他,不处理
@@ -197,13 +200,13 @@ class MockUtil:Handler.Callback {
Logger.d(TAG, "准备开始红绿灯模拟数据发送===")
Thread.sleep(20_000)
Logger.d(TAG, "开始红绿灯模拟数据发送===")
val trafficLightInfo = TrafficLightInfo()
val trafficLightInfo = MogoObuTrafficLightInfo()
trafficLightInfo.id = "12"
// 先来6秒红灯
trafficLightInfo.lightStatus = "R"
for (i in 0..5) {
trafficLightInfo.surplusTime = (5 - i).toString()
dataCallback?.showTrafficLightInfo(trafficLightInfo)
dataCallback?.onTrafficLightInfoCallback(trafficLightInfo)
Thread.sleep(1000)
}
// 停5秒
@@ -212,7 +215,7 @@ class MockUtil:Handler.Callback {
trafficLightInfo.lightStatus = "Y"
for (i in 0..5) {
trafficLightInfo.surplusTime = (5 - i).toString()
dataCallback?.showTrafficLightInfo(trafficLightInfo)
dataCallback?.onTrafficLightInfoCallback(trafficLightInfo)
Thread.sleep(1000)
}
// 停5秒
@@ -221,7 +224,7 @@ class MockUtil:Handler.Callback {
trafficLightInfo.lightStatus = "G"
for (i in 0..5) {
trafficLightInfo.surplusTime = (5 - i).toString()
dataCallback?.showTrafficLightInfo(trafficLightInfo)
dataCallback?.onTrafficLightInfoCallback(trafficLightInfo)
Thread.sleep(1000)
}
Logger.d(TAG, "红绿灯模拟数据发送结束====")

View File

@@ -3,10 +3,8 @@ package com.zhidao.mogo.module.obu
import android.content.Context
import com.mogo.commons.debug.DebugConfig
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.mogo.module.obu.obu.*
import com.zhidao.mogo.module.obu.socket.IUdpSocketCallback
/**
* obu provider
@@ -21,9 +19,10 @@ class ObuManager {
// private var handler = Handler(Looper.getMainLooper(), this)
private lateinit var obu: IObu
private lateinit var context: Context
fun init(context: Context) {
Logger.d(TAG, "init=======")
this.context = context
obu = if (DebugConfig.getObuType() == DebugConfig.OBU_TYPE_CIDI) {
CidiObu()
} else {
@@ -35,6 +34,10 @@ class ObuManager {
fun registerObuDataChangedListener(listener: IObuCallback?) {
if (listener != null) {
obu.registerObuCallback(listener)
if(DebugConfig.isUseMockObuData() ) {
val mockUtil = MockUtil()
mockUtil.init(context, obu as BaseObu)
}
}
}

View File

@@ -1,7 +1,7 @@
package com.zhidao.mogo.module.obu.obu
abstract class BaseObu : IObu {
protected var callback: IObuCallback? = null
var callback: IObuCallback? = null
override fun init() {
}

View File

@@ -69,7 +69,7 @@ class HualiObu : BaseObu(), IUdpSocketCallback {
}
override fun onMessageReceived(msg: ByteArray) {
// 处理数据
// 接收到obu原始数据处理数据
// val m = String(msg)
// Logger.d(TAG, "onMessageReceived: $m")
// printByteArray(msg)
@@ -277,6 +277,9 @@ class HualiObu : BaseObu(), IUdpSocketCallback {
}
}
/**
* 根据末位校验数据可用性
*/
private fun isAvailable(msg: ByteArray): Boolean {
val checkSum = msg.last()
var check = msg[0].xor(0xff.toByte())
@@ -299,6 +302,9 @@ class HualiObu : BaseObu(), IUdpSocketCallback {
Logger.d(TAG, arrayBuilder.toString())
}
/**
* byte数组转int
*/
private fun convertTwoUnSignInt(byteArray: ByteArray): Int =
(byteArray[0].toInt() shl 24) or (byteArray[1].toInt() and 0xFF) or (byteArray[2].toInt() shl 8) or (byteArray[3].toInt() and 0xFF)