Merge remote-tracking branch 'origin/demo/shunyi_vr_map' into demo/shunyi_vr_map

This commit is contained in:
wangcongtao
2020-12-01 15:13:10 +08:00
15 changed files with 419 additions and 48 deletions

1
.idea/gradle.xml generated
View File

@@ -88,6 +88,7 @@
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
<option name="useQualifiedModuleNames" value="true" />
</GradleProjectSettings>
</option>
</component>

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" default="true" project-jdk-name="JDK" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="SuppressionsComponent">

View File

@@ -30,7 +30,7 @@ dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation rootProject.ext.dependencies.arouter
implementation "com.mogo.module.carchatting:module-carchatt-socket:1.1.1"
implementation "com.mogo.module.carchatting:module-carchatt-socket:1.1.2"
if (Boolean.valueOf(RELEASE)) {
implementation rootProject.ext.dependencies.mogoutils

View File

@@ -5,13 +5,21 @@ import com.mogo.commons.debug.DebugConfig;
public class WebSocketConstant {
private static final String HOST_DEV = "ws://62.234.196.121:14001/ws";
private static final String HOST_QA = "ws://62.234.196.121:14001/ws";
private static final String HOST_DEMO = "ws://62.234.196.121:14001/ws";
private static final String HOST_RELEASE = "ws://62.234.196.121:14001/ws";
private static final String HOST_DEV = "ws://62.234.196.121";
private static final String HOST_QA = "ws://62.234.196.121";
private static final String HOST_DEMO = "ws://62.234.196.121";
private static final String HOST_RELEASE = "ws://62.234.196.121";
// private static final String PORT = ":14001/ws";
public static final String PORT = ":4003/ws";
public static final String PROTOCOL = "ws://";
public static String getSocketServer(){
switch (DebugConfig.getNetMode()){
private static final String DOMAIN_DEV = "dzt-city.zhidaozhixing.com";
private static final String DOMAIN_QA = "dzt-city.zhidaozhixing.com";
private static final String DOMAIN_DEMO = "dzt-city.zhidaozhixing.com";
private static final String DOMAIN_RELEASE = "dzt-city.zhidaozhixing.com";
public static String getSocketServer() {
switch (DebugConfig.getNetMode()) {
case DebugConfig.NET_MODE_DEV:
return HOST_DEV;
case DebugConfig.NET_MODE_QA:
@@ -21,7 +29,25 @@ public class WebSocketConstant {
case DebugConfig.NET_MODE_RELEASE:
default:
return HOST_RELEASE;
}
}
public static String getDomain(){
switch (DebugConfig.getNetMode()) {
case DebugConfig.NET_MODE_DEV:
return DOMAIN_DEV;
case DebugConfig.NET_MODE_QA:
return DOMAIN_QA;
case DebugConfig.NET_MODE_DEMO:
return DOMAIN_DEMO;
case DebugConfig.NET_MODE_RELEASE:
default:
return DOMAIN_RELEASE;
}
}
// public static String getSocketPort() {
// return PORT;
// }
}

View File

@@ -12,6 +12,8 @@ public class WebSocketData implements Serializable {
private String data;
private long utcTime;
public long getSeq() {
return seq;
}
@@ -43,4 +45,12 @@ public class WebSocketData implements Serializable {
public void setData(String data) {
this.data = data;
}
public long getUtcTime() {
return utcTime;
}
public void setUtcTime(long utcTime) {
this.utcTime = utcTime;
}
}

View File

@@ -27,28 +27,30 @@ public class WebSocketDnsManager {
public void getHttpDnsIp(WebSocketDns webSocketDns) {
this.webSocketDns = webSocketDns;
IMogoHttpDns mogoHttpDns = ARouter.getInstance().navigation(IMogoHttpDns.class);
ThreadPoolService.execute(() -> mogoHttpDns.getHttpDnsIp(WebSocketConstant.getSocketServer(), true, ip -> {
ThreadPoolService.execute(() -> mogoHttpDns.getHttpDnsIp(WebSocketConstant.getDomain(), false, ip -> {
Logger.d(TAG, "getHttpDnsIp ip : " + ip + " , 得到Dns IP,准备回调 初始化webSocket");
this.cacheIp = ip;
this.webSocketDns.getDnsIp(cacheIp != null ? cacheIp : WebSocketConstant.getSocketServer());
this.webSocketDns.getDnsIp((cacheIp != null ?
WebSocketConstant.PROTOCOL + ip + WebSocketConstant.PORT :
WebSocketConstant.getSocketServer() + WebSocketConstant.PORT));
}));
mogoHttpDns.addHttpDnsTtlCallback(WebSocketConstant.getSocketServer(), () -> {
mogoHttpDns.addHttpDnsTtlCallback(WebSocketConstant.getDomain(), () -> {
Logger.d(TAG, "ttl callBack ,ready to getCache Dns IP");
String dnsCacheIp = mogoHttpDns.getCachedHttpDnsIps(WebSocketConstant.getSocketServer());
String dnsCacheIp = mogoHttpDns.getCachedHttpDnsIps(WebSocketConstant.getDomain());
if (dnsCacheIp == null) {
return;
}
Logger.d(TAG, "获取缓存Dns IP : " + dnsCacheIp + " , 原缓存 IP " + cacheIp);
if (cacheIp != null && !cacheIp.equals(dnsCacheIp)) {
this.webSocketDns.ttlIp(dnsCacheIp);
this.webSocketDns.ttlIp(dnsCacheIp + WebSocketConstant.PORT);
}
});
}
public interface WebSocketDns {
void getDnsIp(String ip);
void getDnsIp(String url);
void ttlIp(String ip);
void ttlIp(String url);
}
}

View File

@@ -1,6 +1,7 @@
package com.mogo.base.websocket;
import android.content.Context;
import android.os.SystemClock;
import androidx.annotation.Keep;
@@ -22,6 +23,7 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import static com.mogo.service.connection.WebSocketMsgType.MSG_TYPE_ACK;
import static com.mogo.service.connection.WebSocketMsgType.MSG_TYPE_DOWNLINK_CAR_DATA;
@Keep
@@ -70,18 +72,18 @@ public class WebSocketManager implements IMogoWebSocketManager, ISocketMsgSettin
public void init(Context context, String appId) {
WebSocketDnsManager.getInstance().getHttpDnsIp(new WebSocketDnsManager.WebSocketDns() {
@Override
public void getDnsIp(String ip) {
Logger.d(TAG,"getDnsIp ip : " + ip);
initWebSocket(ip);
public void getDnsIp(String url) {
Logger.d(TAG,"getDnsIp url : " + url);
initWebSocket(url);
}
@Override
public void ttlIp(String ip) {
Logger.d(TAG,"ttlIp ip : " + ip);
public void ttlIp(String url) {
Logger.d(TAG,"ttlIp url : " + url);
SocketClient.getInstance().getClientProxy().stop();
SocketClient.getInstance().getClientProxy().disConnect();
Logger.d(TAG,"ready to re initWebSocket : " + ip);
initWebSocket(ip);
Logger.d(TAG,"ready to re initWebSocket : " + url);
initWebSocket(url);
}
});
}
@@ -133,12 +135,13 @@ public class WebSocketManager implements IMogoWebSocketManager, ISocketMsgSettin
Logger.d(TAG, "websocket sendMsg body = " + body);
if (handlerThread != null) {
WebSocketData webSocketData = new WebSocketData();
webSocketData.setSeq(System.currentTimeMillis());
webSocketData.setSeq(computeSendMsgTime());
webSocketData.setMsgType(listener.getUpLinkType().getMsgType());
webSocketData.setSn(Utils.getSn());
webSocketData.setData(new Gson().toJson(body));
Logger.d(TAG,"sendMsg : " + new Gson().toJson(webSocketData));
handlerThread.sendMsg(new Gson().toJson(webSocketData));
webSocketData.setData(GsonUtil.jsonFromObject(body));
String msg = GsonUtil.jsonFromObject(webSocketData);
Logger.d(TAG,"sendMsg : " + msg);
handlerThread.sendMsg(msg);
}
}
@@ -152,12 +155,34 @@ public class WebSocketManager implements IMogoWebSocketManager, ISocketMsgSettin
Logger.d(TAG, "websocket onConnectOpen");
}
private long serverTime = 0;
private long receiveMsgTime = 0;
/**
* 服务端会在ack数据中增加服务端的时间戳{@link #serverTime}, 收到消息时,记录收到消息的时间{@link #receiveMsgTime},收消息的时间用{@link SystemClock#elapsedRealtime()}可以避免系统时间改变造成的影响
* 在发送数据时使用serverTime+(elapseRealtime()-receiveMsgTime)计算发送数据时的时间戳这个时间戳是基本相对服务端的时间戳为基准的时间忽略了ack下发时的时间延迟
*
* 如果{@link #serverTime}或{@link #receiveMsgTime}数据有异常,则使用{@link System#currentTimeMillis()}当做当前时间,作为容错
*
* @return 基本相对服务端的时间戳为基准的时间
*/
private long computeSendMsgTime(){
long sendMsgTime = 0;
if (serverTime > 0 && receiveMsgTime > 0) {
sendMsgTime = serverTime + (SystemClock.elapsedRealtime() - receiveMsgTime);
}else{
sendMsgTime = System.currentTimeMillis();
}
return sendMsgTime;
}
@Override
public void handleMessage(String message) {
Logger.d(TAG, "websocket received msg = " + message);
WebSocketData webSocketData = GsonUtil.objectFromJson(message, WebSocketData.class);
int msgType = webSocketData.getMsgType();
Logger.d(TAG, "websocket received msg type = " + msgType);
//服务端下发数据返回,上传数据回执默认不返回
if (msgType == MSG_TYPE_DOWNLINK_CAR_DATA.getMsgType()) {
List<IMogoOnWebSocketMessageListener> listeners = mListeners.get(msgType);
@@ -172,6 +197,12 @@ public class WebSocketManager implements IMogoWebSocketManager, ISocketMsgSettin
}
}
}
} else if (msgType == MSG_TYPE_ACK.getMsgType()) {
if (webSocketData.getUtcTime() > 0) {
serverTime = webSocketData.getUtcTime();
receiveMsgTime = SystemClock.elapsedRealtime();
Logger.d(TAG, "设置serverTime");
}
}
}

View File

@@ -3,6 +3,8 @@ package com.mogo.module.common.entity;
import android.os.Parcel;
import android.os.Parcelable;
import java.util.Objects;
/**
* 云端定位信息和自车定位信息
*
@@ -17,7 +19,17 @@ public class CloudLocationInfo implements Parcelable {
private double alt;
private double speed;
public CloudLocationInfo(){
public CloudLocationInfo() {
}
public CloudLocationInfo(CloudLocationInfo info) {
this.lat = info.getLat();
this.lon = info.getLon();
this.heading = info.getHeading();
this.systemTime = System.currentTimeMillis();
this.satelliteTime = System.currentTimeMillis();
this.alt = info.alt;
this.speed = info.speed;
}
protected CloudLocationInfo(Parcel in) {
@@ -126,4 +138,27 @@ public class CloudLocationInfo implements Parcelable {
", speed=" + speed +
'}';
}
public String print() {
return "CloudLocation{ lon: " + lon + " lat: " + lat + " heading: " + heading + " speed: "
+ speed+"}";
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
CloudLocationInfo that = (CloudLocationInfo) o;
return Double.compare(that.lat, lat) == 0 &&
Double.compare(that.lon, lon) == 0;
}
@Override
public int hashCode() {
return Objects.hash(lat, lon);
}
}

View File

@@ -17,6 +17,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.ConstraintSet;
import androidx.constraintlayout.widget.Group;
import com.alibaba.android.arouter.launcher.ARouter;
import com.bumptech.glide.request.RequestOptions;
@@ -257,7 +258,7 @@ public class EntranceFragment extends MvpFragment<EntranceView, EntrancePresente
}
}
} );
mUserHeadImg = findViewById(R.id.ivUserHeadImg);
if (DebugConfig.isDebug()) {
mMove2CurrentLocation.setOnLongClickListener(view -> {
mApis.getSearchManagerApi().goSettings();
@@ -268,8 +269,19 @@ public class EntranceFragment extends MvpFragment<EntranceView, EntrancePresente
mApis.getMogoMonitorApi().showLogDebugDialog();
return true;
});
mUserHeadImg.setOnLongClickListener(view ->{
if (groupFix.getVisibility() == View.VISIBLE) {
groupFix.setVisibility(View.GONE);
}else{
groupFix.setVisibility(View.VISIBLE);
}
return true;
});
}
groupFix = findViewById(R.id.groupFix);
ConstraintLayout rootView = findViewById(R.id.module_entrance_id_top_motion_layout);
if (rootView != null) {
TopViewAnimHelper.getInstance().init(rootView);
@@ -347,8 +359,6 @@ public class EntranceFragment extends MvpFragment<EntranceView, EntrancePresente
mWeatherIcon = findViewById(R.id.module_ext_id_weather_icon);
mWeatherTemp = findViewById(R.id.module_ext_id_weather_temp);
mUserHeadImg = findViewById(R.id.ivUserHeadImg);
mMsgContainer = findViewById(R.id.module_ext_id_msg);
mMsgContainer.setOnClickListener( new OnPreventFastClickListener() {
@@ -419,8 +429,30 @@ public class EntranceFragment extends MvpFragment<EntranceView, EntrancePresente
if (mStatusManager.isVrMode()) {
enterVrMode();
}
etTimes = findViewById(R.id.etTimes);
findViewById(R.id.btnFix).setOnClickListener((view)->{
try {
String times = etTimes.getText().toString().trim();
int fixTime = Integer.parseInt(times);
Logger.d(TAG, "修改上报时间间隔: " + times + " fixTime: " + fixTime);
if(fixTime > 0) {
Intent intent = new Intent("com.mogo.launcher.action.FIX_UPLOAT_DELAY");
intent.putExtra("fixTime", fixTime);
getContext().sendBroadcast(intent);
TipToast.tip("已经发送修改广播");
}else{
TipToast.tip("fixTime为0不发送广播");
}
} catch (Exception e) {
TipToast.tip("fixTime异常");
e.printStackTrace();
}
});
}
private EditText etTimes;
private Group groupFix;
private void enterVrMode(){
tvEnterVrMode.setVisibility(View.GONE);
mMove2CurrentLocation.setVisibility(View.GONE);
@@ -444,6 +476,7 @@ public class EntranceFragment extends MvpFragment<EntranceView, EntrancePresente
tvExitVrMode.setVisibility(View.GONE);
adasNoticeHelper.exitVrMode();
}
private void debugCrashWarn(){

View File

@@ -353,4 +353,35 @@
layout="@layout/module_ext_layout_crash_threshold_set"
android:visibility="gone" />
<EditText
android:layout_width="400px"
android:layout_height="wrap_content"
android:id="@+id/etTimes"
android:textSize="40sp"
android:background="#fff"
android:textColor="#000"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnFix"
android:text="修改"
android:textSize="40sp"
app:layout_constraintLeft_toRightOf="@id/etTimes"
app:layout_constraintTop_toTopOf="@id/etTimes"
android:layout_marginStart="10px"
android:background="#fff"
android:textColor="#000" />
<androidx.constraintlayout.widget.Group
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/groupFix"
android:visibility="gone"
app:constraint_referenced_ids="etTimes,btnFix" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -55,6 +55,8 @@ import com.mogo.module.service.refresh.AutoRefreshStrategy;
import com.mogo.module.service.refresh.CustomRefreshStrategy;
import com.mogo.module.service.refresh.RefreshObject;
import com.mogo.module.service.strategy.CarIconDisplayStrategy;
import com.mogo.module.service.utils.LocationParseUtil;
import com.mogo.module.service.utils.SimpleLocationCorrectStrategy;
import com.mogo.module.service.vrmode.VrModeController;
import com.mogo.module.service.websocket.LocationResult;
import com.mogo.module.service.websocket.OnePerSecondSendContent;
@@ -465,22 +467,29 @@ public class MogoServices implements IMogoMapListener,
}
private void startSendCarLocationAndAdasRecognizedResult2Server(List<CloudLocationInfo> cloudLocationInfo) {
Location lastCarLocation = mLastCarLocation;
// Location lastCarLocation = mLastCarLocation;
CloudLocationInfo lastInfo = LocationParseUtil.locationToCloudLocation(mLastCarLocation);
// 如果数组内容不为空,就用数组最后一个值
if (cloudLocationInfo != null && !cloudLocationInfo.isEmpty()) {
lastInfo = cloudLocationInfo.get(cloudLocationInfo.size() - 1);
}
LocationResult locationResult = null;
if ( lastCarLocation != null ) {
if ( lastInfo != null ) {
// 定位点预测纠偏
lastInfo = SimpleLocationCorrectStrategy.getInstance().correct(lastInfo);
if (lastInfo == null) {
return;
}
locationResult = new LocationResult();
locationResult.lastCoordinate = new CloudLocationInfo();
locationResult.lastCoordinate.setAlt( lastCarLocation.getAltitude() );
locationResult.lastCoordinate.setHeading( lastCarLocation.getBearing() );
locationResult.lastCoordinate.setLat( lastCarLocation.getLatitude() );
locationResult.lastCoordinate.setLon( lastCarLocation.getLongitude() );
locationResult.lastCoordinate.setSatelliteTime( lastCarLocation.getTime() );
locationResult.lastCoordinate.setSystemTime( System.currentTimeMillis() );
locationResult.lastCoordinate.setSpeed( lastCarLocation.getSpeed() );
locationResult.lastCoordinate = lastInfo;
locationResult.coordinates = new ArrayList<>();
locationResult.sn = com.mogo.commons.network.Utils.getSn();
locationResult.mortonCode = MortonCode.wrapEncodeMorton( locationResult.lastCoordinate.getLon(), locationResult.lastCoordinate.getLat() );
locationResult.coordinates.addAll( cloudLocationInfo );
locationResult.mortonCode = MortonCode.wrapEncodeMorton( lastInfo.getLon(), lastInfo.getLat() );
if(cloudLocationInfo == null){
locationResult.coordinates.addAll(new ArrayList<>());
}else {
locationResult.coordinates.addAll(cloudLocationInfo);
}
}
List< ADASRecognizedResult > recognizedResults = MarkerServiceHandler.getADASController().getLastADASRecognizedResult();
OnePerSecondSendContent content = new OnePerSecondSendContent();

View File

@@ -1,6 +1,9 @@
package com.mogo.module.service.location;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
@@ -21,7 +24,7 @@ public class MogoRTKLocation {
private static final String TAG = "MogoRTKLocation";
private static final int MSG_DATA_CHANGED = 0x100;
private static final long MSG_DATA_INTERNAL = 1 * 1_000L;
private static final long MSG_DATA_INTERNAL = 500L;
private Handler mHandler;
private LocationManager locationManager;
@@ -43,7 +46,7 @@ public class MogoRTKLocation {
super.handleMessage(msg);
if (msg.what == MSG_DATA_CHANGED) {
sendLocationData();
mHandler.sendEmptyMessageDelayed(MSG_DATA_CHANGED, MSG_DATA_INTERNAL);
mHandler.sendEmptyMessageDelayed(MSG_DATA_CHANGED, uploadDelay);
}
}
};
@@ -57,8 +60,7 @@ public class MogoRTKLocation {
private void sendLocationData() {
if (rtkLocationListener != null) {
Logger.d(TAG, "sendLocationData size : " + cacheList.size());
List list = new ArrayList();
list.addAll(cacheList);
List<CloudLocationInfo> list = new ArrayList<>(cacheList);
rtkLocationListener.onLocationChanged(list);
}
if (cacheList != null && cacheList.size() > 0) {
@@ -89,6 +91,10 @@ public class MogoRTKLocation {
} else {
Logger.d(TAG, "RTK LocationManager Provider GPS_PROVIDER unable");
}
// 注册修改上报间隔的广播, 临时使用后面可直接干掉发送广播的地方在EntranceFragment
IntentFilter filter = new IntentFilter("com.mogo.launcher.action.FIX_UPLOAT_DELAY");
AbsMogoApplication.getApp().registerReceiver(fixUploadDelayReceiver, filter);
}
private Criteria getCriteria() {
@@ -142,4 +148,15 @@ public class MogoRTKLocation {
Logger.d(TAG, "stop failed , reason : loc" + locationManager + " , or loc listener: " + locationListener + " is null");
}
}
private long uploadDelay = MSG_DATA_INTERNAL;
private FixUploadDelayReceiver fixUploadDelayReceiver = new FixUploadDelayReceiver();
private class FixUploadDelayReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
uploadDelay = intent.getIntExtra("fixTime", 0);
}
}
}

View File

@@ -0,0 +1,40 @@
package com.mogo.module.service.utils;
import android.location.Location;
import com.mogo.map.MogoLatLng;
import com.mogo.module.common.entity.CloudLocationInfo;
/**
* 定位数据类型转换工具
*
* @author tongchenfei
*/
public class LocationParseUtil {
/**
* 从Location 转 CloudLocationInfo
* @param info 待转数据
* @return 转后数据
*/
public static CloudLocationInfo locationToCloudLocation(Location info) {
if (info == null) {
return null;
}
CloudLocationInfo cloud = new CloudLocationInfo();
cloud.setLat(info.getLatitude());
cloud.setLon(info.getLongitude());
cloud.setAlt(info.getAltitude());
cloud.setHeading(info.getBearing());
cloud.setSpeed(info.getSpeed());
cloud.setSatelliteTime(info.getTime());
cloud.setSystemTime(System.currentTimeMillis());
return cloud;
}
public static MogoLatLng cloudLocationToMogoLatLng(CloudLocationInfo info) {
if (info == null) {
return null;
}
return new MogoLatLng(info.getLat(), info.getLon());
}
}

View File

@@ -0,0 +1,135 @@
package com.mogo.module.service.utils;
import android.location.Location;
import android.os.SystemClock;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.entity.CloudLocationInfo;
import com.mogo.utils.logger.Logger;
import java.util.ArrayList;
import java.util.List;
/**
* 定位预测纠错策略
*
* @author tongchenfei
*/
public class SimpleLocationCorrectStrategy {
private static final String TAG = "SimpleLocationCorrectStrategy";
private static final int ERR_COUNT_THRESHOLD = 3;
/**
* 目标距离误差是10米就是在原目标距离基础上增加10米
*/
private static final float TARGET_DISTANCE_DEVIATION = 10;
private CloudLocationInfo lastLocation = null;
private long anchorTime;
private int errCount;
private static SimpleLocationCorrectStrategy instance = new SimpleLocationCorrectStrategy();
public static SimpleLocationCorrectStrategy getInstance(){
return instance;
}
private List<CloudLocationInfo> tmpList = new ArrayList<>();
public CloudLocationInfo correct(CloudLocationInfo info) {
Logger.d(TAG, "info: " + info.print());
Logger.d("tmpList", "tmpList: " + tmpList);
if(isLocationValid(info)) {
tmpList.add(info);
if (lastLocation == null) {
lastLocation = info;
anchorTime = SystemClock.elapsedRealtime();
Logger.d(TAG, "第一条数据");
return info;
}
if (lastLocation.equals(info)) {
Logger.d(TAG, "相同坐标点==");
return info;
}
try {
float targetDistance =
(float) (lastLocation.getSpeed() * (SystemClock.elapsedRealtime() - anchorTime) / 1000) + TARGET_DISTANCE_DEVIATION;
float distance = MogoApisHandler.getInstance().getApis().getMapServiceApi().getMapUIController().calculateLineDistance(LocationParseUtil.cloudLocationToMogoLatLng(lastLocation), LocationParseUtil.cloudLocationToMogoLatLng(info));
Logger.d(TAG,
"准备计算{ lastInfo: " + lastLocation.print() + " info: " + info.print() + " targetDistance: " + targetDistance + " distance : " + distance + "}");
if (distance <= targetDistance) {
// 新的定位点在目标距离范围内,认为此数据有效
lastLocation = info;
anchorTime = SystemClock.elapsedRealtime();
errCount = 0;
Logger.d(TAG, "在范围内,为有效点");
return info;
} else {
// 出现异常点
if (errCount >= ERR_COUNT_THRESHOLD) {
// 出错次数超过阈值,认为本次出错点为正确点
lastLocation = info;
anchorTime = SystemClock.elapsedRealtime();
errCount = 0;
Logger.d(TAG, "出错次数超限,异常点变有效点");
return info;
} else {
// 按照上一个点的方向和速度,计算下一个点的位置,下一个点除坐标点外,其余数据与上一个点相同
// CloudLocationInfo nextInfo = new CloudLocationInfo(lastLocation);
// nextInfo.setLon(targetDistance * Math.sin(lastLocation.getHeading() * Math.PI / 180));
// nextInfo.setLat(targetDistance * Math.cos(lastLocation.getHeading() * Math.PI / 180));
// lastLocation = nextInfo;
anchorTime = SystemClock.elapsedRealtime();
errCount++;
Logger.d(TAG, "异常点纠偏 info: " + lastLocation);
return lastLocation;
// return nextInfo;
}
}
} catch (Exception e) {
Logger.e(TAG, e, "纠偏异常");
e.printStackTrace();
}
}else{
Logger.d(TAG, "定位点异常");
if (lastLocation == null) {
return null;
}else{
try {
float targetDistance =
(float) (lastLocation.getSpeed() * (SystemClock.elapsedRealtime() - anchorTime) / 1000) + TARGET_DISTANCE_DEVIATION;
float distance = MogoApisHandler.getInstance().getApis().getMapServiceApi().getMapUIController().calculateLineDistance(LocationParseUtil.cloudLocationToMogoLatLng(lastLocation), LocationParseUtil.cloudLocationToMogoLatLng(info));
Logger.d(TAG,
"异常定位点\n准备计算{ lastInfo: " + lastLocation.print() + " info: " + info.print() + " targetDistance: " + targetDistance + " distance : " + distance + "}");
// 按照上一个点的方向和速度,计算下一个点的位置,下一个点除坐标点外,其余数据与上一个点相同
// CloudLocationInfo nextInfo = new CloudLocationInfo(lastLocation);
// nextInfo.setLon(targetDistance * Math.sin(lastLocation.getHeading()));
// nextInfo.setLat(targetDistance * Math.cos(lastLocation.getHeading()));
// lastLocation = nextInfo;
anchorTime = SystemClock.elapsedRealtime();
errCount++;
Logger.d(TAG, "异常点纠偏 info: " + lastLocation);
// return nextInfo;
return lastLocation;
}catch (Exception e){
Logger.e(TAG, e, "纠偏异常");
e.printStackTrace();
}
}
}
return null;
}
private boolean isLocationValid(CloudLocationInfo info) {
return info.getLat() != 0 && info.getLon() != 0;
}
private float getDistance(CloudLocationInfo lastInfo, CloudLocationInfo info) {
float[] results=new float[1];
try{
Location.distanceBetween(lastInfo.getLat(), lastInfo.getLon(), info.getLat(), info.getLon(), results);
}catch(Exception e){
e.printStackTrace();
}
return results[0]*1000;
}
}

View File

@@ -3,7 +3,8 @@ package com.mogo.service.connection;
public enum WebSocketMsgType {
MSG_TYPE_UPLINK_CAR_DATA(0,"自车与ADAS数据"),
MSG_TYPE_DOWNLINK_CAR_DATA(1,"服务端下发车辆信息");
MSG_TYPE_DOWNLINK_CAR_DATA(1,"服务端下发车辆信息"),
MSG_TYPE_ACK(3, "ACK");
private int msgType;
private String msg;