This commit is contained in:
zhongchao
2021-02-24 15:38:27 +08:00
18 changed files with 512 additions and 366 deletions

View File

@@ -163,7 +163,7 @@ public class MogoApplication extends AbsMogoApplication {
protected void init() {
super.init();
final IMogoServiceApis apis = MogoApisHandler.getInstance().getApis();
prepareBaseService( apis, 2_000L );
prepareBaseService( apis, 0L );
}
@Override
@@ -198,7 +198,19 @@ public class MogoApplication extends AbsMogoApplication {
// 配置云服务API
MoGoAiCloudClientConfig clientConfig = MoGoAiCloudClientConfig.getInstance();
// 设置网络环境HTTP_DNS_ENV_QA、HTTP_DNS_ENV_RELEASE、HTTP_DNS_ENV_DEV
clientConfig.setNetMode(MogoHttpDnsConfig.HTTP_DNS_ENV_QA);
switch ( DebugConfig.getNetMode() ) {
case DebugConfig.NET_MODE_DEV:
clientConfig.setNetMode(MogoHttpDnsConfig.HTTP_DNS_ENV_DEV);
break;
case DebugConfig.NET_MODE_QA:
clientConfig.setNetMode(MogoHttpDnsConfig.HTTP_DNS_ENV_QA);
break;
case DebugConfig.NET_MODE_DEMO:
clientConfig.setNetMode(MogoHttpDnsConfig.HTTP_DNS_ENV_DEMO);
break;
default:
clientConfig.setNetMode(MogoHttpDnsConfig.HTTP_DNS_ENV_RELEASE);
}
// 设置是否是第三APP登录
clientConfig.setThirdLogin(true);
// 设置是否输出日志

View File

@@ -170,7 +170,7 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
// mFromType
// )
getInfo("", "", mLongitude, mLatitude, mType, 1.0f, "", "", 1, mFromType, CarCorderController.mainInfoId)?.let { uploadRoadInfo(it) }
getInfo("", mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 1, mFromType, CarCorderController.mainInfoId)?.let { uploadRoadInfo(it) }
//地图上打点
taskAsync(3_000) {
@@ -213,7 +213,7 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
// mFromType
// )
getInfo("", "", mLongitude, mLatitude, mType, 1.0f, "", "", 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
getInfo("", mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
}
@@ -259,7 +259,7 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
// mLatitude, mSpeed)
if (photoPath != null) {
getInfo(photoPath, "", mLongitude, mLatitude, mType, 1.0f, "", "", 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
getInfo(photoPath, mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
}
} else {
@@ -283,7 +283,7 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
// )
if (photoPath != null) {
getInfo(photoPath, "", mLongitude, mLatitude, mType, 1.0f, "", "", 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
getInfo(photoPath, mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
}
}
}
@@ -303,7 +303,7 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
// )
if (photoPath != null) {
getInfo(photoPath, "", mLongitude, mLatitude, mType, 1.0f, "", "", 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
getInfo(photoPath, mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
}
}
@@ -343,13 +343,11 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
entity?.let {
if (it.isCustom) {
// compressVideo(videoPath, thumbnailPath, it)
getInfo(videoPath, "", mLongitude, mLatitude, mType, 1.0f, "", "", 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
compressVideo(videoPath, thumbnailPath, it)
} else if (entity.fromType in STRATEGY_UPLOAD_TYPE_ARRAY) {
// 属于策略上报
// compressVideo(videoPath, thumbnailPath, it)
getInfo(videoPath, "", mLongitude, mLatitude, mType, 1.0f, "", "", 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
compressVideo(videoPath, thumbnailPath, it)
} else {
Log.d(
@@ -360,16 +358,14 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
Log.d(TAG, "onTakeVideoSuccess 111 abs =" + (abs(minSpeedVideo) / 3.6f))
if (speed >= (abs(minSpeedVideo) / 3.6f)) {
//获取视频以及缩略图成功,开始上报
// compressVideo(videoPath, thumbnailPath, it)
getInfo(videoPath, "", mLongitude, mLatitude, mType, 1.0f, "", "", 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
compressVideo(videoPath, thumbnailPath, it)
}
}
if (minSpeedVideo > 0 && maxSpeedVideo > 0) {
Log.d(TAG, "onTakeVideoSuccess minSpeedVideo > 0 -- speed = $speed")
if ((speed >= (minSpeedVideo / 3.6f)) && speed <= (maxSpeedVideo / 3.6f)) {
// compressVideo(videoPath, thumbnailPath, it)
getInfo(videoPath, "", mLongitude, mLatitude, mType, 1.0f, "", "", 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
compressVideo(videoPath, thumbnailPath, it)
} else {
}
} else {
@@ -414,7 +410,7 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
// mFromType
// )
getInfo("", "", mLongitude, mLatitude, mType, 1.0f, "", "", 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
getInfo("", mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
//地图上打点
taskAsync(3_000) {
@@ -429,24 +425,24 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
/**
* 压缩视频并且上传
*/
// private fun compressVideo(videoPath: String, thumbnailPath: String, entity: TakeEntity) {
// Log.d(
// TAG,
// "outputVideoPath = " + outputVideoPath + ">> videoPath=" + videoPath + " isCustom = ${entity.isCustom}"
// )
// val startTime = System.currentTimeMillis()
// Thread(Runnable {
// try {
// VideoProcessor.processor(AbsMogoApplication.getApp().applicationContext)
// .input(videoPath)
// .output(outputVideoPath)
// .removeAudio(true)
// .outWidth(1920)
// .outHeight(1080)
// .bitrate(2000 * 1024)
// .frameRate(25)
// .process()
// Log.d(TAG, "compress cost time =" + (System.currentTimeMillis() - startTime))
private fun compressVideo(videoPath: String, thumbnailPath: String, entity: TakeEntity) {
Log.d(
TAG,
"outputVideoPath = " + outputVideoPath + ">> videoPath=" + videoPath + " isCustom = ${entity.isCustom}"
)
val startTime = System.currentTimeMillis()
Thread(Runnable {
try {
VideoProcessor.processor(AbsMogoApplication.getApp().applicationContext)
.input(videoPath)
.output(outputVideoPath)
.removeAudio(true)
.outWidth(1920)
.outHeight(1080)
.bitrate(2000 * 1024)
.frameRate(25)
.process()
Log.d(TAG, "compress cost time =" + (System.currentTimeMillis() - startTime))
// CosStatusController().uploadFile(
// mutableListOf(outputVideoPath, thumbnailPath),
// entity,
@@ -457,17 +453,19 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
// mLatitude,
// mSpeed
// )
//
// //删除压缩前的视频
// deletePicFile(videoPath)
// } catch (e: Exception) {
// Log.e(TAG, "compressVideo e = $e")
// //删除压缩前的视频
// deletePicFile(videoPath)
// e.printStackTrace()
// }
// }).start()
// }
getInfo(outputVideoPath, mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
//删除压缩前的视频
deletePicFile(videoPath)
} catch (e: Exception) {
Log.e(TAG, "compressVideo e = $e")
//删除压缩前的视频
deletePicFile(videoPath)
e.printStackTrace()
}
}).start()
}
/**
* 上报路况的视频和图片
@@ -475,7 +473,9 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
fun uploadRoadInfo(info: UploadInfo) {
MogoUploadManager.getInstance(AbsMogoApplication.getApp().applicationContext).uploadInfo(info, object : ITanluUploadCallback {
override fun onSuccess(result: BaseData<UploadResult>) {
if (result != null) {
Log.d(TAG, "result =" + result.result);
}
}
override fun onFailure(code: Int) {
@@ -531,7 +531,7 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
// mFromType
// )
getInfo("", "", mLongitude, mLatitude, mType, 1.0f, "", "", 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
getInfo("", mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
}

View File

@@ -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( () -> {

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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<CloudLocationInfo> 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<CloudLocationInfo> cloudLocationInfos);
}
private void sendLocationData() {
List<CloudLocationInfo> 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" );
}
}
}

View File

@@ -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<CloudLocationInfo> getLocationMsg() {
return null;
return SnapshotLocationController.getInstance().getSendLocationData();
}
}

View File

@@ -38,7 +38,7 @@ public class MogoRefreshStrategyController implements IMogoRefreshStrategyContro
@Override
public void resetLocationUpDelay(long delay) {
MogoRTKLocation.getInstance().resetUploadDelay(delay);
// MogoRTKLocation.getInstance().resetUploadDelay(delay);
}
@Override

View File

@@ -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;
}
}

View File

@@ -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<CloudLocationInfo> 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;
}
}

View File

@@ -628,7 +628,6 @@ public class TanluManager implements IMogoMarkerClickListener,
private void showBonndsRoadtion() {
Logger.e(TAG, "showBonndsRoadtion markerExploreWayList.size() = " + markerExploreWayList.size());
Logger.d(TAG, "showBonndsRoadtion getMogoList().size() = " + getMogoList().size());
//经度
Double longit = TanluServiceManager.getLocationClient().getLastKnowLocation().getLongitude();
//纬度
@@ -642,8 +641,15 @@ public class TanluManager implements IMogoMarkerClickListener,
moveNotFresh();
//第一个参数:调用者,第二个参数:当前自车的位置,第三个参数:需要显示在范围内的点(不包含自车的位置)
//第四个参数显示范围的UI边界,第五个参数:是否锁定自车位置(看业务需要)
mMApUIController.showBounds(ShareConstants.MODEL_NAME, null,
getMogoList(), rect, false);
if (getMogoList() != null && getMogoList().size() > 0) {
Log.d(TAG, "showBonndsRoadtion size = " + getMogoList().size());
MogoLatLng mogoLatLng = new MogoLatLng(lat, longit);
mMApUIController.showBounds(ShareConstants.MODEL_NAME, mogoLatLng,
getMogoList(), rect, false);
} else {
Log.e(TAG, "getMogoList() == null ");
}
}

View File

@@ -69,6 +69,7 @@ dependencies {
kapt rootProject.ext.dependencies.roomAnnotationProcessor
kapt rootProject.ext.dependencies.aroutercompiler
api rootProject.ext.dependencies.mogoaicloudtrafficlive
if (Boolean.valueOf(RELEASE)) {
implementation rootProject.ext.dependencies.mogomap

View File

@@ -14,6 +14,7 @@ import com.mogo.module.v2x.entity.net.V2XLiveCrossRoad;
import com.mogo.module.v2x.network.V2XRefreshCallback;
import com.mogo.module.v2x.network.V2XRefreshModel;
import com.mogo.module.v2x.utils.ToastUtils;
import com.mogo.module.v2x.view.V2XCarLiveVideoView;
import com.mogo.module.v2x.voice.V2XVoiceCallbackListener;
import com.mogo.module.v2x.voice.V2XVoiceManager;
import com.mogo.service.statusmanager.StatusDescriptor;
@@ -52,6 +53,7 @@ public class V2XVoiceCallLiveBiz {
}
private Context mContext;
private V2XVoiceCallLiveScenario mV2XVoiceCallLiveScenario = new V2XVoiceCallLiveScenario();
//语音词指令 查看前车视频回调
private V2XVoiceCallbackListener v2XVoiceCallbackFrontLiveCarListener = (command, intent) -> {
@@ -107,8 +109,7 @@ public class V2XVoiceCallLiveBiz {
return;
}
V2XMessageEntity<V2XPushMessageEntity> v2XMessageEntity = buildCallLiveParams(liveCarSn, null);
// V2XVoiceCallLiveScenario.getInstance().setV2XWindow(new V2XVoiceCallLiveCarWindow());
// V2XVoiceCallLiveScenario.getInstance().init(v2XMessageEntity);
mV2XVoiceCallLiveScenario.init(v2XMessageEntity);
}
public void getOpenRoadCameraLive() {

View File

@@ -6,7 +6,6 @@ import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.mogo.module.common.entity.MarkerCarInfo;
@@ -16,7 +15,7 @@ import com.mogo.module.v2x.V2XServiceManager;
import com.mogo.module.v2x.listener.V2XWindowStatusListener;
import com.mogo.module.v2x.scenario.scene.V2XBasWindow;
import com.mogo.module.v2x.scenario.view.IV2XWindow;
import com.mogo.module.v2x.view.V2XCarLiveVideoView;
import com.mogo.module.v2x.view.CarZegoLiveVideoView;
import com.mogo.utils.logger.Logger;
import static com.mogo.module.v2x.V2XConst.MODULE_NAME;
@@ -24,7 +23,7 @@ import static com.mogo.module.v2x.V2XConst.MODULE_NAME;
public class V2XVoiceCallLiveCarWindow extends V2XBasWindow
implements IV2XWindow<V2XPushMessageEntity> {
private V2XCarLiveVideoView mV2XCarLiveVideoView;
private CarZegoLiveVideoView mV2XCarLiveVideoView;
private TextView tvCountDown;
private ImageView ivVideoPlayingSign;
private boolean isVideoPlay = false;

View File

@@ -12,6 +12,7 @@ import com.mogo.module.v2x.V2XConst;
import com.mogo.module.v2x.V2XServiceManager;
import com.mogo.module.v2x.scenario.impl.AbsV2XScenario;
import com.mogo.module.v2x.utils.V2XUtils;
import com.mogo.module.v2x.view.CarZegoLiveVideoView;
import com.mogo.service.windowview.IMogoTopViewStatusListener;
import com.mogo.utils.TipToast;
import com.mogo.utils.logger.Logger;
@@ -25,7 +26,7 @@ import static com.mogo.module.v2x.V2XConst.MODULE_NAME;
public class V2XVoiceCallLiveScenario extends AbsV2XScenario<V2XPushMessageEntity> implements IMogoTopViewStatusListener {
public V2XVoiceCallLiveScenario() {
setV2XWindow(new V2XVoiceCallLiveCarWindow());
}
@Override

View File

@@ -0,0 +1,261 @@
package com.mogo.module.v2x.view;
import android.content.Context;
import android.content.Intent;
import android.graphics.PorterDuff;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.SurfaceView;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.content.ContextCompat;
import com.mogo.cloud.trafficlive.api.ITrafficLiveCallBack;
import com.mogo.cloud.trafficlive.api.MoGoAiCloudTrafficLive;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.commons.voice.AIAssist;
import com.mogo.module.common.entity.MarkerCarInfo;
import com.mogo.module.v2x.R;
import com.mogo.module.v2x.V2XServiceManager;
import com.mogo.module.v2x.entity.net.V2XLivePushVoRes;
import com.mogo.module.v2x.network.V2XRefreshCallback;
import com.mogo.module.v2x.utils.V2XUtils;
import com.mogo.module.v2x.voice.V2XVoiceCallbackListener;
import com.mogo.module.v2x.voice.V2XVoiceConstants;
import com.mogo.module.v2x.voice.V2XVoiceManager;
import com.mogo.utils.logger.Logger;
import com.tencent.rtmp.ui.TXCloudVideoView;
import static com.mogo.module.v2x.V2XConst.MODULE_NAME;
/**
* @author liujing
* @description 描述
* @since: 2021/2/23
*/
public class CarZegoLiveVideoView extends RoundLayout {
private SurfaceView mSurfaceView;
private ProgressBar mLoading;
private ConstraintLayout mClLoadError;
private TextView mTvRefreshButton;
private MarkerCarInfo.CarLiveInfo mCarLiveInfo;
// 重新刷新直播流
private V2XVoiceCallbackListener v2XVoiceCallbackRefreshListener = new V2XVoiceCallbackListener() {
@Override
public void onCallback(String command, Intent intent) {
mLoading.setVisibility(VISIBLE);
mClLoadError.setVisibility(GONE);
if (mCarLiveInfo != null) {
startLive(mCarLiveInfo);
}
}
};
public CarZegoLiveVideoView() {
this(V2XServiceManager.getContext(), null);
}
public CarZegoLiveVideoView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public CarZegoLiveVideoView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initView(context);
}
private void initView(Context context) {
LayoutInflater.from(context)
.inflate(R.layout.view_video_layout_see_live, this);
mSurfaceView = findViewById(R.id.surfaceView);
mSurfaceView.setZOrderOnTop(true);
mLoading = findViewById(R.id.loading);
mLoading.getIndeterminateDrawable().setColorFilter(ContextCompat.getColor(context, R.color.live_video_progress_bar_loading_color), PorterDuff.Mode.MULTIPLY);
mClLoadError = findViewById(R.id.clLoadError);
mTvRefreshButton = findViewById(R.id.tvRefreshButton);
mTvRefreshButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mLoading.setVisibility(VISIBLE);
mClLoadError.setVisibility(GONE);
if (mCarLiveInfo != null) {
startLive(mCarLiveInfo);
}
}
});
}
/**
* 设置直播信息
*/
public void setCarLiveInfo(MarkerCarInfo.CarLiveInfo carLiveInfo) {
mCarLiveInfo = carLiveInfo;
}
/**
* 开始直播
*
* @param carLiveInfo 要直播的车机,如果没有直播的地址需要重新获取最新的直播地址
*/
public void startLive(MarkerCarInfo.CarLiveInfo carLiveInfo) {
// 进行直播播放
if (mSurfaceView != null
&& carLiveInfo != null) {
if (!TextUtils.isEmpty(carLiveInfo.getVideoUrl())) {
AIAssist.getInstance(AbsMogoApplication.getApp()).speakTTSVoice(AbsMogoApplication.getApp().getString(R.string.v2x_voice_see_front_car_live));
setCarLiveInfo(carLiveInfo);
playLiveVideo(carLiveInfo);
}
// 根据SN重新获取直播流地址
else {
V2XServiceManager
.getV2XRefreshModel()
.livePush(new V2XRefreshCallback<V2XLivePushVoRes>() {
@Override
public void onSuccess(V2XLivePushVoRes result) {
AIAssist.getInstance(AbsMogoApplication.getApp()).speakTTSVoice(AbsMogoApplication.getApp().getString(R.string.v2x_voice_see_front_car_live));
mClLoadError.setVisibility(GONE);
mClLoadError.setVisibility(GONE);
try {
MarkerCarInfo.CarLiveInfo carRealLiveInfo = new MarkerCarInfo.CarLiveInfo();
carRealLiveInfo.setVideoUrl(result.getResult().getPlayUrl().getRtmp());
carRealLiveInfo.setVideoSn(carLiveInfo.getVideoSn());
carRealLiveInfo.setVideoChannel(result.getResult().getVideoChannel());
setCarLiveInfo(carLiveInfo);
playLiveVideo(carRealLiveInfo);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onFail(String msg) {
Logger.e(MODULE_NAME, "播放器:" + msg);
AIAssist.getInstance(AbsMogoApplication.getApp()).speakTTSVoice(AbsMogoApplication.getApp().getString(R.string.v2x_voice_see_front_car_live_error));
mLoading.setVisibility(GONE);
mClLoadError.setVisibility(VISIBLE);
}
}, carLiveInfo.getVideoSn(), 0);
}
}
}
/**
* 播放直播流,且开始心跳
*/
private void playLiveVideo(MarkerCarInfo.CarLiveInfo carLiveInfo) {
startHeartLive(carLiveInfo);
if (mSurfaceView != null) {
MoGoAiCloudTrafficLive.viewVehicleHeadLive(AbsMogoApplication.getApp(), carLiveInfo.getVideoSn(), mSurfaceView, new ITrafficLiveCallBack() {
@Override
public void onLive() {
mLoading.setVisibility(VISIBLE);
mClLoadError.setVisibility(GONE);
refreshStatusToListener(true);
mLoading.setVisibility(GONE);
mClLoadError.setVisibility(GONE);
}
@Override
public void onDisConnect() {
}
@Override
public void onError(String errorMsg) {
refreshStatusToListener(false);
AIAssist.getInstance(V2XUtils.getApp()).speakTTSVoice("直播获取识败,可以对我说重试", null);
stopLive(mCarLiveInfo);
mLoading.setVisibility(GONE);
mClLoadError.setVisibility(VISIBLE);
// 注册语音交互
V2XVoiceManager.INSTANCE
.registerWakeCmd(V2XVoiceConstants.COMMAND_ZHIDAO_V2X_REFRESH_CAR_LIVE,
v2XVoiceCallbackRefreshListener)
.registerUnWakeVoice(V2XVoiceConstants.COMMAND_ZHIDAO_V2X_REFRESH_LIVE_UN_WAKEUP,
v2XVoiceCallbackRefreshListener);
}
});
}
}
// 刷新直播心跳
private void startHeartLive(MarkerCarInfo.CarLiveInfo carLiveInfo) {
try {
if (!TextUtils.isEmpty(carLiveInfo.getVideoSn())
&& !TextUtils.isEmpty(carLiveInfo.getVideoChannel())) {
V2XServiceManager
.getV2XRefreshModel()
.refreshHeartBeat(carLiveInfo.getVideoSn(),
carLiveInfo.getVideoChannel(),
null);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void stopLive(MarkerCarInfo.CarLiveInfo carLiveInfo) {
try {
Logger.w(MODULE_NAME, "心跳:关闭直播...");
// 暂停
MoGoAiCloudTrafficLive.stopLive(carLiveInfo.getVideoSn());
// 停止推流
V2XServiceManager
.getV2XRefreshModel()
.livePush(new V2XRefreshCallback<V2XLivePushVoRes>() {
@Override
public void onSuccess(V2XLivePushVoRes result) {
Logger.d(MODULE_NAME, "播放器:" + result);
}
@Override
public void onFail(String msg) {
Logger.e(MODULE_NAME, "播放器:" + msg);
}
}, carLiveInfo.getVideoSn(), 1);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
if (mCarLiveInfo != null) {
startLive(mCarLiveInfo);
}
}
@Override
protected void onDetachedFromWindow() {
stopLive(mCarLiveInfo);
mLoading.setVisibility(VISIBLE);
// 反注册语音交互
V2XVoiceManager.INSTANCE
.unRegisterWakeCmd(V2XVoiceConstants.COMMAND_ZHIDAO_V2X_REFRESH_CAR_LIVE)
.unRegisterUnWakeVoice(V2XVoiceConstants.COMMAND_ZHIDAO_V2X_REFRESH_LIVE_UN_WAKEUP);
super.onDetachedFromWindow();
}
private void refreshStatusToListener(boolean videoPlaying) {
if (onVideoStatusChange != null) {
onVideoStatusChange.videoPlaying(videoPlaying);
}
}
private V2XCarLiveVideoView.OnVideoStatusChange onVideoStatusChange;
public void addOnVideoStatusChangeListener(V2XCarLiveVideoView.OnVideoStatusChange onVideoStatusChange) {
this.onVideoStatusChange = onVideoStatusChange;
}
public interface OnVideoStatusChange {
void videoPlaying(boolean videoPlaying);
}
}

View File

@@ -15,7 +15,7 @@
android:layout_centerInParent="true"
android:src="@drawable/v2x_icon_live_logo" />
<com.mogo.module.v2x.view.V2XCarLiveVideoView
<com.mogo.module.v2x.view.CarZegoLiveVideoView
android:id="@+id/videoPlayer"
android:layout_width="match_parent"
android:layout_height="@dimen/module_v2x_event_see_live_window_height"

View File

@@ -7,9 +7,10 @@
android:background="@color/live_video_background_color"
app:roundLayoutRadius="@dimen/dp_20">
<com.tencent.rtmp.ui.TXCloudVideoView
android:id="@+id/txcVideoView"
<SurfaceView
android:id="@+id/surfaceView"
android:layout_width="match_parent"
android:background="#003F4057"
android:layout_height="@dimen/module_v2x_event_see_live_window_height"
android:gravity="center" />