add socket to invoke
This commit is contained in:
@@ -27,21 +27,21 @@ public class SimpleLocationCorrectStrategy {
|
||||
private long anchorTime;
|
||||
private int errCount;
|
||||
|
||||
private static SimpleLocationCorrectStrategy instance = new SimpleLocationCorrectStrategy();
|
||||
private final static SimpleLocationCorrectStrategy instance = new SimpleLocationCorrectStrategy();
|
||||
|
||||
public static SimpleLocationCorrectStrategy getInstance(){
|
||||
public static SimpleLocationCorrectStrategy getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private List<CloudLocationInfo> historyList = new ArrayList<>();
|
||||
private List<CloudLocationInfo> validList = new ArrayList<>();
|
||||
private List<CloudLocationInfo> correctList = new ArrayList<>();
|
||||
private List<CloudLocationInfo> errList = new ArrayList<>();
|
||||
private final List<CloudLocationInfo> historyList = new ArrayList<>();
|
||||
private final List<CloudLocationInfo> validList = new ArrayList<>();
|
||||
private final List<CloudLocationInfo> correctList = new ArrayList<>();
|
||||
private final List<CloudLocationInfo> errList = new ArrayList<>();
|
||||
|
||||
public CloudLocationInfo correct(CloudLocationInfo info) {
|
||||
Logger.d(TAG, "info: " + info.print());
|
||||
if(isLocationValid(info)) {
|
||||
if(recordLocation()) {
|
||||
if (isLocationValid(info)) {
|
||||
if (recordLocation()) {
|
||||
historyList.add(info);
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class SimpleLocationCorrectStrategy {
|
||||
lastLocation = info;
|
||||
anchorTime = SystemClock.elapsedRealtime();
|
||||
Logger.d(TAG, "第一条数据");
|
||||
if(recordLocation()) {
|
||||
if (recordLocation()) {
|
||||
validList.add(lastLocation);
|
||||
}
|
||||
return info;
|
||||
@@ -70,7 +70,7 @@ public class SimpleLocationCorrectStrategy {
|
||||
anchorTime = SystemClock.elapsedRealtime();
|
||||
errCount = 0;
|
||||
Logger.d(TAG, "在范围内,为有效点");
|
||||
if(recordLocation()) {
|
||||
if (recordLocation()) {
|
||||
validList.add(lastLocation);
|
||||
}
|
||||
return info;
|
||||
@@ -78,7 +78,7 @@ public class SimpleLocationCorrectStrategy {
|
||||
// 出现异常点
|
||||
if (errCount >= ERR_COUNT_THRESHOLD) {
|
||||
// 出错次数超过阈值,认为本次出错点为正确点
|
||||
if(recordLocation()) {
|
||||
if (recordLocation()) {
|
||||
errList.add(new CloudLocationInfo(lastLocation));
|
||||
correctList.add(info);
|
||||
}
|
||||
@@ -94,7 +94,7 @@ public class SimpleLocationCorrectStrategy {
|
||||
lastLocation.getLat(), lastLocation.getHeading(), targetDistance);
|
||||
nextInfo.setLon(nextLatLon.lon);
|
||||
nextInfo.setLat(nextLatLon.lat);
|
||||
if(recordLocation()) {
|
||||
if (recordLocation()) {
|
||||
errList.add(info);
|
||||
correctList.add(nextInfo);
|
||||
}
|
||||
@@ -103,7 +103,7 @@ public class SimpleLocationCorrectStrategy {
|
||||
errCount++;
|
||||
Logger.d(TAG, "异常点纠偏 info: " + lastLocation);
|
||||
// return lastLocation;
|
||||
if(recordLocation()) {
|
||||
if (recordLocation()) {
|
||||
correctList.add(nextInfo);
|
||||
}
|
||||
return nextInfo;
|
||||
@@ -113,11 +113,11 @@ public class SimpleLocationCorrectStrategy {
|
||||
Logger.e(TAG, e, "纠偏异常");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
Logger.d(TAG, "定位点异常");
|
||||
if (lastLocation == null) {
|
||||
return null;
|
||||
}else{
|
||||
} else {
|
||||
try {
|
||||
float targetDistance =
|
||||
(float) (lastLocation.getSpeed() * (SystemClock.elapsedRealtime() - anchorTime) / 1000) + TARGET_DISTANCE_DEVIATION;
|
||||
@@ -130,7 +130,7 @@ public class SimpleLocationCorrectStrategy {
|
||||
lastLocation.getLat(), lastLocation.getHeading(), targetDistance);
|
||||
nextInfo.setLon(nextLatLon.lon);
|
||||
nextInfo.setLat(nextLatLon.lat);
|
||||
if(recordLocation()) {
|
||||
if (recordLocation()) {
|
||||
errList.add(info);
|
||||
correctList.add(nextInfo);
|
||||
}
|
||||
@@ -138,12 +138,12 @@ public class SimpleLocationCorrectStrategy {
|
||||
anchorTime = SystemClock.elapsedRealtime();
|
||||
errCount++;
|
||||
Logger.d(TAG, "异常点纠偏 info: " + lastLocation);
|
||||
if(recordLocation()) {
|
||||
if (recordLocation()) {
|
||||
correctList.add(nextInfo);
|
||||
}
|
||||
// return lastLocation;
|
||||
return nextInfo;
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
Logger.e(TAG, e, "纠偏异常");
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -157,16 +157,16 @@ public class SimpleLocationCorrectStrategy {
|
||||
}
|
||||
|
||||
private RecordLocationListener recordLocationListener = null;
|
||||
private boolean hasCallbackReocrd = false;
|
||||
private boolean hasCallbackRecord = false;
|
||||
|
||||
public void setRecordLocationListener(RecordLocationListener recordLocationListener) {
|
||||
this.recordLocationListener = recordLocationListener;
|
||||
}
|
||||
|
||||
private boolean recordLocation(){
|
||||
if (historyList.size() >= 100 && !hasCallbackReocrd && recordLocationListener != null) {
|
||||
hasCallbackReocrd = true;
|
||||
recordLocationListener.onRecordFinish(historyList, correctList,validList,correctList);
|
||||
private boolean recordLocation() {
|
||||
if (historyList.size() >= 100 && !hasCallbackRecord && recordLocationListener != null) {
|
||||
hasCallbackRecord = true;
|
||||
recordLocationListener.onRecordFinish(historyList, correctList, validList, correctList);
|
||||
}
|
||||
return historyList.size() < 100;
|
||||
}
|
||||
@@ -198,9 +198,9 @@ public class SimpleLocationCorrectStrategy {
|
||||
double A = 1 + uSq / 16384 * (4096 + uSq * (-768 + uSq * (320 - 175 * uSq)));
|
||||
double B = uSq / 1024 * (256 + uSq * (-128 + uSq * (74 - 47 * uSq)));
|
||||
|
||||
double cos2SigmaM=0;
|
||||
double sinSigma=0;
|
||||
double cosSigma=0;
|
||||
double cos2SigmaM = 0;
|
||||
double sinSigma = 0;
|
||||
double cosSigma = 0;
|
||||
double sigma = dist / (b * A), sigmaP = 2 * Math.PI;
|
||||
while (Math.abs(sigma - sigmaP) > 1e-12) {
|
||||
cos2SigmaM = Math.cos(2 * sigma1 + sigma);
|
||||
@@ -224,15 +224,14 @@ public class SimpleLocationCorrectStrategy {
|
||||
double revAz = Math.atan2(sinAlpha, -tmp);
|
||||
|
||||
System.out.println(revAz);
|
||||
System.out.println(lon+deg(L)+","+deg(lat2));
|
||||
System.out.println(lon + deg(L) + "," + deg(lat2));
|
||||
return new MogoLatLng(deg(lat2), lon + deg(L));
|
||||
}
|
||||
|
||||
/**
|
||||
* 度换成弧度
|
||||
*
|
||||
* @param d
|
||||
* 度
|
||||
* @param d 度
|
||||
* @return 弧度
|
||||
*/
|
||||
private double rad(double d) {
|
||||
@@ -242,15 +241,14 @@ public class SimpleLocationCorrectStrategy {
|
||||
/**
|
||||
* 弧度换成度
|
||||
*
|
||||
* @param x
|
||||
* 弧度
|
||||
* @param x 弧度
|
||||
* @return 度
|
||||
*/
|
||||
private double deg(double x) {
|
||||
return x * 180 / Math.PI;
|
||||
}
|
||||
|
||||
public interface RecordLocationListener{
|
||||
public interface RecordLocationListener {
|
||||
void onRecordFinish(List<CloudLocationInfo> history, List<CloudLocationInfo> correct, List<CloudLocationInfo> valid, List<CloudLocationInfo> err);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,28 @@
|
||||
package com.mogo.realtime.constant;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.SystemClock;
|
||||
import android.util.Log;
|
||||
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClient;
|
||||
import com.mogo.cloud.socket.IMogoCloudSocketOnMessageListener;
|
||||
import com.mogo.cloud.socket.MsgBody;
|
||||
import com.mogo.cloud.socket.SocketManager;
|
||||
import com.mogo.realtime.Interface.RealTimeApisHandler;
|
||||
import com.mogo.realtime.entity.ADASRecognizedResult;
|
||||
import com.mogo.realtime.entity.CloudLocationInfo;
|
||||
import com.mogo.realtime.entity.WebSocketData;
|
||||
import com.mogo.realtime.location.LocationResult;
|
||||
import com.mogo.realtime.location.MogoRTKLocation;
|
||||
import com.mogo.realtime.entity.OnePerSecondSendContent;
|
||||
import com.mogo.realtime.util.MortonCode;
|
||||
import com.mogo.utils.network.utils.GsonUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.mogo.realtime.connect.WebSocketMsgType.MSG_TYPE_ACK;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/12/14
|
||||
@@ -27,6 +35,8 @@ public class SnapshotUploadInTime implements MogoRTKLocation.RTKLocationListener
|
||||
|
||||
private static volatile SnapshotUploadInTime sInstance;
|
||||
private Context mContext;
|
||||
private long serverTime = 0;
|
||||
private long receiveMsgTime = 0;
|
||||
|
||||
private SnapshotUploadInTime() {
|
||||
}
|
||||
@@ -54,11 +64,40 @@ public class SnapshotUploadInTime implements MogoRTKLocation.RTKLocationListener
|
||||
public void start(Context context) {
|
||||
mContext = context.getApplicationContext();
|
||||
MogoRTKLocation.getInstance().registerRTKLocationListener(this);
|
||||
//todo
|
||||
SocketManager.getInstance().init(context,"com.mogo.launcher");
|
||||
SocketManager.getInstance().registerOnMessageListener(0x040002,onMessageListener);
|
||||
SocketManager.getInstance().registerOnMessageListener(0x040003,onMessageListener);
|
||||
}
|
||||
|
||||
private final IMogoCloudSocketOnMessageListener<String> onMessageListener = new IMogoCloudSocketOnMessageListener<String>() {
|
||||
@Override
|
||||
public Class<String> target() {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMsgReceived(String message) {
|
||||
WebSocketData webSocketData = GsonUtil.objectFromJson(message, WebSocketData.class);
|
||||
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;
|
||||
MogoRTKLocation.getInstance().resetUploadDelay(nextDelay);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public void stop() {
|
||||
MogoRTKLocation.getInstance().unregisterRTKLocationListener();
|
||||
MogoRTKLocation.getInstance().stop();
|
||||
SocketManager.getInstance().unregisterOnMessageListener(0x040002,onMessageListener);
|
||||
SocketManager.getInstance().unregisterOnMessageListener(0x040003,onMessageListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -101,7 +140,49 @@ public class SnapshotUploadInTime implements MogoRTKLocation.RTKLocationListener
|
||||
Log.d(TAG, "no information 2 sent");
|
||||
return;
|
||||
}
|
||||
//todo 发送socket msg
|
||||
//发送socket msg
|
||||
WebSocketData webSocketData = new WebSocketData();
|
||||
webSocketData.setSeq(computeSendMsgTime());
|
||||
webSocketData.setSn(MoGoAiCloudClient.getInstance().getAiCloudClientConfig().getSn());
|
||||
webSocketData.setData(GsonUtil.jsonFromObject(content));
|
||||
// MogoLocation lastKnown = MogoApisHandler.getInstance().getApis().getMapServiceApi()
|
||||
// .getSingletonLocationClient(mContext)
|
||||
// .getLastKnowLocation();
|
||||
// if (lastKnown != null && !lastKnown.getCityCode().isEmpty()) {
|
||||
// webSocketData.setCityCode(lastKnown.getCityCode());
|
||||
// } else {
|
||||
// webSocketData.setCityCode(null);
|
||||
// }
|
||||
String msg = GsonUtil.jsonFromObject(webSocketData);
|
||||
|
||||
int msgType = 0x040003; //低频数据
|
||||
if (cloudLocationInfo.size() > 2) {
|
||||
msgType = 0x040002; //高频数据
|
||||
}
|
||||
MsgBody msgBody = new MsgBody();
|
||||
msgBody.msgType(msgType);
|
||||
msgBody.content(msg);
|
||||
SocketManager.getInstance().sendMsg(msgBody,msgId -> {
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 服务端会在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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ package com.mogo.realtime.entity;
|
||||
import java.util.List;
|
||||
|
||||
public
|
||||
/**
|
||||
/*
|
||||
* @author congtaowang
|
||||
* @since 2020/10/25
|
||||
*
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.mogo.realtime.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class WebSocketData implements Serializable {
|
||||
|
||||
private long seq;
|
||||
|
||||
private int msgType;
|
||||
|
||||
private String sn;
|
||||
|
||||
private String data;
|
||||
|
||||
private long utcTime;
|
||||
|
||||
private long upUtcTime;
|
||||
|
||||
private String cityCode;
|
||||
|
||||
public long getSeq() {
|
||||
return seq;
|
||||
}
|
||||
|
||||
public void setSeq(long seq) {
|
||||
this.seq = seq;
|
||||
}
|
||||
|
||||
public int getMsgType() {
|
||||
return msgType;
|
||||
}
|
||||
|
||||
public void setMsgType(int msgType) {
|
||||
this.msgType = msgType;
|
||||
}
|
||||
|
||||
public String getSn() {
|
||||
return sn;
|
||||
}
|
||||
|
||||
public void setSn(String sn) {
|
||||
this.sn = sn;
|
||||
}
|
||||
|
||||
public String getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public long getUtcTime() {
|
||||
return utcTime;
|
||||
}
|
||||
|
||||
public void setUtcTime(long utcTime) {
|
||||
this.utcTime = utcTime;
|
||||
}
|
||||
|
||||
public long getUpUtcTime() {
|
||||
return upUtcTime;
|
||||
}
|
||||
|
||||
public void setUpUtcTime(long upUtcTime) {
|
||||
this.upUtcTime = upUtcTime;
|
||||
}
|
||||
|
||||
public String getCityCode() {
|
||||
return cityCode;
|
||||
}
|
||||
|
||||
public void setCityCode(String cityCode) {
|
||||
this.cityCode = cityCode;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user