This commit is contained in:
zhongchao
2021-02-24 14:25:22 +08:00
11 changed files with 147 additions and 37 deletions

View File

@@ -3,6 +3,7 @@
<words>
<w>amap</w>
<w>coor</w>
<w>mogo</w>
</words>
</dictionary>
</component>

View File

@@ -50,6 +50,8 @@ public class MoGoApplication extends MultiDexApplication {
clientConfig.setThirdPartyDeviceId(Devices.getSn());
// 设置循环检测间隔时间
clientConfig.setLoopCheckDelay(15 * 1000);
// 设置是否属于高精定位设备
clientConfig.setIsAccuracyDevice(false);
// 设置DNS经纬度位置
clientConfig.setIHttpDnsCurrentLocation(new IHttpDnsCurrentLocation() {

View File

@@ -27,6 +27,7 @@ class SPIRealTimeTestClass implements IRealTimeProvider {
recognizedResult.carId = "11";
recognizedResult.alt = 55;
recognizedResult.speed = 7.0;
recognizedResult.dataAccuracy = 0;
list.add(recognizedResult);
return list;
}
@@ -45,4 +46,9 @@ class SPIRealTimeTestClass implements IRealTimeProvider {
list.add(info);
return list;
}
@Override
public int getLocationAccuracy() {
return 0;
}
}

View File

@@ -82,6 +82,11 @@ public class MoGoAiCloudClientConfig {
*/
private boolean mIsUseExternalLocation;
/**
* 是否为高精定位设备
*/
private boolean mIsAccuracyDevice;
/**
* 设置HttpDns的位置监听
*/
@@ -304,6 +309,24 @@ public class MoGoAiCloudClientConfig {
mIsUseExternalLocation = isUseExternalLocation;
}
/**
* 获取是否为高精定位设备
*
* @return true-使用false-使用sdk的定位数据
*/
public boolean getIsAccuracyDevice() {
return mIsAccuracyDevice;
}
/**
* 设置是否为高精定位设备
*
* @param isAccuracyDevice true-属于高精定位设备false-不属于高精定位设备
*/
public void setIsAccuracyDevice(boolean isAccuracyDevice) {
mIsAccuracyDevice = isAccuracyDevice;
}
/**
* 返回HttpDns的位置信息必须设置否则将无法使用网络请求
*

View File

@@ -27,7 +27,7 @@ SNAPSHOT_REPOSITORY_URL=http://nexus.zhidaoauto.com/repository/maven-snapshots/
USERNAME=xintai
PASSWORD=xintai2018
# 编译模式: false - 依赖本地版本, true - 依赖 maven 版本
RELEASE=true
RELEASE=false
# AI CLOUD 云平台
# 工具类
MOGO_UTILS_VERSION=1.0.35-SNAPSHOT

View File

@@ -16,8 +16,13 @@ public interface IRealTimeProvider {
List<ADASRecognizedResult> getLastADASRecognizedResult();
/**
* 发送息,由外部传入
* 发送自车定位信息,由外部传入
*/
List<CloudLocationInfo> getLocationMsg();
/**
* 自车定位信息 精度
* @see com.mogo.realtime.entity.LocationResult dataAccuracy 字段
*/
int getLocationAccuracy();
}

View File

@@ -66,4 +66,16 @@ class ADASRecognizedResult {
*/
public long mortonCode;
/**
* 实际距离
* 使用distanceX和distanceY计算
*/
public double distance;
/**
* 数据来源精度
* 0普通定位
* 1高精定位
*/
public int dataAccuracy;
}

View File

@@ -0,0 +1,63 @@
package com.mogo.realtime.entity;
public class FrequencyData {
/**
* 采集单位:
* 1.毫秒
* 2.秒
* 3.分钟
* 4.小时
*/
private int unit = 1;
/**
* 采集时间间隔如时间单位选毫秒则时间间隔设置为200ms采集一次
*/
private long collectionInterval;
/**
* 采集设备上报时间如准时在200ms时上报采集的数据
*/
private long reportStartTime;
/**
* 采集设备类型:
* 1.车机
* 2.路设
* 3.全部
*/
private int type;
public int getUnit() {
return unit;
}
public void setUnit(int unit) {
this.unit = unit;
}
public long getCollectionInterval() {
return collectionInterval;
}
public void setCollectionInterval(long collectionInterval) {
this.collectionInterval = collectionInterval;
}
public long getReportStartTime() {
return reportStartTime;
}
public void setReportStartTime(long reportStartTime) {
this.reportStartTime = reportStartTime;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
}

View File

@@ -27,4 +27,11 @@ public class LocationResult {
* 1s 内的连续定位点
*/
public List< CloudLocationInfo > coordinates;
/**
* 数据来源精度
* 0普通定位
* 1高精定位
*/
public int dataAccuracy = 0;
}

View File

@@ -1,7 +1,6 @@
package com.mogo.realtime.socket;
import android.content.Context;
import android.os.SystemClock;
import com.mogo.cloud.GsonUtil;
import com.mogo.cloud.passport.MoGoAiCloudClient;
@@ -13,6 +12,7 @@ import com.mogo.cloud.utils.logger.Logger;
import com.mogo.realtime.core.SimpleLocationCorrectStrategy;
import com.mogo.realtime.entity.ADASRecognizedResult;
import com.mogo.realtime.entity.CloudLocationInfo;
import com.mogo.realtime.entity.FrequencyData;
import com.mogo.realtime.entity.LocationResult;
import com.mogo.realtime.entity.MogoSnapshotSetData;
import com.mogo.realtime.entity.OnePerSecondSendContent;
@@ -39,8 +39,6 @@ public class SocketHandler {
private static final int LOW_FREQUENCY_CHANNEL_ID = 0x040003; //低频数据
private String mAppId;
private long serverTime = 0;
private long receiveMsgTime = 0;
private CloudLocationInfo mLastInfo;
private final List<IMogoCloudOnMsgListener> onMsgListenerList = new ArrayList<>();
private final List<IMogoCloudOnAckListener> onAckListenerList = new ArrayList<>();
@@ -96,28 +94,29 @@ public class SocketHandler {
@Override
public void onMsgReceived(int msgType, WebSocketData webSocketData) {
if (msgType == MSG_TYPE_ACK.getMsgType()) {
if (webSocketData.getUtcTime() > 0) {
serverTime = webSocketData.getUtcTime();
receiveMsgTime = SystemClock.elapsedRealtime();
if (webSocketData.getUpUtcTime() > 0) {
long nextDelay = webSocketData.getUpUtcTime() - serverTime;
for (IMogoCloudOnAckListener ackListener : onAckListenerList) {
if (ackListener != null) {
ackListener.onAck(nextDelay);
}
FrequencyData frequencyData = GsonUtil.objectFromJson(webSocketData.getData(), FrequencyData.class);
if (frequencyData == null) {
Logger.e(TAG, "onMsgReceived FrequencyData == null ");
return;
}
long reportStartTime = frequencyData.getReportStartTime();
if (reportStartTime > 0) {
for (IMogoCloudOnAckListener ackListener : onAckListenerList) {
if (ackListener != null) {
ackListener.onAck(reportStartTime);
}
}
}
}
if (msgType == MSG_TYPE_DOWNLINK_CAR_DATA.getMsgType()) {
MogoSnapshotSetData data = GsonUtil.objectFromJson(webSocketData.getData(), MogoSnapshotSetData.class);
if (data == null) {
MogoSnapshotSetData snapshotSetData = GsonUtil.objectFromJson(webSocketData.getData(), MogoSnapshotSetData.class);
if (snapshotSetData == null) {
Logger.e(TAG, "onMsgReceived MogoSnapshotSetData == null ");
return;
}
for (IMogoCloudOnMsgListener listener : onMsgListenerList) {
if (listener != null) {
listener.onMsgReceived(data);
listener.onMsgReceived(snapshotSetData);
}
}
}
@@ -155,6 +154,7 @@ public class SocketHandler {
locationResult.coordinates = new ArrayList<>();
locationResult.sn = MoGoAiCloudClient.getInstance().getAiCloudClientConfig().getSn();
locationResult.coordinates.addAll(cloudLocationInfo);
locationResult.dataAccuracy = RealTimeProviderImp.getInstance().getLocationAccuracy();//SPI接口返回
}
List<ADASRecognizedResult> recognizedResults = RealTimeProviderImp.getInstance().getLastADASRecognizedResult();//SPI接口返回
OnePerSecondSendContent content = new OnePerSecondSendContent();
@@ -169,13 +169,14 @@ public class SocketHandler {
WebSocketData webSocketData = new WebSocketData();
webSocketData.setMsgType(MSG_TYPE_UPLINK_CAR_DATA.getMsgType());
webSocketData.setSeq(computeSendMsgTime());
webSocketData.setSeq(System.currentTimeMillis());
webSocketData.setSn(MoGoAiCloudClient.getInstance().getAiCloudClientConfig().getSn());
webSocketData.setData(GsonUtil.jsonFromObject(content));
String msg = GsonUtil.jsonFromObject(webSocketData);
boolean isAccuracyDevice = MoGoAiCloudClient.getInstance().getAiCloudClientConfig().getIsAccuracyDevice();
int msgType = LOW_FREQUENCY_CHANNEL_ID;
if (cloudLocationInfo.size() > 2) {
if (isAccuracyDevice && cloudLocationInfo.size() > 2) {
msgType = HIGH_FREQUENCY_CHANNEL_ID;
}
MsgBody msgBody = new MsgBody();
@@ -200,22 +201,4 @@ public class SocketHandler {
mInstance = null;
}
/**
* 服务端会在ack数据中增加服务端的时间戳{@link #serverTime}, 收到消息时,记录收到消息的时间{@link #receiveMsgTime},收消息的时间用{@link SystemClock#elapsedRealtime()}可以避免系统时间改变造成的影响
* 在发送数据时使用serverTime+(elapseRealtime()-receiveMsgTime)计算发送数据时的时间戳这个时间戳是基本相对服务端的时间戳为基准的时间忽略了ack下发时的时间延迟
* <p>
* 如果{@link #serverTime}或{@link #receiveMsgTime}数据有异常,则使用{@link System#currentTimeMillis()}当做当前时间,作为容错
*
* @return 基本相对服务端的时间戳为基准的时间
*/
private long computeSendMsgTime() {
long sendMsgTime;
if (serverTime > 0 && receiveMsgTime > 0) {
sendMsgTime = serverTime + (SystemClock.elapsedRealtime() - receiveMsgTime);
} else {
sendMsgTime = System.currentTimeMillis();
}
return sendMsgTime;
}
}

View File

@@ -47,4 +47,12 @@ public class RealTimeProviderImp implements IRealTimeProvider {
return null;
}
@Override
public int getLocationAccuracy() {
if (mDelegate != null) {
return mDelegate.getLocationAccuracy();
}
return 0;
}
}