reset the mock upload location service code

This commit is contained in:
zhongchao
2021-06-08 18:46:25 +08:00
parent 836684287a
commit d7b5d0ccbb
10 changed files with 242 additions and 6 deletions

View File

@@ -73,6 +73,7 @@ ext {
googlezxing : "com.google.zxing:core:3.3.3",
litezxing : "com.google.zxing:litezxing:1.0.29.8",
cossdk : "com.zhidao.cosupload:cosuploadsdk:1.1.6",
spi : 'com.elegant.spi:api:1.0.9.1' //运行时spi库
]

View File

@@ -108,11 +108,10 @@ public class SocketManager implements IMogoCloudSocketManager {
@Override
public void sendMsg(String appId, int headerType, MsgBody body, IMogoCloudSocketMsgAckListener listener) {
Logger.d(TAG, "sendMsg msgId : " + body.getMsgId());
final byte[] pb = convertToPBBytes(body.getMsgType(), body.getContent());
if (cloudClientConfig.isThirdLogin()) {
ThirdSocketManager.getInstance().sendMsg(appId, pb, headerType, true, body.getMsgId());
ThirdSocketManager.getInstance().sendMsg(appId, body.getContent(), headerType, true, body.getMsgId());
} else {
InternalSocketManager.getInstance().sendMsg(pb, headerType, true, body.getMsgId());
InternalSocketManager.getInstance().sendMsg(body.getContent(), headerType, true, body.getMsgId());
}
mAckListeners.put(body.getMsgId(), listener);
}
@@ -138,7 +137,7 @@ public class SocketManager implements IMogoCloudSocketManager {
Class clz = listener.target(msgType);
if ("SocketDownDataProto".equals(clz.getSimpleName())) {
obj = SocketDownData.SocketDownDataProto.parseFrom(payload.getPayload());
}else{
} else {
obj = GsonUtil.objectFromJson(payload.getPayload().toStringUtf8(), listener.target(msgType));
}
}
@@ -180,6 +179,13 @@ public class SocketManager implements IMogoCloudSocketManager {
}
}
/**
* 将byte数组转换成PB数据
*
* @param msgType 消息类型
* @param payloadBytes 原始数据
* @return PB数据
*/
private byte[] convertToPBBytes(int msgType, byte[] payloadBytes) {
MogoConnsvr.Payload payloadData = MogoConnsvr.Payload.newBuilder()
.setMsgType(msgType)

View File

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

View File

@@ -28,6 +28,7 @@ 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

@@ -0,0 +1,18 @@
package com.mogo.realtime.api;
/**
* 蘑菇AI云平台实时定位点上报服务接口
*/
public interface IRealTimeProvider {
/**
* 获取 adas 识别列表,由外部传入
*/
// List<ADASRecognizedResult> getLastADASRecognizedResult(); // todo 数据实体替换成PB
/**
* 发送消息,由外部传入ø
*/
// List<CloudLocationInfo> getLocationMsg(); // todo 数据实体替换成PB
}

View File

@@ -3,14 +3,18 @@ package com.mogo.realtime.core;
import android.content.Context;
import com.mogo.realtime.socket.SocketHandler;
import com.mogo.realtime.spi.RealTimeProviderImp;
/**
* 上报坐标服务
*/
public class SnapshotUploadInTime {
public class SnapshotUploadInTime implements UploadInTimeHandler.IUploadInTimeListener {
private static volatile SnapshotUploadInTime sInstance;
private SnapshotUploadInTime() {
}
public static SnapshotUploadInTime getInstance() {
if (sInstance == null) {
synchronized (SnapshotUploadInTime.class) {
@@ -31,15 +35,24 @@ public class SnapshotUploadInTime {
public void start(Context context, String appId) {
//开启长链服务
SocketHandler.getInstance().initSocket(context, appId);
//上传数据服务启动,定时上报
UploadInTimeHandler.getInstance().start();
UploadInTimeHandler.getInstance().setUploadInTimeListener(this);
}
/**
* 停止实时定位数据上报
*/
public void stop() {
//上传数据服务关闭
UploadInTimeHandler.getInstance().stop();
//关闭长链服务
SocketHandler.getInstance().stop();
sInstance = null;
}
@Override
public void sendLocationData() {
// SocketHandler.getInstance().sendMsg(); // todo 构建数据传输对象
}
}

View File

@@ -0,0 +1,101 @@
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 = 50L;
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;
}
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

@@ -4,6 +4,7 @@ import android.content.Context;
import com.mogo.cloud.socket.IMogoCloudSocketOnMessageListener;
import com.mogo.cloud.socket.SocketManager;
import com.mogo.cloud.socket.entity.MsgBody;
import com.mogo.cloud.socket.entity.SocketDownData;
import com.mogo.cloud.utils.logger.Logger;
import com.zhidao.ptech.connsvr.protocol.MogoConnsvr;
@@ -85,6 +86,21 @@ public class SocketHandler {
}
};
/**
* 发送自车和ADAS数据
*
* @param msgBody socket消息
*/
public void sendMsg(MsgBody msgBody) {
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);

View File

@@ -0,0 +1,34 @@
package com.mogo.realtime.spi;
import com.elegant.spi.AbstractDelegateManager;
import com.mogo.cloud.passport.MoGoAiCloudClient;
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)
-> mRealTimeProvider = p);
}
public IRealTimeProvider getRealTimeProvider(){
return mRealTimeProvider;
}
}

View File

@@ -0,0 +1,46 @@
package com.mogo.realtime.spi;
import com.mogo.realtime.api.IRealTimeProvider;
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() {
mDelegate = RealTimeProviderDelegateManager.getInstance().getRealTimeProvider();
}
// @Override
// public List<ADASRecognizedResult> getLastADASRecognizedResult() { // todo 数据实体替换成PB
// if (mDelegate != null) {
// return mDelegate.getLastADASRecognizedResult();
// }
// return null;
// }
//
// @Override
// public List<CloudLocationInfo> getLocationMsg() { // todo 数据实体替换成PB
// if (mDelegate != null) {
// mDelegate.getLocationMsg();
// }
// return null;
// }
}