fixbug and wait socket to fic
This commit is contained in:
1
.idea/gradle.xml
generated
1
.idea/gradle.xml
generated
@@ -23,6 +23,7 @@
|
||||
</set>
|
||||
</option>
|
||||
<option name="resolveModulePerSourceSet" value="false" />
|
||||
<option name="useQualifiedModuleNames" value="true" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
|
||||
@@ -32,7 +32,7 @@ import static com.mogo.cloud.httpdns.MogoHttpDnsConfig.HTTP_DNS_ENV_QA;
|
||||
import static com.mogo.cloud.httpdns.MogoHttpDnsConfig.HTTP_DNS_ENV_RELEASE;
|
||||
|
||||
/**
|
||||
* Socket 长链服务
|
||||
* Socket 长链核心服务
|
||||
*/
|
||||
public class SocketManager implements IMogoCloudSocketManager, Callback {
|
||||
|
||||
|
||||
@@ -33,12 +33,13 @@ public class SnapshotUploadInTime implements UploadInTimeHandler.IUploadInTimeLi
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public synchronized void release() {
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始实时定位数据上报
|
||||
* @param context 上下文对象
|
||||
* @param appId 注册id
|
||||
*/
|
||||
public void start(Context context, String appId) {
|
||||
//开启内部定位
|
||||
//开启内部定位服务
|
||||
if (!isUseExternalLocation) {
|
||||
MogoRTKLocation.getInstance().init();
|
||||
}
|
||||
@@ -53,12 +54,19 @@ public class SnapshotUploadInTime implements UploadInTimeHandler.IUploadInTimeLi
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止实时定位数据上报
|
||||
*/
|
||||
public void stop() {
|
||||
//上传数据服务关闭
|
||||
UploadInTimeHandler.getInstance().stop();
|
||||
//关闭长链服务
|
||||
SocketHandler.getInstance().stop();
|
||||
//关闭内部定位服务
|
||||
if (!isUseExternalLocation) {
|
||||
MogoRTKLocation.getInstance().stop();
|
||||
}
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,6 +5,9 @@ import android.os.Message;
|
||||
|
||||
import com.mogo.utils.WorkThreadHandler;
|
||||
|
||||
/**
|
||||
* AI云 实时上报数据频率处理类
|
||||
*/
|
||||
public class UploadInTimeHandler {
|
||||
|
||||
private static final String TAG = "UploadInTimeHandler";
|
||||
@@ -17,14 +20,14 @@ public class UploadInTimeHandler {
|
||||
|
||||
private IUploadInTimeListener iUploadInTimeListener;
|
||||
|
||||
private UploadInTimeHandler(){
|
||||
private UploadInTimeHandler() {
|
||||
|
||||
}
|
||||
|
||||
public static UploadInTimeHandler getInstance(){
|
||||
if(uploadInTimeHandler == null){
|
||||
synchronized (UploadInTimeHandler.class){
|
||||
if(uploadInTimeHandler == null){
|
||||
public static UploadInTimeHandler getInstance() {
|
||||
if (uploadInTimeHandler == null) {
|
||||
synchronized (UploadInTimeHandler.class) {
|
||||
if (uploadInTimeHandler == null) {
|
||||
uploadInTimeHandler = new UploadInTimeHandler();
|
||||
}
|
||||
}
|
||||
@@ -32,14 +35,14 @@ public class UploadInTimeHandler {
|
||||
return uploadInTimeHandler;
|
||||
}
|
||||
|
||||
public void start(){
|
||||
public void start() {
|
||||
mHandler = new Handler(WorkThreadHandler.newInstance(TAG).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){
|
||||
if (iUploadInTimeListener != null) {
|
||||
iUploadInTimeListener.sendLocationData();
|
||||
}
|
||||
}
|
||||
@@ -48,7 +51,7 @@ public class UploadInTimeHandler {
|
||||
mHandler.sendEmptyMessage(MSG_DATA_CHANGED);
|
||||
}
|
||||
|
||||
public void setUploadInTimeListener(IUploadInTimeListener uploadInTimeListener){
|
||||
public void setUploadInTimeListener(IUploadInTimeListener uploadInTimeListener) {
|
||||
this.iUploadInTimeListener = uploadInTimeListener;
|
||||
}
|
||||
|
||||
@@ -64,13 +67,23 @@ public class UploadInTimeHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public void stop(){
|
||||
mHandler.removeMessages(MSG_DATA_CHANGED);
|
||||
mHandler = null;
|
||||
public void stop() {
|
||||
if (mHandler.hasMessages(MSG_DATA_CHANGED)) {
|
||||
mHandler.removeMessages(MSG_DATA_CHANGED);
|
||||
mHandler = null;
|
||||
}
|
||||
iUploadInTimeListener = null;
|
||||
uploadInTimeHandler = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 实时上报数据回调
|
||||
*/
|
||||
public interface IUploadInTimeListener {
|
||||
|
||||
/**
|
||||
* 上报自车数据
|
||||
*/
|
||||
void sendLocationData();
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,9 @@ public class MogoRTKLocation {
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 开启定位服务
|
||||
*/
|
||||
public void init() {
|
||||
locationManager = (LocationManager) MoGoAiCloudClient.getInstance().getContext().getSystemService(Context.LOCATION_SERVICE);
|
||||
String provider = locationManager.getBestProvider(getCriteria(), true);
|
||||
@@ -110,6 +113,9 @@ public class MogoRTKLocation {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 关闭定位服务
|
||||
*/
|
||||
public void stop() {
|
||||
Logger.d(TAG, "stop RTK Location");
|
||||
if (locationManager != null && locationListener != null) {
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
package com.mogo.realtime.net;
|
||||
|
||||
/**
|
||||
* @author liujing
|
||||
* @description <>
|
||||
* date: 2021/1/20
|
||||
*/
|
||||
interface RealTimeApiService {
|
||||
|
||||
}
|
||||
@@ -1,6 +1,13 @@
|
||||
package com.mogo.realtime.socket;
|
||||
|
||||
/**
|
||||
* 长连接数据消息ack回调
|
||||
*/
|
||||
public interface IMogoCloudOnAckListener {
|
||||
|
||||
/**
|
||||
* 对齐系统时间
|
||||
* @param resetTime 系统时间
|
||||
*/
|
||||
void onAck(long resetTime);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,20 @@ package com.mogo.realtime.socket;
|
||||
|
||||
import com.mogo.realtime.entity.MogoSnapshotSetData;
|
||||
|
||||
/**
|
||||
* 长连接数据上报下发回调
|
||||
*/
|
||||
public interface IMogoCloudOnMsgListener {
|
||||
|
||||
/**
|
||||
* 长连接数据发送回调
|
||||
* @param id 发送消息id
|
||||
*/
|
||||
void onMsgSend(long id);
|
||||
|
||||
/**
|
||||
* 长连接数据接收回调
|
||||
* @param mogoSnapshotSetData 自车周边数据
|
||||
*/
|
||||
void onMsgReceived(MogoSnapshotSetData mogoSnapshotSetData);
|
||||
}
|
||||
|
||||
@@ -121,6 +121,10 @@ public class SocketHandler {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 发送自车和ADAS数据
|
||||
* @param cloudLocationInfo 自车定位信息
|
||||
*/
|
||||
public void sendMsg(List<CloudLocationInfo> cloudLocationInfo) {
|
||||
if (cloudLocationInfo == null) {
|
||||
Log.e(TAG, "请检查传入数组对象为Null");
|
||||
@@ -158,6 +162,7 @@ public class SocketHandler {
|
||||
Log.d(TAG, "no information to sent");
|
||||
return;
|
||||
}
|
||||
|
||||
WebSocketData webSocketData = new WebSocketData();
|
||||
webSocketData.setMsgType(MSG_TYPE_UPLINK_CAR_DATA.getMsgType());
|
||||
webSocketData.setSeq(computeSendMsgTime());
|
||||
@@ -173,15 +178,22 @@ public class SocketHandler {
|
||||
msgBody.msgType(msgType);
|
||||
msgBody.content(msg);
|
||||
SocketManager.getInstance().sendMsg(msgBody, msgId -> {
|
||||
|
||||
for (IMogoCloudOnMsgListener listener : onMsgListenerList) {
|
||||
if (listener != null) {
|
||||
listener.onMsgSend(msgId);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
SocketManager.getInstance().unregisterOnMessageListener(0x040002, onMessageListener);
|
||||
SocketManager.getInstance().unregisterOnMessageListener(0x040003, onMessageListener);
|
||||
SocketManager.getInstance().release();
|
||||
onMsgListenerList.clear();
|
||||
onAckListenerList.clear();
|
||||
mLastInfo = null;
|
||||
mInstance = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user