This commit is contained in:
wangcongtao
2020-04-13 19:07:05 +08:00
parent 9f4c8a704f
commit dccc9be8be
44 changed files with 1151 additions and 448 deletions

View File

@@ -0,0 +1 @@
/build

View File

@@ -0,0 +1,53 @@
apply plugin: 'com.android.library'
android {
compileSdkVersion rootProject.ext.android.compileSdkVersion
// buildToolsVersion rootProject.ext.android.buildToolsVersion
defaultConfig {
minSdkVersion rootProject.ext.android.minSdkVersion
targetSdkVersion rootProject.ext.android.targetSdkVersion
versionCode Integer.valueOf(VERSION_CODE)
versionName getValueFromRootProperties("${project.name.replace("-", "_").toUpperCase()}_VERSION")
javaCompileOptions {
annotationProcessorOptions {
arguments = [AROUTER_MODULE_NAME: project.getName()]
}
}
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation rootProject.ext.dependencies.arouter
annotationProcessor rootProject.ext.dependencies.aroutercompiler
implementation "org.java-websocket:Java-WebSocket:1.4.0"
if (Boolean.valueOf(RELEASE)) {
implementation rootProject.ext.dependencies.mogoutils
implementation rootProject.ext.dependencies.mogocommons
implementation rootProject.ext.dependencies.gpssimulator
implementation rootProject.ext.dependencies.mogoserviceapi
} else {
implementation project(':foudations:mogo-utils')
implementation project(":foudations:mogo-commons")
implementation project(':modules:mogo-module-gps-simulator')
implementation project(':services:mogo-service-api')
}
}

View File

@@ -0,0 +1,3 @@
GROUP=com.mogo.module
POM_ARTIFACT_ID=module-gps-simulator-debug
VERSION_CODE=1

View File

@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

View File

@@ -0,0 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mogo.module.gps.simulator.debug" />

View File

@@ -0,0 +1,134 @@
package com.mogo.module.gps.simulator;
/**
* @author zyz
* 2020-04-08.
*/
public class CationVo {
/**
* vehicleSpeed : 1.0
* instantSpeed : 1.0
* lon : 116.401615
* lat : 39.968812
* carStatus : 1
* direction : 267
* sn : ZD801C1928L00371
* locationTime : 1586339911534
* distance : 0.0
* adCode : 2
* cityCode : 3
* vehicleType : 0
*/
private float vehicleSpeed;
private double instantSpeed;
private double lon;
private double lat;
private int carStatus;
private int direction;
private String sn;
private long locationTime;
private double distance;
private String adCode;
private String cityCode;
private int vehicleType;
public float getVehicleSpeed() {
return vehicleSpeed;
}
public void setVehicleSpeed( float vehicleSpeed ) {
this.vehicleSpeed = vehicleSpeed;
}
public double getInstantSpeed() {
return instantSpeed;
}
public void setInstantSpeed( double instantSpeed ) {
this.instantSpeed = instantSpeed;
}
public double getLon() {
return lon;
}
public void setLon( double lon ) {
this.lon = lon;
}
public double getLat() {
return lat;
}
public void setLat( double lat ) {
this.lat = lat;
}
public int getCarStatus() {
return carStatus;
}
public void setCarStatus( int carStatus ) {
this.carStatus = carStatus;
}
public int getDirection() {
return direction;
}
public void setDirection( int direction ) {
this.direction = direction;
}
public String getSn() {
return sn;
}
public void setSn( String sn ) {
this.sn = sn;
}
public long getLocationTime() {
return locationTime;
}
public void setLocationTime( long locationTime ) {
this.locationTime = locationTime;
}
public double getDistance() {
return distance;
}
public void setDistance( double distance ) {
this.distance = distance;
}
public String getAdCode() {
return adCode;
}
public void setAdCode( String adCode ) {
this.adCode = adCode;
}
public String getCityCode() {
return cityCode;
}
public void setCityCode( String cityCode ) {
this.cityCode = cityCode;
}
public int getVehicleType() {
return vehicleType;
}
public void setVehicleType( int vehicleType ) {
this.vehicleType = vehicleType;
}
}

View File

@@ -0,0 +1,47 @@
package com.mogo.module.gps.simulator;
import com.mogo.utils.logger.Logger;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.drafts.Draft_6455;
import org.java_websocket.handshake.ServerHandshake;
import java.net.URI;
/**
* @author zyz
* 2020-04-07.
*/
public class JWebSocketClient extends WebSocketClient {
public JWebSocketClient( URI serverUri ) {
super( serverUri, new Draft_6455() );
}
@Override
public void onOpen( ServerHandshake handshakedata ) {
Logger.e( "JWebSocketClient", "onOpen()" );
bindSN();
}
private void bindSN() {
String data = String.format( "{ \"sn\": \"%s\", \"bind\": true }", Utils.getSn() );
send( data );
}
@Override
public void onMessage( String message ) {
Logger.e( "JWebSocketClient", "onMessage()" );
}
@Override
public void onClose( int code, String reason, boolean remote ) {
Logger.e( "JWebSocketClient", "onClose()" );
}
@Override
public void onError( Exception ex ) {
Logger.e( "JWebSocketClient", "onError()" );
ex.printStackTrace();
}
}

View File

@@ -0,0 +1,33 @@
package com.mogo.module.gps.simulator;
import android.content.Context;
import com.alibaba.android.arouter.facade.annotation.Route;
/**
* @author congtaowang
* @since 2020-04-13
* <p>
* 描述
*/
@Route( path = GpsSimulatorConstants.API_PATH )
public class MogoGpsSimulatorManagerDebug implements IMogoGpsSimulatorManager {
private static final String TAG = "MogoGpsSimulatorManagerDebug";
@Override
public void open() {
WebSocketManager.getInstance().connect( true );
}
@Override
public void close() {
WebSocketManager.getInstance().disConnect();
}
@Override
public void init( Context context ) {
}
}

View File

@@ -0,0 +1,43 @@
package com.mogo.module.gps.simulator;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
* Created by congtaowang on 2018/3/29.
*/
class Utils {
public static final String GET = "get";
public static final String GSM_SERIAL = "gsm.serial";
public static final String FOTA_VERSION = "ro.fota.version";
public static final String PROPERTIES = "android.os.SystemProperties";
public static String getSn() {
return getSystemProperties( GSM_SERIAL );
}
public static String getFotaVersion() {
return getSystemProperties( FOTA_VERSION );
}
public static String getSystemProperties( String name ) {
String value = "";
try {
Class< ? > c = Class.forName( PROPERTIES );
Method get = c.getMethod( GET, String.class );
value = ( String ) get.invoke( c, name );
} catch ( ClassNotFoundException var3 ) {
var3.printStackTrace();
} catch ( NoSuchMethodException var4 ) {
var4.printStackTrace();
} catch ( InvocationTargetException var5 ) {
var5.printStackTrace();
} catch ( IllegalAccessException var6 ) {
var6.printStackTrace();
}
return value;
}
}

View File

@@ -0,0 +1,122 @@
package com.mogo.module.gps.simulator;
import com.alibaba.android.arouter.launcher.ARouter;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.map.navi.IMogoNavi;
import com.mogo.service.IMogoServiceApis;
import com.mogo.service.MogoServicePaths;
import com.mogo.utils.logger.Logger;
import com.mogo.utils.network.utils.GsonUtil;
import org.json.JSONObject;
import java.net.URI;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* @author zyz
* 2020-04-07.
*/
public class WebSocketManager {
private static final String TAG = "WebSocketManager";
private static Object sLock = new Object();
private static WebSocketManager sWebSocketManager;
private IMogoNavi mNavi;
private JWebSocketClient mClient;
private URI mUri;
private ExecutorService mService = Executors.newSingleThreadExecutor();
public static WebSocketManager getInstance() {
if ( sWebSocketManager == null ) {
synchronized ( sLock ) {
if ( sWebSocketManager == null ) {
sWebSocketManager = new WebSocketManager();
}
}
}
return sWebSocketManager;
}
private WebSocketManager() {
final IMogoServiceApis mServiceApis = ( IMogoServiceApis ) ARouter.getInstance().build( MogoServicePaths.PATH_SERVICE_APIS ).navigation();
mNavi = mServiceApis.getMapServiceApi().getNavi( AbsMogoApplication.getApp() );
mUri = URI.create( "ws://152.136.10.223:4001/realtimeLocations-ws" );
mClient = new JWebSocketClient( mUri ) {
@Override
public void onMessage( String message ) {
try {
parseMessage( message );
} catch ( Exception e ) {
Logger.e( TAG, e, "error." );
}
}
};
}
private void parseMessage( String jsonStr ) throws Exception {
//message就是接收到的消息
Logger.d( TAG, jsonStr );
JSONObject jsonObject = new JSONObject( jsonStr );
if ( jsonObject.has( "detailMsg" ) ) {
Logger.d( TAG, "绑定成功" );
} else if ( jsonObject.has( "realTimeLocationVo" ) ) {
Logger.d( TAG, "收到定位消息" );
CationVo realTimeLocationVo = GsonUtil.objectFromJson( jsonObject.getString( "realTimeLocationVo" ), CationVo.class );
mNavi.setExtraGPSData(
realTimeLocationVo.getLon(),
realTimeLocationVo.getLat(),
realTimeLocationVo.getVehicleSpeed(),
1,
realTimeLocationVo.getDirection(),
realTimeLocationVo.getLocationTime()
);
}
}
public void connect( final boolean block ) {
if ( mClient == null ) {
return;
}
if ( mClient.isOpen() ) {
return;
}
mService.execute( () -> {
if ( block ) {
try {
if ( mClient.isClosed() ) {
mClient.reconnectBlocking();
} else {
mClient.connectBlocking();
}
} catch ( InterruptedException e ) {
Logger.e( TAG, e, "error." );
}
} else {
if ( mClient.isClosed() ) {
mClient.reconnect();
} else {
mClient.connect();
}
}
} );
}
public void disConnect() {
if ( mClient == null ) {
return;
}
if ( mClient.isClosing() || mClient.isClosed() || !mClient.isOpen() ) {
return;
}
try {
mService.execute( () -> { mClient.close(); } );
} catch ( Exception e ) {
Logger.e( TAG, e, "error." );
}
}
}

View File

@@ -0,0 +1,3 @@
<resources>
<string name="app_name">mogo-module-gps-simulator</string>
</resources>