From 2dce3f825496468c5afa61b8572d7d060a366386 Mon Sep 17 00:00:00 2001 From: tongchenfei Date: Tue, 27 Oct 2020 15:53:34 +0800 Subject: [PATCH] opt --- .../base/services/socket/SocketManager.java | 2 +- .../websocket/WebSocketHandlerThread.java | 17 ++- .../mogo/base/websocket/WebSocketManager.java | 20 +-- .../common/entity/AITrafficLightEntity.java | 75 ---------- .../common/entity/CloudLocationInfo.java | 129 ++++++++++++++++++ .../module/common/entity/CloudRoadData.java | 95 +++++++++++++ .../common/entity/MogoSnapshotSetData.java | 80 +++++++++-- .../extensions/utils/AdasNoticeHelper.java | 11 +- .../com/mogo/module/service/MogoServices.java | 21 +-- .../service/websocket/LocationResult.java | 16 +-- 10 files changed, 336 insertions(+), 130 deletions(-) delete mode 100644 modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/AITrafficLightEntity.java create mode 100644 modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/CloudLocationInfo.java create mode 100644 modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/CloudRoadData.java diff --git a/foudations/mogo-base-services-apk/src/main/java/com/mogo/base/services/socket/SocketManager.java b/foudations/mogo-base-services-apk/src/main/java/com/mogo/base/services/socket/SocketManager.java index 22e6fb427c..ee75e2f5b0 100644 --- a/foudations/mogo-base-services-apk/src/main/java/com/mogo/base/services/socket/SocketManager.java +++ b/foudations/mogo-base-services-apk/src/main/java/com/mogo/base/services/socket/SocketManager.java @@ -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(); diff --git a/foudations/mogo-base-websocket-sdk/src/main/java/com/mogo/base/websocket/WebSocketHandlerThread.java b/foudations/mogo-base-websocket-sdk/src/main/java/com/mogo/base/websocket/WebSocketHandlerThread.java index e26eb49929..bf17ae09c5 100644 --- a/foudations/mogo-base-websocket-sdk/src/main/java/com/mogo/base/websocket/WebSocketHandlerThread.java +++ b/foudations/mogo-base-websocket-sdk/src/main/java/com/mogo/base/websocket/WebSocketHandlerThread.java @@ -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); + } } } diff --git a/foudations/mogo-base-websocket-sdk/src/main/java/com/mogo/base/websocket/WebSocketManager.java b/foudations/mogo-base-websocket-sdk/src/main/java/com/mogo/base/websocket/WebSocketManager.java index ac6cfd162b..5f96ec5c18 100644 --- a/foudations/mogo-base-websocket-sdk/src/main/java/com/mogo/base/websocket/WebSocketManager.java +++ b/foudations/mogo-base-websocket-sdk/src/main/java/com/mogo/base/websocket/WebSocketManager.java @@ -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 *

* key - msgType */ - private Map> mListeners = new ConcurrentHashMap<>(); + private Map> 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 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 diff --git a/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/AITrafficLightEntity.java b/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/AITrafficLightEntity.java deleted file mode 100644 index fbd6bf98ee..0000000000 --- a/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/AITrafficLightEntity.java +++ /dev/null @@ -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; - } -} diff --git a/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/CloudLocationInfo.java b/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/CloudLocationInfo.java new file mode 100644 index 0000000000..e6ea7dcfdd --- /dev/null +++ b/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/CloudLocationInfo.java @@ -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 CREATOR = new Creator() { + @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 + + '}'; + } +} diff --git a/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/CloudRoadData.java b/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/CloudRoadData.java new file mode 100644 index 0000000000..9c9ecbad4e --- /dev/null +++ b/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/CloudRoadData.java @@ -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 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 CREATOR = new Creator() { + @Override + public CloudRoadData createFromParcel(Parcel in) { + return new CloudRoadData(in); + } + + @Override + public CloudRoadData[] newArray(int size) { + return new CloudRoadData[size]; + } + }; +} diff --git a/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/MogoSnapshotSetData.java b/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/MogoSnapshotSetData.java index cb7702c8df..11acfdbe96 100644 --- a/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/MogoSnapshotSetData.java +++ b/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/MogoSnapshotSetData.java @@ -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 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 CREATOR = new Creator() { @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 + + '}'; + } } diff --git a/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/utils/AdasNoticeHelper.java b/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/utils/AdasNoticeHelper.java index cc59e48718..c3b9b78e28 100644 --- a/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/utils/AdasNoticeHelper.java +++ b/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/utils/AdasNoticeHelper.java @@ -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 { 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); + } } diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/MogoServices.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/MogoServices.java index 722ff32c2f..4bde03d82e 100644 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/MogoServices.java +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/MogoServices.java @@ -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(); diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/websocket/LocationResult.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/websocket/LocationResult.java index e31fb2398a..4b8d133085 100644 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/websocket/LocationResult.java +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/websocket/LocationResult.java @@ -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; }