协议解析基本完成

This commit is contained in:
tongchenfei
2020-09-21 17:39:48 +08:00
parent a60089b632
commit 156586d63e
10 changed files with 261 additions and 23 deletions

View File

@@ -18,6 +18,7 @@ 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.module.v2x.utils.TestOnLineCarUtils;
import com.mogo.utils.logger.Logger;
import com.zhidao.mogo.module.obu.ObuConstant;
import com.zhidao.mogo.module.obu.ObuManager;
@@ -31,7 +32,10 @@ import org.json.JSONObject;
import java.util.Map;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import static com.mogo.module.v2x.V2XConst.MODULE_NAME;
import static com.mogo.module.v2x.V2XServiceManager.getContext;
import static com.mogo.module.v2x.scenario.scene.obu.V2XObuEventScenario.ACTION_LAUNCHER_ADAS_APP_BIZ;
/**
@@ -143,7 +147,7 @@ public class V2XObuManager implements IObuCallback, Handler.Callback {
Logger.d(MODULE_NAME, "发送红绿灯广播: " + data);
intent.putExtra("data", data);
intent.putExtra("type", 2);
V2XServiceManager.getContext().sendBroadcast(intent);
getContext().sendBroadcast(intent);
} catch (Exception e) {
e.printStackTrace();
Logger.e(MODULE_NAME, e, "发送红绿灯广播异常==");
@@ -166,7 +170,8 @@ public class V2XObuManager implements IObuCallback, Handler.Callback {
if (last == null) {
last = 0L;
}
int eventType = parseObuEvent(info.getTypeCode());
// int eventType = parseObuEvent(info.getTypeCode());
int eventType = info.getMogoEventId();
if (eventType == ObuConstant.TYPE_OPTIMAL_SPEED_ADVISORY) {
// 加一个容错机制如果已经驶过绿波车速路口那么再收到绿波车速obu事件就不再上报
MogoLocation currentLocation = V2XLocationListener.getInstance().getLastCarLocation();
@@ -213,7 +218,7 @@ public class V2XObuManager implements IObuCallback, Handler.Callback {
entity.setTts("前方行人,注意减速");
entity.setExpireTime(30_000);
entity.setAlarmContent("前方行人,注意减速");
ADASUtils.broadcastToADAS(V2XServiceManager.getContext(), entity);
ADASUtils.broadcastToADAS(getContext(), entity);
break;
case ObuConstant.TYPE_CHANGE_LIGHT_FOR_VIP:
// vip变灯提醒
@@ -223,6 +228,23 @@ public class V2XObuManager implements IObuCallback, Handler.Callback {
messageEntity.setContent(changeLightEvent);
V2XObuEventScenario.getInstance().init(messageEntity);
break;
case ObuConstant.TYPE_RUSH_RED_LIGHT:
// 闯红灯预警
V2XObuEventEntity rushRedLightEvent = new V2XObuEventEntity();
rushRedLightEvent.setType(ObuConstant.TYPE_RUSH_RED_LIGHT);
rushRedLightEvent.setDesc(info.getDescribe());
messageEntity.setContent(rushRedLightEvent);
V2XObuEventScenario.getInstance().init(messageEntity);
break;
case ObuConstant.TYPE_CROSS_COLLISION_WARNING:
// 交叉口碰撞预警
V2XMessageEntity<V2XPushMessageEntity> v2XMessageEntity =
TestOnLineCarUtils.getV2XScenarioCrossCrash();
Intent intent = new Intent(V2XConst.BROADCAST_SCENE_HANDLER_ACTION);
intent.putExtra(V2XConst.BROADCAST_SCENE_EXTRA_KEY, v2XMessageEntity);
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
break;
default:
break;
}
@@ -234,7 +256,7 @@ public class V2XObuManager implements IObuCallback, Handler.Callback {
if (ObuConfig.useObuLocation) {
MogoLocation currentLocation = new MogoLocation();
CoordinateConverter converter = new CoordinateConverter(V2XServiceManager.getContext());
CoordinateConverter converter = new CoordinateConverter(getContext());
converter.from(CoordinateConverter.CoordType.GPS);
LatLng latLng = new LatLng(locationInfo.getLat(), locationInfo.getLon());
converter.coord(latLng);

View File

@@ -88,6 +88,12 @@ public class V2XObuEventWindow extends FrameLayout implements IV2XWindow<V2XObuE
tvType.setText("优先通行");
tvType.setBackgroundResource(R.drawable.bg_v2x_event_type_green);
break;
case ObuConstant.TYPE_RUSH_RED_LIGHT:
ivTypeIcon.setImageResource(R.drawable.v2x_icon_obu_rush_red_light);
tvDesc.setText(entity.getDesc());
tvType.setText("红灯警告");
tvType.setBackgroundResource(R.drawable.bg_v2x_event_type_read);
break;
default:
Logger.w(MODULE_NAME, "其他obu类型暂不处理: " + entity.getType());
break;

View File

@@ -189,6 +189,39 @@ public class TestOnLineCarUtils {
return null;
}
/**
* 模拟H5推送场景--十字路口碰撞
*/
public static V2XMessageEntity<V2XPushMessageEntity> getV2XScenarioCrossCrash() {
try {
InputStream inputStream = V2XUtils.getApp()
.getResources()
.openRawResource(R.raw.scenario_push_cross_crash);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int len = -1;
byte[] buffer = new byte[1024];
while ((len = inputStream.read(buffer)) != -1) {
baos.write(buffer, 0, len);
}
inputStream.close();
// 加载数据源
V2XPushMessageEntity v2xRoadEventEntity = GsonUtil.objectFromJson(baos.toString(), V2XPushMessageEntity.class);
V2XMessageEntity<V2XPushMessageEntity> v2xMessageEntity = new V2XMessageEntity<>();
// 控制类型
v2xMessageEntity.setType(V2XMessageEntity.V2XTypeEnum.ALERT_ANIMATION_WARNING);
// 设置数据
v2xMessageEntity.setContent(v2xRoadEventEntity);
// 控制展示状态
v2xMessageEntity.setShowState(true);
return v2xMessageEntity;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* 模拟 疲劳驾驶
*/