opt
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.mogo.module.gps.simulator.debug" />
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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 ) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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." );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
<resources>
|
||||
<string name="app_name">mogo-module-gps-simulator</string>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user