add new func of httpdns switch city to fit socketserver

This commit is contained in:
zhongchao
2021-07-30 17:22:37 +08:00
100 changed files with 1985 additions and 2080 deletions

View File

@@ -21,6 +21,8 @@ public class HostConst {
public static final String IM_SOCKET_DOMAIN = "dzt-im.zhidaozhixing.com";
public static final String WEBSOCKET_DOMAIN = "dzt-Instant.zhidaozhixing.com";
public static final String SOCKET_CENTER_DOMAIN = "socketRegion";
// 网约车
public static final String OCH_DOMAIN = "http://dzt-hailing.zhidaozhixing.com";

View File

@@ -0,0 +1,68 @@
package com.mogo.module.common.datacenter;
public class RealTimeData {
private static volatile RealTimeData realTimeData;
private static final byte[] bytes = new byte[0];
private double lat;
private double lon;
private double heading;
private int speed;
private long satelliteTime;
private RealTimeData() {
}
public static RealTimeData getInstance() {
if (realTimeData == null) {
synchronized (bytes) {
if (realTimeData == null) {
realTimeData = new RealTimeData();
}
}
}
return realTimeData;
}
public void setLat(double lat) {
this.lat = lat;
}
public void setLon(double lon) {
this.lon = lon;
}
public void setHeading(double heading) {
this.heading = heading;
}
public void setSpeed(int speed) {
this.speed = speed;
}
public void setSatelliteTime(long satelliteTime) {
this.satelliteTime = satelliteTime;
}
public double getLat() {
return lat;
}
public double getLon() {
return lon;
}
public double getHeading() {
return heading;
}
public int getSpeed() {
return speed;
}
public long getSatelliteTime() {
return satelliteTime;
}
}

View File

@@ -1,35 +1,30 @@
package com.mogo.module.common.uploadintime;
package com.mogo.module.common.datacenter;
import com.mogo.commons.debug.DebugConfig;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.service.locationinfo.CloudLocationInfo;
import com.mogo.utils.logger.Logger;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
/*
* @author congtaowang
* @since 2020/12/14
*
* 实时坐标数据处理中心
/**
* 定位坐标同步数据中心
* 接收来自工控机实际定位数据
*/
public class SnapshotLocationController {
public class SnapshotLocationDataCenter {
private static final String TAG = "SnapshotLocationController";
private static volatile SnapshotLocationDataCenter sInstance;
private static volatile SnapshotLocationController sInstance;
private SnapshotLocationController() {
private SnapshotLocationDataCenter() {
}
public static SnapshotLocationController getInstance() {
public static SnapshotLocationDataCenter getInstance() {
if (sInstance == null) {
synchronized (SnapshotLocationController.class) {
synchronized (SnapshotLocationDataCenter.class) {
if (sInstance == null) {
sInstance = new SnapshotLocationController();
sInstance = new SnapshotLocationDataCenter();
}
}
}
@@ -52,6 +47,7 @@ public class SnapshotLocationController {
private double mCurSpeed;
private double mCurLon;
private double mCurLat;
private long mSatelliteTime = 0;
/**
* 同步从定位来的数据也可能是rtk
@@ -81,7 +77,6 @@ public class SnapshotLocationController {
//测试面板状态同步
DebugConfig.setStatus(DebugConfig.sLocation, true);
// Logger.d(TAG, "同步到rtk数据");
double lon = data.optDouble("lon", -1);
double lat = data.optDouble("lat", -1);
double alt = data.optDouble("alt", -1);
@@ -111,6 +106,7 @@ public class SnapshotLocationController {
mCurSpeed = cloudLocationInfo.getSpeed();
mCurLon = cloudLocationInfo.getLon();
mCurLat = cloudLocationInfo.getLat();
mSatelliteTime = cloudLocationInfo.getSatelliteTime();
}
/**
@@ -143,7 +139,6 @@ public class SnapshotLocationController {
if (list.size() == 0) {
return null;
}
//Logger.d( TAG, "upload loc size = %s", list == null ? 0 : list.size() );
return list;
}
@@ -153,7 +148,6 @@ public class SnapshotLocationController {
* @return 精度
*/
public int getDataAccuracy() {
//Logger.d( TAG, "upload loc accuracy = %s", mDataAccuracy );
return mDataAccuracy;
}
@@ -168,4 +162,8 @@ public class SnapshotLocationController {
public double getCurLat() {
return mCurLat;
}
public long getSatelliteTime(){
return mSatelliteTime;
}
}

View File

@@ -0,0 +1,61 @@
package com.mogo.module.common.datacenter;
import com.elegant.spi.annotations.Service;
import com.mogo.cloud.passport.MoGoAiCloudClientConfig;
import com.mogo.realtime.api.IRealTimeProvider;
import com.mogo.realtime.entity.SocketReceiveDataProto3;
import com.mogo.realtime.util.MortonCode;
import static com.mogo.cloud.socket.SocketMsgType.MSG_TYPE_UPLINK_CAR_DATA;
@Service(value = IRealTimeProvider.class)
public class SpiRealTimeProvider implements IRealTimeProvider {
@Override
public SocketReceiveDataProto3.SocketReceiveDataProto getLocationMsg() {
double lat = RealTimeData.getInstance().getLat();
double lon = RealTimeData.getInstance().getLon();
if (lat == 0.0f || lon == 0.0f) {
return null;
}
double heading = RealTimeData.getInstance().getHeading();
int speed = RealTimeData.getInstance().getSpeed();
long satelliteTime = RealTimeData.getInstance().getSatelliteTime();
long mortonCode = MortonCode.encodeMorton(lon, lat);
SocketReceiveDataProto3.LocationInfoProto locationInfoProto =
SocketReceiveDataProto3.LocationInfoProto.newBuilder()
.setLat(lat)
.setLon(lon)
.setHeading(heading)
.setSystemTime(System.currentTimeMillis())
.setSatelliteTime(satelliteTime)
.setAlt(0)
.setDataAccuracy(1)
.setSpeed(speed)
.setMortonCode(mortonCode)
.setSn(MoGoAiCloudClientConfig.getInstance().getSn())
.build();
SocketReceiveDataProto3.MyLocationReq myLocationReq =
SocketReceiveDataProto3.MyLocationReq.newBuilder()
.setLastCoordinate(locationInfoProto)
.setDataAccuracy(1)
.setMortonCode(mortonCode)
.setFromType(0)
.setSn(MoGoAiCloudClientConfig.getInstance().getSn())
.build();
SocketReceiveDataProto3.OnePerSecondSendReqProto self =
SocketReceiveDataProto3.OnePerSecondSendReqProto.newBuilder()
.setSelf(myLocationReq)
.build();
return SocketReceiveDataProto3.SocketReceiveDataProto.newBuilder()
.setIPCSn(MoGoAiCloudClientConfig.getInstance().getSn() + "xavier")
.setSn(MoGoAiCloudClientConfig.getInstance().getSn())
.setData(self)
.setMsgType(MSG_TYPE_UPLINK_CAR_DATA.getMsgType())
.setSeq(System.currentTimeMillis()).build();
}
}

View File

@@ -0,0 +1,59 @@
package com.mogo.module.common.datacenter.receiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import com.mogo.module.common.datacenter.RealTimeData;
import com.mogo.module.common.datacenter.SnapshotLocationDataCenter;
import com.mogo.utils.logger.Logger;
public class SnapShotMockTestPanelBroadCastReceiver extends BroadcastReceiver {
private static final String TAG = "SnapShotMockTestPanelBroadCastReceiver";
/**
* 定位模拟测试控制面板广播Action
*/
public static final String BROADCAST_TEST_PANEL_CONTROL_TYPE_EXTRA_KEY = "sceneType";
private Context mContext;
@Override
public void onReceive(Context context, Intent intent) {
try {
this.mContext = context;
int sceneType = intent.getIntExtra(BROADCAST_TEST_PANEL_CONTROL_TYPE_EXTRA_KEY, 0);
Logger.d(TAG, "textPanelOpenType:" + sceneType);
// 分发场景
dispatchSceneTest(sceneType);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 分发处理场景
* 定位模拟分发场景中需要case自己处理数据以生产者消费者模式来提供 RealTimeData 所需字段
*
* @param sceneType 场景类型
*/
private void dispatchSceneTest(int sceneType) {
Logger.d(TAG, "sceneType=" + sceneType);
if (sceneType == 1) {
//模拟顺义固定位置
RealTimeData.getInstance().setLat(39.968309);
RealTimeData.getInstance().setLon(116.410871);
RealTimeData.getInstance().setHeading(120);
RealTimeData.getInstance().setSpeed(30);
long satelliteTime = SnapshotLocationDataCenter.getInstance().getSatelliteTime();
if (satelliteTime == 0) {
satelliteTime = System.currentTimeMillis();
}
RealTimeData.getInstance().setSatelliteTime(satelliteTime);
} else if (sceneType == 2) {
}
}
}

View File

@@ -1,6 +1,7 @@
package com.mogo.module.common.drawer;
import android.os.Build;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
@@ -11,6 +12,7 @@ import com.mogo.map.marker.IMogoMarker;
import com.mogo.map.marker.MogoMarkerOptions;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.constants.DataTypes;
import com.mogo.module.common.drawer.bean.SpeedData;
import com.mogo.module.common.utils.Trigonometric;
import com.mogo.service.adas.entity.ADASRecognizedResult;
@@ -19,6 +21,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import static com.mogo.cloud.socket.entity.SocketDownDataHelper.FROM_ADAS;
@@ -38,7 +41,7 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
/**
* 上一帧数据的缓存
*/
protected static Map<String, IMogoMarker> mMarkersCaches = new ConcurrentHashMap<>();
private static Map<String, IMogoMarker> mMarkersCaches = new ConcurrentHashMap<>();
public AdasRecognizedResultDrawer() {
super();
@@ -73,9 +76,10 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
/**
* 渲染 adas 识别的数据
*
* @param resultList
* @param resultList adas感知融合数据
*/
public void renderAdasRecognizedResult(List<ADASRecognizedResult> resultList) {
final long start = System.nanoTime();
if (resultList == null || resultList.isEmpty() || !DebugConfig.isUseAdasRecognize()) {
clearOldMarker();
return;
@@ -100,9 +104,9 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
String uniqueKey = recognizedListResult.uuid;
IMogoMarker marker = mMarkersCaches.remove(uniqueKey);
if (marker != null && !marker.isDestroyed()) {
Log.d(TAG, "发现缓存marker id : " + uniqueKey);
// Log.d(TAG, "发现缓存marker id : " + uniqueKey);
updateCacheMarkerRes(marker, recognizedListResult);
renderAdasOneFrame(true, marker, uniqueKey, recognizedListResult, newAdasRecognizedMarkersCaches);
renderAdasOneFrame(marker, uniqueKey, recognizedListResult, newAdasRecognizedMarkersCaches);
} else {
// 新增添加进差集
newDiffSet.add(recognizedListResult);
@@ -110,10 +114,9 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
}
removeUselessMarker(mMarkersCaches);
removeUselessLastRecord();
// 需要新增的 marker 数量
int newDiffSetSize = newDiffSet.size();
Log.d(TAG, "原数据量 " + resultList.size() + " 新增marker数量 " + newDiffSetSize);
// Log.d(TAG, "原数据量 " + resultList.size() + " 新增marker数量 " + newDiffSetSize);
// 复用过期 marker
if (newDiffSetSize > 0) {
for (int i = 0; i < newDiffSetSize; i++) {
ADASRecognizedResult recognizedListResult = newDiffSet.get(i);
@@ -122,14 +125,14 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
if (marker == null) {
continue;
}
Log.d(TAG, "新增marker id : " + uniqueKey);
renderAdasOneFrame(false, marker, uniqueKey, recognizedListResult, newAdasRecognizedMarkersCaches);
// Log.d(TAG, "新增marker id : " + uniqueKey);
renderAdasOneFrame(marker, uniqueKey, recognizedListResult, newAdasRecognizedMarkersCaches);
}
}
sendMessage(MSG_REMOVE_DIRTY_MARKERS, mMarkersCaches);
mMarkersCaches.clear();
mMarkersCaches = newAdasRecognizedMarkersCaches;
Log.d(TAG, "更新缓存marker, size : " + mMarkersCaches.size());
Log.d("ADAS数据延时绘制", "render 接收数据 -> 处理结束 " + TimeUnit.NANOSECONDS.toMillis((System.nanoTime() - start)) + "ms");
}
/**
@@ -212,7 +215,7 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
while (iterator.hasNext()) {
ADASRecognizedResult result = iterator.next();
long internal = result.satelliteTime - getCurSatelliteTime();
if (internal > 300) {
if (internal > 3000) { //防止帧率过低导致误删除上一个节点对象,从而出现跳跃现象
iterator.remove();
}
}
@@ -228,7 +231,7 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
if (recognizedListResult == null) {
return true;
}
if (!isRenderType(recognizedListResult.type)) {
if (nonRenderType(recognizedListResult.type)) {
return true;
}
String uniqueKey = recognizedListResult.uuid;
@@ -241,13 +244,12 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
* @param recognizedListResult {@link ADASRecognizedResult}
* @param newAdasRecognizedMarkersCaches 缓存集合
*/
private void renderAdasOneFrame(boolean useCache, IMogoMarker marker,
private void renderAdasOneFrame(IMogoMarker marker,
String uniqueKey,
ADASRecognizedResult recognizedListResult,
Map<String, IMogoMarker> newAdasRecognizedMarkersCaches) {
final long start = System.currentTimeMillis();
Log.d(TAG, "renderAdasOneFrame uuid : " + uniqueKey + " type : " + recognizedListResult.type);
final long start = System.nanoTime();
// Log.d(TAG, "renderAdasOneFrame uuid : " + uniqueKey + " type : " + recognizedListResult.type + " heading : " + recognizedListResult.heading);
ADASRecognizedResult lastPosition = mLastPositions.remove(uniqueKey);
// 道路吸附
// double lastLon = -1;
@@ -257,36 +259,43 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
// lastLat = lastPosition.lat;
// }
// double[] matchLonLat = getMatchLonLat(recognizedListResult.uuid, recognizedListResult.lon, recognizedListResult.lat, recognizedListResult.heading, lastLon, lastLat);
//
// recognizedListResult.lon = matchLonLat[0];
// recognizedListResult.lat = matchLonLat[1];
// Log.d( "matchRoad", "cost = %s", System.currentTimeMillis() - start );
mLastPositions.put(uniqueKey, recognizedListResult);
if (useCache) {
Log.d(TAG, "使用缓存 id : " + uniqueKey);
long interval = 45;
if(lastPosition != null){
interval = computeAnimDuration(lastPosition.systemTime, recognizedListResult.systemTime, lastPosition.satelliteTime, recognizedListResult.satelliteTime);
}
final MogoLatLng renderLoc = new MogoLatLng(recognizedListResult.lat, recognizedListResult.lon);
long cost = System.currentTimeMillis() - start;
final long intervalRef = interval - cost;
marker.addDynamicAnchorPosition(renderLoc, (float) recognizedListResult.heading, intervalRef);
} else {
Log.d(TAG, "未使用缓存 id : " + uniqueKey);
marker.setRotateAngle(((float) recognizedListResult.heading));
marker.setPosition(recognizedListResult.lat, recognizedListResult.lon);
// Log.d(TAG, "使用缓存 id : " + uniqueKey);
long interval = 45;
if (lastPosition != null) {
interval = computeAnimDuration(lastPosition.satelliteTime, recognizedListResult.satelliteTime);
}
final MogoLatLng renderLoc = new MogoLatLng(recognizedListResult.lat, recognizedListResult.lon);
long cost = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start);
Log.d("ADAS动画数据","cost : " + cost);
final long intervalRef = interval - cost;
Log.d("ADAS动画数据", "最终赋值 : " + intervalRef + " 两帧间隔 : " + interval + " uuid : " + recognizedListResult.uuid);
marker.addDynamicAnchorPosition(renderLoc, (float) recognizedListResult.heading, intervalRef);
String carColor = recognizedListResult.color;
if (TextUtils.isEmpty(carColor)) {
carColor = getModelRenderColor(recognizedListResult.type, FROM_ADAS, recognizedListResult.drawlevel);
}
marker.setAnchorColor(carColor);
newAdasRecognizedMarkersCaches.put(uniqueKey, marker);
// if (shouldShowSpeed(recognizedListResult.type)) {
// showSelfSpeed(marker, recognizedListResult.speed, recognizedListResult.uuid, recognizedListResult.type, recognizedListResult.heading, MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode());
// }
if (shouldShowSpeed(recognizedListResult.type)) {
Message msg = mRenderThreadHandler.obtainMessage();
msg.obj = new SpeedData(marker
, recognizedListResult.speed
, recognizedListResult.uuid
, recognizedListResult.type
, recognizedListResult.heading
, MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode());
msg.what = MSG_DISPLAY_SPEED;
msg.sendToTarget();
}
Log.d("ADAS数据延时", "render 刷新一台车 cost : " + TimeUnit.NANOSECONDS.toMillis((System.nanoTime() - start)));
}
/**
@@ -296,6 +305,7 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
* @return {@link IMogoMarker}
*/
private IMogoMarker drawAdasRecognizedDataMarker(ADASRecognizedResult recognizedListResult) {
long start = System.nanoTime();
if (recognizedListResult == null) {
return null;
}
@@ -320,6 +330,7 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
.position(new MogoLatLng(recognizedListResult.lat, recognizedListResult.lon));
IMogoMarker marker = MogoApisHandler.getInstance().getApis().getMapServiceApi().getMarkerManager(mContext).addMarker(DataTypes.TYPE_MARKER_ADAS, options);
cacheMarkerIconResMd5Val(resIdVal, marker);
Log.d("ADAS数据延时", "创建一个新 marker cost : " + TimeUnit.NANOSECONDS.toMillis((System.nanoTime() - start)));
return marker;
}

View File

@@ -1,5 +1,11 @@
package com.mogo.module.common.drawer;
import static com.mogo.cloud.socket.entity.SocketDownDataHelper.FROM_ADAS;
import static com.mogo.cloud.socket.entity.SocketDownDataHelper.FROM_MY_LOCATION;
import static com.mogo.module.common.constants.DataTypes.TYPE_MARKER_ADAS;
import static com.mogo.module.common.constants.DataTypes.TYPE_MARKER_CLOUD_DATA;
import static java.lang.Math.PI;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
@@ -15,21 +21,17 @@ import com.mogo.map.marker.IMogoMarker;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.R;
import com.mogo.module.common.constants.AdasRecognizedType;
import com.mogo.module.common.uploadintime.SnapshotLocationController;
import com.mogo.module.common.datacenter.SnapshotLocationDataCenter;
import com.mogo.module.common.drawer.bean.SpeedData;
import com.mogo.utils.WorkThreadHandler;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import static com.mogo.cloud.socket.entity.SocketDownDataHelper.FROM_ADAS;
import static com.mogo.cloud.socket.entity.SocketDownDataHelper.FROM_MY_LOCATION;
import static com.mogo.module.common.constants.DataTypes.TYPE_MARKER_ADAS;
import static com.mogo.module.common.constants.DataTypes.TYPE_MARKER_CLOUD_DATA;
import static java.lang.Math.PI;
public
/*
* @author congtaowang
@@ -47,6 +49,11 @@ class BaseDrawer {
*/
public static final int MAP_RENDER_FRAME_FREQUENCY = 30;
/**
* 显示速度
*/
public static final int MSG_DISPLAY_SPEED = 11;
/**
* 移动点的时间间隔
*/
@@ -59,7 +66,7 @@ class BaseDrawer {
protected final Context mContext;
private TextView mSpeedView;
private static TextView mSpeedView;
public BaseDrawer() {
mContext = AbsMogoApplication.getApp();
@@ -78,6 +85,7 @@ class BaseDrawer {
}
private static Handler mWorkThreadHandler;
protected static Handler mRenderThreadHandler = null;
/**
* 处理 marker 移除的线程
@@ -106,6 +114,29 @@ class BaseDrawer {
}
};
}
if (mRenderThreadHandler == null) {
mRenderThreadHandler = new Handler(WorkThreadHandler.newInstance("render-thread-" + new Random().nextLong()).getLooper()) {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (msg.what == MSG_DISPLAY_SPEED) {
if (msg.obj instanceof SpeedData) {
showSpeed((SpeedData) msg.obj);
}
}
}
};
}
}
private static void showSpeed(SpeedData speedData) {
showSelfSpeed(speedData.getMarker()
, speedData.getSpeed()
, speedData.getUuid()
, speedData.getType()
, speedData.getHeading()
, speedData.getIsVrMode());
}
/**
@@ -145,15 +176,15 @@ class BaseDrawer {
* @param type {@link AdasRecognizedType}
* @return render
*/
public boolean isRenderType(int type) {
public boolean nonRenderType(int type) {
AdasRecognizedType recognizedType = AdasRecognizedType.valueFrom(type);
return recognizedType == AdasRecognizedType.classIdCar
|| recognizedType == AdasRecognizedType.classIdMoto
|| recognizedType == AdasRecognizedType.classIdBicycle
|| recognizedType == AdasRecognizedType.classIdPerson
|| recognizedType == AdasRecognizedType.classIdTrafficBus
|| recognizedType == AdasRecognizedType.classIdTrafficTruck
|| recognizedType == AdasRecognizedType.classIdUnKnow;
return recognizedType != AdasRecognizedType.classIdCar
&& recognizedType != AdasRecognizedType.classIdMoto
&& recognizedType != AdasRecognizedType.classIdBicycle
&& recognizedType != AdasRecognizedType.classIdPerson
&& recognizedType != AdasRecognizedType.classIdTrafficBus
&& recognizedType != AdasRecognizedType.classIdTrafficTruck
&& recognizedType != AdasRecognizedType.classIdUnKnow;
}
/**
@@ -163,8 +194,9 @@ class BaseDrawer {
* @return showSpeed
*/
public boolean shouldShowSpeed(int type) {
AdasRecognizedType recognizedType = AdasRecognizedType.valueFrom(type);
return recognizedType != AdasRecognizedType.classIdPerson;
return true; //todo 验证行人预警,对行人和自行车不做infoWindow过滤
// AdasRecognizedType recognizedType = AdasRecognizedType.valueFrom(type);
// return recognizedType != AdasRecognizedType.classIdPerson;
// &&recognizedType != AdasRecognizedType.classIdBicycle //todo Bicycle显示
// && recognizedType != AdasRecognizedType.classIdMoto //todo moto显示
}
@@ -178,7 +210,8 @@ class BaseDrawer {
public int getModelRes(int type) {
AdasRecognizedType recognizedType = AdasRecognizedType.valueFrom(type);
if (recognizedType == AdasRecognizedType.classIdCar) {
return R.raw.othercar;
// TODO 这里临时替换模型解决穿模现象
return R.raw.tachexiaoche;
} else if (recognizedType == AdasRecognizedType.classIdTrafficBus) {
return R.raw.bus;
} else if (recognizedType == AdasRecognizedType.classIdMoto) {
@@ -192,14 +225,18 @@ class BaseDrawer {
} else if (recognizedType == AdasRecognizedType.classIdBicycle) {
return R.raw.zixingche;
} else if (recognizedType == AdasRecognizedType.classIdTrafficTruck) {
return R.raw.kache;
// TODO 这里临时替换模型解决穿模现象
return R.raw.daba;
}
return R.raw.people;
}
/**
* 根据速度、经纬度计算距离判断车辆颜色
* 根据数据源判断车辆预警颜色
*
* @param speed 车速
* @param lon 经度
* @param lat 纬度
* @return 实际车辆颜色
*/
protected String getModelRenderColor(int type, int fromType, int drawLevel) {
@@ -220,6 +257,8 @@ class BaseDrawer {
}
}
return Car3DModelColor.Normal.color;
// todo 方案2
// return Car3DTestModelColor.getTestModelColor(fromType, Waring_Normal);
}
/**
@@ -230,7 +269,7 @@ class BaseDrawer {
protected double getCurSpeed() {
double speed = MogoApisHandler.getInstance().getApis().getAdasControllerApi().getLastSpeed();
if (speed <= 0) {
speed = SnapshotLocationController.getInstance().getCurSpeed();
speed = SnapshotLocationDataCenter.getInstance().getCurSpeed();
}
return speed;
}
@@ -246,8 +285,8 @@ class BaseDrawer {
MogoApisHandler.getInstance().getApis().getAdasControllerApi().getLastLat(),
};
if (coordinates[0] <= 0) {
coordinates[0] = SnapshotLocationController.getInstance().getCurLon();
coordinates[1] = SnapshotLocationController.getInstance().getCurLat();
coordinates[0] = SnapshotLocationDataCenter.getInstance().getCurLon();
coordinates[1] = SnapshotLocationDataCenter.getInstance().getCurLat();
}
return coordinates;
}
@@ -290,8 +329,7 @@ class BaseDrawer {
* @param speed 是否显示速度
* @param isVrMode 是否是vrMode
*/
public void showSelfSpeed(IMogoMarker mogoMarker, double speed, String uuid, int type, double heading, boolean isVrMode) {
Log.d("EmArrow", "showSelf uuid : " + uuid + " speed : " + speed);
public static void showSelfSpeed(IMogoMarker mogoMarker, double speed, String uuid, int type, double heading, boolean isVrMode) {
if (mogoMarker == null || mogoMarker.isDestroyed()) {
return;
}
@@ -305,7 +343,8 @@ class BaseDrawer {
return;
}
mogoMarker.setInfoWindowOffset(0, 20);
String text = "speed : " + speedIntVal + "\n" + uuid + "\n" + "type : " + type + "\n" + "heading : " + heading;
// String text = "speed : " + speedIntVal + "\n" + uuid + "\n" + "type : " + type + "\n" + "heading : " + heading;
String text = uuid + " " + (int) heading;
mSpeedView.setText(text);
mogoMarker.updateInfoWindowView(mSpeedView);
}
@@ -382,16 +421,18 @@ class BaseDrawer {
/**
* 使用系统时间或卫星时间计算出动画的运动时间最小值45防止两个点距离过近设置的最小动画执行时间
*
* @param lastSystemTime 上一个点系统时间,误差值
* @param curSystemTime 当前点系统时间,误差值
* @param lastSatelliteTime 上一个点SNTP时间精确值
* @param curSatelliteTime 当前点SNTP时间精确值
* @return 动画运动时间
*/
public long computeAnimDuration(long lastSystemTime, long curSystemTime, long lastSatelliteTime, long curSatelliteTime) {
long systemTimeInterval = curSystemTime - lastSystemTime;
long satelliteTimeInterval = curSatelliteTime - lastSatelliteTime;
long interval = systemTimeInterval < satelliteTimeInterval || satelliteTimeInterval == 0 ? systemTimeInterval : satelliteTimeInterval;
public long computeAnimDuration(long lastSatelliteTime, long curSatelliteTime) {
if (lastSatelliteTime == 0 || curSatelliteTime == 0) {
Log.d("ADAS动画数据", "卫星时间存在错误");
return 45;
}
long interval = curSatelliteTime - lastSatelliteTime;
Log.d("ADAS动画数据", "lastSatelliteTime : " + lastSatelliteTime +
" ---- curSatelliteTime : " + curSatelliteTime + " ===== 插值 " + interval);
if (interval < 45) {
interval = 45;
}

View File

@@ -1,5 +1,7 @@
package com.mogo.module.common.drawer;
import static com.mogo.module.common.constants.DataTypes.TYPE_MARKER_CLOUD_DATA;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
@@ -33,6 +35,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
/**
* @author congtaowang
@@ -70,20 +73,13 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
sInstance = null;
}
private Object readResolve() {
// 阻止反序列化,必须实现 Serializable 接口
return sInstance;
}
/**
* 上一帧数据的缓存
*/
protected static Map<String, IMogoMarker> mMarkersCaches = new ConcurrentHashMap<>();
private static final Map<String, IMogoMarker> mMarkersCaches = new ConcurrentHashMap<>();
private final Map<String, SocketDownData.CloudRoadDataProto> mLastPositions = new ConcurrentHashMap<>();
private boolean mIsVrMode = false;
/**
* 注册StatusDescriptor.VR_MODE类型VR_MODE状态改变回调
*
@@ -96,15 +92,10 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
mChangeCarModeStatus = true;
sendMessage(MSG_REMOVE_DIRTY_MARKERS, mMarkersCaches);
removeUselessMarker(mMarkersCaches);
mMarkersCaches = new ConcurrentHashMap<>();
mLastPositions.clear();
AdasRecognizedResultDrawer.getInstance().notifyVrModeChanged(); //清除ADAS old marker data
}
public boolean isVrMode() {
return mIsVrMode;
}
public boolean isChangeCarModeStatus() {
return mChangeCarModeStatus;
}
@@ -148,7 +139,7 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
* @param data 自车周边数据
*/
public void renderSnapshotData(SocketDownData.LauncherSnapshotProto data) {
final long start = System.nanoTime();
if (clear(data)) {
return;
}
@@ -162,8 +153,8 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
Map<String, IMogoMarker> newMarkersCaches = new ConcurrentHashMap<>(allDatumsList.size());
List<SocketDownData.CloudRoadDataProto> newDiffSet = new ArrayList<>();
for (SocketDownData.CloudRoadDataProto cloudRoadData : allDatumsList) {
if (isUselessValue(cloudRoadData)) {
continue;
}
@@ -171,16 +162,16 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
IMogoMarker marker = mMarkersCaches.remove(uniqueKey);
if (marker != null && !marker.isDestroyed()) {
updateCacheMarkerRes(marker, cloudRoadData);
renderSnapshotOneFrame(true, marker, uniqueKey, cloudRoadData, newMarkersCaches);
renderSnapshotOneFrame(marker, uniqueKey, cloudRoadData, newMarkersCaches);
} else {
newDiffSet.add(cloudRoadData);
}
}
removeUselessMarker(mMarkersCaches);
removeUselessLastRecord();
// 需要新增的 marker 数量
int newDiffSetSize = newDiffSet.size();
// 复用过期 marker
if (newDiffSetSize > 0) {
// 复用过后还需新增的 marker
for (int i = 0; i < newDiffSetSize; i++) {
SocketDownData.CloudRoadDataProto cloudRoadData = newDiffSet.get(i);
String uniqueKey = cloudRoadData.getUuid();
@@ -188,13 +179,14 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
if (marker == null) {
continue;
}
renderSnapshotOneFrame(false, marker, uniqueKey, cloudRoadData, newMarkersCaches);
renderSnapshotOneFrame(marker, uniqueKey, cloudRoadData, newMarkersCaches);
}
}
sendMessage(MSG_REMOVE_DIRTY_MARKERS, mMarkersCaches);
mMarkersCaches.clear();
mMarkersCaches = newMarkersCaches;
mMarkersCaches.putAll(newMarkersCaches);
// 移除超时 marker
delayRemoveUselessMarker();
removeUselessLastRecord();
Log.d("云端数据延时绘制", "render 接收数据 -> 处理结束 " + TimeUnit.NANOSECONDS.toMillis((System.nanoTime() - start)) + "ms");
}
/**
@@ -218,6 +210,33 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
}
}
private void delayRemoveUselessMarker() {
if (mMarkersCaches.isEmpty()) {
return;
}
IMogoADASController adasControllerApi = MogoApisHandler.getInstance().getApis().getAdasControllerApi();
if (TextUtils.isEmpty(adasControllerApi.getSatelliteTime())) {
return;
}
Iterator<IMogoMarker> iterator = mMarkersCaches.values().iterator();
while (iterator.hasNext()) {
IMogoMarker result = iterator.next();
SocketDownData.CloudRoadDataProto proto = ((SocketDownData.CloudRoadDataProto) result.getObject());
if(proto == null){ // 后续有业务数据在操作,更新数据,不做处理
continue;
}
long internal = Long.parseLong(adasControllerApi.getSatelliteTime()) - proto.getSatelliteTime();
Log.d("MogoArrow", "delayRemoveUselessMarker uuid : " + proto.getUuid()
+ " localTime : " + adasControllerApi.getSatelliteTime()
+ " originTime : " + proto.getSatelliteTime()
+ " internal : " + internal);
if (internal > 5000) {
iterator.remove();
result.destroy();
}
}
}
private void removeUselessLastRecord() { // todo 最好重新设计一个数据结构用于多线程数据过期失效的场景参见redis数据过期
if (mLastPositions.isEmpty()) {
return;
@@ -230,8 +249,8 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
Log.d("EmArrow", "removeUselessLastRecord size : " + mLastPositions.size());
while (iterator.hasNext()) {
SocketDownData.CloudRoadDataProto result = iterator.next();
long internal = result.getSatelliteTime() - Long.parseLong(adasControllerApi.getSatelliteTime());
if (internal > 300) {
long internal = Long.parseLong(adasControllerApi.getSatelliteTime()) - result.getSatelliteTime();
if (internal > 3000) {
iterator.remove();
}
}
@@ -247,7 +266,7 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
if (cloudRoadData == null) {
return true;
}
if (!isRenderType(cloudRoadData.getType())) {
if (nonRenderType(cloudRoadData.getType())) {
return true;
}
@@ -261,49 +280,45 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
* @param cloudRoadData {@link SocketDownData.CloudRoadDataProto}
* @param newSnapshotCaches 缓存数据
*/
private void renderSnapshotOneFrame(boolean useCache, IMogoMarker marker, String uniqueKey, SocketDownData.CloudRoadDataProto cloudRoadData, Map<String, IMogoMarker> newSnapshotCaches) {
Logger.d(TAG, "renderSnapshotOneFrame");
final long start = System.currentTimeMillis();
private void renderSnapshotOneFrame(IMogoMarker marker, String uniqueKey, SocketDownData.CloudRoadDataProto cloudRoadData, Map<String, IMogoMarker> newSnapshotCaches) {
final long start = System.nanoTime();
SocketDownData.CloudRoadDataProto lastPosition = mLastPositions.remove(uniqueKey);
double lastLon = -1;
double lastLat = -1;
if (lastPosition != null) {
lastLon = lastPosition.getWgslon();
lastLat = lastPosition.getWgslat();
}
double[] matchLonLat = getMatchLonLat(cloudRoadData.getUuid(), cloudRoadData.getWgslon(), cloudRoadData.getWgslat(), cloudRoadData.getHeading(), lastLon, lastLat);
SocketDownData.CloudRoadDataProto.Builder builder = cloudRoadData.toBuilder();
builder.setWgslon(matchLonLat[0]);
builder.setWgslat(matchLonLat[1]);
cloudRoadData = builder.build();
// 道路吸附
// double lastLon = -1;
// double lastLat = -1;
// if (lastPosition != null) {
// lastLon = lastPosition.getWgslon();
// lastLat = lastPosition.getWgslat();
// }
// double[] matchLonLat = getMatchLonLat(cloudRoadData.getUuid(), cloudRoadData.getWgslon(), cloudRoadData.getWgslat(), cloudRoadData.getHeading(), lastLon, lastLat);
// SocketDownData.CloudRoadDataProto.Builder builder = cloudRoadData.toBuilder();
// builder.setWgslon(matchLonLat[0]);
// builder.setWgslat(matchLonLat[1]);
// cloudRoadData = builder.build();
mLastPositions.put(uniqueKey, cloudRoadData);
if (useCache) {
long interval = 45;
if (lastPosition != null) {
interval = computeAnimDuration(lastPosition.getSystemTime(), cloudRoadData.getSystemTime(), lastPosition.getSatelliteTime(), cloudRoadData.getSatelliteTime());
}
final MogoLatLng point = new MogoLatLng(cloudRoadData.getWgslat(), cloudRoadData.getWgslon());
long cost = System.currentTimeMillis() - start;
final long intervalRef = interval - cost;
marker.addDynamicAnchorPosition(point, (float) cloudRoadData.getHeading(), intervalRef);
} else {
marker.setRotateAngle(((float) cloudRoadData.getHeading()));
marker.setPosition(cloudRoadData.getWgslat(), cloudRoadData.getWgslon());
long interval = 45;
if (lastPosition != null) {
interval = computeAnimDuration(lastPosition.getSatelliteTime(), cloudRoadData.getSatelliteTime());
}
newSnapshotCaches.put(uniqueKey, marker);
final MogoLatLng point = new MogoLatLng(cloudRoadData.getWgslat(), cloudRoadData.getWgslon());
long cost = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start);
final long intervalRef = interval - cost;
marker.addDynamicAnchorPosition(point, (float) cloudRoadData.getHeading(), intervalRef);
marker.setAnchorColor(getModelRenderColor(cloudRoadData.getType(), cloudRoadData.getFromType(), 1));
if (shouldShowSpeed(cloudRoadData.getType())) {
showSelfSpeed(marker, cloudRoadData.getSpeed(), cloudRoadData.getUuid(), cloudRoadData.getType(), cloudRoadData.getHeading(), MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode());
}
newSnapshotCaches.put(uniqueKey, marker);
// if (shouldShowSpeed(cloudRoadData.getType())) {
// Message msg = mRenderThreadHandler.obtainMessage();
// msg.obj = new SpeedData(marker
// , cloudRoadData.getSpeed()
// , cloudRoadData.getUuid()
// , cloudRoadData.getType()
// , cloudRoadData.getHeading()
// , MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode());
// msg.what = MSG_DISPLAY_SPEED;
// msg.sendToTarget();
// }
Log.d("云端数据延时", "render 刷新一台车 cost : " + TimeUnit.NANOSECONDS.toMillis((System.nanoTime() - start)));
}
/**
@@ -313,35 +328,10 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
* @param out 输出集合
*/
private void prepareData(List<SocketDownData.CloudRoadDataProto> in, List<SocketDownData.CloudRoadDataProto> out) {
filterData(in);
// foreCastPoint(in, out);
out.addAll(in);
}
/**
* vr 模式下显示合并数据,否则只显示 mogo 车辆上报的数据
* 展示融合数据不包括自车定位数据和adas识别数据
*
* @param data 道路数据集合
*/
private void filterData(List<SocketDownData.CloudRoadDataProto> data) {
if (data == null || data.isEmpty()) {
return;
}
if (MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode()) {
return;
}
List<SocketDownData.CloudRoadDataProto> newList = new ArrayList<>();
for (SocketDownData.CloudRoadDataProto cloudRoadData : data) {
if (cloudRoadData.getFromType() != SocketDownDataHelper.FROM_MY_LOCATION) {
continue;
}
newList.add(cloudRoadData);
}
data.clear();
data.addAll(newList);
}
private final static String FORECAST = "snapshotForecast";
/**
@@ -402,12 +392,13 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
* @return {@link IMogoMarker}
*/
public IMogoMarker drawSnapshotDataMarker(SocketDownData.CloudRoadDataProto data) {
long start = System.nanoTime();
if (data == null) {
return null;
}
MogoMarkerOptions options = new MogoMarkerOptions()
.owner(getDataTypes(data.getFromType()))
.owner(TYPE_MARKER_CLOUD_DATA)
.anchor(0.5f, 0.5f)
.rotate((float) data.getHeading())
.object(data)
@@ -428,13 +419,13 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
options.icon(view);
resIdVal = view.getId() + "";
}
IMogoMarker marker = MogoApisHandler.getInstance().getApis().getMapServiceApi().getMarkerManager(mContext).addMarker(getDataTypes(data.getFromType()), options);
IMogoMarker marker = MogoApisHandler.getInstance().getApis().getMapServiceApi().getMarkerManager(mContext).addMarker(TYPE_MARKER_CLOUD_DATA, options);
cacheMarkerIconResMd5Val(resIdVal, marker);
if (!TextUtils.isEmpty(data.getSn())) {
bindClickListener(marker);
}
Log.d("云端数据延时", "创建一个新 marker cost : " + TimeUnit.NANOSECONDS.toMillis((System.nanoTime() - start)));
return marker;
}

View File

@@ -74,43 +74,36 @@ public class V2XWarnDataDrawer extends BaseDrawer implements IMogoStatusChangedL
/**
* 绘制行人和二轮车,前方和左右
* 识别物移动
*
* @param data
*/
public void renderWarnData(V2XWarningEntity data) {
MarkerLocation location = new MarkerLocation();
location.setLat(data.getDirection() == 1 ? data.getStopLines().get(0).lat : data.getLat());
location.setLon(data.getDirection() == 1 ? data.getStopLines().get(0).lon : data.getLon());
location.setLat(data.getLat());
location.setLon(data.getLon());
MarkerShowEntity markerShowEntity = new MarkerShowEntity();
markerShowEntity.setMarkerLocation(location);
markerShowEntity.setMarkerType(TYPE_MARKER_CLOUD_WARN_DATA);
IMogoMarker marker = drawMarker(markerShowEntity, modeResType(data.getType()));
//识别物
marker.addDynamicAnchorPosition(new MogoLatLng(
data.getDirection() == 1 ? data.getStopLines().get(1).lat : data.getCollisionLat(),
data.getDirection() == 1 ? data.getStopLines().get(1).lon : data.getCollisionLon()), (float) data.getHeading(), 5000);
//移动完成以后3s后消失
marker.addDynamicAnchorPosition(new MogoLatLng(data.getCollisionLat(), data.getCollisionLon()), (float) data.getHeading(), (long) (data.getShowTime() * 1000));
UiThreadHandler.postDelayed(() -> {
marker.remove();
}, data.getShowTime());
}, data.getShowTime() * 1000);
}
//根据识别物类型 (行人0/自行车1/摩托车2/小汽车3/公交车4)获取3D模型(对应查看getModelRes)
//根据识别物类型 (行人1/自行车2/摩托车4/骑行车辆11)获取3D模型(对应查看getModelRes)
private int modeResType(int dataType) {
switch (dataType) {
case 0:
return 1;
case 1:
return 2;
case 11:
return 1;
case 2:
return 4;
case 3:
return 3;
return 2;
case 4:
return 6;
return 4;
}
return 1;
}
@@ -181,8 +174,6 @@ public class V2XWarnDataDrawer extends BaseDrawer implements IMogoStatusChangedL
markerShowEntity.setMarkerLocation(location);
markerShowEntity.setMarkerType(TYPE_MARKER_CLOUD_STOP_LINE_DATA);
IMogoMarker marker = drawStopLineMarker(markerShowEntity);
}
/**

View File

@@ -0,0 +1,73 @@
package com.mogo.module.common.drawer.bean;
import com.mogo.map.marker.IMogoMarker;
/**
* 速度显示对象
*/
public class SpeedData {
public IMogoMarker marker;
public double speed;
public String uuid;
public int type;
public double heading;
public boolean isVrMode;
public SpeedData(IMogoMarker marker, double speed, String uuid, int type, double heading, boolean isVrMode) {
this.marker = marker;
this.speed = speed;
this.uuid = uuid;
this.type = type;
this.heading = heading;
this.isVrMode = isVrMode;
}
public IMogoMarker getMarker() {
return marker;
}
public void setMarker(IMogoMarker marker) {
this.marker = marker;
}
public double getSpeed() {
return speed;
}
public void setSpeed(double speed) {
this.speed = speed;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public double getHeading() {
return heading;
}
public void setHeading(double heading) {
this.heading = heading;
}
public boolean getIsVrMode() {
return isVrMode;
}
public void setIsVrMode(boolean isVrMode) {
this.isVrMode = isVrMode;
}
}

View File

@@ -12,7 +12,7 @@ import java.util.List;
*/
public class V2XWarningEntity implements Serializable {
//事件类型 行人0/自行车1/摩托车2/小汽车3/公交车4
//事件类型 行人1/自行车2/摩托车4/骑行车辆11
private int type;
//目标物位置
private double lat;