From fea65e541de2d31ea381897ce456028f08a196c8 Mon Sep 17 00:00:00 2001 From: zhongchao Date: Tue, 23 Feb 2021 17:24:30 +0800 Subject: [PATCH 1/3] update MoGoAiCloud sdk version and replace the CloudLocationInfo --- .idea/gradle.xml | 1 + gradle.properties | 14 +- .../common/entity/CloudLocationInfo.java | 183 ------------------ .../service/location/MogoRTKLocation.java | 3 +- .../uploadintime/SnapshotUploadInTime.java | 6 +- .../service/utils/LocationParseUtil.java | 2 +- .../utils/SimpleLocationCorrectStrategy.java | 19 +- .../service/websocket/LocationResult.java | 5 +- 8 files changed, 25 insertions(+), 208 deletions(-) delete mode 100644 modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/CloudLocationInfo.java diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 83405b8de1..4ff10f68a5 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -91,6 +91,7 @@ diff --git a/gradle.properties b/gradle.properties index 0e81775ae9..97a676134e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -155,19 +155,19 @@ LOGLIB_VERSION = 1.0.4 ######## MogoAiCloudSDK Version # 网络请求 -MOGO_NETWORK_VERSION=1.0.32-SNAPSHOT +MOGO_NETWORK_VERSION=1.0.33-SNAPSHOT # 鉴权 -MOGO_PASSPORT_VERSION=1.0.32-SNAPSHOT +MOGO_PASSPORT_VERSION=1.0.33-SNAPSHOT # 常链接 -MOGO_SOCKET_VERSION=1.0.32-SNAPSHOT +MOGO_SOCKET_VERSION=1.0.33-SNAPSHOT # 数据采集 -MOGO_REALTIME_VERSION=1.0.32-SNAPSHOT +MOGO_REALTIME_VERSION=1.0.33-SNAPSHOT # 探路,道路事件发布,获取 -MOGO_TANLU_VERSION=1.0.32-SNAPSHOT +MOGO_TANLU_VERSION=1.0.33-SNAPSHOT # 直播推流 -MOGO_LIVE_VERSION=1.0.32-SNAPSHOT +MOGO_LIVE_VERSION=1.0.33-SNAPSHOT # 直播拉流 -MOGO_TRAFFICLIVE_VERSION=1.0.32-SNAPSHOT +MOGO_TRAFFICLIVE_VERSION=1.0.33-SNAPSHOT ######## Foundation MogoAiCloud Module # mogoAiCloud apk services 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 deleted file mode 100644 index c7fb628568..0000000000 --- a/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/CloudLocationInfo.java +++ /dev/null @@ -1,183 +0,0 @@ -package com.mogo.module.common.entity; - -import android.os.Parcel; -import android.os.Parcelable; - -import com.mogo.commons.debug.DebugConfig; -import com.mogo.utils.CoordinateUtils; - -import java.util.Objects; - -/** - * 云端定位信息和自车定位信息 - * - * @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; - private int vehicleType = 0; - - public CloudLocationInfo() { - if ( DebugConfig.getProductFlavor().contains( "taxi" ) ) { - vehicleType = 9; - } else if ( DebugConfig.getProductFlavor().contains( "bus" ) ) { - vehicleType = 10; - } - } - - public CloudLocationInfo( CloudLocationInfo info ) { - this.lat = info.getLat(); - this.lon = info.getLon(); - this.heading = info.getHeading(); - this.systemTime = System.currentTimeMillis(); - this.satelliteTime = info.getSatelliteTime(); - this.alt = info.alt; - this.speed = info.speed; - } - - public void convertCoor2GCJ02(){ - double[] amapCoord = CoordinateUtils.transformWgsToGcj( lat, lon ); - if ( amapCoord != null ) { - this.lat = amapCoord[1]; - this.lon = amapCoord[0]; - } - } - - 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 + - '}'; - } - - public String print() { - return "CloudLocation{ lon: " + lon + " lat: " + lat + " heading: " + heading + " speed: " - + speed + "}"; - } - - @Override - public boolean equals( Object o ) { - if ( this == o ) { - return true; - } - if ( o == null || getClass() != o.getClass() ) { - return false; - } - CloudLocationInfo that = ( CloudLocationInfo ) o; - return Double.compare( that.lat, lat ) == 0 && - Double.compare( that.lon, lon ) == 0; - } - - @Override - public int hashCode() { - return Objects.hash( lat, lon ); - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel( Parcel dest, int flags ) { - dest.writeDouble( this.lat ); - dest.writeDouble( this.lon ); - dest.writeDouble( this.heading ); - dest.writeLong( this.systemTime ); - dest.writeLong( this.satelliteTime ); - dest.writeDouble( this.alt ); - dest.writeDouble( this.speed ); - dest.writeInt( this.vehicleType ); - } - - protected CloudLocationInfo( Parcel in ) { - this.lat = in.readDouble(); - this.lon = in.readDouble(); - this.heading = in.readDouble(); - this.systemTime = in.readLong(); - this.satelliteTime = in.readLong(); - this.alt = in.readDouble(); - this.speed = in.readDouble(); - this.vehicleType = in.readInt(); - } - - public static final Creator< CloudLocationInfo > CREATOR = new Creator< CloudLocationInfo >() { - @Override - public CloudLocationInfo createFromParcel( Parcel source ) { - return new CloudLocationInfo( source ); - } - - @Override - public CloudLocationInfo[] newArray( int size ) { - return new CloudLocationInfo[size]; - } - }; -} diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/location/MogoRTKLocation.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/location/MogoRTKLocation.java index a6acfaaa9c..afdf3b93a1 100644 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/location/MogoRTKLocation.java +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/location/MogoRTKLocation.java @@ -11,12 +11,11 @@ import android.location.LocationManager; import android.os.Bundle; import android.os.Handler; import android.os.Message; -import android.util.Log; import com.mogo.commons.AbsMogoApplication; import com.mogo.commons.debug.DebugConfig; -import com.mogo.module.common.entity.CloudLocationInfo; import com.mogo.module.service.uploadintime.SnapshotUploadInTime; +import com.mogo.realtime.entity.CloudLocationInfo; import com.mogo.utils.WorkThreadHandler; import com.mogo.utils.logger.Logger; diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/uploadintime/SnapshotUploadInTime.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/uploadintime/SnapshotUploadInTime.java index 54e3e9407a..b24e2d4111 100644 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/uploadintime/SnapshotUploadInTime.java +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/uploadintime/SnapshotUploadInTime.java @@ -3,12 +3,12 @@ package com.mogo.module.service.uploadintime; import android.content.Context; import com.mogo.commons.utils.MortonCode; -import com.mogo.module.common.entity.CloudLocationInfo; import com.mogo.module.service.MarkerServiceHandler; import com.mogo.module.service.location.MogoRTKLocation; import com.mogo.module.service.utils.SimpleLocationCorrectStrategy; import com.mogo.module.service.websocket.LocationResult; import com.mogo.module.service.websocket.OnePerSecondSendContent; +import com.mogo.realtime.entity.CloudLocationInfo; import com.mogo.service.adas.entity.ADASRecognizedResult; import com.mogo.service.connection.IMogoOnWebSocketMessageListener; import com.mogo.service.connection.WebSocketMsgType; @@ -20,7 +20,7 @@ import java.util.ArrayList; import java.util.List; public -/** +/* * @author congtaowang * @since 2020/12/14 * @@ -67,7 +67,7 @@ class SnapshotUploadInTime implements MogoRTKLocation.RTKLocationListener { } @Override - public void onLocationChanged( int dataAccuracy, List< CloudLocationInfo > cloudLocationInfos ) { + public void onLocationChanged( int dataAccuracy, List cloudLocationInfos ) { startSendCarLocationAndAdasRecognizedResult2Server( dataAccuracy, cloudLocationInfos ); } diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/utils/LocationParseUtil.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/utils/LocationParseUtil.java index 17a20c8115..3df873b013 100644 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/utils/LocationParseUtil.java +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/utils/LocationParseUtil.java @@ -3,7 +3,7 @@ package com.mogo.module.service.utils; import android.location.Location; import com.mogo.map.MogoLatLng; -import com.mogo.module.common.entity.CloudLocationInfo; +import com.mogo.realtime.entity.CloudLocationInfo; /** * 定位数据类型转换工具 diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/utils/SimpleLocationCorrectStrategy.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/utils/SimpleLocationCorrectStrategy.java index 57bf885f2e..e441e845ac 100644 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/utils/SimpleLocationCorrectStrategy.java +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/utils/SimpleLocationCorrectStrategy.java @@ -1,11 +1,10 @@ package com.mogo.module.service.utils; -import android.location.Location; import android.os.SystemClock; import com.mogo.map.MogoLatLng; import com.mogo.module.common.MogoApisHandler; -import com.mogo.module.common.entity.CloudLocationInfo; +import com.mogo.realtime.entity.CloudLocationInfo; import com.mogo.utils.logger.Logger; import java.util.ArrayList; @@ -28,16 +27,16 @@ public class SimpleLocationCorrectStrategy { private long anchorTime; private int errCount; - private static SimpleLocationCorrectStrategy instance = new SimpleLocationCorrectStrategy(); + private static final SimpleLocationCorrectStrategy instance = new SimpleLocationCorrectStrategy(); public static SimpleLocationCorrectStrategy getInstance(){ return instance; } - private List historyList = new ArrayList<>(); - private List validList = new ArrayList<>(); - private List correctList = new ArrayList<>(); - private List errList = new ArrayList<>(); + private final List historyList = new ArrayList<>(); + private final List validList = new ArrayList<>(); + private final List correctList = new ArrayList<>(); + private final List errList = new ArrayList<>(); public CloudLocationInfo correct(CloudLocationInfo info) { Logger.d(TAG, "info: " + info.print()); @@ -158,15 +157,15 @@ public class SimpleLocationCorrectStrategy { } private RecordLocationListener recordLocationListener = null; - private boolean hasCallbackReocrd = false; + private boolean hasCallbackRecord = false; public void setRecordLocationListener(RecordLocationListener recordLocationListener) { this.recordLocationListener = recordLocationListener; } private boolean recordLocation(){ - if (historyList.size() >= 100 && !hasCallbackReocrd && recordLocationListener != null) { - hasCallbackReocrd = true; + if (historyList.size() >= 100 && !hasCallbackRecord && recordLocationListener != null) { + hasCallbackRecord = true; recordLocationListener.onRecordFinish(historyList, correctList,validList,correctList); } return historyList.size() < 100; 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 8d0e4d2709..ad6c167c2d 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,11 +1,12 @@ package com.mogo.module.service.websocket; -import com.mogo.module.common.entity.CloudLocationInfo; + +import com.mogo.realtime.entity.CloudLocationInfo; import java.util.List; public -/** +/* * @author congtaowang * @since 2020/10/25 * From e2125cd6244d1ca7811bac191155c591b0cbbe4d Mon Sep 17 00:00:00 2001 From: zhongchao Date: Tue, 23 Feb 2021 17:34:40 +0800 Subject: [PATCH 2/3] add aiCloud sdk config --- app/src/main/java/com/mogo/launcher/MogoApplication.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/com/mogo/launcher/MogoApplication.java b/app/src/main/java/com/mogo/launcher/MogoApplication.java index 4bfe42b333..bcff92196b 100644 --- a/app/src/main/java/com/mogo/launcher/MogoApplication.java +++ b/app/src/main/java/com/mogo/launcher/MogoApplication.java @@ -210,6 +210,8 @@ public class MogoApplication extends AbsMogoApplication { clientConfig.setThirdPartyDeviceId(Utils.getSn()); // 设置循环检测间隔时间 clientConfig.setLoopCheckDelay(15 * 1000); + // 设置是否使用MoGoAiCloud SDK内部定位进行实时数据上报 + clientConfig.setIsUseExternalLocation(false); // 设置DNS经纬度位置 clientConfig.setIHttpDnsCurrentLocation(new IHttpDnsCurrentLocation() { From 0552dc0768f95375da4c2a6126430f2593abf47d Mon Sep 17 00:00:00 2001 From: wangcongtao Date: Tue, 23 Feb 2021 18:06:39 +0800 Subject: [PATCH 3/3] opt --- .idea/gradle.xml | 1 - .../module/service/MogoServiceProvider.java | 6 +- .../com/mogo/module/service/MogoServices.java | 4 +- .../intent/ADASStatusIntentHandler.java | 4 +- .../service/location/MogoRTKLocation.java | 164 ++++------------- .../module/service/spi/SPIRealTimeUpload.java | 4 +- .../MogoRefreshStrategyController.java | 2 +- .../SnapshotLocationController.java | 123 +++++++++++++ .../uploadintime/SnapshotUploadInTime.java | 171 ------------------ 9 files changed, 171 insertions(+), 308 deletions(-) create mode 100644 modules/mogo-module-service/src/main/java/com/mogo/module/service/uploadintime/SnapshotLocationController.java delete mode 100644 modules/mogo-module-service/src/main/java/com/mogo/module/service/uploadintime/SnapshotUploadInTime.java diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 4ff10f68a5..83405b8de1 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -91,7 +91,6 @@ diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/MogoServiceProvider.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/MogoServiceProvider.java index fd8276d2da..baa8ddec73 100644 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/MogoServiceProvider.java +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/MogoServiceProvider.java @@ -99,9 +99,9 @@ public class MogoServiceProvider implements IMogoModuleProvider { public void init( Context context ) { Logger.d( TAG, "init" ); MarkerServiceHandler.init( context ); - if ( DebugConfig.isNeedUploadCoordinatesDurationInTime() ) { - MogoRTKLocation.getInstance().init(); - } +// if ( DebugConfig.isNeedUploadCoordinatesDurationInTime() ) { +// } + MogoRTKLocation.getInstance().init(); MogoServices.getInstance().preInit( context ); MogoServices.getInstance().init( AbsMogoApplication.getApp() ); UiThreadHandler.postDelayed( () -> { 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 6438bf0b5a..98272ec65f 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 @@ -47,7 +47,7 @@ import com.mogo.module.service.refresh.CustomRefreshStrategy; import com.mogo.module.service.refresh.RefreshObject; import com.mogo.module.service.strategy.CarIconDisplayStrategy; import com.mogo.module.service.ttsConfig.TtsConfigModleData; -import com.mogo.module.service.uploadintime.SnapshotUploadInTime; +import com.mogo.module.service.uploadintime.SnapshotLocationController; import com.mogo.realtime.api.MoGoAiCloudRealTime; import com.mogo.service.adas.IMogoADASController; import com.mogo.service.adas.IMogoAdasCarDataCallback; @@ -982,7 +982,7 @@ public class MogoServices implements IMogoMapListener, e.printStackTrace(); } MarkerServiceHandler.getApis().getMapServiceApi().getMapUIController().syncLocation2Map( data ); - SnapshotUploadInTime.getInstance().syncAdasLocationInfo( data ); + SnapshotLocationController.getInstance().syncAdasLocationInfo( data ); } catch ( Exception e ) { e.printStackTrace(); } diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/intent/ADASStatusIntentHandler.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/intent/ADASStatusIntentHandler.java index 6d335d0afd..08feacc8f9 100644 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/intent/ADASStatusIntentHandler.java +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/intent/ADASStatusIntentHandler.java @@ -8,7 +8,7 @@ import com.mogo.module.service.MarkerServiceHandler; import com.mogo.module.service.ServiceConst; import com.mogo.module.service.carinfo.CarStateInfo; import com.mogo.module.service.receiver.MogoReceiver; -import com.mogo.module.service.uploadintime.SnapshotUploadInTime; +import com.mogo.module.service.uploadintime.SnapshotLocationController; import com.mogo.utils.logger.Logger; import com.mogo.utils.network.utils.GsonUtil; @@ -73,7 +73,7 @@ class ADASStatusIntentHandler implements IntentHandler { data.putOpt( "acceleration", stateInfo.getValues().getAcceleration() ); data.putOpt( "yawRate", stateInfo.getValues().getYaw_rate() ); MarkerServiceHandler.getApis().getMapServiceApi().getMapUIController().syncLocation2Map( data ); - SnapshotUploadInTime.getInstance().syncAdasLocationInfo( data ); + SnapshotLocationController.getInstance().syncAdasLocationInfo( data ); } catch ( Exception e ) { e.printStackTrace(); } diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/location/MogoRTKLocation.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/location/MogoRTKLocation.java index afdf3b93a1..3bbe6d2ed6 100644 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/location/MogoRTKLocation.java +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/location/MogoRTKLocation.java @@ -1,37 +1,21 @@ package com.mogo.module.service.location; -import android.content.BroadcastReceiver; import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; -import android.os.Handler; -import android.os.Message; import com.mogo.commons.AbsMogoApplication; -import com.mogo.commons.debug.DebugConfig; -import com.mogo.module.service.uploadintime.SnapshotUploadInTime; +import com.mogo.module.service.uploadintime.SnapshotLocationController; import com.mogo.realtime.entity.CloudLocationInfo; -import com.mogo.utils.WorkThreadHandler; import com.mogo.utils.logger.Logger; -import java.util.ArrayList; -import java.util.List; - public class MogoRTKLocation { private static final String TAG = "MogoRTKLocation"; - private static final int MSG_DATA_CHANGED = 0x100; - private static final long MSG_DATA_INTERNAL = 500L; - - private Handler mHandler; private LocationManager locationManager; - private RTKLocationListener rtkLocationListener; - private List cacheList = new ArrayList<>(); public static MogoRTKLocation getInstance() { return RTKHolder.rtkLoc; @@ -42,151 +26,79 @@ public class MogoRTKLocation { } private MogoRTKLocation() { - 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); - sendLocationData(); - -// Logger.d(TAG,"handleMessage开始发送消息"); - } - } - }; - mHandler.sendEmptyMessage(MSG_DATA_CHANGED); - Logger.d(TAG,"构造方法开始发送消息"); - } - - public interface RTKLocationListener { - void onLocationChanged(int dataAccuracy, List cloudLocationInfos); - } - - private void sendLocationData() { - - List list = null; - int dataAccuracy = 0; - if ( DebugConfig.isUseAdasRtkLocationInfo() ) { - dataAccuracy = 1; - list = new ArrayList<>(SnapshotUploadInTime.getInstance().getSendLocationData()); - } - if ( list == null || list.isEmpty() ) { - dataAccuracy = 0; - list = new ArrayList<>(cacheList); - } - if (cacheList != null && cacheList.size() > 0) { - cacheList.clear(); - } - if (rtkLocationListener != null) { - rtkLocationListener.onLocationChanged(dataAccuracy, list); - } - } - - public void registerRTKLocationListener(RTKLocationListener locationListener) { - rtkLocationListener = locationListener; - } - - public void unregisterRTKLocationListener(){ - rtkLocationListener = null; } public void init() { - locationManager = (LocationManager) AbsMogoApplication.getApp().getApplicationContext().getSystemService(Context.LOCATION_SERVICE); - String provider = locationManager.getBestProvider(getCriteria(), true); - Logger.d(TAG, "init provider : " + provider); - if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { + locationManager = ( LocationManager ) AbsMogoApplication.getApp().getApplicationContext().getSystemService( Context.LOCATION_SERVICE ); + String provider = locationManager.getBestProvider( getCriteria(), true ); + Logger.d( TAG, "init provider : " + provider ); + if ( locationManager.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) { try { - locationManager.requestLocationUpdates(provider, 0, 0, locationListener); - Location location = locationManager.getLastKnownLocation(provider); - if (location != null) { - Logger.i(TAG, "location : " + location.toString()); + locationManager.requestLocationUpdates( provider, 0, 0, locationListener ); + Location location = locationManager.getLastKnownLocation( provider ); + if ( location != null ) { + Logger.i( TAG, "location : " + location.toString() ); } - } catch (Exception e) { + } catch ( Exception e ) { e.printStackTrace(); - Logger.d(TAG, "RTK LocationManager requestLocationUpdates has Exception : " + e.getMessage()); + Logger.d( TAG, "RTK LocationManager requestLocationUpdates has Exception : " + e.getMessage() ); } } else { - Logger.d(TAG, "RTK LocationManager Provider GPS_PROVIDER unable"); + Logger.d( TAG, "RTK LocationManager Provider GPS_PROVIDER unable" ); } - - // 注册修改上报间隔的广播, 临时使用,后面可直接干掉,发送广播的地方在EntranceFragment - IntentFilter filter = new IntentFilter("com.mogo.launcher.action.FIX_UPLOAT_DELAY"); - AbsMogoApplication.getApp().registerReceiver(fixUploadDelayReceiver, filter); } private Criteria getCriteria() { Criteria criteria = new Criteria(); - criteria.setAccuracy(Criteria.ACCURACY_FINE); //高精 - criteria.setAltitudeRequired(false); - criteria.setBearingRequired(true); - criteria.setSpeedRequired(true); - criteria.setPowerRequirement(Criteria.POWER_LOW); + criteria.setAccuracy( Criteria.ACCURACY_FINE ); //高精 + criteria.setAltitudeRequired( false ); + criteria.setBearingRequired( true ); + criteria.setSpeedRequired( true ); + criteria.setPowerRequirement( Criteria.POWER_LOW ); return criteria; } private LocationListener locationListener = new LocationListener() { @Override - public void onLocationChanged(Location location) { - if (location != null) { + public void onLocationChanged( Location location ) { + if ( location != null ) { CloudLocationInfo cloudLocationInfo = new CloudLocationInfo(); - cloudLocationInfo.setAlt(location.getAltitude()); - cloudLocationInfo.setHeading(location.getBearing()); - cloudLocationInfo.setLat(location.getLatitude()); - cloudLocationInfo.setLon(location.getLongitude()); - cloudLocationInfo.setSpeed(location.getSpeed()); - cloudLocationInfo.setSatelliteTime(location.getTime()); - cloudLocationInfo.setSystemTime(System.currentTimeMillis()); + cloudLocationInfo.setAlt( location.getAltitude() ); + cloudLocationInfo.setHeading( location.getBearing() ); + cloudLocationInfo.setLat( location.getLatitude() ); + cloudLocationInfo.setLon( location.getLongitude() ); + cloudLocationInfo.setSpeed( location.getSpeed() ); + cloudLocationInfo.setSatelliteTime( location.getTime() ); + cloudLocationInfo.setSystemTime( System.currentTimeMillis() ); cloudLocationInfo.convertCoor2GCJ02(); - cacheList.add(cloudLocationInfo); + SnapshotLocationController.getInstance().syncLocationInfo( cloudLocationInfo ); } else { - Logger.e(TAG, "location == null"); + Logger.e( TAG, "location == null" ); } } @Override - public void onStatusChanged(String provider, int status, Bundle extras) { - Logger.d(TAG, "onStatusChanged status: " + status); + public void onStatusChanged( String provider, int status, Bundle extras ) { + Logger.d( TAG, "onStatusChanged status: " + status ); } @Override - public void onProviderEnabled(String provider) { - Logger.d(TAG, "onProviderEnabled"); + public void onProviderEnabled( String provider ) { + Logger.d( TAG, "onProviderEnabled" ); } @Override - public void onProviderDisabled(String provider) { - Logger.d(TAG, "onProviderEnabled"); + public void onProviderDisabled( String provider ) { + Logger.d( TAG, "onProviderEnabled" ); } }; public void stop() { - Logger.d(TAG, "stop RTK Location"); - if (locationManager != null && locationListener != null) { - locationManager.removeUpdates(locationListener); + Logger.d( TAG, "stop RTK Location" ); + if ( locationManager != null && locationListener != null ) { + locationManager.removeUpdates( locationListener ); } else { - Logger.d(TAG, "stop failed , reason : loc" + locationManager + " , or loc listener: " + locationListener + " is null"); - } - } - - private long uploadDelay = MSG_DATA_INTERNAL; - - private FixUploadDelayReceiver fixUploadDelayReceiver = new FixUploadDelayReceiver(); - - private class FixUploadDelayReceiver extends BroadcastReceiver{ - @Override - public void onReceive(Context context, Intent intent) { - uploadDelay = intent.getIntExtra("fixTime", 0); - } - } - - /** - * 默认保持{@link #uploadDelay}间隔进行位置上报,如遇服务端控制,进行上报间隔修改 - * @param delay 上报间隔 - */ - public void resetUploadDelay(long delay) { - if (mHandler != null && mHandler.hasMessages(MSG_DATA_CHANGED)) { - mHandler.removeMessages(MSG_DATA_CHANGED); - mHandler.sendEmptyMessageDelayed(MSG_DATA_CHANGED, delay); + Logger.d( TAG, "stop failed , reason : loc" + locationManager + " , or loc listener: " + locationListener + " is null" ); } } } diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/spi/SPIRealTimeUpload.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/spi/SPIRealTimeUpload.java index 6d8be6e2fa..94150778a4 100644 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/spi/SPIRealTimeUpload.java +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/spi/SPIRealTimeUpload.java @@ -1,7 +1,7 @@ package com.mogo.module.service.spi; import com.elegant.spi.annotations.Service; -import com.mogo.module.service.MarkerServiceHandler; +import com.mogo.module.service.uploadintime.SnapshotLocationController; import com.mogo.realtime.api.IRealTimeProvider; import com.mogo.realtime.entity.ADASRecognizedResult; import com.mogo.realtime.entity.CloudLocationInfo; @@ -20,6 +20,6 @@ public class SPIRealTimeUpload implements IRealTimeProvider { @Override public List getLocationMsg() { - return null; + return SnapshotLocationController.getInstance().getSendLocationData(); } } diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/strategy/MogoRefreshStrategyController.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/strategy/MogoRefreshStrategyController.java index cf1fd09e11..505564565c 100644 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/strategy/MogoRefreshStrategyController.java +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/strategy/MogoRefreshStrategyController.java @@ -38,7 +38,7 @@ public class MogoRefreshStrategyController implements IMogoRefreshStrategyContro @Override public void resetLocationUpDelay(long delay) { - MogoRTKLocation.getInstance().resetUploadDelay(delay); +// MogoRTKLocation.getInstance().resetUploadDelay(delay); } @Override diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/uploadintime/SnapshotLocationController.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/uploadintime/SnapshotLocationController.java new file mode 100644 index 0000000000..6963a99047 --- /dev/null +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/uploadintime/SnapshotLocationController.java @@ -0,0 +1,123 @@ +package com.mogo.module.service.uploadintime; + +import com.mogo.realtime.entity.CloudLocationInfo; +import com.mogo.utils.logger.Logger; + +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.List; + +public +/** + * @author congtaowang + * @since 2020/12/14 + * + * 实时坐标 + */ +class SnapshotLocationController { + + private static final String TAG = "SnapshotLocationController"; + + private static volatile SnapshotLocationController sInstance; + + private SnapshotLocationController() { + } + + public static SnapshotLocationController getInstance() { + if ( sInstance == null ) { + synchronized ( SnapshotLocationController.class ) { + if ( sInstance == null ) { + sInstance = new SnapshotLocationController(); + } + } + } + return sInstance; + } + + public synchronized void release() { + sInstance = null; + } + + private Object readResolve() { + // 阻止反序列化,必须实现 Serializable 接口 + return sInstance; + } + + private List< CloudLocationInfo > mLocationList = new ArrayList<>(); + + /** + * 同步从定位来的数据(也可能是rtk) + * + * @param cli + */ + public void syncLocationInfo( CloudLocationInfo cli ) { + if ( cli == null ) { + return; + } + mLocationList.add( cli ); + } + + // adda 工控机数据缓存 + private List< CloudLocationInfo > mMachineCacheList = new ArrayList<>(); + + /** + * 同步从工控机来的数据 + * + * @param data + */ + public void syncAdasLocationInfo( JSONObject data ) { + if ( data == null ) { + return; + } + Logger.d( TAG, "同步到rtk数据" ); + double lon = data.optDouble( "lon", -1 ); + double lat = data.optDouble( "lat", -1 ); + double alt = data.optDouble( "alt", -1 ); + double heading = data.optDouble( "heading", -1 ); + double acceleration = data.optDouble( "acceleration", -1 ); + double yawRate = data.optDouble( "yawRate", -1 ); + double speed = data.optDouble( "speed", -1 ); + long satelliteTime = 0L; + try { + satelliteTime = Long.valueOf( data.optString( "satelliteTime" ) ); + } catch ( Exception e ) { + e.printStackTrace(); + } + + CloudLocationInfo cloudLocationInfo = new CloudLocationInfo(); + cloudLocationInfo.setAlt( alt ); + cloudLocationInfo.setHeading( heading ); + cloudLocationInfo.setLat( lat ); + cloudLocationInfo.setLon( lon ); + cloudLocationInfo.setSpeed( speed ); + cloudLocationInfo.setSatelliteTime( satelliteTime ); + cloudLocationInfo.setSystemTime( System.currentTimeMillis() ); + cloudLocationInfo.convertCoor2GCJ02(); + mMachineCacheList.add( cloudLocationInfo ); + } + + /** + * 获取某一段时间内的坐标集合 + * + * @return + */ + public List< CloudLocationInfo > getSendLocationData() { + + List< CloudLocationInfo > list = null; + int dataAccuracy = 0; + if ( mMachineCacheList != null ) { + dataAccuracy = 1; + list = new ArrayList<>( mMachineCacheList ); + mMachineCacheList.clear(); + } + if ( list == null || list.isEmpty() ) { + dataAccuracy = 0; + if ( mLocationList != null ) { + list = new ArrayList<>( mLocationList ); + mLocationList.clear(); + } + } + return list; + } +} diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/uploadintime/SnapshotUploadInTime.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/uploadintime/SnapshotUploadInTime.java deleted file mode 100644 index b24e2d4111..0000000000 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/uploadintime/SnapshotUploadInTime.java +++ /dev/null @@ -1,171 +0,0 @@ -package com.mogo.module.service.uploadintime; - -import android.content.Context; - -import com.mogo.commons.utils.MortonCode; -import com.mogo.module.service.MarkerServiceHandler; -import com.mogo.module.service.location.MogoRTKLocation; -import com.mogo.module.service.utils.SimpleLocationCorrectStrategy; -import com.mogo.module.service.websocket.LocationResult; -import com.mogo.module.service.websocket.OnePerSecondSendContent; -import com.mogo.realtime.entity.CloudLocationInfo; -import com.mogo.service.adas.entity.ADASRecognizedResult; -import com.mogo.service.connection.IMogoOnWebSocketMessageListener; -import com.mogo.service.connection.WebSocketMsgType; -import com.mogo.utils.logger.Logger; - -import org.json.JSONObject; - -import java.util.ArrayList; -import java.util.List; - -public -/* - * @author congtaowang - * @since 2020/12/14 - * - * 实时上报坐标、识别物体 - */ -class SnapshotUploadInTime implements MogoRTKLocation.RTKLocationListener { - - private static final String TAG = "SnapshotUploadInTime"; - - private static volatile SnapshotUploadInTime sInstance; - private Context mContext; - - private SnapshotUploadInTime() { - } - - public static SnapshotUploadInTime getInstance() { - if ( sInstance == null ) { - synchronized ( SnapshotUploadInTime.class ) { - if ( sInstance == null ) { - sInstance = new SnapshotUploadInTime(); - } - } - } - return sInstance; - } - - public synchronized void release() { - sInstance = null; - } - - private Object readResolve() { - // 阻止反序列化,必须实现 Serializable 接口 - return sInstance; - } - - public void start( Context context ) { - mContext = context.getApplicationContext(); - MogoRTKLocation.getInstance().registerRTKLocationListener( this ); - } - - public void stop() { - MogoRTKLocation.getInstance().unregisterRTKLocationListener(); - MogoRTKLocation.getInstance().stop(); - } - - @Override - public void onLocationChanged( int dataAccuracy, List cloudLocationInfos ) { - startSendCarLocationAndAdasRecognizedResult2Server( dataAccuracy, cloudLocationInfos ); - } - - private CloudLocationInfo mLastInfo; - - private void startSendCarLocationAndAdasRecognizedResult2Server( int dataAccuracy, List< CloudLocationInfo > cloudLocationInfo ) { - CloudLocationInfo lastInfo = null; - // 如果数组内容不为空,就用数组最后一个值 - if ( cloudLocationInfo != null && !cloudLocationInfo.isEmpty() ) { - lastInfo = cloudLocationInfo.get( cloudLocationInfo.size() - 1 ); - mLastInfo = lastInfo; - } - if ( lastInfo == null ) { - lastInfo = mLastInfo; - } - LocationResult locationResult = null; - if ( lastInfo != null ) { - // 定位点预测纠偏 - lastInfo = SimpleLocationCorrectStrategy.getInstance().correct( lastInfo ); - locationResult = new LocationResult(); - locationResult.dataAccuracy = dataAccuracy; - if ( lastInfo != null ) { - locationResult.lastCoordinate = lastInfo; - locationResult.mortonCode = MortonCode.wrapEncodeMorton( lastInfo.getLon(), lastInfo.getLat() ); - } - locationResult.coordinates = new ArrayList<>(); - locationResult.sn = com.mogo.commons.network.Utils.getSn(); - if ( cloudLocationInfo == null || cloudLocationInfo.isEmpty() ) { - locationResult.coordinates.addAll( new ArrayList<>() ); - } else { - locationResult.coordinates.addAll( cloudLocationInfo ); - } - } - List< ADASRecognizedResult > recognizedResults = MarkerServiceHandler.getADASController().getLastADASRecognizedResult(); - Logger.d( TAG, "发送的adas识别数量 = %s", recognizedResults == null ? 0 : recognizedResults.size() ); - OnePerSecondSendContent content = new OnePerSecondSendContent(); - content.self = locationResult; - content.adas = recognizedResults; - - if ( content.self == null && - ( content.adas == null || content.adas.isEmpty() ) ) { - Logger.d( TAG, "no information 2 sent" ); - return; - } - - - MarkerServiceHandler.getApis().getWebSocketManagerApi( mContext ).sendMsg( content, new IMogoOnWebSocketMessageListener() { - @Override - public WebSocketMsgType getDownLinkType() { - return null; - } - - @Override - public WebSocketMsgType getUpLinkType() { - return WebSocketMsgType.MSG_TYPE_UPLINK_CAR_DATA; - } - } ); - } - - // adda 工控机数据缓存 - private List< CloudLocationInfo > cacheList = new ArrayList<>(); - - public void syncAdasLocationInfo( JSONObject data ) { - if ( data == null ) { - return; - } - Logger.d( TAG, "同步到rtk数据" ); - double lon = data.optDouble( "lon", -1 ); - double lat = data.optDouble( "lat", -1 ); - double alt = data.optDouble( "alt", -1 ); - double heading = data.optDouble( "heading", -1 ); - double acceleration = data.optDouble( "acceleration", -1 ); - double yawRate = data.optDouble( "yawRate", -1 ); - double speed = data.optDouble( "speed", -1 ); - long satelliteTime = 0L; - try { - satelliteTime = Long.valueOf( data.optString( "satelliteTime" ) ); - } catch ( Exception e ) { - e.printStackTrace(); - } - - CloudLocationInfo cloudLocationInfo = new CloudLocationInfo(); - cloudLocationInfo.setAlt( alt ); - cloudLocationInfo.setHeading( heading ); - cloudLocationInfo.setLat( lat ); - cloudLocationInfo.setLon( lon ); - cloudLocationInfo.setSpeed( speed ); - cloudLocationInfo.setSatelliteTime( satelliteTime ); - cloudLocationInfo.setSystemTime( System.currentTimeMillis() ); - cloudLocationInfo.convertCoor2GCJ02(); - cacheList.add( cloudLocationInfo ); - } - - public List< CloudLocationInfo > getSendLocationData() { - List< CloudLocationInfo > list = new ArrayList<>( cacheList ); - if ( cacheList != null && cacheList.size() > 0 ) { - cacheList.clear(); - } - return list; - } -}