change the logic of socket service and stop the uploadService,but tanlu version can not upgrade

This commit is contained in:
zhongchao
2021-05-20 17:47:22 +08:00
parent a7d6978c3e
commit 43a463504d
46 changed files with 3407 additions and 2008 deletions

View File

@@ -28,7 +28,6 @@ android {
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
api rootProject.ext.dependencies.spi
if (Boolean.valueOf(RELEASE)) {
implementation "com.mogo.cloud:network:${MOGO_NETWORK_VERSION}"

View File

@@ -1,5 +1,4 @@
-keep class com.mogo.realtime.entity.*{*;}
-keep class com.mogo.realtime.api.*{*;}
-keep class com.mogo.realtime.socket.IMogoCloudOnMsgListener{*;}
-keep class com.mogo.realtime.socket.IMogoCloudOnAckListener{*;}
-keep class com.mogo.realtime.util.MogoLatLng{*;}

View File

@@ -1,28 +0,0 @@
package com.mogo.realtime.api;
import com.mogo.realtime.entity.ADASRecognizedResult;
import com.mogo.realtime.entity.CloudLocationInfo;
import java.util.List;
/**
* 蘑菇AI云平台实时定位点上报服务接口
*/
public interface IRealTimeProvider {
/**
* 获取 adas 识别列表,由外部传入
*/
List<ADASRecognizedResult> getLastADASRecognizedResult();
/**
* 发送自车定位信息,由外部传入
*/
List<CloudLocationInfo> getLocationMsg();
/**
* 自车定位信息 精度
* @see com.mogo.realtime.entity.LocationResult dataAccuracy 字段
*/
int getLocationAccuracy();
}

View File

@@ -1,278 +0,0 @@
package com.mogo.realtime.core;
import android.os.SystemClock;
import android.support.annotation.Keep;
import com.mogo.cloud.commons.utils.CoordinateUtils;
import com.mogo.cloud.passport.MoGoAiCloudClient;
import com.mogo.realtime.entity.CloudLocationInfo;
import com.mogo.realtime.util.MogoLatLng;
import com.mogo.cloud.utils.logger.Logger;
import java.util.ArrayList;
import java.util.List;
/**
* 定位预测纠错策略
*/
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 final static SimpleLocationCorrectStrategy instance = new SimpleLocationCorrectStrategy();
public static SimpleLocationCorrectStrategy getInstance() {
return instance;
}
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) {
if (MoGoAiCloudClient.getInstance().getAiCloudClientConfig().isShowDebugLog()) {
Logger.d(TAG, "info: " + info.print());
}
if (isLocationValid(info)) {
if (recordLocation()) {
historyList.add(info);
}
if (lastLocation == null) {
lastLocation = info;
anchorTime = SystemClock.elapsedRealtime();
if (MoGoAiCloudClient.getInstance().getAiCloudClientConfig().isShowDebugLog()) {
Logger.d(TAG, "第一条数据");
}
if (recordLocation()) {
validList.add(lastLocation);
}
return info;
}
if (lastLocation.equals(info)) {
if (MoGoAiCloudClient.getInstance().getAiCloudClientConfig().isShowDebugLog()) {
Logger.d(TAG, "相同坐标点==");
}
return info;
}
try {
float targetDistance =
(float) (lastLocation.getSpeed() * (SystemClock.elapsedRealtime() - anchorTime) / 1000) + TARGET_DISTANCE_DEVIATION;
float distance = CoordinateUtils.calculateLineDistance(lastLocation.getLon(), lastLocation.getLat(), info.getLon(), info.getLat());
if (MoGoAiCloudClient.getInstance().getAiCloudClientConfig().isShowDebugLog()) {
Logger.d(TAG,
"准备计算{ lastInfo: " + lastLocation.print() + " info: " + info.print() + " targetDistance: " + targetDistance + " distance : " + distance + "}");
}
if (distance <= targetDistance) {
// 新的定位点在目标距离范围内,认为此数据有效
lastLocation = info;
anchorTime = SystemClock.elapsedRealtime();
errCount = 0;
if (MoGoAiCloudClient.getInstance().getAiCloudClientConfig().isShowDebugLog()) {
Logger.d(TAG, "在范围内,为有效点");
}
if (recordLocation()) {
validList.add(lastLocation);
}
return info;
} else {
// 出现异常点
if (errCount >= ERR_COUNT_THRESHOLD) {
// 出错次数超过阈值,认为本次出错点为正确点
if (recordLocation()) {
errList.add(new CloudLocationInfo(lastLocation));
correctList.add(info);
}
lastLocation = info;
anchorTime = SystemClock.elapsedRealtime();
errCount = 0;
if (MoGoAiCloudClient.getInstance().getAiCloudClientConfig().isShowDebugLog()) {
Logger.d(TAG, "出错次数超限,异常点变有效点");
}
return info;
} else {
// 按照上一个点的方向和速度,计算下一个点的位置,下一个点除坐标点外,其余数据与上一个点相同
CloudLocationInfo nextInfo = new CloudLocationInfo(lastLocation);
MogoLatLng nextLatLon = computerThatLonLat(lastLocation.getLon(),
lastLocation.getLat(), lastLocation.getHeading(), targetDistance);
nextInfo.setLon(nextLatLon.lon);
nextInfo.setLat(nextLatLon.lat);
if (recordLocation()) {
errList.add(info);
correctList.add(nextInfo);
}
lastLocation = nextInfo;
anchorTime = SystemClock.elapsedRealtime();
errCount++;
if (MoGoAiCloudClient.getInstance().getAiCloudClientConfig().isShowDebugLog()) {
Logger.d(TAG, "异常点纠偏 info: " + lastLocation);
}
if (recordLocation()) {
correctList.add(nextInfo);
}
return nextInfo;
}
}
} catch (Exception e) {
if (MoGoAiCloudClient.getInstance().getAiCloudClientConfig().isShowDebugLog()) {
Logger.e(TAG, e, "纠偏异常");
}
e.printStackTrace();
}
} else {
if (MoGoAiCloudClient.getInstance().getAiCloudClientConfig().isShowDebugLog()) {
Logger.d(TAG, "定位点异常");
}
if (lastLocation == null) {
return null;
} else {
try {
float targetDistance =
(float) (lastLocation.getSpeed() * (SystemClock.elapsedRealtime() - anchorTime) / 1000) + TARGET_DISTANCE_DEVIATION;
float distance = CoordinateUtils.calculateLineDistance(lastLocation.getLon(), lastLocation.getLat(), info.getLon(), info.getLat());
if (MoGoAiCloudClient.getInstance().getAiCloudClientConfig().isShowDebugLog()) {
Logger.d(TAG,
"异常定位点\n准备计算{ lastInfo: " + lastLocation.print() + " info: " + info.print() + " targetDistance: " + targetDistance + " distance : " + distance + "}");
}
// 按照上一个点的方向和速度,计算下一个点的位置,下一个点除坐标点外,其余数据与上一个点相同
CloudLocationInfo nextInfo = new CloudLocationInfo(lastLocation);
MogoLatLng nextLatLon = computerThatLonLat(lastLocation.getLon(),
lastLocation.getLat(), lastLocation.getHeading(), targetDistance);
nextInfo.setLon(nextLatLon.lon);
nextInfo.setLat(nextLatLon.lat);
if (recordLocation()) {
errList.add(info);
correctList.add(nextInfo);
}
lastLocation = nextInfo;
anchorTime = SystemClock.elapsedRealtime();
errCount++;
if (MoGoAiCloudClient.getInstance().getAiCloudClientConfig().isShowDebugLog()) {
Logger.d(TAG, "异常点纠偏 info: " + lastLocation);
}
if (recordLocation()) {
correctList.add(nextInfo);
}
return nextInfo;
} catch (Exception e) {
if (MoGoAiCloudClient.getInstance().getAiCloudClientConfig().isShowDebugLog()) {
Logger.e(TAG, e, "纠偏异常");
}
e.printStackTrace();
}
}
}
return null;
}
private boolean isLocationValid(CloudLocationInfo info) {
return info.getLat() != 0 && info.getLon() != 0;
}
private RecordLocationListener recordLocationListener = null;
private boolean hasCallbackRecord = false;
public void setRecordLocationListener(RecordLocationListener recordLocationListener) {
this.recordLocationListener = recordLocationListener;
}
private boolean recordLocation() {
if (historyList.size() >= 100 && !hasCallbackRecord && recordLocationListener != null) {
hasCallbackRecord = true;
recordLocationListener.onRecordFinish(historyList, correctList, validList, correctList);
}
return historyList.size() < 100;
}
/**
* 根据距离和角度计算下一个经纬度
* 大地坐标系资料WGS-84 长半径a=6378137 短半径b=6356752.3142 扁率f=1/298.2572236
*/
public MogoLatLng computerThatLonLat(double lon, double lat, double brng, double dist) {
double alpha1 = rad(brng);
double sinAlpha1 = Math.sin(alpha1);
double cosAlpha1 = Math.cos(alpha1);
// 扁率f=1/298.2572236
double f = 1 / 298.2572236;
double tanU1 = (1 - f) * Math.tan(rad(lat));
double cosU1 = 1 / Math.sqrt((1 + tanU1 * tanU1));
double sinU1 = tanU1 * cosU1;
double sigma1 = Math.atan2(tanU1, cosAlpha1);
double sinAlpha = cosU1 * sinAlpha1;
double cosSqAlpha = 1 - sinAlpha * sinAlpha;
// 长半径a=6378137
double a = 6378137;
// 短半径b=6356752.3142
double b = 6356752.3142;
double uSq = cosSqAlpha * (a * a - b * b) / (b * b);
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 sigma = dist / (b * A), sigmaP = 2 * Math.PI;
while (Math.abs(sigma - sigmaP) > 1e-12) {
cos2SigmaM = Math.cos(2 * sigma1 + sigma);
sinSigma = Math.sin(sigma);
cosSigma = Math.cos(sigma);
double deltaSigma = B * sinSigma * (cos2SigmaM + B / 4 * (cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM)
- B / 6 * cos2SigmaM * (-3 + 4 * sinSigma * sinSigma) * (-3 + 4 * cos2SigmaM * cos2SigmaM)));
sigmaP = sigma;
sigma = dist / (b * A) + deltaSigma;
}
double tmp = sinU1 * sinSigma - cosU1 * cosSigma * cosAlpha1;
double lat2 = Math.atan2(sinU1 * cosSigma + cosU1 * sinSigma * cosAlpha1,
(1 - f) * Math.sqrt(sinAlpha * sinAlpha + tmp * tmp));
double lambda = Math.atan2(sinSigma * sinAlpha1, cosU1 * cosSigma - sinU1 * sinSigma * cosAlpha1);
double C = f / 16 * cosSqAlpha * (4 + f * (4 - 3 * cosSqAlpha));
double L = lambda - (1 - C) * f * sinAlpha
* (sigma + C * sinSigma * (cos2SigmaM + C * cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM)));
// final bearing
double revAz = Math.atan2(sinAlpha, -tmp);
System.out.println(revAz);
System.out.println(lon + deg(L) + "," + deg(lat2));
return new MogoLatLng(deg(lat2), lon + deg(L));
}
/**
* 度换成弧度
*
* @param d 度
* @return 弧度
*/
private double rad(double d) {
return d * Math.PI / 180.0;
}
/**
* 弧度换成度
*
* @param x 弧度
* @return 度
*/
private double deg(double x) {
return x * 180 / Math.PI;
}
@Keep
public interface RecordLocationListener {
@Keep
void onRecordFinish(List<CloudLocationInfo> history, List<CloudLocationInfo> correct, List<CloudLocationInfo> valid, List<CloudLocationInfo> err);
}
}

View File

@@ -2,23 +2,14 @@ package com.mogo.realtime.core;
import android.content.Context;
import com.mogo.cloud.passport.MoGoAiCloudClient;
import com.mogo.realtime.spi.RealTimeProviderImp;
import com.mogo.realtime.location.MogoRTKLocation;
import com.mogo.realtime.socket.SocketHandler;
/**
* 上报坐标服务
*/
public class SnapshotUploadInTime implements UploadInTimeHandler.IUploadInTimeListener {
public class SnapshotUploadInTime {
private static volatile SnapshotUploadInTime sInstance;
//是否使用外部定位数据
private final boolean isUseExternalLocation;
private SnapshotUploadInTime() {
isUseExternalLocation = MoGoAiCloudClient.getInstance().getAiCloudClientConfig().getIsUseExternalLocation();
}
public static SnapshotUploadInTime getInstance() {
if (sInstance == null) {
@@ -33,46 +24,22 @@ public class SnapshotUploadInTime implements UploadInTimeHandler.IUploadInTimeLi
/**
* 开始实时定位数据上报
*
* @param context 上下文对象
* @param appId 注册id
* @param appId 注册id
*/
public void start(Context context, String appId) {
//开启内部定位服务
if (!isUseExternalLocation) {
MogoRTKLocation.getInstance().init();
}
//开启长链服务
SocketHandler.getInstance().initSocket(context, appId);
SocketHandler.getInstance().resetUploadDelayListener(resetTime ->
UploadInTimeHandler.getInstance().resetUploadDelay(resetTime)
);
//上传数据服务启动,定时上报
UploadInTimeHandler.getInstance().start();
UploadInTimeHandler.getInstance().setUploadInTimeListener(this);
}
/**
* 停止实时定位数据上报
*/
public void stop() {
//上传数据服务关闭
UploadInTimeHandler.getInstance().stop();
//关闭长链服务
SocketHandler.getInstance().stop();
//关闭内部定位服务
if (!isUseExternalLocation) {
MogoRTKLocation.getInstance().stop();
}
sInstance = null;
}
@Override
public void sendLocationData() {
if (!isUseExternalLocation) {
SocketHandler.getInstance().sendMsg(MogoRTKLocation.getInstance().sendLocationData());
} else {
SocketHandler.getInstance().sendMsg(RealTimeProviderImp.getInstance().getLocationMsg());
}
}
}

View File

@@ -1,113 +0,0 @@
package com.mogo.realtime.core;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.support.annotation.Keep;
import com.mogo.cloud.utils.logger.Logger;
import static com.mogo.realtime.constant.RealTimeConstant.TAG;
/**
* AI云 实时上报数据频率处理类
*/
public class UploadInTimeHandler {
private static final int MSG_DATA_CHANGED = 0x100;
private static final long MSG_DATA_INTERNAL = 500L;
private final long uploadDelay = MSG_DATA_INTERNAL;
private volatile HandlerThread mThread;
private volatile Handler mHandler;
private static volatile UploadInTimeHandler uploadInTimeHandler;
private IUploadInTimeListener iUploadInTimeListener;
private UploadInTimeHandler() {
}
public static UploadInTimeHandler getInstance() {
if (uploadInTimeHandler == null) {
synchronized (UploadInTimeHandler.class) {
if (uploadInTimeHandler == null) {
uploadInTimeHandler = new UploadInTimeHandler();
}
}
}
return uploadInTimeHandler;
}
public synchronized void start() {
Logger.d(TAG, "UploadInTimeHandler start");
if (mHandler == null) {
if (mThread == null) {
mThread = new HandlerThread(TAG);
Logger.d(TAG, "start Handler Thread");
mThread.start();
}
mHandler = new Handler(mThread.getLooper()) {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (msg.what == MSG_DATA_CHANGED) {
mHandler.sendEmptyMessageDelayed(MSG_DATA_CHANGED, uploadDelay);
if (iUploadInTimeListener != null) {
iUploadInTimeListener.sendLocationData();
}
}
}
};
mHandler.sendEmptyMessage(MSG_DATA_CHANGED);
}
}
public void setUploadInTimeListener(IUploadInTimeListener uploadInTimeListener) {
this.iUploadInTimeListener = uploadInTimeListener;
}
/**
* 默认保持{@link #uploadDelay}间隔进行位置上报,如遇服务端控制,进行上报间隔修改
*
* @param delay 上报间隔
*/
public void resetUploadDelay(long delay) {
if (mHandler != null && mHandler.hasMessages(MSG_DATA_CHANGED)) {
mHandler.removeMessages(MSG_DATA_CHANGED);
mHandler.sendEmptyMessageDelayed(MSG_DATA_CHANGED, delay);
}
}
public synchronized void stop() {
if (mHandler != null) {
mHandler.removeMessages(MSG_DATA_CHANGED);
mHandler = null;
}
if (mThread != null) {
try {
mThread.quit();
} catch (Exception e) {
e.printStackTrace();
}
mThread = null;
Logger.d(TAG, "stop Thread set null");
}
iUploadInTimeListener = null;
uploadInTimeHandler = null;
}
/**
* 实时上报数据回调
*/
@Keep
public interface IUploadInTimeListener {
/**
* 上报自车数据
*/
@Keep
void sendLocationData();
}
}

View File

@@ -1,115 +0,0 @@
package com.mogo.realtime.entity;
/*
* adas 识别物体参数
*/
public class ADASRecognizedResult {
/**
* 识别物体类型
*/
public int type;
/**
* 识别物体唯一标识
*/
public String uuid;
/**
* 红绿灯颜色
*/
public String color;
/**
* 车ID
*/
public String carId;
/**
* 识别物体的纬度
*/
public double lat;
/**
* 识别物体的经度
*/
public double lon;
/**
* 车头朝向
*/
public double heading;
/**
* 系统时间
*/
public long systemTime;
/**
* 定位卫星时间
*/
public long satelliteTime;
/**
* 海拔
*/
public double alt;
/**
* 速度
*/
public double speed;
/**
* 莫顿码
*/
public long mortonCode;
/**
* 实际距离
* 使用distanceX和distanceY计算
*/
public double distance;
/**
* 数据来源精度
* 0普通定位
* 1高精定位
*/
public int dataAccuracy;
/**
* 道路ID
*/
public String roadId;
/**
* 车道ID-2D路段
*/
public String laneId;
/**
* 车道号中心线编号为0中心线右侧编号为负数3车道通行Road的车道编号0-1-2-3
*/
public int laneNum;
/**
* 限速
*/
public double rateLimiting;
/**
* 瓦片id
*/
public String tileId;
/**
* 车道宽度
*/
public double roadWidth;
/**
* 1 绿, 2 黄, 3 红
*/
public int drawlevel;
}

View File

@@ -1,313 +0,0 @@
package com.mogo.realtime.entity;
import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.RequiresApi;
import java.util.Objects;
/**
* 自车定位信息
*/
public class CloudLocationInfo implements Parcelable {
/**
* 纬度
*/
private double lat;
/**
* 经度
*/
private double lon;
/**
* 车头方向
*/
private double heading;
/**
* 系统时间
*/
private long systemTime;
/**
* 卫星时间
*/
private long satelliteTime;
/**
* 海拔
*/
private double alt;
/**
* 车速
*/
private double speed;
/**
* 车辆类型
* 0:普通车辆、家用车
*/
private int vehicleType = 0;
/**
* 道路ID
*/
private String roadId;
/**
* 车道ID-2D路段
*/
private String laneId;
/**
* 车道号中心线编号为0中心线右侧编号为负数3车道通行Road的车道编号0-1-2-3
*/
private int laneNum;
/**
* 限速
*/
private double rateLimiting;
/**
* 瓦片id
*/
private String tileId;
/**
* 车道宽度
*/
private double roadWidth;
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;
this.vehicleType = info.vehicleType;
this.roadId = info.roadId;
this.laneId = info.laneId;
this.laneNum = info.laneNum;
this.rateLimiting = info.rateLimiting;
this.tileId = info.tileId;
this.roadWidth = info.roadWidth;
}
protected CloudLocationInfo(Parcel in) {
lat = in.readDouble();
lon = in.readDouble();
heading = in.readDouble();
systemTime = in.readLong();
satelliteTime = in.readLong();
alt = in.readDouble();
speed = in.readDouble();
vehicleType = in.readInt();
roadId = in.readString();
laneId = in.readString();
laneNum = in.readInt();
rateLimiting = in.readDouble();
tileId = in.readString();
roadWidth = in.readDouble();
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeDouble(lat);
dest.writeDouble(lon);
dest.writeDouble(heading);
dest.writeLong(systemTime);
dest.writeLong(satelliteTime);
dest.writeDouble(alt);
dest.writeDouble(speed);
dest.writeInt(vehicleType);
dest.writeString(roadId);
dest.writeString(laneId);
dest.writeInt(laneNum);
dest.writeDouble(rateLimiting);
dest.writeString(tileId);
dest.writeDouble(roadWidth);
}
@Override
public int describeContents() {
return 0;
}
public static final Creator<CloudLocationInfo> CREATOR = new Creator<CloudLocationInfo>() {
@Override
public CloudLocationInfo createFromParcel(Parcel in) {
return new CloudLocationInfo(in);
}
@Override
public CloudLocationInfo[] newArray(int size) {
return new CloudLocationInfo[size];
}
};
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 getHeading() {
return heading;
}
public void setHeading(double heading) {
this.heading = heading;
}
public long getSystemTime() {
return systemTime;
}
public void setSystemTime(long systemTime) {
this.systemTime = systemTime;
}
public long getSatelliteTime() {
return satelliteTime;
}
public void setSatelliteTime(long satelliteTime) {
this.satelliteTime = satelliteTime;
}
public double getAlt() {
return alt;
}
public void setAlt(double alt) {
this.alt = alt;
}
public double getSpeed() {
return speed;
}
public void setSpeed(double speed) {
this.speed = speed;
}
public int getVehicleType() {
return vehicleType;
}
public void setVehicleType(int vehicleType) {
this.vehicleType = vehicleType;
}
public String getRoadId() {
return roadId;
}
public void setRoadId(String roadId) {
this.roadId = roadId;
}
public String getLaneId() {
return laneId;
}
public void setLaneId(String laneId) {
this.laneId = laneId;
}
public int getLaneNum() {
return laneNum;
}
public void setLaneNum(int laneNum) {
this.laneNum = laneNum;
}
public double getRateLimiting() {
return rateLimiting;
}
public void setRateLimiting(double rateLimiting) {
this.rateLimiting = rateLimiting;
}
public String getTileId() {
return tileId;
}
public void setTileId(String tileId) {
this.tileId = tileId;
}
public double getRoadWidth() {
return roadWidth;
}
public void setRoadWidth(double roadWidth) {
this.roadWidth = roadWidth;
}
@Override
public String toString() {
return "CloudLocationInfo{" +
"lat=" + lat +
", lon=" + lon +
", heading=" + heading +
", systemTime=" + systemTime +
", satelliteTime=" + satelliteTime +
", alt=" + alt +
", speed=" + speed +
", vehicleType=" + vehicleType +
", roadId='" + roadId + '\'' +
", laneId='" + laneId + '\'' +
", laneNum=" + laneNum +
", rateLimiting=" + rateLimiting +
", tileId=" + tileId +
", roadWidth=" + roadWidth +
'}';
}
public String print() {
return "CloudLocation{ lon: " + lon + " lat: " + lat + " heading: " + heading + " speed: "
+ speed + " vehicleType: " + vehicleType + "}";
}
@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;
}
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public int hashCode() {
return Objects.hash(lat, lon);
}
}

View File

@@ -1,294 +0,0 @@
package com.mogo.realtime.entity;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import java.util.List;
/**
* AI云平台下发 道路数据
*/
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 double wgslat;
private double wgslon;
private String uuid;
private String sn;
private double speed;
private double heading;
private long systemTime;
private long satelliteTime;
/**
* 红绿灯状态 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 getWgslat() {
return wgslat;
}
public void setWgslat(double wgslat) {
this.wgslat = wgslat;
}
public double getWgslon() {
return wgslon;
}
public void setWgslon(double wgslon) {
this.wgslon = wgslon;
}
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 long getSatelliteTime() {
return satelliteTime;
}
public void setSatelliteTime( long satelliteTime ) {
this.satelliteTime = satelliteTime;
}
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.writeDouble( this.wgslat );
dest.writeDouble( this.wgslon );
dest.writeString( this.uuid );
dest.writeString( this.sn );
dest.writeDouble( this.speed );
dest.writeDouble( this.heading );
dest.writeLong( this.systemTime );
dest.writeLong( this.satelliteTime );
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.wgslat = in.readDouble();
this.wgslon = in.readDouble();
this.uuid = in.readString();
this.sn = in.readString();
this.speed = in.readDouble();
this.heading = in.readDouble();
this.systemTime = in.readLong();
this.satelliteTime = 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;
}
@Override
public String toString() {
return "CloudRoadData{" +
"type=" + type +
", fromType=" + fromType +
", lat=" + lat +
", lon=" + lon +
", wgslat=" + wgslat +
", wgslon=" + wgslon +
", uuid='" + uuid + '\'' +
", sn='" + sn + '\'' +
", speed=" + speed +
", heading=" + heading +
", systemTime=" + systemTime +
", satelliteTime=" + satelliteTime +
", lightStatus=" + lightStatus +
", lightLeftTime=" + lightLeftTime +
", rtmpUrl='" + rtmpUrl + '\'' +
", distance=" + distance +
", coordinates=" + coordinates +
'}';
}
}

View File

@@ -1,73 +0,0 @@
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;
}
@Override
public String toString() {
return "FrequencyData{" +
"unit=" + unit +
", collectionInterval=" + collectionInterval +
", reportStartTime=" + reportStartTime +
", type=" + type +
'}';
}
}

View File

@@ -1,37 +0,0 @@
package com.mogo.realtime.entity;
import java.util.List;
/*
* 自车定位信息
*/
public class LocationResult {
/**
* sn 车辆唯一识别号
*/
public String sn;
/**
* 最后一个定位点的莫顿码
*/
public long mortonCode;
/**
* 最后一个定位点
*/
public CloudLocationInfo lastCoordinate;
/**
* 1s 内的连续定位点
*/
public List< CloudLocationInfo > coordinates;
/**
* 数据来源精度
* 0普通定位
* 1高精定位
*/
public int dataAccuracy = 0;
}

View File

@@ -1,164 +0,0 @@
package com.mogo.realtime.entity;
import android.os.Parcel;
import android.os.Parcelable;
import java.util.List;
/*
* AI云平台下发 自车周边数据
*/
public class MogoSnapshotSetData implements Parcelable {
/**
* 消息ID
*/
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];
}
};
}

View File

@@ -1,20 +0,0 @@
package com.mogo.realtime.entity;
import java.util.List;
/**
* 自车上报数据 1s内一次
*/
public class OnePerSecondSendContent {
/**
* 自车定位点
*/
public LocationResult self;
/**
* adas 识别物体1s 识别到的最后帧
*/
public List<ADASRecognizedResult> adas;
}

View File

@@ -1,136 +0,0 @@
package com.mogo.realtime.location;
import android.content.Context;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import com.mogo.cloud.passport.MoGoAiCloudClient;
import com.mogo.realtime.entity.CloudLocationInfo;
import com.mogo.cloud.utils.logger.Logger;
import java.util.ArrayList;
import java.util.List;
import static com.mogo.realtime.constant.RealTimeConstant.TAG;
/**
* AI云SDK内部定位服务
*/
public class MogoRTKLocation {
private LocationManager locationManager;
private final List<CloudLocationInfo> cacheList = new ArrayList<>();
private CloudLocationInfo locInfo;
public static MogoRTKLocation getInstance() {
return RTKHolder.rtkLoc;
}
private static class RTKHolder {
private static final MogoRTKLocation rtkLoc = new MogoRTKLocation();
}
private MogoRTKLocation() {
}
public List<CloudLocationInfo> sendLocationData() {
List<CloudLocationInfo> list = new ArrayList<>(cacheList);
if (cacheList.size() == 0) {
if (locInfo != null) {
cacheList.add(locInfo);
} else {
Logger.e(TAG, "暂无定位数据");
return list;
}
} else {
cacheList.clear();
}
return list;
}
/**
* 开启定位服务
*/
public void init() {
locationManager = (LocationManager) MoGoAiCloudClient.getInstance().getContext().getSystemService(Context.LOCATION_SERVICE);
String provider = locationManager.getBestProvider(getCriteria(), true);
Logger.d(TAG, "init provider : " + provider);
if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
try {
locationManager.requestLocationUpdates(provider, 0, 0, locationListener);
Location location = locationManager.getLastKnownLocation(provider);
if (location != null) {
Logger.i(TAG, "location : " + location.toString());
}
} catch (Exception e) {
e.printStackTrace();
Logger.d(TAG, "RTK LocationManager requestLocationUpdates has Exception : " + e.getMessage());
}
} else {
Logger.d(TAG, "RTK LocationManager Provider GPS_PROVIDER unable");
}
}
private Criteria getCriteria() {
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE); //高精
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(true);
criteria.setSpeedRequired(true);
criteria.setPowerRequirement(Criteria.POWER_LOW);
return criteria;
}
private final LocationListener locationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
if (location != null) {
CloudLocationInfo cloudLocationInfo = new CloudLocationInfo();
cloudLocationInfo.setAlt(location.getAltitude());
cloudLocationInfo.setHeading(location.getBearing());
cloudLocationInfo.setLat(location.getLatitude());
cloudLocationInfo.setLon(location.getLongitude());
cloudLocationInfo.setSpeed(location.getSpeed());
cloudLocationInfo.setSatelliteTime(location.getTime());
cloudLocationInfo.setSystemTime(System.currentTimeMillis());
locInfo = cloudLocationInfo;
cacheList.add(cloudLocationInfo);
} else {
Logger.e(TAG, "location == null");
}
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
Logger.d(TAG, "onStatusChanged status: " + status);
}
@Override
public void onProviderEnabled(String provider) {
Logger.d(TAG, "onProviderEnabled");
}
@Override
public void onProviderDisabled(String provider) {
Logger.d(TAG, "onProviderEnabled");
}
};
/**
* 关闭定位服务
*/
public void stop() {
Logger.d(TAG, "stop RTK Location");
if (locationManager != null && locationListener != null) {
locationManager.removeUpdates(locationListener);
} else {
Logger.d(TAG, "stop failed , reason : loc" + locationManager + " , or loc listener: " + locationListener + " is null");
}
}
}

View File

@@ -1,13 +0,0 @@
package com.mogo.realtime.socket;
/**
* 长连接数据消息ack回调
*/
public interface IMogoCloudOnAckListener {
/**
* 对齐系统时间
* @param resetTime 系统时间
*/
void onAck(long resetTime);
}

View File

@@ -1,6 +1,6 @@
package com.mogo.realtime.socket;
import com.mogo.realtime.entity.MogoSnapshotSetData;
import com.mogo.cloud.socket.entity.SocketDownData;
/**
* 长连接数据上报下发回调
@@ -17,5 +17,5 @@ public interface IMogoCloudOnMsgListener {
* 长连接数据接收回调
* @param mogoSnapshotSetData 自车周边数据
*/
void onMsgReceived(MogoSnapshotSetData mogoSnapshotSetData);
void onMsgReceived(SocketDownData.LauncherSnapshotProto mogoSnapshotSetData);
}

View File

@@ -2,30 +2,16 @@ package com.mogo.realtime.socket;
import android.content.Context;
import com.mogo.cloud.GsonUtil;
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.cloud.socket.WebSocketData;
import com.mogo.cloud.socket.entity.SocketDownData;
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;
import com.mogo.realtime.spi.RealTimeProviderImp;
import com.mogo.realtime.util.MortonCode;
import com.zhidao.ptech.connsvr.protocol.MogoConnsvr;
import java.util.ArrayList;
import java.util.List;
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;
import static com.mogo.cloud.socket.SocketMsgType.MSG_TYPE_DOWNLINK_CAR_DATA;
import static com.mogo.realtime.constant.RealTimeConstant.TAG;
/**
@@ -39,9 +25,7 @@ public class SocketHandler {
private static final int LOW_FREQUENCY_CHANNEL_ID = 0x040003; //低频数据
private String mAppId;
private CloudLocationInfo mLastInfo;
private final List<IMogoCloudOnMsgListener> onMsgListenerList = new ArrayList<>();
private final List<IMogoCloudOnAckListener> onAckListenerList = new ArrayList<>();
public static SocketHandler getInstance() {
if (mInstance == null) {
@@ -79,126 +63,33 @@ public class SocketHandler {
}
}
public void resetUploadDelayListener(IMogoCloudOnAckListener onAckListener) {
if (onAckListener != null) {
onAckListenerList.add(onAckListener);
}
}
private final IMogoCloudSocketOnMessageListener<WebSocketData> onMessageListener = new IMogoCloudSocketOnMessageListener<WebSocketData>() {
private final IMogoCloudSocketOnMessageListener<SocketDownData.SocketDownDataProto> onMessageListener = new IMogoCloudSocketOnMessageListener<SocketDownData.SocketDownDataProto>() {
@Override
public Class<WebSocketData> target(int msgType) {
return WebSocketData.class;
public Class<SocketDownData.SocketDownDataProto> target(int msgType) {
return SocketDownData.SocketDownDataProto.class;
}
@Override
public void onMsgReceived(int msgType, WebSocketData webSocketData) {
if (webSocketData.getMsgType() == MSG_TYPE_ACK.getMsgType()) {
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);
}
}
}
public void onMsgReceived(int msgType, SocketDownData.SocketDownDataProto webSocketData) {
if (webSocketData == null) {
Logger.e(TAG, "onMsgReceived SocketDownDataProto3 == null ");
return;
}
if (webSocketData.getMsgType() == MSG_TYPE_DOWNLINK_CAR_DATA.getMsgType()) {
MogoSnapshotSetData snapshotSetData = GsonUtil.objectFromJson(webSocketData.getData(), MogoSnapshotSetData.class);
if (snapshotSetData == null) {
Logger.e(TAG, "onMsgReceived MogoSnapshotSetData == null ");
return;
}
if (webSocketData.getMsgType() == MSG_TYPE_DOWNLINK_CAR_DATA.getMsgType()) {
for (IMogoCloudOnMsgListener listener : onMsgListenerList) {
if (listener != null) {
listener.onMsgReceived(snapshotSetData);
listener.onMsgReceived(webSocketData.getData());
}
}
}
}
};
/**
* 发送自车和ADAS数据
*
* @param cloudLocationInfo 自车定位信息
*/
public void sendMsg(List<CloudLocationInfo> cloudLocationInfo) {
if (cloudLocationInfo == null) {
Logger.e(TAG, "请检查传入数组对象为Null");
return;
}
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);
locationResult.dataAccuracy = RealTimeProviderImp.getInstance().getLocationAccuracy();//SPI接口返回
}
List<ADASRecognizedResult> recognizedResults = RealTimeProviderImp.getInstance().getLastADASRecognizedResult();//SPI接口返回
OnePerSecondSendContent content = new OnePerSecondSendContent();
content.self = locationResult;
content.adas = recognizedResults;
if (content.self == null &&
(content.adas == null || content.adas.isEmpty())) {
Logger.d(TAG, "no information to sent");
return;
}
WebSocketData webSocketData = new WebSocketData();
webSocketData.setMsgType(MSG_TYPE_UPLINK_CAR_DATA.getMsgType());
webSocketData.setSeq(System.currentTimeMillis());
webSocketData.setSn(MoGoAiCloudClient.getInstance().getAiCloudClientConfig().getSn());
webSocketData.setData(GsonUtil.jsonFromObject(content));
String msg = GsonUtil.jsonFromObject(webSocketData);
Logger.d(TAG,"SocketHandler ready to sendMsg : " + msg);
boolean isAccuracyDevice = MoGoAiCloudClient.getInstance().getAiCloudClientConfig().getIsAccuracyDevice();
int msgType = LOW_FREQUENCY_CHANNEL_ID;
if (isAccuracyDevice && cloudLocationInfo.size() > 2) {
msgType = HIGH_FREQUENCY_CHANNEL_ID;
}
MsgBody msgBody = new MsgBody();
msgBody.msgType(msgType);
msgBody.content(msg.getBytes());
SocketManager.getInstance().sendMsg(mAppId, HEADER_TYPE, msgBody, msgId -> {
for (IMogoCloudOnMsgListener listener : onMsgListenerList) {
if (listener != null) {
listener.onMsgSend(msgId);
}
}
});
}
public void stop() {
SocketManager.getInstance().unregisterOnMessageListener(HIGH_FREQUENCY_CHANNEL_ID, onMessageListener);
SocketManager.getInstance().unregisterOnMessageListener(LOW_FREQUENCY_CHANNEL_ID, onMessageListener);
SocketManager.getInstance().release();
onMsgListenerList.clear();
onAckListenerList.clear();
mLastInfo = null;
mInstance = null;
}

View File

@@ -1,38 +0,0 @@
package com.mogo.realtime.spi;
import com.elegant.spi.AbstractDelegateManager;
import com.mogo.cloud.passport.MoGoAiCloudClient;
import com.mogo.cloud.utils.logger.Logger;
import com.mogo.realtime.api.IRealTimeProvider;
/**
* 提供RealTime SPI接口实例对象管理类
*/
class RealTimeProviderDelegateManager extends AbstractDelegateManager<IRealTimeProvider> {
private static RealTimeProviderDelegateManager sInstance = null;
private IRealTimeProvider mRealTimeProvider = null;
public static RealTimeProviderDelegateManager getInstance() {
if (sInstance == null) {
synchronized (RealTimeProviderDelegateManager.class) {
if (sInstance == null) {
sInstance = new RealTimeProviderDelegateManager();
}
}
}
return sInstance;
}
public RealTimeProviderDelegateManager() {
loadDelegates(MoGoAiCloudClient.getInstance().getContext(), IRealTimeProvider.class, (unit, p)
-> {
Logger.d("RealTimeProviderDelegateManager", "init provider : " + p);
mRealTimeProvider = p;
});
}
public IRealTimeProvider getRealTimeProvider() {
return mRealTimeProvider;
}
}

View File

@@ -1,58 +0,0 @@
package com.mogo.realtime.spi;
import com.mogo.realtime.api.IRealTimeProvider;
import com.mogo.realtime.entity.ADASRecognizedResult;
import com.mogo.realtime.entity.CloudLocationInfo;
import com.mogo.cloud.utils.logger.Logger;
import java.util.List;
/**
* RealTime Provider SPI 单例对象
*/
public class RealTimeProviderImp implements IRealTimeProvider {
private static volatile RealTimeProviderImp sInstance = null;
private final IRealTimeProvider mDelegate;
public static RealTimeProviderImp getInstance() {
if (sInstance == null) {
synchronized (RealTimeProviderImp.class) {
if (sInstance == null) {
sInstance = new RealTimeProviderImp();
}
}
}
return sInstance;
}
public RealTimeProviderImp() {
Logger.d("RealTimeProviderImp","init --->");
mDelegate = RealTimeProviderDelegateManager.getInstance().getRealTimeProvider();
}
@Override
public List<ADASRecognizedResult> getLastADASRecognizedResult() {
if (mDelegate != null) {
return mDelegate.getLastADASRecognizedResult();
}
return null;
}
@Override
public List<CloudLocationInfo> getLocationMsg() {
if (mDelegate != null) {
return mDelegate.getLocationMsg();
}
return null;
}
@Override
public int getLocationAccuracy() {
if (mDelegate != null) {
return mDelegate.getLocationAccuracy();
}
return 0;
}
}