From 859eb86eced326807fce68cedf5ef73e883d5db5 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 30 Oct 2020 16:25:14 +0800 Subject: [PATCH] fix bug --- libraries/map-custom/build.gradle | 2 +- .../com/mogo/module/service/MogoServices.java | 14 ++--- .../service/location/MogoRTKLocation.java | 55 +++++++++++++++++++ 3 files changed, 63 insertions(+), 8 deletions(-) diff --git a/libraries/map-custom/build.gradle b/libraries/map-custom/build.gradle index 2a4d16460d..ee7e68bcb6 100644 --- a/libraries/map-custom/build.gradle +++ b/libraries/map-custom/build.gradle @@ -55,7 +55,7 @@ dependencies { implementation project(':foudations:mogo-commons') } - implementation 'com.zhidaoauto.machine:map:1.0.0-online-27' + implementation 'com.zhidaoauto.machine:map:1.0.0-online-30' } apply from: new File(rootProject.rootDir, "gradle/upload.gradle").toString() 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 65f2869d04..f8eaa380c4 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 @@ -43,6 +43,7 @@ import com.mogo.module.common.map.Scene; import com.mogo.module.service.autopilot.AutoPilotRemoteController; import com.mogo.module.service.intent.IntentHandlerFactory; import com.mogo.module.service.launchercard.LauncherCardRefresher; +import com.mogo.module.service.location.MogoRTKLocation; import com.mogo.module.service.marker.MapMarkerManager; import com.mogo.module.service.network.RefreshCallback; import com.mogo.module.service.network.RefreshModel; @@ -445,8 +446,10 @@ public class MogoServices implements IMogoMapListener, } AutoPilotRemoteController.getInstance().start(); - - mThreadHandler.sendEmptyMessageDelayed( ServiceConst.MSG_SEND_CAR_LOCATION_AND_ADAS_RECOGNIZED_RESULT_2_SERVER, 0 ); + MogoRTKLocation.getInstance().registerRTKLocationListener( cloudLocationInfos -> { + Logger.i(TAG,"cloudLocationInfos size : " + cloudLocationInfos.size()); + startSendCarLocationAndAdasRecognizedResult2Server(cloudLocationInfos); + }); } private void initLocationServiceProcess( Context context ) { @@ -461,7 +464,7 @@ public class MogoServices implements IMogoMapListener, } } - private void startSendCarLocationAndAdasRecognizedResult2Server() { + private void startSendCarLocationAndAdasRecognizedResult2Server(List cloudLocationInfo) { Location lastCarLocation = mLastCarLocation; LocationResult locationResult = null; if ( lastCarLocation != null ) { @@ -477,7 +480,7 @@ public class MogoServices implements IMogoMapListener, locationResult.coordinates = new ArrayList<>(); locationResult.sn = com.mogo.commons.network.Utils.getSn(); locationResult.mortonCode = MortonCode.wrapEncodeMorton( locationResult.lastCoordinate.getLon(), locationResult.lastCoordinate.getLat() ); - locationResult.coordinates.add( locationResult.lastCoordinate ); + locationResult.coordinates.addAll( cloudLocationInfo ); } List< ADASRecognizedResult > recognizedResults = MarkerServiceHandler.getADASController().getLastADASRecognizedResult(); OnePerSecondSendContent content = new OnePerSecondSendContent(); @@ -531,9 +534,6 @@ public class MogoServices implements IMogoMapListener, } mStatusManager.setUserInteractionStatus( TAG, true, false ); mUiController.recoverLockMode(); - } else if ( msg.what == ServiceConst.MSG_SEND_CAR_LOCATION_AND_ADAS_RECOGNIZED_RESULT_2_SERVER ) { - startSendCarLocationAndAdasRecognizedResult2Server(); - mThreadHandler.sendEmptyMessageDelayed( ServiceConst.MSG_SEND_CAR_LOCATION_AND_ADAS_RECOGNIZED_RESULT_2_SERVER, ServiceConst.INTERVAL_SEND_CAR_LOCATION_AND_ADAS_RECOGNIZED_RESULT_2_SERVER ); } } }; 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 9087fc2698..b1676ccc7c 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 @@ -6,14 +6,27 @@ 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.module.common.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 = 1 * 1_000L; + + private Handler mHandler; private LocationManager locationManager; + private RTKLocationListener rtkLocationListener; + private List cacheList = new ArrayList<>(); public static MogoRTKLocation getInstance() { return RTKHolder.rtkLoc; @@ -24,7 +37,38 @@ public class MogoRTKLocation { } private MogoRTKLocation() { + mHandler = new Handler(WorkThreadHandler.getInstance().getLooper()) { + @Override + public void handleMessage(Message msg) { + super.handleMessage(msg); + if (msg.what == MSG_DATA_CHANGED) { + sendLocationData(); + mHandler.sendEmptyMessageDelayed(MSG_DATA_CHANGED, MSG_DATA_INTERNAL); + } + } + }; + mHandler.sendEmptyMessage(MSG_DATA_CHANGED); + } + public interface RTKLocationListener { + void onLocationChanged(List cloudLocationInfos); + } + + private void sendLocationData() { + if (rtkLocationListener != null) { + Logger.d(TAG, "sendLocationData size : " + cacheList.size()); + List list = new ArrayList(); + list.addAll(cacheList); + rtkLocationListener.onLocationChanged(list); + } + if (cacheList != null && cacheList.size() > 0) { + cacheList = null; + cacheList = new ArrayList<>(); + } + } + + public void registerRTKLocationListener(RTKLocationListener locationListener) { + rtkLocationListener = locationListener; } public void init() { @@ -61,6 +105,17 @@ public class MogoRTKLocation { @Override public void onLocationChanged(Location location) { Logger.d(TAG, "onLocationChanged : " + location.toString()); + 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()); + cacheList.add(cloudLocationInfo); + } } @Override