diff --git a/core/function-impl/mogo-core-function-datacenter/src/main/java/com/mogo/eagle/core/function/datacenter/v2x/TrafficLightDispatcher.kt b/core/function-impl/mogo-core-function-datacenter/src/main/java/com/mogo/eagle/core/function/datacenter/v2x/TrafficLightDispatcher.kt index 8e9cd40442..e58fba21b8 100644 --- a/core/function-impl/mogo-core-function-datacenter/src/main/java/com/mogo/eagle/core/function/datacenter/v2x/TrafficLightDispatcher.kt +++ b/core/function-impl/mogo-core-function-datacenter/src/main/java/com/mogo/eagle/core/function/datacenter/v2x/TrafficLightDispatcher.kt @@ -24,8 +24,10 @@ import com.mogo.eagle.core.data.multidisplay.TelematicConstant import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotIdentifyListener import com.mogo.eagle.core.function.api.autopilot.IMoGoChassisLocationGCJ02Listener import com.mogo.eagle.core.function.api.datacenter.union.IMoGoTrafficLightListener +import com.mogo.eagle.core.function.api.devatools.INDECloudListener import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotIdentifyListenerManager import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationGCJ02ListenerManager +import com.mogo.eagle.core.function.call.devatools.CallerNDECloudManager import com.mogo.eagle.core.function.call.map.CallerMapRoadListenerManager import com.mogo.eagle.core.function.call.telematic.CallerTelematicManager import com.mogo.eagle.core.function.call.v2x.CallerTrafficLightListenerManager @@ -36,6 +38,9 @@ import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant import com.mogo.eagle.core.utilcode.util.GsonUtils import com.mogo.eagle.core.utilcode.util.UiThreadHandler import com.mogo.skin.utils.SkinResources +import com.zhjt.mogo.adas.common.cloud.AstFuncTlmPhaseStateLightState +import com.zhjt.mogo.adas.data.bean.cloud.info.AstFuncTlmInfo +import com.zhjt.mogo.adas.data.bean.cloud.pojo.AstFuncPojo import com.zhjt.service.chain.ChainLog import perception.FusionTrafficLightOuterClass import kotlin.math.abs @@ -66,7 +71,7 @@ fun convert(state: FusionTrafficLightOuterClass.FusionLightState): TrafficLightE * @since: 2022/4/28 */ class TrafficLightDispatcher : IMoGoAutopilotIdentifyListener, IMoGoTrafficLightListener, - IMoGoChassisLocationGCJ02Listener { + IMoGoChassisLocationGCJ02Listener, INDECloudListener { companion object { const val TAG = "TrafficLightDispatcher" @@ -93,6 +98,11 @@ class TrafficLightDispatcher : IMoGoAutopilotIdentifyListener, IMoGoTrafficLight @Volatile private var hasFusionLightStatus: Boolean = false + //是否有云控基础平台红绿灯数据 + @Volatile + private var hasCloudControlLight: Boolean = false + + //红绿灯定时器,超时未更新隐藏红绿灯 @Volatile private var lightCountDownTimer: CountDownTimer? = null @@ -110,6 +120,8 @@ class TrafficLightDispatcher : IMoGoAutopilotIdentifyListener, IMoGoTrafficLight CallerAutopilotIdentifyListenerManager.addListener(TAG, this) //注册获取当前车速 CallerChassisLocationGCJ02ListenerManager.addListener(TAG, 1, this) + //注册监听云控基础平台数据 + CallerNDECloudManager.addListener(TAG,this) } /** @@ -362,7 +374,7 @@ class TrafficLightDispatcher : IMoGoAutopilotIdentifyListener, IMoGoTrafficLight "${SceneConstant.M_D_C}${TAG}", "resetTrafficLight ------> isReset = $isReset ---hasObuLightStatus = $hasObuLightStatus" ) - if (!hasObuLightStatus && !hasAutopilotPerception && !hasFusionLightStatus) { + if (!hasObuLightStatus && !hasAutopilotPerception && !hasFusionLightStatus && !hasCloudControlLight) { if (isReset) { hide("云端重置红绿灯数据", DataSourceType.AICLOUD) } @@ -425,6 +437,7 @@ class TrafficLightDispatcher : IMoGoAutopilotIdentifyListener, IMoGoTrafficLight hasObuLightStatus = false hasAutopilotPerception = false hasAiLightStatus = false + hasCloudControlLight = false hasFusionLightStatus = true CallerTrafficLightListenerManager.showFusionTrafficLight(currentState, currentDuration, nextState, nextDuration, nextTwoState, nextTwoDuration, lightSource) @@ -542,6 +555,8 @@ class TrafficLightDispatcher : IMoGoAutopilotIdentifyListener, IMoGoTrafficLight CallerAutopilotIdentifyListenerManager.removeListener(TAG) //取消注册获取当前车速 CallerChassisLocationGCJ02ListenerManager.removeListener(TAG) + //取消注册云控基础平台数据 + CallerNDECloudManager.removeListener(TAG) } /** @@ -551,4 +566,64 @@ class TrafficLightDispatcher : IMoGoAutopilotIdentifyListener, IMoGoTrafficLight currentSpeed = abs(mogoLocation?.gnssSpeed ?: 0f) } + /** + * NDE下发 信号灯信息 + * @param astFuncPojo 云端辅助功能信息 + * @param astFuncTlmInfo 云端下发信号灯信息 + */ + override fun onNdeCloudAstFuncTlm(astFuncPojo: AstFuncPojo, astFuncTlmInfo: AstFuncTlmInfo) { + super.onNdeCloudAstFuncTlm(astFuncPojo, astFuncTlmInfo) + if(astFuncTlmInfo.phaseState.isNotEmpty()){ + if(hasFusionLightStatus){ + return + }else{ + val currentState = getLightStatus(astFuncTlmInfo.phaseState[0].lightState) + val nextState = getLightStatus(astFuncTlmInfo.phaseState[0].nextLightState) + val currentDuration = astFuncTlmInfo.phaseState[0].timeLeft + val nextDuration = astFuncTlmInfo.phaseState[0].nextLightTime + if(currentState!=TrafficLightEnum.BLACK && nextState != TrafficLightEnum.BLACK + && currentDuration != 0 && nextDuration != 0){ + hasCloudControlLight = true + //展示云控基础平台信号灯信息 + CallerTrafficLightListenerManager.showCloudTrafficLight(currentState, currentDuration, nextState, nextDuration) + } + } + }else{ + hasCloudControlLight = false + } + } + + /** + * 获取云控基础平台灯态 + * @param lightState 当前灯态 + */ + private fun getLightStatus(lightState: AstFuncTlmPhaseStateLightState): TrafficLightEnum { + return when (lightState) { + //红闪、红灯 + AstFuncTlmPhaseStateLightState.RED_FLASH, + AstFuncTlmPhaseStateLightState.RED -> { + TrafficLightEnum.RED + } + //绿灯待行状态、绿灯状态、受保护相位绿灯(箭头灯) + AstFuncTlmPhaseStateLightState.GREEN_WAIT, + AstFuncTlmPhaseStateLightState.GREEN, + AstFuncTlmPhaseStateLightState.GREEN_PROTECTED -> { + TrafficLightEnum.GREEN + } + //黄灯状态、黄闪 + AstFuncTlmPhaseStateLightState.YELLOW, + AstFuncTlmPhaseStateLightState.YELLOW_FLASH -> { + TrafficLightEnum.YELLOW + } + //异常、预留、未知状态、信号灯未工作、故障 + AstFuncTlmPhaseStateLightState.ERROR, + AstFuncTlmPhaseStateLightState.RESERVED, + AstFuncTlmPhaseStateLightState.UNKNOWN, + AstFuncTlmPhaseStateLightState.OFF, + AstFuncTlmPhaseStateLightState.FAULT -> { + TrafficLightEnum.BLACK + } + } + } + } \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/widget/ProportionChartTwoView.java b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/widget/ProportionChartTwoView.java new file mode 100644 index 0000000000..b53701dcfe --- /dev/null +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/widget/ProportionChartTwoView.java @@ -0,0 +1,205 @@ +package com.mogo.eagle.core.function.hmi.ui.widget; + +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Matrix; +import android.graphics.Paint; +import android.graphics.RectF; +import android.graphics.SweepGradient; +import android.util.AttributeSet; +import android.view.View; + +import androidx.annotation.Nullable; + +import com.mogo.eagle.core.data.enums.TrafficLightEnum; +import com.mogo.eagle.core.function.hmi.R; + +import java.util.ArrayList; +import java.util.List; + +import me.jessyan.autosize.utils.AutoSizeUtils; + +/** + * 融合红绿灯红、黄、绿时间占比示意View + * 鹰眼6.5.0需求 + */ +public class ProportionChartTwoView extends View { + + private static final int DEFAULT_RING_WIDTH = 5; + private float mRingWidth = 0; + private Paint mRingPaint; + private RectF mRectF; + //红绿灯绿灯、黄灯、红灯灯色时间 + private List proportionList = new ArrayList<>(); + //红绿灯灯态 + private List lightStatusList = new ArrayList<>(); + + //一轮灯态的总时长 + private int totalDuration = 0; + + int[] greenColorArray = new int[]{Color.parseColor("#45E041"),Color.parseColor("#45E041")}; + int[] yellowColorArray = new int[]{Color.parseColor("#FFF000"),Color.parseColor("#FFF000")}; + int[] redColorArray = new int[]{Color.parseColor("#FF4E41"),Color.parseColor("#FF4E41")}; + + public ProportionChartTwoView(Context context) { + super(context); + initSize(context); + init(); + } + + public ProportionChartTwoView(Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + initAttr(context, attrs); + initSize(context); + init(); + } + + /** + * 更新红绿灯时间 + * @param durationList 时间列表 + * @param colorList 灯态列表 + */ + public void updateProportion(List durationList, List colorList){ + if(durationList != null && colorList != null){ + this.proportionList = durationList; + totalDuration = 0; + for(int element: proportionList){ + totalDuration += element; + } + this.lightStatusList = colorList; + postInvalidate(); + } + } + + public ProportionChartTwoView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + initAttr(context, attrs); + initSize(context); + init(); + } + + private void initAttr(Context context, AttributeSet attrs){ + if (attrs == null) { + return; + } + TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.ProportionChartTwoView); + int n = array.getIndexCount(); + for (int i = 0; i < n; i++) { + int attr = array.getIndex(i); + if (attr == R.styleable.ProportionChartTwoView_chartRingWidth) { + mRingWidth = array.getDimension(attr, AutoSizeUtils.dp2px(context, DEFAULT_RING_WIDTH)); + } + } + array.recycle(); + } + + /** + * 初始化Size + * @param context 上下文 + */ + private void initSize(Context context){ + if (mRingWidth == 0) { + mRingWidth = AutoSizeUtils.dp2px(context, AutoSizeUtils.dp2px(context, DEFAULT_RING_WIDTH)); + } + } + + /** + * 初始化画笔 + */ + private void init(){ + mRectF = new RectF(); + mRingPaint = new Paint(); + //抗锯齿 + mRingPaint.setAntiAlias(true); + //防抖动 + mRingPaint.setDither(true); + //仅描边(圆环) + mRingPaint.setStyle(Paint.Style.STROKE); + //圆环宽度 + mRingPaint.setStrokeWidth(mRingWidth); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + int size = Math.max(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.getSize(widthMeasureSpec)); + setMeasuredDimension(size, size); + } + + @Override + protected void onSizeChanged(int w, int h, int oldw, int oldh) { + super.onSizeChanged(w, h, oldw, oldh); + //宽和高分别去掉padding值,取min的一半即圆的半径(这里demo没有用到,可自行做一些其他计算使用) +// mRadius = Math.min(w - getPaddingLeft() - getPaddingRight(), h - getPaddingTop() - getPaddingBottom()) / 2f; + } + + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + drawRingView(canvas); + } + + /** + * 画Ring + */ + private void drawRingView(Canvas canvas){ + float sweepAngle = 0f; + float startAngle = -90f; + //矩形坐标 + mRectF.set(getPaddingLeft() + mRingWidth / 2 , getPaddingTop() + mRingWidth / 2 , + getWidth() - getPaddingRight() - mRingWidth / 2, getHeight() - getPaddingBottom() - mRingWidth / 2 ); + + for(int i=0;i { + LayoutInflater.from(context).inflate(R.layout.hmi_view_traffic_light_driver, this, true) + } + //乘客端 + 1 -> { + LayoutInflater.from(context).inflate(R.layout.hmi_view_traffic_light_passenger, this, true) + } + } + CallerTrafficLightListenerManager.addListener(TAG, this) + initView() + } + + private fun initView(){ + ivLightStatus = findViewById(R.id.ivLightStatus) + pcvLightProportion = findViewById(R.id.pcvLightProportion) + tvLightRemain = findViewById(R.id.tvLightRemain) + tvLightSource = findViewById(R.id.tvLightSource) + } + + /** + * 关闭红绿灯预警展示,并重制灯态 + */ + override fun disableTrafficLight() { + super.disableTrafficLight() + UiThreadHandler.post{ + this@TrafficLightView.visibility = GONE + CallerHmiViewControlListenerManager.invokeV2XEvent(View.GONE, TAG) + //将灯态轮归零 + returnToZero() + resetLight() + } + } + + /** + * 将灯态轮归零 + */ + private fun returnToZero(){ + redLightRoundNum = 0 //当前路口红灯出现的轮数 + greenLightRoundNum = 0 //当前路口绿灯出现的轮数 + yellowLightRoundNum = 0 //当前路口黄灯出现的轮数 + } + + /** + * 重置灯态 + */ + private fun resetLight(){ + currentLightState = TrafficLightEnum.BLACK + currentLightDuration = 0 + previousLightStatus = TrafficLightEnum.BLACK + previousLightDuration = 0 + currentSource = -1 + } + + /** + * 判断是否进入新的一轮灯态 + * @param currentState 当前灯态 + */ + private fun judgeRoundNum(currentState: TrafficLightEnum): Boolean{ + if(currentLightState == currentState){ + return false + }else{ + currentLightState = currentState + when(currentState){ + TrafficLightEnum.RED->{ + redLightRoundNum++ + return redLightRoundNum > greenLightRoundNum && redLightRoundNum > yellowLightRoundNum + } + TrafficLightEnum.GREEN->{ + greenLightRoundNum++ + return greenLightRoundNum > redLightRoundNum && greenLightRoundNum > yellowLightRoundNum + } + TrafficLightEnum.YELLOW->{ + yellowLightRoundNum++ + return yellowLightRoundNum > redLightRoundNum && yellowLightRoundNum > greenLightRoundNum + } + TrafficLightEnum.BLACK->{ + return false + } + } + } + } + + /** + * 展示红绿灯预警 + * @param checkLightId 0-都是默认,1-红,2-黄,3-绿 + * @param lightSource 1:云端下发;2:自车感知 3:OBU + */ + override fun showTrafficLight(checkLightId: TrafficLightEnum, lightSource: DataSourceType) { + super.showTrafficLight(checkLightId, lightSource) + UiThreadHandler.post { + CallerLogger.d("$M_HMI$TAG","update checkLightId:$checkLightId, lightSource: $lightSource") + isShowLight = true + currentLightState = checkLightId + updateTrafficLightIcon(checkLightId, lightSource) + } + } + + /** + * @param redNum 红灯倒计时 + * @param yellowNum 黄灯倒计时 + * @param greenNum 绿灯倒计时 + */ + override fun changeCountdownTrafficLightNum(redNum: Int, yellowNum: Int, greenNum: Int) { + super.changeCountdownTrafficLightNum(redNum, yellowNum, greenNum) + UiThreadHandler.post { + when (currentLightState) { + TrafficLightEnum.RED -> changeCountdownRed(redNum) + TrafficLightEnum.YELLOW -> changeCountdownYellow(yellowNum) + TrafficLightEnum.GREEN -> changeCountdownGreen(greenNum) + else ->{} + } + } + } + + override fun changeCountdownRed(redNum: Int) { + super.changeCountdownRed(redNum) + UiThreadHandler.post { + if (redNum > 0) { + tvLightRemain.text = redNum.toString() + } else { + disableTrafficLightCountDown() + } + } + } + + override fun changeCountdownGreen(greenNum: Int) { + super.changeCountdownGreen(greenNum) + UiThreadHandler.post { + if (greenNum > 0) { + tvLightRemain.text = greenNum.toString() + } else { + disableTrafficLightCountDown() + } + } + } + + override fun changeCountdownYellow(yellowNum: Int) { + super.changeCountdownYellow(yellowNum) + UiThreadHandler.post { + if (yellowNum > 0) { + tvLightRemain.text = yellowNum.toString() + } else { + disableTrafficLightCountDown() + } + } + } + + /** + * 更新红绿灯icon + * + * @param lightId 0-都是默认,1-红,2-黄,3-绿 + * @param lightSource 1:云端下发;2:自车感知; 3:OBU + */ + private fun updateTrafficLightIcon(lightId: TrafficLightEnum, lightSource: DataSourceType) { + if(currentSource == 0 || currentSource == 1){ + return + } + if(currentSource == -1){ + this@TrafficLightView.visibility = View.VISIBLE + currentSource = 2 + } + when (lightId) { + TrafficLightEnum.RED -> { + if(user == 0){ + ivLightStatus.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.icon_red_light_driver)) + }else{ + ivLightStatus.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.icon_red_light_passenger)) + } + } + TrafficLightEnum.YELLOW -> { + if(user == 0){ + ivLightStatus.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.icon_yellow_light_driver)) + }else{ + ivLightStatus.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.icon_yellow_light_passenger)) + } + } + TrafficLightEnum.GREEN -> { + if(user == 0){ + ivLightStatus.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.icon_green_light_driver)) + }else{ + ivLightStatus.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.icon_green_light_passenger)) + } + } + else -> this@TrafficLightView.visibility = GONE + } + when (lightSource) { + DataSourceType.AICLOUD -> { + tvLightSource.text = context.getString(R.string.light_source_ai_cloud) + } + DataSourceType.TELEMATIC_UNION_V2I, + DataSourceType.TELEMATIC_UNION_V2N, + DataSourceType.TELEMATIC -> { + tvLightSource.text = context.getString(R.string.light_source_perception) + } + DataSourceType.OBU -> { + tvLightSource.text = context.getString(R.string.light_source_obu) + } + else -> { + tvLightSource.visibility = GONE + } + } + } + + /** + * 展示融合带有下一下二灯态的红绿灯 + * @param currentState 当前灯态 + * @param currentDuration 当前灯态倒计时 + * @param nextState 下一灯态 + * @param nextDuration 下一灯态倒计时 + * @param nextTwoState 下二灯态 + * @param nextTwoDuration 下二灯态倒计时 + * @param lightSource 数据来源 + */ + override fun showFusionTrafficLight(currentState: TrafficLightEnum, currentDuration: Int, nextState: TrafficLightEnum, + nextDuration: Int, nextTwoState: TrafficLightEnum, nextTwoDuration: Int, lightSource: DataSourceType + ) { + super.showFusionTrafficLight(currentState, currentDuration, nextState, nextDuration, nextTwoState, nextTwoDuration, lightSource) + if(currentLightState == currentState && currentLightDuration == currentDuration){ + return + } + currentLightDuration = currentDuration + ThreadUtils.runOnUiThread { + //如果初次获取的路口灯态倒计时时长小于1秒则返回不处理,灯态进入下一轮灯态开始进行显示 + if(this@TrafficLightView.visibility == View.GONE && currentDuration < 1){ + return@runOnUiThread + } + //兼容融合异常数据,当下一下二灯态时长均大于0时展示 + if(this@TrafficLightView.visibility == View.GONE && (nextDuration == 0) || nextTwoDuration == 0){ + return@runOnUiThread + } + /** + * 如果红绿灯显示过程中遇到突然灯态发生改变即当前灯态未倒计时完成灯态发生变化 + * (正常情况下不会出现此情况,兼容异常状态) + * 重置灯态占比和指针指向 + */ + if(previousLightStatus == TrafficLightEnum.BLACK && previousLightDuration == 0 + && currentState != TrafficLightEnum.BLACK && currentDuration != 0){ + previousLightStatus = currentState + previousLightDuration = currentDuration + }else{ + if((currentState != previousLightStatus && previousLightDuration >1) + || (currentState == previousLightStatus && previousLightDuration < currentDuration)){ + //灯态未倒计时到1,灯态发生变化(正常情况是倒计时到0,考虑到可能存在的异常情况,倒计时到1也算正常) + returnToZero() + resetLight() + }else{ + previousLightStatus = currentState + previousLightDuration = currentDuration + } + } + + + //如果当前红绿灯视图为隐藏状态则设置为显示状态 + if(judgeRoundNum(currentState) || currentSource == 1){ + //从云控基础平台信号源切换到融合感知信号源 + currentSource = 0 + if(this@TrafficLightView.visibility == View.GONE){ + this@TrafficLightView.visibility = View.VISIBLE + CallerHmiViewControlListenerManager.invokeV2XEvent(View.VISIBLE, TAG) + CallerServicesEventManager.updateServicesNum(CallerServicesEventManager.ServiceType.LIGHT) + } + + val colorList = ArrayList() + val durationList = ArrayList() + + colorList.add(currentState) + colorList.add(nextState) + colorList.add(nextTwoState) + + if(currentDuration < 3){ + durationList.add(3) + totalDuration = 3 + nextDuration + nextTwoDuration + currentAngle = 360f/totalDuration*(3-currentDuration) - 90f + }else{ + durationList.add(currentDuration) + totalDuration = currentDuration + nextDuration + nextTwoDuration + currentAngle = -90f + } + durationList.add(nextDuration) + durationList.add(nextTwoDuration) + //没轮灯态绘制一次灯态时长比例 + pcvLightProportion.updateProportion(durationList,colorList) + }else{ + if(currentAngle < 360f){ + currentAngle += 360f/totalDuration + } + } + + //根据当前灯态设置转盘、刻度、指针背景 + when(currentState){ + TrafficLightEnum.GREEN -> { + if(user == 0){ + ivLightStatus.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.icon_green_light_pointer_driver)) + }else{ + ivLightStatus.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.icon_green_light_pointer_passenger)) + } + } + TrafficLightEnum.YELLOW -> { + if(user == 0){ + ivLightStatus.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.icon_yellow_light_pointer_driver)) + }else{ + ivLightStatus.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.icon_yellow_light_pointer_passenger)) + } + } + else -> { + if(user == 0){ + ivLightStatus.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.icon_red_light_pointer_driver)) + }else{ + ivLightStatus.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.icon_red_light_pointer_passenger)) + } + } + } + if(ivLightStatus.visibility != View.VISIBLE){ + ivLightStatus.visibility = View.VISIBLE + } + + if(pcvLightProportion.visibility != View.VISIBLE){ + pcvLightProportion.visibility = View.VISIBLE + } + + if(tvLightSource.visibility == View.VISIBLE){ + tvLightSource.visibility = View.INVISIBLE + } + if(tvLightRemain.visibility != View.VISIBLE){ + tvLightRemain.visibility = View.VISIBLE + } + + //更新当前灯态倒计时时间 + if(currentDuration>0){ + tvLightRemain.text = currentDuration.toString() + }else{ + tvLightRemain.text = "0" + } + + //更新指针指向 + val pointerLayoutParams = ivLightStatus.layoutParams as LayoutParams + pointerLayoutParams.circleAngle = currentAngle + ivLightStatus.rotation = currentAngle + ivLightStatus.layoutParams = pointerLayoutParams + + } + } + + /** + * 展示云控基础平台数据红绿灯 + * @param currentState 当前灯态 + * @param currentDuration 当前灯态倒计时 + * @param nextState 下一灯态 + * @param nextDuration 下一灯态倒计时 + */ + override fun showCloudTrafficLight(currentState: TrafficLightEnum, currentDuration: Int, + nextState: TrafficLightEnum, nextDuration: Int) { + super.showCloudTrafficLight(currentState, currentDuration, nextState, nextDuration) + currentSource = 1 + if(currentLightState == currentState && currentLightDuration == currentDuration){ + return + } + currentLightDuration = currentDuration + ThreadUtils.runOnUiThread{ + //如果初次获取的路口灯态倒计时时长小于1秒则返回不处理,灯态进入下一轮灯态开始进行显示 + if(this@TrafficLightView.visibility == View.GONE && currentDuration < 1){ + return@runOnUiThread + } + //如果当前红绿灯视图为隐藏状态则设置为显示状态 + if(judgeRoundNum(currentState)){ + if(this@TrafficLightView.visibility == View.GONE){ + this@TrafficLightView.visibility = View.VISIBLE + CallerHmiViewControlListenerManager.invokeV2XEvent(View.VISIBLE, TAG) + CallerServicesEventManager.updateServicesNum(CallerServicesEventManager.ServiceType.LIGHT) + } + + val colorList = ArrayList() + val durationList = ArrayList() + + colorList.add(currentState) + colorList.add(nextState) + + if(currentDuration < 3){ + durationList.add(3) + totalDuration = 3 + nextDuration + currentAngle = 360f/totalDuration*(3-currentDuration) - 90f + }else{ + durationList.add(currentDuration) + totalDuration = currentDuration + nextDuration + currentAngle = -90f + } + durationList.add(nextDuration) + //没轮灯态绘制一次灯态时长比例 + pcvLightProportion.updateProportion(durationList,colorList) + }else{ + if(currentAngle < 360f){ + currentAngle += 360f/totalDuration + } + } + //根据当前灯态设置转盘、刻度、指针背景 + when(currentState){ + TrafficLightEnum.GREEN -> { + if(user == 0){ + ivLightStatus.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.icon_green_light_pointer_driver)) + }else{ + ivLightStatus.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.icon_green_light_pointer_passenger)) + } + } + TrafficLightEnum.YELLOW -> { + if(user == 0){ + ivLightStatus.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.icon_yellow_light_pointer_driver)) + }else{ + ivLightStatus.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.icon_yellow_light_pointer_passenger)) + } + } + else -> { + if(user == 0){ + ivLightStatus.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.icon_red_light_pointer_driver)) + }else{ + ivLightStatus.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.icon_red_light_pointer_passenger)) + } + } + } + if(ivLightStatus.visibility != View.VISIBLE){ + ivLightStatus.visibility = View.VISIBLE + } + if(pcvLightProportion.visibility != View.VISIBLE){ + pcvLightProportion.visibility = View.VISIBLE + } + + if(tvLightSource.visibility == View.VISIBLE){ + tvLightSource.visibility = View.INVISIBLE + } + if(tvLightRemain.visibility != View.VISIBLE){ + tvLightRemain.visibility = View.VISIBLE + } + + //更新当前灯态倒计时时间 + if(currentDuration>0){ + tvLightRemain.text = currentDuration.toString() + }else{ + tvLightRemain.text = "0" + } + + //更新指针指向 + val pointerLayoutParams = ivLightStatus.layoutParams as LayoutParams + pointerLayoutParams.circleAngle = currentAngle + ivLightStatus.rotation = currentAngle + ivLightStatus.layoutParams = pointerLayoutParams + } + } + + + override fun onDetachedFromWindow() { + super.onDetachedFromWindow() + CallerTrafficLightListenerManager.removeListener(TAG) + } + + override fun onVisibilityChanged(changedView: View, visibility: Int) { + super.onVisibilityChanged(changedView, visibility) + if(visibility == View.VISIBLE && isShowLight){ + CallerServicesEventManager.updateServicesNum(CallerServicesEventManager.ServiceType.LIGHT) + } + } + + +} \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/bg_traffic_light_driver.png b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/bg_traffic_light_driver.png new file mode 100644 index 0000000000..fe1b0417fb Binary files /dev/null and b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/bg_traffic_light_driver.png differ diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/bg_traffic_light_passenger.png b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/bg_traffic_light_passenger.png new file mode 100644 index 0000000000..f76d61a0a8 Binary files /dev/null and b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/bg_traffic_light_passenger.png differ diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/icon_green_light_driver.png b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/icon_green_light_driver.png new file mode 100644 index 0000000000..edeafa09af Binary files /dev/null and b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/icon_green_light_driver.png differ diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/icon_green_light_passenger.png b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/icon_green_light_passenger.png new file mode 100644 index 0000000000..491098b2f5 Binary files /dev/null and b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/icon_green_light_passenger.png differ diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/icon_green_light_pointer_driver.png b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/icon_green_light_pointer_driver.png new file mode 100644 index 0000000000..464dfe15b9 Binary files /dev/null and b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/icon_green_light_pointer_driver.png differ diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/icon_green_light_pointer_passenger.png b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/icon_green_light_pointer_passenger.png new file mode 100644 index 0000000000..abf336608e Binary files /dev/null and b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/icon_green_light_pointer_passenger.png differ diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/icon_red_light_driver.png b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/icon_red_light_driver.png new file mode 100644 index 0000000000..3ff7761605 Binary files /dev/null and b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/icon_red_light_driver.png differ diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/icon_red_light_passenger.png b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/icon_red_light_passenger.png new file mode 100644 index 0000000000..0b90bd8c3a Binary files /dev/null and b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/icon_red_light_passenger.png differ diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/icon_red_light_pointer_driver.png b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/icon_red_light_pointer_driver.png new file mode 100644 index 0000000000..9fb1e1d2b9 Binary files /dev/null and b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/icon_red_light_pointer_driver.png differ diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/icon_red_light_pointer_passenger.png b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/icon_red_light_pointer_passenger.png new file mode 100644 index 0000000000..2f336f9809 Binary files /dev/null and b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/icon_red_light_pointer_passenger.png differ diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/icon_yellow_light_driver.png b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/icon_yellow_light_driver.png new file mode 100644 index 0000000000..86419d4716 Binary files /dev/null and b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/icon_yellow_light_driver.png differ diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/icon_yellow_light_passenger.png b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/icon_yellow_light_passenger.png new file mode 100644 index 0000000000..74bd416689 Binary files /dev/null and b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/icon_yellow_light_passenger.png differ diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/icon_yellow_light_pointer_driver.png b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/icon_yellow_light_pointer_driver.png new file mode 100644 index 0000000000..2be4a35d97 Binary files /dev/null and b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/icon_yellow_light_pointer_driver.png differ diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/icon_yellow_light_pointer_passenger.png b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/icon_yellow_light_pointer_passenger.png new file mode 100644 index 0000000000..2119bd9b9e Binary files /dev/null and b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/icon_yellow_light_pointer_passenger.png differ diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/layout/hmi_view_traffic_light_driver.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/hmi_view_traffic_light_driver.xml new file mode 100644 index 0000000000..ec8e11fa9d --- /dev/null +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/hmi_view_traffic_light_driver.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/layout/hmi_view_traffic_light_passenger.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/hmi_view_traffic_light_passenger.xml new file mode 100644 index 0000000000..36ce2ee1e0 --- /dev/null +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/hmi_view_traffic_light_passenger.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/values/attr.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/values/attr.xml index a80b58aaa8..fca153ea35 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/res/values/attr.xml +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/values/attr.xml @@ -123,6 +123,10 @@ + + + + @@ -131,6 +135,13 @@ + + + + + + + diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/values/strings.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/values/strings.xml index af2e72aa77..e2a7d5ac30 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/res/values/strings.xml +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/values/strings.xml @@ -107,13 +107,13 @@ 红绿灯灯态 - 云端下发 + 云端 云\n端 - 自车感知 + 自车 自\n车 融合V2I 融合V2N - \u2000OBU\u2000 + OBU O\nB\nU 远程代驾 请求中... @@ -296,4 +296,6 @@ 剩余空间不足 所选日期无法拷贝 + 红绿灯灯态背景 + diff --git a/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/datacenter/union/IMoGoTrafficLightListener.kt b/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/datacenter/union/IMoGoTrafficLightListener.kt index 5148f2525d..c0ea702e35 100644 --- a/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/datacenter/union/IMoGoTrafficLightListener.kt +++ b/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/datacenter/union/IMoGoTrafficLightListener.kt @@ -88,6 +88,16 @@ interface IMoGoTrafficLightListener { nextTwoState: TrafficLightEnum, nextTwoDuration: Int, lightSource: DataSourceType){} + /** + * 云控基础平台红绿灯 + * @param currentState 当前灯态 + * @param currentDuration 当前灯态倒计时 + * @param nextState 下一灯态 + * @param nextDuration 下一灯态倒计时 + */ + fun showCloudTrafficLight(currentState: TrafficLightEnum, currentDuration: Int, + nextState: TrafficLightEnum, nextDuration: Int){} + /** * @param redNum 红灯倒计时 * @param yellowNum 黄灯倒计时 diff --git a/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/devatools/INDECloudListener.kt b/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/devatools/INDECloudListener.kt index effbc78232..61d1a49cd3 100644 --- a/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/devatools/INDECloudListener.kt +++ b/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/devatools/INDECloudListener.kt @@ -19,14 +19,14 @@ interface INDECloudListener { * @param astFuncPojo 云端辅助功能信息 * @param astFuncTlmInfo 云端下发信号灯信息 */ - fun onNdeCloudAstFuncTlm(astFuncPojo: AstFuncPojo, astFuncTlmInfo: AstFuncTlmInfo) + fun onNdeCloudAstFuncTlm(astFuncPojo: AstFuncPojo, astFuncTlmInfo: AstFuncTlmInfo){} /** * NDE下发 信号灯路口车速引导功能指令 * @param advicePojo 实时决策建议 * @param adviceGlosaInfo 信号灯路口车速引导功能指令 */ - fun onNdeCloudAdviceGlosa(advicePojo: AdvicePojo, adviceGlosaInfo: AdviceGlosaInfo) + fun onNdeCloudAdviceGlosa(advicePojo: AdvicePojo, adviceGlosaInfo: AdviceGlosaInfo){} /** * NDE下发 通用 RSI 预警指令 @@ -42,27 +42,27 @@ interface INDECloudListener { * @param advicePojo 实时决策建议 * @param adviceComRsiInfo 通用RSI预警指令 */ - fun onNdeCloudAdviceComRsi(advicePojo: AdvicePojo, adviceComRsiInfo: AdviceComRsiInfo) + fun onNdeCloudAdviceComRsi(advicePojo: AdvicePojo, adviceComRsiInfo: AdviceComRsiInfo){} /** * NDE下发 紧急车辆预警指令 * @param advicePojo 实时决策建议 * @param adviceEvwInfo 紧急车辆预警指令 */ - fun onNdeCloudAdviceEvw(advicePojo: AdvicePojo, adviceEvwInfo: AdviceEvwInfo) + fun onNdeCloudAdviceEvw(advicePojo: AdvicePojo, adviceEvwInfo: AdviceEvwInfo){} /** * NDE下发 动态车道级限速指令 * @param advicePojo 实时决策建议 * @param adviceLaneSpdLmtInfo 动态车道级限速指令 */ - fun onNdeCloudAdviceLaneSpdLmt(advicePojo: AdvicePojo, adviceLaneSpdLmtInfo: AdviceLaneSpdLmtInfo) + fun onNdeCloudAdviceLaneSpdLmt(advicePojo: AdvicePojo, adviceLaneSpdLmtInfo: AdviceLaneSpdLmtInfo){} /** * NDE下发 异常车辆预警指令 * @param advicePojo 实时决策建议 * @param adviceAvwInfo 异常车辆预警指令 */ - fun onNdeCloudAdviceAvw(advicePojo: AdvicePojo, adviceAvwInfo: AdviceAvwInfo) + fun onNdeCloudAdviceAvw(advicePojo: AdvicePojo, adviceAvwInfo: AdviceAvwInfo){} } \ No newline at end of file diff --git a/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/v2x/CallerTrafficLightListenerManager.kt b/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/v2x/CallerTrafficLightListenerManager.kt index 556608159d..fef16a7ff8 100644 --- a/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/v2x/CallerTrafficLightListenerManager.kt +++ b/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/v2x/CallerTrafficLightListenerManager.kt @@ -106,6 +106,21 @@ object CallerTrafficLightListenerManager : CallerBase } } + /** + * 云控基础平台红绿灯信号 + * @param currentState 当前灯态 + * @param currentDuration 当前灯态倒计时 + * @param nextState 下一灯态 + * @param nextDuration 下一灯态倒计时 + */ + fun showCloudTrafficLight(currentState: TrafficLightEnum,currentDuration: Int, + nextState: TrafficLightEnum, nextDuration: Int){ + M_LISTENERS.forEach{ + val listener = it.value + listener.showCloudTrafficLight(currentState, currentDuration, nextState, nextDuration) + } + } + fun changeCountdownTrafficLightNum(redNum: Int, yellowNum: Int, greenNum: Int) { M_LISTENERS.forEach { val listener = it.value