changed the ack
This commit is contained in:
7
.idea/dictionaries/zhongchao.xml
generated
Normal file
7
.idea/dictionaries/zhongchao.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
<component name="ProjectDictionaryState">
|
||||
<dictionary name="zhongchao">
|
||||
<words>
|
||||
<w>mogo</w>
|
||||
</words>
|
||||
</dictionary>
|
||||
</component>
|
||||
@@ -49,6 +49,8 @@ public class MoGoApplication extends MultiDexApplication {
|
||||
clientConfig.setThirdPartyDeviceId(Devices.getSn());
|
||||
// 设置循环检测间隔时间
|
||||
clientConfig.setLoopCheckDelay(15 * 1000);
|
||||
// 设置是否属于高精定位设备
|
||||
clientConfig.setIsAccuracyDevice(false);
|
||||
|
||||
// 设置DNS经纬度位置
|
||||
clientConfig.setIHttpDnsCurrentLocation(new IHttpDnsCurrentLocation() {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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的位置信息,必须设置,否则将无法使用网络请求
|
||||
*
|
||||
|
||||
@@ -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.20-SNAPSHOT
|
||||
MOGO_NETWORK_VERSION=1.0.20-SNAPSHOT
|
||||
|
||||
@@ -66,4 +66,16 @@ class ADASRecognizedResult {
|
||||
*/
|
||||
public long mortonCode;
|
||||
|
||||
/**
|
||||
* 实际距离
|
||||
* 使用distanceX和distanceY计算
|
||||
*/
|
||||
public double distance;
|
||||
|
||||
/**
|
||||
* 数据来源精度
|
||||
* 0:普通定位
|
||||
* 1:高精定位
|
||||
*/
|
||||
public int dataAccuracy;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -27,4 +27,11 @@ public class LocationResult {
|
||||
* 1s 内的连续定位点
|
||||
*/
|
||||
public List< CloudLocationInfo > coordinates;
|
||||
|
||||
/**
|
||||
* 数据来源精度
|
||||
* 0:普通定位
|
||||
* 1:高精定位
|
||||
*/
|
||||
public int dataAccuracy = 0;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.mogo.realtime.socket;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.SystemClock;
|
||||
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClient;
|
||||
import com.mogo.cloud.socket.IMogoCloudSocketOnMessageListener;
|
||||
@@ -11,6 +10,7 @@ import com.mogo.cloud.socket.WebSocketData;
|
||||
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<>();
|
||||
@@ -97,30 +95,29 @@ public class SocketHandler {
|
||||
public void onMsgReceived(WebSocketData webSocketData) {
|
||||
int msgType = webSocketData.getMsgType();
|
||||
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;
|
||||
if (!MoGoAiCloudClient.getInstance().getAiCloudClientConfig().getIsUseExternalLocation()) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -157,7 +154,15 @@ public class SocketHandler {
|
||||
}
|
||||
locationResult.coordinates = new ArrayList<>();
|
||||
locationResult.sn = MoGoAiCloudClient.getInstance().getAiCloudClientConfig().getSn();
|
||||
boolean isAccuracyDevice = MoGoAiCloudClient.getInstance().getAiCloudClientConfig().getIsAccuracyDevice();
|
||||
locationResult.coordinates.addAll(cloudLocationInfo);
|
||||
if (isAccuracyDevice) {
|
||||
if (cloudLocationInfo.size() > 2) {
|
||||
locationResult.dataAccuracy = 1;
|
||||
} else {
|
||||
Logger.w(TAG, "MoGoAiCloudClient setAccuracyDevice is true , but the amount of data does not meet the requirements");
|
||||
}
|
||||
}
|
||||
}
|
||||
List<ADASRecognizedResult> recognizedResults = RealTimeProviderImp.getInstance().getLastADASRecognizedResult();//SPI接口返回
|
||||
OnePerSecondSendContent content = new OnePerSecondSendContent();
|
||||
@@ -172,7 +177,7 @@ 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);
|
||||
@@ -203,22 +208,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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user