Merge remote-tracking branch 'origin/master'
This commit is contained in:
1
.idea/gradle.xml
generated
1
.idea/gradle.xml
generated
@@ -23,6 +23,7 @@
|
|||||||
</set>
|
</set>
|
||||||
</option>
|
</option>
|
||||||
<option name="resolveModulePerSourceSet" value="false" />
|
<option name="resolveModulePerSourceSet" value="false" />
|
||||||
|
<option name="useQualifiedModuleNames" value="true" />
|
||||||
</GradleProjectSettings>
|
</GradleProjectSettings>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
@@ -26,6 +26,11 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import static com.mogo.cloud.httpdns.MogoHttpDnsConfig.HTTP_DNS_ENV_DEMO;
|
||||||
|
import static com.mogo.cloud.httpdns.MogoHttpDnsConfig.HTTP_DNS_ENV_DEV;
|
||||||
|
import static com.mogo.cloud.httpdns.MogoHttpDnsConfig.HTTP_DNS_ENV_QA;
|
||||||
|
import static com.mogo.cloud.httpdns.MogoHttpDnsConfig.HTTP_DNS_ENV_RELEASE;
|
||||||
|
|
||||||
public class SocketManager implements IMogoCloudSocketManager, Callback {
|
public class SocketManager implements IMogoCloudSocketManager, Callback {
|
||||||
|
|
||||||
private static final String TAG = "SocketManager";
|
private static final String TAG = "SocketManager";
|
||||||
@@ -177,12 +182,12 @@ public class SocketManager implements IMogoCloudSocketManager, Callback {
|
|||||||
|
|
||||||
private Environment getEnvironment() {
|
private Environment getEnvironment() {
|
||||||
switch (cloudClientConfig.getNetMode()) {
|
switch (cloudClientConfig.getNetMode()) {
|
||||||
case 1:
|
case HTTP_DNS_ENV_DEV:
|
||||||
return Environment.dev;
|
return Environment.dev;
|
||||||
case 2:
|
case HTTP_DNS_ENV_QA:
|
||||||
case 4:
|
case HTTP_DNS_ENV_DEMO:
|
||||||
return Environment.qa;
|
return Environment.qa;
|
||||||
case 3:
|
case HTTP_DNS_ENV_RELEASE:
|
||||||
default:
|
default:
|
||||||
return Environment.release;
|
return Environment.release;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,17 @@ android {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
allprojects {
|
||||||
|
repositories {
|
||||||
|
maven {
|
||||||
|
url 'http://nexus.zhidaoauto.com/repository/maven-releases/'
|
||||||
|
}
|
||||||
|
maven {
|
||||||
|
url 'http://nexus.zhidaoauto.com/repository/maven-public/'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation fileTree(dir: "libs", include: ["*.jar"])
|
implementation fileTree(dir: "libs", include: ["*.jar"])
|
||||||
implementation project(path: ':foudations:mogo-passport')
|
implementation project(path: ':foudations:mogo-passport')
|
||||||
@@ -36,5 +47,7 @@ dependencies {
|
|||||||
implementation project(":foudations:mogo-socket")
|
implementation project(":foudations:mogo-socket")
|
||||||
implementation project(":foudations:mogo-commons")
|
implementation project(":foudations:mogo-commons")
|
||||||
}
|
}
|
||||||
|
implementation 'com.elegant.spi:api:1.0.9' //运行时库
|
||||||
|
annotationProcessor 'com.elegant.spi:compiler:1.0.3' //编译时库
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package com.mogo.realtime.Imp;
|
||||||
|
|
||||||
|
|
||||||
|
import com.elegant.spi.AbstractDelegateManager;
|
||||||
|
import com.mogo.cloud.passport.MoGoAiCloudClient;
|
||||||
|
import com.mogo.realtime.Interface.RealTimeProvider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author liujing
|
||||||
|
* @description 描述
|
||||||
|
* @since: 2021/1/25
|
||||||
|
*/
|
||||||
|
class RealTimeDelegateManager extends AbstractDelegateManager<RealTimeProvider> {
|
||||||
|
private static RealTimeDelegateManager sInstance = null;
|
||||||
|
private Class<? extends RealTimeProvider> mRealTimeProvider = null;
|
||||||
|
|
||||||
|
public static RealTimeDelegateManager getInstance() {
|
||||||
|
if (sInstance == null) {
|
||||||
|
synchronized (RealTimeDelegateManager.class) {
|
||||||
|
if (sInstance == null) {
|
||||||
|
sInstance = new RealTimeDelegateManager();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RealTimeDelegateManager() {
|
||||||
|
loadDelegateClasses(MoGoAiCloudClient.getInstance().getContext(), RealTimeProvider.class, new DelegateListener<Class<? extends RealTimeProvider>>() {
|
||||||
|
@Override
|
||||||
|
public void onDelegate(String unit, Class<? extends RealTimeProvider> p) {
|
||||||
|
mRealTimeProvider = p;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,40 +1,21 @@
|
|||||||
package com.mogo.realtime.constant;
|
package com.mogo.realtime.constant;
|
||||||
|
|
||||||
import android.content.Context;
|
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.entity.ADASRecognizedResult;
|
|
||||||
import com.mogo.realtime.entity.CloudLocationInfo;
|
import com.mogo.realtime.entity.CloudLocationInfo;
|
||||||
import com.mogo.cloud.socket.WebSocketData;
|
|
||||||
import com.mogo.realtime.location.LocationResult;
|
|
||||||
import com.mogo.realtime.location.MogoRTKLocation;
|
import com.mogo.realtime.location.MogoRTKLocation;
|
||||||
import com.mogo.realtime.entity.OnePerSecondSendContent;
|
import com.mogo.realtime.socket.IMogoCloudOnMsgListener;
|
||||||
import com.mogo.realtime.socket.SocketHandler;
|
import com.mogo.realtime.socket.SocketHandler;
|
||||||
import com.mogo.realtime.util.MortonCode;
|
|
||||||
import com.mogo.utils.network.utils.GsonUtil;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author congtaowang
|
*
|
||||||
* @since 2020/12/14
|
|
||||||
* <p>
|
|
||||||
* 实时上报坐标、识别物体
|
|
||||||
*/
|
*/
|
||||||
public class SnapshotUploadInTime implements MogoRTKLocation.RTKLocationListener {
|
public class SnapshotUploadInTime implements MogoRTKLocation.RTKLocationListener {
|
||||||
|
|
||||||
private static final String TAG = "SnapshotUploadInTime";
|
private static final String TAG = "SnapshotUploadInTime";
|
||||||
|
|
||||||
private static volatile SnapshotUploadInTime sInstance;
|
private static volatile SnapshotUploadInTime sInstance;
|
||||||
private Context mContext;
|
|
||||||
private long serverTime = 0;
|
|
||||||
private long receiveMsgTime = 0;
|
|
||||||
|
|
||||||
private SnapshotUploadInTime() {
|
private SnapshotUploadInTime() {
|
||||||
}
|
}
|
||||||
@@ -54,13 +35,8 @@ public class SnapshotUploadInTime implements MogoRTKLocation.RTKLocationListener
|
|||||||
sInstance = null;
|
sInstance = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object readResolve() {
|
//todo 检查是否需要配置 默认开始定位上报
|
||||||
// 阻止反序列化,必须实现 Serializable 接口
|
public void start(Context context, boolean useInner, String appId, IMogoCloudOnMsgListener listener) {
|
||||||
return sInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void start(Context context, boolean useInner, String appId, IMogoCloudSocketOnMessageListener listener) {
|
|
||||||
mContext = context.getApplicationContext();
|
|
||||||
MogoRTKLocation.getInstance().registerRTKLocationListener(this);
|
MogoRTKLocation.getInstance().registerRTKLocationListener(this);
|
||||||
SocketHandler.getInstance().initSocket(context, useInner, appId, listener);
|
SocketHandler.getInstance().initSocket(context, useInner, appId, listener);
|
||||||
}
|
}
|
||||||
@@ -71,87 +47,7 @@ public class SnapshotUploadInTime implements MogoRTKLocation.RTKLocationListener
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLocationChanged(List<CloudLocationInfo> cloudLocationInfos) {
|
public void onLocationChanged(List<CloudLocationInfo> cloudLocationInfos) {
|
||||||
startSendCarLocationAndAdasRecognizedResult2Server(cloudLocationInfos);
|
SocketHandler.getInstance().sendMsg(cloudLocationInfos);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CloudLocationInfo mLastInfo;
|
|
||||||
|
|
||||||
private void startSendCarLocationAndAdasRecognizedResult2Server(List<CloudLocationInfo> cloudLocationInfo) {
|
|
||||||
CloudLocationInfo lastInfo = null;
|
|
||||||
// 如果数组内容不为空,就用数组最后一个值
|
|
||||||
if (!cloudLocationInfo.isEmpty()) {
|
|
||||||
lastInfo = cloudLocationInfo.get(cloudLocationInfo.size() - 1);
|
|
||||||
mLastInfo = lastInfo;
|
|
||||||
}
|
|
||||||
if (lastInfo == null) {
|
|
||||||
lastInfo = mLastInfo;
|
|
||||||
}
|
|
||||||
LocationResult locationResult = null;
|
|
||||||
if (lastInfo != null) {
|
|
||||||
// 定位点预测纠偏
|
|
||||||
lastInfo = SimpleLocationCorrectStrategy.getInstance().correct(lastInfo);
|
|
||||||
locationResult = new LocationResult();
|
|
||||||
if (lastInfo != null) {
|
|
||||||
locationResult.lastCoordinate = lastInfo;
|
|
||||||
locationResult.mortonCode = MortonCode.wrapEncodeMorton(lastInfo.getLon(), lastInfo.getLat());
|
|
||||||
}
|
|
||||||
locationResult.coordinates = new ArrayList<>();
|
|
||||||
locationResult.sn = MoGoAiCloudClient.getInstance().getAiCloudClientConfig().getSn();
|
|
||||||
locationResult.coordinates.addAll(cloudLocationInfo);
|
|
||||||
}
|
|
||||||
List<ADASRecognizedResult> recognizedResults = SocketHandler.getInstance().getRealTimeProvider().getLastADASRecognizedResult();//外显接口返回
|
|
||||||
OnePerSecondSendContent content = new OnePerSecondSendContent();
|
|
||||||
content.self = locationResult;
|
|
||||||
content.adas = recognizedResults;
|
|
||||||
|
|
||||||
if (content.self == null &&
|
|
||||||
(content.adas == null || content.adas.isEmpty())) {
|
|
||||||
Log.d(TAG, "no information 2 sent");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//发送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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,240 @@
|
|||||||
|
package com.mogo.realtime.entity;
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 云端道路数据
|
||||||
|
*
|
||||||
|
* @author tongchenfei
|
||||||
|
*/
|
||||||
|
public class CloudRoadData implements Parcelable {
|
||||||
|
|
||||||
|
public static final int FROM_MY_LOCATION = 1;
|
||||||
|
public static final int FROM_ADAS = 2;
|
||||||
|
public static final int FROM_ROAD_UNIT = 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 物体类型
|
||||||
|
*/
|
||||||
|
private int type = -1;
|
||||||
|
|
||||||
|
private int fromType;
|
||||||
|
|
||||||
|
private double lat;
|
||||||
|
private double lon;
|
||||||
|
|
||||||
|
private String uuid;
|
||||||
|
private String sn;
|
||||||
|
|
||||||
|
private double speed;
|
||||||
|
private double heading;
|
||||||
|
|
||||||
|
private long systemTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 红绿灯状态 1红 2绿 3黄
|
||||||
|
*/
|
||||||
|
private int lightStatus;//
|
||||||
|
/**
|
||||||
|
* 红绿灯剩余时间 读秒
|
||||||
|
*/
|
||||||
|
private int lightLeftTime;
|
||||||
|
/**
|
||||||
|
* 视频流直播地址
|
||||||
|
*/
|
||||||
|
private String rtmpUrl;//
|
||||||
|
|
||||||
|
private double distance;//距离
|
||||||
|
|
||||||
|
private List< CloudLocationInfo > coordinates;
|
||||||
|
|
||||||
|
|
||||||
|
public int getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType( int type ) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getLat() {
|
||||||
|
return lat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLat( double lat ) {
|
||||||
|
this.lat = lat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getLon() {
|
||||||
|
return lon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLon( double lon ) {
|
||||||
|
this.lon = lon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getSpeed() {
|
||||||
|
return speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSpeed( double speed ) {
|
||||||
|
this.speed = speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getSystemTime() {
|
||||||
|
return systemTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSystemTime( long systemTime ) {
|
||||||
|
this.systemTime = systemTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLightStatus() {
|
||||||
|
return lightStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLightStatus( int lightStatus ) {
|
||||||
|
this.lightStatus = lightStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLightLeftTime() {
|
||||||
|
return lightLeftTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLightLeftTime( int lightLeftTime ) {
|
||||||
|
this.lightLeftTime = lightLeftTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRtmpUrl() {
|
||||||
|
return rtmpUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRtmpUrl( String rtmpUrl ) {
|
||||||
|
this.rtmpUrl = rtmpUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getDistance() {
|
||||||
|
return distance * 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDistance( double distance ) {
|
||||||
|
this.distance = distance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List< CloudLocationInfo > getCoordinates() {
|
||||||
|
return coordinates;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCoordinates( List< CloudLocationInfo > coordinates ) {
|
||||||
|
this.coordinates = coordinates;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUuid( String uuid ) {
|
||||||
|
this.uuid = uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUuid() {
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSn() {
|
||||||
|
return sn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getHeading() {
|
||||||
|
return heading;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHeading( double heading ) {
|
||||||
|
this.heading = heading;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUniqueKey() {
|
||||||
|
if ( !TextUtils.isEmpty( uuid ) ) {
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
return sn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getFromType() {
|
||||||
|
return fromType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFromType( int fromType ) {
|
||||||
|
this.fromType = fromType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CloudRoadData() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel( Parcel dest, int flags ) {
|
||||||
|
dest.writeInt( this.type );
|
||||||
|
dest.writeInt( this.fromType );
|
||||||
|
dest.writeDouble( this.lat );
|
||||||
|
dest.writeDouble( this.lon );
|
||||||
|
dest.writeString( this.uuid );
|
||||||
|
dest.writeString( this.sn );
|
||||||
|
dest.writeDouble( this.speed );
|
||||||
|
dest.writeDouble( this.heading );
|
||||||
|
dest.writeLong( this.systemTime );
|
||||||
|
dest.writeInt( this.lightStatus );
|
||||||
|
dest.writeInt( this.lightLeftTime );
|
||||||
|
dest.writeString( this.rtmpUrl );
|
||||||
|
dest.writeDouble( this.distance );
|
||||||
|
dest.writeTypedList( this.coordinates );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected CloudRoadData(Parcel in ) {
|
||||||
|
this.type = in.readInt();
|
||||||
|
this.fromType = in.readInt();
|
||||||
|
this.lat = in.readDouble();
|
||||||
|
this.lon = in.readDouble();
|
||||||
|
this.uuid = in.readString();
|
||||||
|
this.sn = in.readString();
|
||||||
|
this.speed = in.readDouble();
|
||||||
|
this.heading = in.readDouble();
|
||||||
|
this.systemTime = in.readLong();
|
||||||
|
this.lightStatus = in.readInt();
|
||||||
|
this.lightLeftTime = in.readInt();
|
||||||
|
this.rtmpUrl = in.readString();
|
||||||
|
this.distance = in.readDouble();
|
||||||
|
this.coordinates = in.createTypedArrayList( CloudLocationInfo.CREATOR );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Creator<CloudRoadData> CREATOR = new Creator<CloudRoadData>() {
|
||||||
|
@Override
|
||||||
|
public CloudRoadData createFromParcel(Parcel source ) {
|
||||||
|
return new CloudRoadData( source );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CloudRoadData[] newArray(int size ) {
|
||||||
|
return new CloudRoadData[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals( Object o ) {
|
||||||
|
if ( this == o ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if ( o == null || getClass() != o.getClass() ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
CloudRoadData that = (CloudRoadData) o;
|
||||||
|
return Double.compare( that.lat, lat ) == 0 &&
|
||||||
|
Double.compare( that.lon, lon ) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,151 @@
|
|||||||
|
package com.mogo.realtime.entity;
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public
|
||||||
|
/*
|
||||||
|
* @author congtaowang
|
||||||
|
* @since 2020/10/26
|
||||||
|
*
|
||||||
|
* 描述
|
||||||
|
*/
|
||||||
|
class MogoSnapshotSetData implements Parcelable {
|
||||||
|
|
||||||
|
private String msgId;
|
||||||
|
|
||||||
|
private long time;
|
||||||
|
|
||||||
|
//过期时间
|
||||||
|
private long expire;
|
||||||
|
|
||||||
|
//总数据集合
|
||||||
|
private List<CloudRoadData> allList;
|
||||||
|
|
||||||
|
// 近景adas数据
|
||||||
|
private List<CloudRoadData> nearList;
|
||||||
|
|
||||||
|
//红绿灯
|
||||||
|
private CloudRoadData trafficLight;
|
||||||
|
|
||||||
|
//路边摄像头
|
||||||
|
private CloudRoadData camera;
|
||||||
|
|
||||||
|
// 自车速度 本地添加
|
||||||
|
public double curSpeed = 0.0;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "MogoSnapshotSetData{" +
|
||||||
|
"msgId='" + msgId + '\'' +
|
||||||
|
", time=" + time +
|
||||||
|
", expire=" + expire +
|
||||||
|
", allList=" + allList +
|
||||||
|
", nearList=" + nearList +
|
||||||
|
", camera=" + camera +
|
||||||
|
", curSpeed=" + curSpeed +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMsgId() {
|
||||||
|
return msgId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMsgId(String msgId) {
|
||||||
|
this.msgId = msgId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTime() {
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTime(long time) {
|
||||||
|
this.time = time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getExpire() {
|
||||||
|
return expire;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExpire(long expire) {
|
||||||
|
this.expire = expire;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<CloudRoadData> getAllList() {
|
||||||
|
return allList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAllList(List<CloudRoadData> allList) {
|
||||||
|
this.allList = allList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CloudRoadData getTrafficLight() {
|
||||||
|
return trafficLight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTrafficLight(CloudRoadData trafficLight) {
|
||||||
|
this.trafficLight = trafficLight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CloudRoadData getCamera() {
|
||||||
|
return camera;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCamera(CloudRoadData camera) {
|
||||||
|
this.camera = camera;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List< CloudRoadData > getNearList() {
|
||||||
|
return nearList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNearList( List< CloudRoadData > nearList ) {
|
||||||
|
this.nearList = nearList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MogoSnapshotSetData() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel( Parcel dest, int flags ) {
|
||||||
|
dest.writeString( this.msgId );
|
||||||
|
dest.writeLong( this.time );
|
||||||
|
dest.writeLong( this.expire );
|
||||||
|
dest.writeTypedList( this.allList );
|
||||||
|
dest.writeTypedList( this.nearList );
|
||||||
|
dest.writeParcelable( this.trafficLight, flags );
|
||||||
|
dest.writeParcelable( this.camera, flags );
|
||||||
|
dest.writeDouble( this.curSpeed );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected MogoSnapshotSetData(Parcel in ) {
|
||||||
|
this.msgId = in.readString();
|
||||||
|
this.time = in.readLong();
|
||||||
|
this.expire = in.readLong();
|
||||||
|
this.allList = in.createTypedArrayList( CloudRoadData.CREATOR );
|
||||||
|
this.nearList = in.createTypedArrayList( CloudRoadData.CREATOR );
|
||||||
|
this.trafficLight = in.readParcelable( CloudRoadData.class.getClassLoader() );
|
||||||
|
this.camera = in.readParcelable( CloudRoadData.class.getClassLoader() );
|
||||||
|
this.curSpeed = in.readDouble();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Creator<MogoSnapshotSetData> CREATOR = new Creator<MogoSnapshotSetData>() {
|
||||||
|
@Override
|
||||||
|
public MogoSnapshotSetData createFromParcel(Parcel source ) {
|
||||||
|
return new MogoSnapshotSetData( source );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MogoSnapshotSetData[] newArray(int size ) {
|
||||||
|
return new MogoSnapshotSetData[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
package com.mogo.realtime.entity;
|
package com.mogo.realtime.entity;
|
||||||
|
|
||||||
|
|
||||||
import com.mogo.realtime.location.LocationResult;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public
|
public
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
package com.mogo.realtime.location;
|
|
||||||
|
|
||||||
import com.mogo.realtime.entity.CloudLocationInfo;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public
|
|
||||||
/**
|
|
||||||
* @author congtaowang
|
|
||||||
* @since 2020/10/25
|
|
||||||
*
|
|
||||||
* 自车定位信息
|
|
||||||
*/
|
|
||||||
class LocationResult {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* sn
|
|
||||||
*/
|
|
||||||
public String sn;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 最后一个定位点的莫顿码
|
|
||||||
*/
|
|
||||||
public long mortonCode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 最后一个定位点
|
|
||||||
*/
|
|
||||||
public CloudLocationInfo lastCoordinate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 1s 内的连续定位点
|
|
||||||
*/
|
|
||||||
public List< CloudLocationInfo > coordinates;
|
|
||||||
}
|
|
||||||
@@ -46,8 +46,6 @@ public class MogoRTKLocation {
|
|||||||
if (msg.what == MSG_DATA_CHANGED) {
|
if (msg.what == MSG_DATA_CHANGED) {
|
||||||
mHandler.sendEmptyMessageDelayed(MSG_DATA_CHANGED, uploadDelay);
|
mHandler.sendEmptyMessageDelayed(MSG_DATA_CHANGED, uploadDelay);
|
||||||
sendLocationData();
|
sendLocationData();
|
||||||
|
|
||||||
// Logger.d(TAG,"handleMessage开始发送消息");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.mogo.realtime.socket;
|
||||||
|
|
||||||
|
import com.mogo.realtime.entity.MogoSnapshotSetData;
|
||||||
|
|
||||||
|
public interface IMogoCloudOnMsgListener {
|
||||||
|
|
||||||
|
void onMsgReceived(MogoSnapshotSetData mogoSnapshotSetData);
|
||||||
|
}
|
||||||
@@ -2,28 +2,41 @@ package com.mogo.realtime.socket;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.SystemClock;
|
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.IMogoCloudSocketOnMessageListener;
|
||||||
|
import com.mogo.cloud.socket.MsgBody;
|
||||||
import com.mogo.cloud.socket.SocketManager;
|
import com.mogo.cloud.socket.SocketManager;
|
||||||
import com.mogo.cloud.socket.WebSocketData;
|
import com.mogo.cloud.socket.WebSocketData;
|
||||||
import com.mogo.realtime.Interface.RealTimeProvider;
|
import com.mogo.realtime.constant.SimpleLocationCorrectStrategy;
|
||||||
|
import com.mogo.realtime.entity.ADASRecognizedResult;
|
||||||
|
import com.mogo.realtime.entity.CloudLocationInfo;
|
||||||
|
import com.mogo.realtime.entity.LocationResult;
|
||||||
|
import com.mogo.realtime.entity.MogoSnapshotSetData;
|
||||||
|
import com.mogo.realtime.entity.OnePerSecondSendContent;
|
||||||
|
import com.mogo.realtime.util.MortonCode;
|
||||||
import com.mogo.utils.network.utils.GsonUtil;
|
import com.mogo.utils.network.utils.GsonUtil;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.mogo.cloud.socket.WebSocketMsgType.MSG_TYPE_ACK;
|
import static com.mogo.cloud.socket.WebSocketMsgType.MSG_TYPE_ACK;
|
||||||
|
import static com.mogo.cloud.socket.WebSocketMsgType.MSG_TYPE_DOWNLINK_CAR_DATA;
|
||||||
|
import static com.mogo.cloud.socket.WebSocketMsgType.MSG_TYPE_UPLINK_CAR_DATA;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author liujing
|
*
|
||||||
* @description 描述
|
|
||||||
* @since: 2021/1/22
|
|
||||||
*/
|
*/
|
||||||
public class SocketHandler {
|
public class SocketHandler {
|
||||||
|
|
||||||
|
private static final String TAG = "SocketHandler";
|
||||||
private static volatile SocketHandler mInstance;
|
private static volatile SocketHandler mInstance;
|
||||||
|
|
||||||
private long serverTime = 0;
|
private long serverTime = 0;
|
||||||
private long receiveMsgTime = 0;
|
private long receiveMsgTime = 0;
|
||||||
private List<IMogoCloudSocketOnMessageListener> listenerList;
|
private CloudLocationInfo mLastInfo;
|
||||||
public RealTimeProvider realTimeProvider;
|
private final List<IMogoCloudOnMsgListener> listenerList = new ArrayList<>();
|
||||||
|
|
||||||
public static SocketHandler getInstance() {
|
public static SocketHandler getInstance() {
|
||||||
if (mInstance == null) {
|
if (mInstance == null) {
|
||||||
@@ -36,34 +49,26 @@ public class SocketHandler {
|
|||||||
return mInstance;
|
return mInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RealTimeProvider getRealTimeProvider() {
|
|
||||||
return realTimeProvider;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* useInner: 是否注册自己内部的监听
|
* useInner: 是否注册自己内部的监听
|
||||||
* */
|
* */
|
||||||
public void initSocket(Context context, boolean useInner, String appId, IMogoCloudSocketOnMessageListener listener) {
|
public void initSocket(Context context, boolean useInner, String appId, IMogoCloudOnMsgListener listener) {
|
||||||
SocketManager.getInstance().init(context, appId);
|
SocketManager.getInstance().init(context, appId);
|
||||||
if (useInner) {
|
SocketManager.getInstance().registerOnMessageListener(0x040002, onMessageListener);
|
||||||
SocketManager.getInstance().registerOnMessageListener(0x040002, onMessageListener);
|
SocketManager.getInstance().registerOnMessageListener(0x040003, onMessageListener);
|
||||||
SocketManager.getInstance().registerOnMessageListener(0x040003, onMessageListener);
|
if (listener != null && !listenerList.contains(listener)) {
|
||||||
} else {
|
|
||||||
SocketManager.getInstance().registerOnMessageListener(0x040002, listener);
|
|
||||||
SocketManager.getInstance().registerOnMessageListener(0x040003, listener);
|
|
||||||
listenerList.add(listener);
|
listenerList.add(listener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final IMogoCloudSocketOnMessageListener<String> onMessageListener = new IMogoCloudSocketOnMessageListener<String>() {
|
private final IMogoCloudSocketOnMessageListener<WebSocketData> onMessageListener = new IMogoCloudSocketOnMessageListener<WebSocketData>() {
|
||||||
@Override
|
@Override
|
||||||
public Class<String> target() {
|
public Class<WebSocketData> target() {
|
||||||
return String.class;
|
return WebSocketData.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMsgReceived(String message) {
|
public void onMsgReceived(WebSocketData webSocketData) {
|
||||||
WebSocketData webSocketData = GsonUtil.objectFromJson(message, WebSocketData.class);
|
|
||||||
int msgType = webSocketData.getMsgType();
|
int msgType = webSocketData.getMsgType();
|
||||||
if (msgType == MSG_TYPE_ACK.getMsgType()) {
|
if (msgType == MSG_TYPE_ACK.getMsgType()) {
|
||||||
if (webSocketData.getUtcTime() > 0) {
|
if (webSocketData.getUtcTime() > 0) {
|
||||||
@@ -76,17 +81,94 @@ public class SocketHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (msgType == MSG_TYPE_DOWNLINK_CAR_DATA.getMsgType()) {
|
||||||
|
MogoSnapshotSetData data = GsonUtil.objectFromJson(webSocketData.getData(), MogoSnapshotSetData.class);
|
||||||
|
if (data == null) {
|
||||||
|
Log.e(TAG, "onMsgReceived MogoSnapshotSetData == null ");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (IMogoCloudOnMsgListener listener : listenerList) {
|
||||||
|
listener.onMsgReceived(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public void stop() {
|
public void sendMsg(List<CloudLocationInfo> cloudLocationInfo) {
|
||||||
//todo
|
CloudLocationInfo lastInfo = null;
|
||||||
// MogoRTKLocation.getInstance().unregisterRTKLocationListener();
|
// 如果数组内容不为空,就用数组最后一个值
|
||||||
// MogoRTKLocation.getInstance().stop();
|
if (!cloudLocationInfo.isEmpty()) {
|
||||||
for (int i = 0; i < listenerList.size(); i++) {
|
lastInfo = cloudLocationInfo.get(cloudLocationInfo.size() - 1);
|
||||||
SocketManager.getInstance().unregisterOnMessageListener(0x040002, listenerList.get(i));
|
mLastInfo = lastInfo;
|
||||||
SocketManager.getInstance().unregisterOnMessageListener(0x040003, listenerList.get(i));
|
|
||||||
}
|
}
|
||||||
|
if (lastInfo == null) {
|
||||||
|
lastInfo = mLastInfo;
|
||||||
|
}
|
||||||
|
LocationResult locationResult = null;
|
||||||
|
if (lastInfo != null) {
|
||||||
|
// 定位点预测纠偏
|
||||||
|
lastInfo = SimpleLocationCorrectStrategy.getInstance().correct(lastInfo);
|
||||||
|
locationResult = new LocationResult();
|
||||||
|
if (lastInfo != null) {
|
||||||
|
locationResult.lastCoordinate = lastInfo;
|
||||||
|
locationResult.mortonCode = MortonCode.wrapEncodeMorton(lastInfo.getLon(), lastInfo.getLat());
|
||||||
|
}
|
||||||
|
locationResult.coordinates = new ArrayList<>();
|
||||||
|
locationResult.sn = MoGoAiCloudClient.getInstance().getAiCloudClientConfig().getSn();
|
||||||
|
locationResult.coordinates.addAll(cloudLocationInfo);
|
||||||
|
}
|
||||||
|
//todo 改造
|
||||||
|
// List<ADASRecognizedResult> recognizedResults = RealTimeApisHandler.getInstance().getApis().getRecognizedResultManager().getLastADASRecognizedResult();//外显接口返回
|
||||||
|
OnePerSecondSendContent content = new OnePerSecondSendContent();
|
||||||
|
content.self = locationResult;
|
||||||
|
// content.adas = recognizedResults;
|
||||||
|
|
||||||
|
if (content.self == null &&
|
||||||
|
(content.adas == null || content.adas.isEmpty())) {
|
||||||
|
Log.d(TAG, "no information to sent");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
WebSocketData webSocketData = new WebSocketData();
|
||||||
|
webSocketData.setMsgType(MSG_TYPE_UPLINK_CAR_DATA.getMsgType());
|
||||||
|
webSocketData.setSeq(computeSendMsgTime());
|
||||||
|
webSocketData.setSn(MoGoAiCloudClient.getInstance().getAiCloudClientConfig().getSn());
|
||||||
|
webSocketData.setData(GsonUtil.jsonFromObject(content));
|
||||||
|
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 -> {
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stop() {
|
||||||
|
SocketManager.getInstance().unregisterOnMessageListener(0x040002, onMessageListener);
|
||||||
|
SocketManager.getInstance().unregisterOnMessageListener(0x040003, onMessageListener);
|
||||||
|
listenerList.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务端会在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