This commit is contained in:
tongchenfei
2020-10-27 15:53:34 +08:00
parent c18eafb463
commit 2dce3f8254
10 changed files with 336 additions and 130 deletions

View File

@@ -95,7 +95,7 @@ public class SocketManager implements IMogoSocketManager, OnSocketReceiveCallbac
try {
MogoConnsvr.Payload payload = MogoConnsvr.Payload.parseFrom( content );
int msgType = payload.getMsgType();
Logger.d( TAG, "received msg type = %d", msgType );
Logger.d( TAG, "received msg type = " + msgType );
List< IMogoOnMessageListener > listeners = mListeners.get( msgType );
if ( listeners != null && !listeners.isEmpty() ) {
Iterator< IMogoOnMessageListener > iterator = listeners.iterator();

View File

@@ -17,12 +17,17 @@ public class WebSocketHandlerThread extends HandlerThread {
public WebSocketHandlerThread(String name) {
super(name);
tag = name;
}
@Override
public void run() {
super.run();
mHandler = new Handler(this.getLooper()) {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (msg.what == MSG_SEND) {
Logger.d(tag, "WebSocketHandlerThread handleMessage = %d", msg.obj.toString());
Logger.d(tag, "WebSocketHandlerThread handleMessage = " + msg.obj.toString());
SocketClient.getInstance().getClientProxy().sendMessage(msg.obj.toString());
}
}
@@ -30,10 +35,12 @@ public class WebSocketHandlerThread extends HandlerThread {
}
public void sendMsg(String msg) {
Message message = new Message();
message.what = MSG_SEND;
message.obj = msg;
mHandler.sendMessage(message);
if(mHandler!=null) {
Message message = new Message();
message.what = MSG_SEND;
message.obj = msg;
mHandler.sendMessage(message);
}
}
}

View File

@@ -24,7 +24,8 @@ import java.util.concurrent.ConcurrentHashMap;
import static com.mogo.service.connection.WebSocketMsgType.MSG_TYPE_DOWNLINK_CAR_DATA;
@Keep
public class WebSocketManager implements IMogoWebSocketManager, ISocketMsgSetting, ISocketMsgCallBack {
public class WebSocketManager implements IMogoWebSocketManager, ISocketMsgSetting,
ISocketMsgCallBack {
private static final String TAG = "WebSocketManager-sdk";
@@ -53,7 +54,8 @@ public class WebSocketManager implements IMogoWebSocketManager, ISocketMsgSettin
* <p>
* key - msgType
*/
private Map<Integer, List<IMogoOnWebSocketMessageListener>> mListeners = new ConcurrentHashMap<>();
private Map<Integer, List<IMogoOnWebSocketMessageListener>> mListeners =
new ConcurrentHashMap<>();
/**
* 管理消息回执
@@ -77,9 +79,7 @@ public class WebSocketManager implements IMogoWebSocketManager, ISocketMsgSettin
return;
}
int msgType = listener.getDownLinkType().getMsgType();
if (mListeners.containsKey(msgType)) {
Logger.w(TAG, "websocket msgType %d is exist.", msgType);
}
if (!mListeners.containsKey(msgType)) {
mListeners.put(msgType, new ArrayList<>());
}
@@ -109,7 +109,7 @@ public class WebSocketManager implements IMogoWebSocketManager, ISocketMsgSettin
@Override
public void sendMsg(Object body, IMogoOnWebSocketMessageListener listener) {
Logger.d(TAG, "websocket sendMsg body = %d , listener = %d ", body, listener);
Logger.d(TAG, "websocket sendMsg body = " + body);
if (handlerThread != null) {
WebSocketData webSocketData = new WebSocketData();
webSocketData.setSeq(System.currentTimeMillis());
@@ -131,10 +131,10 @@ public class WebSocketManager implements IMogoWebSocketManager, ISocketMsgSettin
@Override
public void handleMessage(String message) {
Logger.d(TAG, "websocket received msg = %d ", message);
Logger.d(TAG, "websocket received msg = " + message);
WebSocketData webSocketData = GsonUtil.objectFromJson(message, WebSocketData.class);
int msgType = webSocketData.getMsgType();
Logger.d(TAG, "websocket received msg type = %d", msgType);
Logger.d(TAG, "websocket received msg type = " + msgType);
//服务端下发数据返回,上传数据回执默认不返回
if (msgType == MSG_TYPE_DOWNLINK_CAR_DATA.getMsgType()) {
List<IMogoOnWebSocketMessageListener> listeners = mListeners.get(msgType);
@@ -143,7 +143,7 @@ public class WebSocketManager implements IMogoWebSocketManager, ISocketMsgSettin
while (iterator.hasNext()) {
IMogoOnWebSocketMessageListener listener = iterator.next();
if (listener != null) {
Logger.d(TAG, "received msgId = %s, content = %s", webSocketData.getSeq(), webSocketData.getT().toString());
Logger.d(TAG, "received msgId = "+webSocketData.getSeq()+", content = "+webSocketData.getT().toString());
listener.onMsgReceived(webSocketData.getT());
}
}
@@ -159,7 +159,7 @@ public class WebSocketManager implements IMogoWebSocketManager, ISocketMsgSettin
@Override
public void handleError(Exception e) {
Logger.e(TAG, "websocket handleError : %d", e.getMessage());
Logger.e(TAG, "websocket handleError :" + e.getMessage());
}
@Override

View File

@@ -1,75 +0,0 @@
package com.mogo.module.common.entity;
/**
* 通过AI云下发的红绿灯状态
*
* @author tongchenfei
*/
public class AITrafficLightEntity {
private int type;
private double lat;
private double lon;
private long systemTime;
/**红绿灯状态 1红 2绿 3黄*/
private Integer lightStatus;//
/**红绿灯剩余时间 读秒*/
private Integer lightLeftTime;
private double distance ;//距离
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 long getSystemTime() {
return systemTime;
}
public void setSystemTime(long systemTime) {
this.systemTime = systemTime;
}
public Integer getLightStatus() {
return lightStatus;
}
public void setLightStatus(Integer lightStatus) {
this.lightStatus = lightStatus;
}
public Integer getLightLeftTime() {
return lightLeftTime;
}
public void setLightLeftTime(Integer lightLeftTime) {
this.lightLeftTime = lightLeftTime;
}
public double getDistance() {
return distance;
}
public void setDistance(double distance) {
this.distance = distance;
}
}

View File

@@ -0,0 +1,129 @@
package com.mogo.module.common.entity;
import android.os.Parcel;
import android.os.Parcelable;
/**
* 云端定位信息和自车定位信息
*
* @author tongchenfei
*/
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;
public CloudLocationInfo(){
}
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();
}
@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);
}
@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;
}
@Override
public String toString() {
return "CloudLocationInfo{" +
"lat=" + lat +
", lon=" + lon +
", heading=" + heading +
", systemTime=" + systemTime +
", satelliteTime=" + satelliteTime +
", alt=" + alt +
", speed=" + speed +
'}';
}
}

View File

@@ -0,0 +1,95 @@
package com.mogo.module.common.entity;
import android.os.Parcel;
import android.os.Parcelable;
import java.util.List;
/**
* 云端道路数据
* @author tongchenfei
*/
public class CloudRoadData implements Parcelable {
/**物体类型*/
private int type;
private double lat;
private double lon;
private double speed;
private long systemTime;
/**红绿灯状态 1红 2绿 3黄*/
private Integer lightStatus;//
/**红绿灯剩余时间 读秒*/
private Integer lightLeftTime;
/**视频流直播地址*/
private String rtmpUrl;//
private double distance ;//距离
public List<CloudLocationInfo> coordinates;
protected CloudRoadData(Parcel in) {
type = in.readInt();
lat = in.readDouble();
lon = in.readDouble();
speed = in.readDouble();
systemTime = in.readLong();
if (in.readByte() == 0) {
lightStatus = null;
} else {
lightStatus = in.readInt();
}
if (in.readByte() == 0) {
lightLeftTime = null;
} else {
lightLeftTime = in.readInt();
}
rtmpUrl = in.readString();
distance = in.readDouble();
coordinates = in.createTypedArrayList(CloudLocationInfo.CREATOR);
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(type);
dest.writeDouble(lat);
dest.writeDouble(lon);
dest.writeDouble(speed);
dest.writeLong(systemTime);
if (lightStatus == null) {
dest.writeByte((byte) 0);
} else {
dest.writeByte((byte) 1);
dest.writeInt(lightStatus);
}
if (lightLeftTime == null) {
dest.writeByte((byte) 0);
} else {
dest.writeByte((byte) 1);
dest.writeInt(lightLeftTime);
}
dest.writeString(rtmpUrl);
dest.writeDouble(distance);
dest.writeTypedList(coordinates);
}
@Override
public int describeContents() {
return 0;
}
public static final Creator<CloudRoadData> CREATOR = new Creator<CloudRoadData>() {
@Override
public CloudRoadData createFromParcel(Parcel in) {
return new CloudRoadData(in);
}
@Override
public CloudRoadData[] newArray(int size) {
return new CloudRoadData[size];
}
};
}

View File

@@ -3,6 +3,8 @@ package com.mogo.module.common.entity;
import android.os.Parcel;
import android.os.Parcelable;
import java.util.List;
public
/**
* @author congtaowang
@@ -12,30 +14,80 @@ public
*/
class MogoSnapshotSetData implements Parcelable {
private String msgId;
private Long time;
//过期时间
private Long expire;
//总数据集合
private List<CloudRoadData> allList;
//红绿灯
private CloudRoadData trafficLight;
protected MogoSnapshotSetData(Parcel in) {
msgId = in.readString();
if (in.readByte() == 0) {
time = null;
} else {
time = in.readLong();
}
if (in.readByte() == 0) {
expire = null;
} else {
expire = in.readLong();
}
allList = in.createTypedArrayList(CloudRoadData.CREATOR);
trafficLight = in.readParcelable(CloudRoadData.class.getClassLoader());
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(msgId);
if (time == null) {
dest.writeByte((byte) 0);
} else {
dest.writeByte((byte) 1);
dest.writeLong(time);
}
if (expire == null) {
dest.writeByte((byte) 0);
} else {
dest.writeByte((byte) 1);
dest.writeLong(expire);
}
dest.writeTypedList(allList);
dest.writeParcelable(trafficLight, flags);
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel( Parcel dest, int flags ) {
}
public MogoSnapshotSetData() {
}
protected MogoSnapshotSetData( Parcel in ) {
}
public static final Creator< MogoSnapshotSetData > CREATOR = new Creator< MogoSnapshotSetData >() {
public static final Creator<MogoSnapshotSetData> CREATOR = new Creator<MogoSnapshotSetData>() {
@Override
public MogoSnapshotSetData createFromParcel( Parcel source ) {
return new MogoSnapshotSetData( source );
public MogoSnapshotSetData createFromParcel(Parcel in) {
return new MogoSnapshotSetData(in);
}
@Override
public MogoSnapshotSetData[] newArray( int size ) {
public MogoSnapshotSetData[] newArray(int size) {
return new MogoSnapshotSetData[size];
}
};
@Override
public String toString() {
return "MogoSnapshotSetData{" +
"msgId='" + msgId + '\'' +
", time=" + time +
", expire=" + expire +
", allList=" + allList +
", trafficLight=" + trafficLight +
'}';
}
}

View File

@@ -12,7 +12,7 @@ import android.widget.TextView;
import com.mogo.map.location.IMogoLocationListener;
import com.mogo.map.location.MogoLocation;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.entity.AITrafficLightEntity;
import com.mogo.module.common.entity.MogoSnapshotSetData;
import com.mogo.module.extensions.R;
import com.mogo.service.adas.IMogoAdasWarnMessageCallback;
import com.mogo.service.adas.MogoADASWarnType;
@@ -30,7 +30,7 @@ import org.json.JSONObject;
* @author tongchenfei
*/
public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLocationListener,
Handler.Callback , IMogoOnWebSocketMessageListener {
Handler.Callback , IMogoOnWebSocketMessageListener<MogoSnapshotSetData> {
private static final String TAG = "AdasNoticeHelper";
private static final int MSG_HIDE_TRAFFIC_LIGHT_BY_OBU = 1001;
@@ -204,7 +204,7 @@ public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLoca
}
}
private void handleCloudTrafficLight(AITrafficLightEntity trafficLightEntity){
private void handleCloudTrafficLight(){
if (tvTrafficLight != null && !handler.hasMessages(MSG_HIDE_TRAFFIC_LIGHT_BY_OBU)) {
handler.removeMessages(MSG_HIDE_TRAFFIC_LIGHT_BY_CLOUD);
// todo drawTrafficLight
@@ -239,4 +239,9 @@ public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLoca
public WebSocketMsgType getDownLinkType() {
return WebSocketMsgType.MSG_TYPE_DOWNLINK_CAR_DATA;
}
@Override
public void onMsgReceived(MogoSnapshotSetData obj) {
Logger.d(TAG, "收到大而全数据: " + obj);
}
}

View File

@@ -36,6 +36,7 @@ import com.mogo.map.navi.MogoTraffic;
import com.mogo.map.uicontroller.IMogoMapUIController;
import com.mogo.module.common.MogoModule;
import com.mogo.module.common.MogoModulePaths;
import com.mogo.module.common.entity.CloudLocationInfo;
import com.mogo.module.common.entity.MarkerResponse;
import com.mogo.module.common.map.MapCenterPointStrategy;
import com.mogo.module.common.map.Scene;
@@ -439,7 +440,7 @@ public class MogoServices implements IMogoMapListener,
AutoPilotRemoteController.getInstance().start();
// mThreadHandler.sendEmptyMessageDelayed( ServiceConst.MSG_SEND_CAR_LOCATION_AND_ADAS_RECOGNIZED_RESULT_2_SERVER, 0 );
mThreadHandler.sendEmptyMessageDelayed( ServiceConst.MSG_SEND_CAR_LOCATION_AND_ADAS_RECOGNIZED_RESULT_2_SERVER, 0 );
}
private void initLocationServiceProcess( Context context ) {
@@ -459,17 +460,17 @@ public class MogoServices implements IMogoMapListener,
LocationResult locationResult = null;
if ( lastCarLocation != null ) {
locationResult = new LocationResult();
locationResult.lastCoordinate = new LocationResult.LocationInfo();
locationResult.lastCoordinate.alt = lastCarLocation.getAltitude();
locationResult.lastCoordinate.heading = lastCarLocation.getBearing();
locationResult.lastCoordinate.lat = lastCarLocation.getLatitude();
locationResult.lastCoordinate.lon = lastCarLocation.getLongitude();
locationResult.lastCoordinate.satelliteTime = lastCarLocation.getTime();
locationResult.lastCoordinate.systemTime = System.currentTimeMillis();
locationResult.lastCoordinate.speed = lastCarLocation.getSpeed();
locationResult.lastCoordinate = new CloudLocationInfo();
locationResult.lastCoordinate.setAlt(lastCarLocation.getAltitude());
locationResult.lastCoordinate.setHeading(lastCarLocation.getBearing());
locationResult.lastCoordinate.setLat(lastCarLocation.getLatitude());
locationResult.lastCoordinate.setLon(lastCarLocation.getLongitude());
locationResult.lastCoordinate.setSatelliteTime(lastCarLocation.getTime());
locationResult.lastCoordinate.setSystemTime(System.currentTimeMillis());
locationResult.lastCoordinate.setSpeed(lastCarLocation.getSpeed());
locationResult.coordinates = new ArrayList<>();
locationResult.sn = com.mogo.commons.network.Utils.getSn();
locationResult.mortonCode = MortonCode.wrapEncodeMorton( locationResult.lastCoordinate.lon, locationResult.lastCoordinate.lat );
locationResult.mortonCode = MortonCode.wrapEncodeMorton( locationResult.lastCoordinate.getLon(), locationResult.lastCoordinate.getLat() );
}
List< ADASRecognizedResult > recognizedResults = MarkerServiceHandler.getADASController().getLastADASRecognizedResult();
OnePerSecondSendContent content = new OnePerSecondSendContent();

View File

@@ -1,5 +1,7 @@
package com.mogo.module.service.websocket;
import com.mogo.module.common.entity.CloudLocationInfo;
import java.util.List;
public
@@ -14,16 +16,6 @@ class LocationResult {
public String sn;
public long mortonCode;
public LocationInfo lastCoordinate;
public List< LocationInfo > coordinates;
public static class LocationInfo {
public double lat;
public double lon;
public double heading;
public long systemTime;
public long satelliteTime;
public double alt;
public double speed;
}
public CloudLocationInfo lastCoordinate;
public List< CloudLocationInfo > coordinates;
}