[add] 添加socketHandler类,提供区分内/外部的注册监听.消息回调分发等方法(未补全)
This commit is contained in:
@@ -5,6 +5,7 @@ import android.content.Context;
|
||||
import com.mogo.cloud.socket.IMogoCloudSocketOnMessageListener;
|
||||
import com.mogo.realtime.Interface.RealTimeProvider;
|
||||
import com.mogo.realtime.entity.ADASRecognizedResult;
|
||||
import com.mogo.realtime.entity.CloudLocationInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -47,9 +48,9 @@ public class RealTimeProviderImp implements RealTimeProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMsg(Object body, IMogoCloudSocketOnMessageListener listener) {
|
||||
if (mDelegate != null) {
|
||||
mDelegate.sendMsg(body, listener);
|
||||
public void sendMsg(List list, IMogoCloudSocketOnMessageListener listener) {
|
||||
if (mDelegate != null){
|
||||
mDelegate.sendMsg(list,listener);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.content.Context;
|
||||
|
||||
import com.mogo.cloud.socket.IMogoCloudSocketOnMessageListener;
|
||||
import com.mogo.realtime.entity.ADASRecognizedResult;
|
||||
import com.mogo.realtime.entity.CloudLocationInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -44,8 +45,8 @@ public interface RealTimeProvider<T> {
|
||||
/**
|
||||
* 发送消息
|
||||
*
|
||||
* @param body 消息体
|
||||
* @param list 消息体
|
||||
* @param listener 回执监听
|
||||
*/
|
||||
void sendMsg(T body, IMogoCloudSocketOnMessageListener listener );
|
||||
public void sendMsg(List <CloudLocationInfo> list, IMogoCloudSocketOnMessageListener listener);
|
||||
}
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.mogo.realtime.connect;
|
||||
|
||||
public enum WebSocketMsgType {
|
||||
|
||||
MSG_TYPE_UPLINK_CAR_DATA(0,"自车与ADAS数据"),
|
||||
MSG_TYPE_DOWNLINK_CAR_DATA(1,"服务端下发车辆信息"),
|
||||
MSG_TYPE_ACK(3, "ACK");
|
||||
|
||||
private int msgType;
|
||||
private String msg;
|
||||
|
||||
WebSocketMsgType(int msgType, String msg) {
|
||||
this.msgType = msgType;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public int getMsgType() {
|
||||
return msgType;
|
||||
}
|
||||
|
||||
public void setMsgType(int msgType) {
|
||||
this.msgType = msgType;
|
||||
}
|
||||
}
|
||||
@@ -7,11 +7,12 @@ 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.SocketHandler;
|
||||
import com.mogo.cloud.socket.SocketManager;
|
||||
import com.mogo.realtime.Interface.RealTimeApisHandler;
|
||||
import com.mogo.realtime.entity.ADASRecognizedResult;
|
||||
import com.mogo.realtime.entity.CloudLocationInfo;
|
||||
import com.mogo.realtime.entity.WebSocketData;
|
||||
import com.mogo.cloud.socket.WebSocketData;
|
||||
import com.mogo.realtime.location.LocationResult;
|
||||
import com.mogo.realtime.location.MogoRTKLocation;
|
||||
import com.mogo.realtime.entity.OnePerSecondSendContent;
|
||||
@@ -21,7 +22,7 @@ import com.mogo.utils.network.utils.GsonUtil;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.mogo.realtime.connect.WebSocketMsgType.MSG_TYPE_ACK;
|
||||
import static com.mogo.cloud.socket.WebSocketMsgType.MSG_TYPE_ACK;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
@@ -61,43 +62,15 @@ public class SnapshotUploadInTime implements MogoRTKLocation.RTKLocationListener
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public void start(Context context) {
|
||||
public void start(Context context, boolean useInner, String appId, IMogoCloudSocketOnMessageListener listener) {
|
||||
mContext = context.getApplicationContext();
|
||||
MogoRTKLocation.getInstance().registerRTKLocationListener(this);
|
||||
//todo
|
||||
SocketManager.getInstance().init(context,"com.mogo.launcher");
|
||||
SocketManager.getInstance().registerOnMessageListener(0x040002,onMessageListener);
|
||||
SocketManager.getInstance().registerOnMessageListener(0x040003,onMessageListener);
|
||||
|
||||
SocketHandler.getInstance().initSocket(context, useInner, appId, listener);
|
||||
}
|
||||
|
||||
private final IMogoCloudSocketOnMessageListener<String> onMessageListener = new IMogoCloudSocketOnMessageListener<String>() {
|
||||
@Override
|
||||
public Class<String> target() {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMsgReceived(String message) {
|
||||
WebSocketData webSocketData = GsonUtil.objectFromJson(message, WebSocketData.class);
|
||||
int msgType = webSocketData.getMsgType();
|
||||
if (msgType == MSG_TYPE_ACK.getMsgType()) {
|
||||
if (webSocketData.getUtcTime() > 0) {
|
||||
serverTime = webSocketData.getUtcTime();
|
||||
receiveMsgTime = SystemClock.elapsedRealtime();
|
||||
if (webSocketData.getUpUtcTime() > 0) {
|
||||
long nextDelay = webSocketData.getUpUtcTime() - serverTime;
|
||||
MogoRTKLocation.getInstance().resetUploadDelay(nextDelay);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public void stop() {
|
||||
MogoRTKLocation.getInstance().unregisterRTKLocationListener();
|
||||
MogoRTKLocation.getInstance().stop();
|
||||
SocketManager.getInstance().unregisterOnMessageListener(0x040002,onMessageListener);
|
||||
SocketManager.getInstance().unregisterOnMessageListener(0x040003,onMessageListener);
|
||||
SocketHandler.getInstance().stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -162,7 +135,7 @@ public class SnapshotUploadInTime implements MogoRTKLocation.RTKLocationListener
|
||||
MsgBody msgBody = new MsgBody();
|
||||
msgBody.msgType(msgType);
|
||||
msgBody.content(msg);
|
||||
SocketManager.getInstance().sendMsg(msgBody,msgId -> {
|
||||
SocketManager.getInstance().sendMsg(msgBody, msgId -> {
|
||||
|
||||
});
|
||||
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
package com.mogo.realtime.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class WebSocketData implements Serializable {
|
||||
|
||||
private long seq;
|
||||
|
||||
private int msgType;
|
||||
|
||||
private String sn;
|
||||
|
||||
private String data;
|
||||
|
||||
private long utcTime;
|
||||
|
||||
private long upUtcTime;
|
||||
|
||||
private String cityCode;
|
||||
|
||||
public long getSeq() {
|
||||
return seq;
|
||||
}
|
||||
|
||||
public void setSeq(long seq) {
|
||||
this.seq = seq;
|
||||
}
|
||||
|
||||
public int getMsgType() {
|
||||
return msgType;
|
||||
}
|
||||
|
||||
public void setMsgType(int msgType) {
|
||||
this.msgType = msgType;
|
||||
}
|
||||
|
||||
public String getSn() {
|
||||
return sn;
|
||||
}
|
||||
|
||||
public void setSn(String sn) {
|
||||
this.sn = sn;
|
||||
}
|
||||
|
||||
public String getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public long getUtcTime() {
|
||||
return utcTime;
|
||||
}
|
||||
|
||||
public void setUtcTime(long utcTime) {
|
||||
this.utcTime = utcTime;
|
||||
}
|
||||
|
||||
public long getUpUtcTime() {
|
||||
return upUtcTime;
|
||||
}
|
||||
|
||||
public void setUpUtcTime(long upUtcTime) {
|
||||
this.upUtcTime = upUtcTime;
|
||||
}
|
||||
|
||||
public String getCityCode() {
|
||||
return cityCode;
|
||||
}
|
||||
|
||||
public void setCityCode(String cityCode) {
|
||||
this.cityCode = cityCode;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user