From: snickersun Date: Fri, 17 Jan 2020 18:11:00 +0000 (+0800) Subject: 1、修改界面,显示更多信息 X-Git-Url: http://git.snicker.com.cn/sitemap.xml?a=commitdiff_plain;h=9658fea807b518e9e85f0bbc5949768a7f1558eb;p=icsupport.git 1、修改界面,显示更多信息 2、修改定位逻辑,不动的时候以及正在定位的时候会忽略定位请求。 --- diff --git a/app/src/main/java/com/ic/protocol/LocationClient.java b/app/src/main/java/com/ic/protocol/LocationClient.java index 6f39cf0e..5f527e82 100644 --- a/app/src/main/java/com/ic/protocol/LocationClient.java +++ b/app/src/main/java/com/ic/protocol/LocationClient.java @@ -468,14 +468,31 @@ public void updateCellInfo() { stringBuilder.append("runtime.preCellInfo="); stringBuilder.append(runtime.preCellInfo); Logger.i(stringBuilder.toString()); - handlerH12(); + handlerH12();//update StepCount this.gSensorListener.startListen(paramWakeLock); performAlarm(paramWakeLock); } + + + + public void startLocationProcess(int mod){ - if (isLocating ) return; + Logger.i("isLocating "+isLocating+", lastStep"+runtime.getLastStepCount()+", currentStep"+ runtime.getTotalStepCount()); + if (isLocating ) { + Logger.i("locating ,skip location!"); + return; + } + + + if (runtime.getLastStepCount() == runtime.getTotalStepCount()){ + + Logger.i("No Move ,skip location!"); + return ; + } isLocating=true; + + runtime.setLastStepCount(runtime.getTotalStepCount()); updateSimSignalInfo(); updateCellInfo(); diff --git a/app/src/main/java/com/ic/protocol/MainActivity.java b/app/src/main/java/com/ic/protocol/MainActivity.java index 5513f490..ab36b24e 100644 --- a/app/src/main/java/com/ic/protocol/MainActivity.java +++ b/app/src/main/java/com/ic/protocol/MainActivity.java @@ -16,20 +16,50 @@ import android.widget.ToggleButton; import com.ic.jni.ICJniUtils; import com.ic.protocol.service.protocolMainServer; +import com.ic.protocol.utils.Logger; import java.util.Timer; import java.util.TimerTask; public class MainActivity extends AppCompatActivity { + TextView tv; + Handler handler=new Handler(new Handler.Callback() { + @Override + public boolean handleMessage(Message message) { + + + StringBuilder sb=new StringBuilder(); + try { + + + + }catch(Exception e){ + e.printStackTrace(); + } + + + sb.append("ppg is available ").append(ICJniUtils.isPPGavailable()) + .append(", ppg isstarted ").append(ICJniUtils.isPPGStarted()) + .append(",ppg ").append(ICJniUtils.getPPG()) + .append("weared ").append(ICJniUtils.isWeared()) + .append(",spo2 ").append(ICJniUtils.getSPO2()) + .append(",bph ").append(ICJniUtils.getHighBloodPressure()) + .append(",bpl ").append(ICJniUtils.getLowBloodPressure()) + .append("\n"); + sb.append(protocolMainServer.getInstance().getServerAlive()); + tv.setText( sb.toString()); + return false; + } + }); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btnConnect = (Button) findViewById(R.id.btnConnect); - TextView tv = (TextView)findViewById(R.id.textView); + tv = (TextView)findViewById(R.id.textView); btnConnect.setOnClickListener(clickListener); @@ -52,37 +82,18 @@ public class MainActivity extends AppCompatActivity { startService(new Intent(this,protocolMainServer.class));// protocol service - - Handler handler=new Handler(new Handler.Callback() { - @Override - public boolean handleMessage(Message message) { - - - StringBuilder sb=new StringBuilder(); - try { - - - - }catch(Exception e){ - e.printStackTrace(); - } - - - sb.append("ppg is available ").append(ICJniUtils.isPPGavailable()) - .append(", ppg isstarted ").append(ICJniUtils.isPPGStarted()) - .append(",ppg ").append(ICJniUtils.getPPG()) - .append("weared ").append(ICJniUtils.isWeared()) - .append(",spo2 ").append(ICJniUtils.getSPO2()) - .append(",bph ").append(ICJniUtils.getHighBloodPressure()) - .append(",bpl ").append(ICJniUtils.getLowBloodPressure()) - .append("\n"); - - sb.append(protocolMainServer.getInstance().getServerAlive()); - tv.setText( sb.toString()); - - return false; - } - }); +// double longitude=113.878339f; +// double latitude=22.580827f; +// double intfen= ((int)(longitude*100) - ((int)longitude)*100)*60/100f; +// double miao= (longitude*100 - (int)(longitude*100)); +// double last= ((int)longitude)*100 +intfen+miao; +// longitude =last; +// intfen= ((int)(latitude*100) - ((int)latitude)*100)*60/100f; +// miao= (latitude*100 - (int)(latitude*100)); +// last= ((int)latitude)*100 +intfen+miao; +// latitude=last; +// +// Logger.i(" lat="+latitude+",lon="+longitude); TimerTask tmt=new TimerTask() { @Override public void run() { diff --git a/app/src/main/java/com/ic/protocol/NMEAListener.java b/app/src/main/java/com/ic/protocol/NMEAListener.java index e391e93d..054d4c4a 100644 --- a/app/src/main/java/com/ic/protocol/NMEAListener.java +++ b/app/src/main/java/com/ic/protocol/NMEAListener.java @@ -1,6 +1,5 @@ package com.ic.protocol; -import android.annotation.SuppressLint; import android.location.Criteria; import android.location.GpsSatellite; import android.location.GpsStatus; @@ -11,14 +10,11 @@ import android.location.LocationManager; import android.os.Bundle; import android.os.Handler; import android.os.Message; -import android.text.TextUtils; -import android.util.Log; -import android.widget.TextView; - import com.ic.protocol.bean.ICLocation; import com.ic.protocol.bean.Runtime; import com.ic.protocol.utils.FileOutputUtil; import com.ic.protocol.utils.Logger; +import com.ic.protocol.utils.TimeUtil; import java.text.DecimalFormat; import java.util.ArrayList; @@ -36,10 +32,10 @@ public class NMEAListener implements NmeaListener, LocationListener { private double longitude; private double latitude; - private int SearchTimeout = 400; + private int SearchTimeout = 120; private int noSignalCount=0; private int searchCout=0; - GPS_CURRENT_STATUS gpsMode; + private GPS_CURRENT_STATUS gpsMode; int numberOfSatellites; Runtime runtime; @@ -78,11 +74,9 @@ public class NMEAListener implements NmeaListener, LocationListener { // +" cost "+status.getTimeToFirstFix()+"ms"); // 定位算通过 gpsMode = GPS_CURRENT_STATUS.GPS_FIXED; - runtime.getLocationInstance().setLocationStat(ICLocation.LOCATION_STAT.LOCATION_FIXED); - getBestLocation(locationManager,status); - stop(); + delaystop(); break; case GpsStatus.GPS_EVENT_STARTED: @@ -115,6 +109,20 @@ public class NMEAListener implements NmeaListener, LocationListener { @Override public boolean handleMessage(Message message) { + if( message.what== 100|| message.what==200){ + //no start + //do nothing + + }else if (message.what==300){ + //fixed + /* + 只有当前GPS已经定位,且location不为空才给 runtime赋值GPS坐标。 + 延迟三秒后才设置runtime的定位标志,以便稳定坐标值。 + */ + runtime.getLocationInstance().setLocationStat(ICLocation.LOCATION_STAT.LOCATION_FIXED); + + } + NMEAListener.this.stopListen(); return false; } @@ -181,28 +189,28 @@ public class NMEAListener implements NmeaListener, LocationListener { if (searchCout>SearchTimeout){ sb2.append(" 搜索"+searchCout+"次,超过"+SearchTimeout+"限制退出GPS定位"); - FileOutputUtil.fileOutput(this.runtime.getContextProxy().context,"GPS",sb2.toString()); gpsMode=GPS_CURRENT_STATUS.GPS_TIMEOUT; runtime.getLocationInstance().setLocationStat(ICLocation.LOCATION_STAT.LOCATION_GPS_TIEMOUT); - stop(); + stop(100); } - if (noSignalCount> 5){ + if (noSignalCount> 10){ sb2.append(" 搜索"+searchCout+"次,超过"+noSignalCount+"次没有收到星,退出GPS定位"); - FileOutputUtil.fileOutput(this.runtime.getContextProxy().context,"GPS",sb2.toString()); gpsMode=GPS_CURRENT_STATUS.GPS_NOSINGAL; runtime.getLocationInstance().setLocationStat(ICLocation.LOCATION_STAT.LOCATION_GPS_TIEMOUT); - stop(); + stop(200); } + FileOutputUtil.fileOutput(this.runtime.getContextProxy().context,"GPS",sb2.toString()); - Log.e("dxc", sb2.toString()); + Logger.i( sb2.toString()); + getBestLocation(locationManager,status); return 0; } //停止定位 - private void stop(){ + private void stop(int id){ // 经纬度 保留6位小数点 // DecimalFormat df = new DecimalFormat("#.000000"); @@ -213,9 +221,17 @@ public class NMEAListener implements NmeaListener, LocationListener { // // Logger.i("Location " +runtime.getLocationInstance().getLocationStat().name()); //发送停止消息 - NMEAListener.this.temHandler.sendMessage(new Message()); + NMEAListener.this.temHandler.sendEmptyMessage(id); } + private void delaystop(){ + /* + 只有当前GPS已经定位,且location不为空才给 runtime赋值GPS坐标。 + 延迟三秒后才设置runtime的定位标志,以便稳定坐标值。 + */ + //发送停止消息 + NMEAListener.this.temHandler.sendEmptyMessageDelayed(300,3000L); + } boolean isFrist = true; /** @@ -228,52 +244,62 @@ public class NMEAListener implements NmeaListener, LocationListener { private void getBestLocation(LocationManager locationManager,GpsStatus status) { Location location = null; if (locationManager != null) { - location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); - if (location == null) { - - - location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); - - } + location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); + if (location == null) { + location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); + } - if (location != null) { - longitude = location.getLongitude(); - latitude = location.getLatitude(); - if (longitude > 0 && latitude > 0 ) { - //sucess - stop();// 定位成功,自动跳转2016.9.19 tyy + /* + 只有当前GPS已经定位,且location不为空才给 runtime赋值GPS坐标。 + 延迟三秒后才设置runtime的定位标志,以便稳定坐标值。 + */ + if (location != null && gpsMode == GPS_CURRENT_STATUS.GPS_FIXED ) { + longitude = location.getLongitude(); + latitude = location.getLatitude(); +// 转换单位,从度转换到分 + double intfen= ((int)(longitude*100) - ((int)longitude)*100)*60/100f; + double miao= (longitude*100 - (int)(longitude*100)); + double last= ((int)longitude)*100 +intfen+miao; + longitude =last; + intfen= ((int)(latitude*100) - ((int)latitude)*100)*60/100f; + miao= (latitude*100 - (int)(latitude*100)); + last= ((int)latitude)*100 +intfen+miao; + latitude=last; + + if (longitude > 0 && latitude > 0 ) { + //sucess + long gpsTime = location.getTime(); + + double altitude = location.getAltitude();// 海拔 + + // 速度 + float speed = location.getSpeed();// 速度 单位 m/s + speed = (speed * 60) / 1000; // 单位转换 km/h + // 保留一位小数点 + DecimalFormat dfSpeed = new DecimalFormat("#.0"); + String strSpeed = dfSpeed.format(speed); + speed = Float.parseFloat(strSpeed); + int intSpeed = (int) (speed * 10); + // SimpleLogger.d("intSpeed:"+intSpeed); + + // 经纬度 保留6位小数点 + DecimalFormat df = new DecimalFormat("#.0000"); + String strLatitude = df.format(latitude); + String strLongitude = df.format(longitude); + + StringBuffer sb = new StringBuffer(); + sb.append("gps time "+TimeUtil.getLocalTime(gpsTime)+" lon " + strLongitude + " lat " + strLatitude +" TimeToFirstFix "+status.getTimeToFirstFix()); + + + + // Logger.i("satelliteInfo:"+); + Logger.i( sb.toString()); + + FileOutputUtil.fileOutput(this.runtime.getContextProxy().context,"GPS",sb.toString()); + runtime.getLocationInstance().setLocation(location.getLatitude(),location.getLongitude(),location.getSpeed(),0,status.getMaxSatellites()); } } - - long gpsTime = location.getTime(); - - double altitude = location.getAltitude();// 海拔 - - // 速度 - float speed = location.getSpeed();// 速度 单位 m/s - speed = (speed * 60) / 1000; // 单位转换 km/h - // 保留一位小数点 - DecimalFormat dfSpeed = new DecimalFormat("#.0"); - String strSpeed = dfSpeed.format(speed); - speed = Float.parseFloat(strSpeed); - int intSpeed = (int) (speed * 10); - // SimpleLogger.d("intSpeed:"+intSpeed); - - // 经纬度 保留6位小数点 - DecimalFormat df = new DecimalFormat("#.000000"); - String strLatitude = df.format(latitude); - String strLongitude = df.format(longitude); - - StringBuffer sb = new StringBuffer(); - sb.append("lon " + strLongitude + " lat " + strLatitude +" TimeToFirstFix "+status.getTimeToFirstFix()); - -// Logger.i("satelliteInfo:"+); - Logger.i( sb.toString()); - - FileOutputUtil.fileOutput(this.runtime.getContextProxy().context,"GPS",sb.toString()); - runtime.getLocationInstance().setLocation(location.getLatitude(),location.getLongitude(),location.getSpeed(),0,status.getMaxSatellites()); - } } diff --git a/app/src/main/java/com/ic/protocol/bean/Runtime.java b/app/src/main/java/com/ic/protocol/bean/Runtime.java index c059dd59..339425d9 100644 --- a/app/src/main/java/com/ic/protocol/bean/Runtime.java +++ b/app/src/main/java/com/ic/protocol/bean/Runtime.java @@ -102,13 +102,18 @@ public class Runtime { private boolean shutdown; - + private int lastStepCount=0; private long timestamp; public int totalStepCount; - - private String videoID; - + + + public int getLastStepCount(){ + return lastStepCount; + } + public void setLastStepCount(int st){ + lastStepCount=st; + } public String IMEI() { return this.imei; } public String IMEI_CID() { return this.imei_cid; } @@ -124,18 +129,14 @@ public class Runtime { public boolean getBatteryLow() { return this.batteryLow; } public boolean getBatterychanging() { return this.batterychanging; } - - public String getBelong() { return this.belong; } + public File getCacheDir() { return this.cacheDir; } public String getCdmaInfo() { return this.cdmaInfo; } public String getCellidInfoByAt() { return this.cellidByAt; } - - public String getCellinfo() { return this.cellinfo; } - - public String getCid() { return this.cid; } + public ContextProxy getContextProxy() { return this.contextProxy; } @@ -150,10 +151,7 @@ public class Runtime { public File getFileDir() { return this.fileDir; } public boolean getHaveBatteryChange() { return this.haveBatteryChange; } - - public String getHaveBuy() { return this.haveBuy; } - - public String getHaveTry() { return this.haveTry; } + public String getHost() { return this.testServerProp ? srvIP : this.host; } @@ -164,16 +162,13 @@ public class Runtime { public String getKey() { return this.key; } public String getLacInfoByAt() { return this.lacByAt; } - - public String getLatitude() { return this.latitude; } - + public LBSHelper getLbsHelper() { return this.lbsHelper; } - -// public String getLocation() { return this.location; } + public boolean getLockSimInfo() { return this.lockSimInfo; } - public String getLongitude() { return this.longitude; } + public String getMccAndMnc() { return this.mccAndMnc; } @@ -182,14 +177,12 @@ public class Runtime { public int getSaveStepCount() { return this.saveStepCount; } public int getSignalStrength() { return this.SignalStrength; } - - public boolean getTestServerProp() { return this.testServerProp; } + public long getTimestamp() { return this.timestamp; } public int getTotalStepCount() { return this.totalStepCount; } - - public String getVideoID() { return this.videoID; } + public boolean isShutdown() { return this.shutdown; } @@ -224,11 +217,7 @@ public class Runtime { public void setFileDir(File paramFile) { this.fileDir = paramFile; } public void setHaveBatteryChange(boolean paramBoolean) { this.haveBatteryChange = paramBoolean; } - - public void setHaveBuy(String paramString) { this.haveBuy = paramString; } - - public void setHaveTry(String paramString) { this.haveTry = paramString; } - + public void setHostAndPort(String paramString, int paramInt) { this.host = paramString; this.port = paramInt; @@ -255,9 +244,7 @@ public class Runtime { stringBuilder.append(paramString); this.imei_cid_key = stringBuilder.toString(); } - - public void setLatitude(String paramString) { this.latitude = paramString; } - + public void setLbsHelper(LBSHelper paramLBSHelper) { this.lbsHelper = paramLBSHelper; } public void setLbsInfoByAt(String paramString1, String paramString2) { @@ -296,13 +283,6 @@ public class Runtime { public void setTimestamp(long paramLong) { this.timestamp = paramLong; } public void setTotalStepCount(int paramInt) { this.totalStepCount = paramInt; } - - public void setVideoID(String paramString) { this.videoID = paramString; } - - - - - private final String UserDebug = "userdebug"; @@ -328,14 +308,6 @@ public class Runtime { public ICLocation getLocationInstance(){ return gpsp; } - public String getIMEI() { - return imei; - } - - - public boolean isNetworkAvailable() { - return true; - } /* @@ -354,14 +326,10 @@ public class Runtime { return "C41-GW-V0.0.1"; } - public String getBatteryLevel() { - return "100"; - } + /* AP03 心跳包 */ - public String getGSMSignal() { - return "060"; - } + public String getGPSLocationStarNums() { return "000"; @@ -375,9 +343,6 @@ public class Runtime { return "00"; } - public String getStepCount() { - return "23425"; - } public String getRolltimes() { return "00"; diff --git a/app/src/main/java/com/ic/protocol/service/protocolMainServer.java b/app/src/main/java/com/ic/protocol/service/protocolMainServer.java index 37de7b7e..8eb74f60 100644 --- a/app/src/main/java/com/ic/protocol/service/protocolMainServer.java +++ b/app/src/main/java/com/ic/protocol/service/protocolMainServer.java @@ -37,6 +37,7 @@ import com.ic.protocol.utils.Logger; import com.ic.protocol.utils.NettyConnection; import com.ic.protocol.utils.SharPreferenceUtil; import com.ic.protocol.utils.SimSignalUtil; +import com.ic.protocol.utils.TimeUtil; import com.ic.protocol.utils.Util; import java.lang.ref.WeakReference; @@ -91,9 +92,11 @@ public class protocolMainServer extends Service { public String getServerAlive(){ - return new StringBuilder().append("Connecttion status is ").append(this.connection.isServerConnected()) + return new StringBuilder() + .append(TimeUtil.getLocalTime()) + .append(" Connecttion status is ").append(this.connection.isServerConnected()) .append("\n KeepAlive ").append(KeepAlive.isConnected) - .append( "\n Working Mode ").append(runtime.getLocationInstance().getWorkingMod()).append(" queue size ").append(LocationClient.queue.size()) + .append( "\n Working Mode ").append(runtime.getLocationInstance().getWorkingMod()).append(" StepCount ").append(runtime.getTotalStepCount()) .append("\n AP01 = ").append(protocolAPIHelper.AP01(runtime)) .toString(); } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 546e4e2b..eec68303 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -54,15 +54,30 @@ android:textOn="SimOn" /> - + android:scrollbars="horizontal|vertical"> + + + + + +