This commit is contained in:
wangcongtao
2020-10-25 15:51:28 +08:00
40 changed files with 946 additions and 92 deletions

View File

@@ -6,7 +6,6 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.location.Location;
import android.net.ConnectivityManager;
import android.net.wifi.WifiManager;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
@@ -20,6 +19,7 @@ import com.mogo.commons.debug.DebugConfig;
import com.mogo.commons.network.ParamsProvider;
import com.mogo.commons.network.SubscribeImpl;
import com.mogo.commons.storage.SpStorage;
import com.mogo.commons.utils.MortonCode;
import com.mogo.commons.voice.AIAssist;
import com.mogo.commons.voice.IMogoVoiceCmdCallBack;
import com.mogo.map.IDestroyable;
@@ -53,9 +53,9 @@ import com.mogo.module.service.refresh.AutoRefreshStrategy;
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.websocket.LocationResult;
import com.mogo.service.adas.IMogoADASController;
import com.mogo.service.cardmanager.IMogoCardManager;
import com.mogo.service.connection.IMogoOnMessageListener;
import com.mogo.service.adas.entity.ADASRecognizedResult;
import com.mogo.service.fragmentmanager.FragmentStackTransactionListener;
import com.mogo.service.fragmentmanager.IMogoFragmentManager;
import com.mogo.service.intent.IMogoIntentListener;
@@ -105,6 +105,7 @@ public class MogoServices implements IMogoMapListener,
IDestroyable {
private boolean mInternalUnWakeupRegisterStatus = false;
private Location mLastCarLocation;
private MogoServices() {
// private constructor
@@ -426,6 +427,8 @@ public class MogoServices implements IMogoMapListener,
}
AutoPilotRemoteController.getInstance().start();
mThreadHandler.sendEmptyMessageDelayed( ServiceConst.MSG_SEND_CAR_LOCATION_AND_ADAS_RECOGNIZED_RESULT_2_SERVER, 0 );
}
private void initLocationServiceProcess( Context context ) {
@@ -440,6 +443,23 @@ public class MogoServices implements IMogoMapListener,
}
}
private void startSendCarLocationAndAdasRecognizedResult2Server() {
Location lastCarLocation = mLastCarLocation;
if ( lastCarLocation != null ) {
LocationResult locationResult = new LocationResult();
locationResult.alt = lastCarLocation.getAltitude();
locationResult.heading = lastCarLocation.getBearing();
locationResult.lat = lastCarLocation.getLatitude();
locationResult.lon = lastCarLocation.getLongitude();
locationResult.satelliteTime = lastCarLocation.getTime();
locationResult.systemTime = System.currentTimeMillis();
locationResult.speed = lastCarLocation.getSpeed();
locationResult.mortonCode = MortonCode.wrapEncodeMorton( locationResult.lon, locationResult.lat );
}
List< ADASRecognizedResult > recognizedResults = MarkerServiceHandler.getADASController().getLastADASRecognizedResult();
}
private void initWorkThread() {
mThreadHandler = new Handler( WorkThreadHandler.getInstance().getLooper() ) {
@Override
@@ -473,6 +493,9 @@ 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 );
}
}
};
@@ -748,6 +771,7 @@ public class MogoServices implements IMogoMapListener,
if ( latLng == null ) {
return;
}
mLastCarLocation = latLng;
// poi 定位无法获取时,使用该定位
if ( mLastAutoRefreshLocation == null ) {
MogoLatLng point = new MogoLatLng( latLng.getLatitude(), latLng.getLongitude() );

View File

@@ -218,4 +218,14 @@ public class ServiceConst {
*/
public static final long INTERVAL_SCHEDULE_CALCULATE_NOT_HOME_COMPANY_DISTANCE_FOR_PUSH = 60 * 1_000L;
/**
* 发送自车位置和adas识别结果给服务端
*/
public static final int MSG_SEND_CAR_LOCATION_AND_ADAS_RECOGNIZED_RESULT_2_SERVER = 0x401;
/**
* 间隔 1s 发送一次
*/
public static final long INTERVAL_SEND_CAR_LOCATION_AND_ADAS_RECOGNIZED_RESULT_2_SERVER = 1 * 1_000L;
}

View File

@@ -0,0 +1,139 @@
package com.mogo.module.service.utils;
import java.util.Arrays;
/**
* 莫顿编码
*
* @author linyang
* @since 2020.07.09
*/
public class MortonCode {
/**
* morton 转 经纬度 时的中间常量
*/
private static final long NDS_180_DEGREES = 0x7fffffff;
/**
* morton 转 经纬度 时的中间常量
*/
private static final long NDS_360_DEGREES = 4294967295L;
/**
* morton 转 经纬度 时的中间常量
*/
private static final long NDS_90_DEGREES = 0x3fffffff;
/**
* 经纬度转 morton 时的中间常量
*/
private static final double RULE_MORTON = Math.pow( 2, 32 ) / 360;
/**
* morton 转 经纬度 时的中间常量
*/
private static final double RULE_MORTON_TO_LONLAT = 360.0 / Math.pow( 2, 32 );
/**
* 编码 morton code
*
* @param lon
* @param lat
* @return
*/
public static long encodeMorton( Double lon, Double lat ) {
Long bit = 1L;
long mortonCode = 0L;
long x = ( long ) ( lon * RULE_MORTON );
long y = ( long ) ( lat * RULE_MORTON );
if ( y < 0 ) {
y += 0x7FFFFFFF;
}
y = y << 1;
for ( int i = 0; i < 32; i++ ) {
// x-part
mortonCode = mortonCode | ( x & bit );
x = x << 1;
bit = bit << 1;
// y-part
mortonCode = mortonCode | ( y & bit );
y = y << 1;
bit = bit << 1;
}
return mortonCode;
}
/**
* 将莫顿码解码为坐标
*
* @param mortonCode
* @return
*/
public static double[] decodeMorton( long mortonCode ) {
long[] midPoint = mortonCodeToCoord( mortonCode );
normalizeCoord( midPoint );
double[] point = new double[2];
// 将经纬度长整数转化为 浮点类型
point[0] = midPoint[0] * RULE_MORTON_TO_LONLAT;
point[1] = midPoint[1] * RULE_MORTON_TO_LONLAT;
return point;
}
/**
* 莫顿码分别拆解为 编码后的经纬度长整数
*
* @param mortonCode
* @return
*/
private static long[] mortonCodeToCoord( long mortonCode ) {
long bit = 1L;
long[] longPoint = new long[2];
for ( int i = 0; i < 32; i++ ) {
longPoint[0] |= mortonCode & bit;
mortonCode >>= 1;
longPoint[1] |= mortonCode & bit;
bit <<= 1;
}
return longPoint;
}
/**
* 对编码后的经纬度长整数进行解码
*
* @param midPoint
*/
private static void normalizeCoord( long[] midPoint ) {
// if x > 180 degrees, then subtract 360 degrees
if ( midPoint[0] > NDS_180_DEGREES ) {
midPoint[0] -=
NDS_360_DEGREES + 1; // add 1 because 0 must be counted as well
} else if ( midPoint[0] < -NDS_180_DEGREES ) // if x < 180 , x += 360
{
midPoint[0] +=
NDS_360_DEGREES + 1; // add 1 because 0 must be counted as well
}
// if y > 90 degrees, then subtract 180 degrees
if ( midPoint[1] > NDS_90_DEGREES ) {
midPoint[1] -=
NDS_180_DEGREES + 1; // add 1 because 0 must be counted as well
} else if ( midPoint[1] < -NDS_90_DEGREES ) // if y < 90, y += 180
{
midPoint[1] +=
NDS_180_DEGREES + 1; // add 1 because 0 must be counted as well
}
return;
}
public static void main( String[] args ) {
System.out.println( encodeMorton( 116.39584, 39.98152 ) );
System.out.println( Arrays.toString( decodeMorton( 1415388919630379091L ) ) );
}
}

View File

@@ -0,0 +1,21 @@
package com.mogo.module.service.websocket;
public
/**
* @author congtaowang
* @since 2020/10/25
*
* 自车定位信息
*/
class LocationResult {
public String sn;
public double lat;
public double lon;
public double heading;
public long systemTime;
public long satelliteTime;
public double alt;
public double speed;
public long mortonCode;
}

View File

@@ -0,0 +1,18 @@
package com.mogo.module.service.websocket;
import com.mogo.service.adas.entity.ADASRecognizedResult;
import java.util.List;
public
/**
* @author congtaowang
* @since 2020/10/25
*
* 一秒一次的上行数据
*/
class OnePerSecondSendContent {
public LocationResult self;
public List< ADASRecognizedResult > adas;
}