From: snickersun Date: Sat, 18 Jan 2020 08:42:36 +0000 (+0800) Subject: 启动初始化计步, X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=7d7f221d968ac1f88a5c18595f7dd91e158ff353;p=icsupport.git 启动初始化计步, WifiInfo为Null 处理 修复GPS坐标转换错误 --- diff --git a/app/src/main/java/com/ic/protocol/LocationClient.java b/app/src/main/java/com/ic/protocol/LocationClient.java index 482601e0..8907605d 100644 --- a/app/src/main/java/com/ic/protocol/LocationClient.java +++ b/app/src/main/java/com/ic/protocol/LocationClient.java @@ -267,7 +267,8 @@ public class LocationClient { public void startWifiScan(){ Logger.i("开启wifi扫描"); - runtime.currentWifiInfo = ""; +// runtime.currentWifiInfo = ""; + runtime.setWifiinfo(""); mHasWifiResult = false; this.mLbsHelper.registerBroadReceiver(); this.mLbsHelper.getWifiInfo(); @@ -276,8 +277,8 @@ public class LocationClient { // LocationClient.access$002(true); Logger.i("get wifi scan Callback " + param1String); LocationClient.mHasWifiResult=true; - runtime.currentWifiInfo = param1String; - runtime.setWifiinfo(param1String); +// runtime.currentWifiInfo = param1String==null?"":param1String; + runtime.setWifiinfo(param1String==null?"":param1String); } }); } @@ -326,15 +327,15 @@ public class LocationClient { public void waitAndSendLocation(){ - checktimes++; - if (checktimes> 20) timeout=true; - wifi_ok=false; + wifi_ok=false; gps_ok=false; lbs_ok=false; gps_nosignal=false; + + checktimes++; int mode=runtime.getLocationInstance().getWorkingMod(); - if (runtime.currentWifiInfo.length()>0 ) wifi_ok =true; + if (runtime.getWifiInfo().length()>0 ) wifi_ok =true; if (runtime.getLocationInstance().getLocationStat() == ICLocation.LOCATION_STAT.LOCATION_FIXED) gps_ok=true; if (runtime.getLocationInstance().getLocationStat() == ICLocation.LOCATION_STAT.LOCATION_GPS_TIEMOUT) gps_nosignal=true; lbs_ok=( runtime.getLocationInstance().isDataChanged()==false @@ -348,6 +349,10 @@ public class LocationClient { switch(mode){ case ICLocation.EMERGNECY_MOD: case ICLocation.REALTIME_MOD: + + //GPS 优先的话多给些时间(10秒) + if (checktimes> 60) timeout=true; + if ((lbs_ok && timeout==true) ||(lbs_ok && gps_ok && wifi_ok )||(lbs_ok&&gps_nosignal&&wifi_ok)){ Logger.i("offerQueue "+protocolAPIHelper.AP01(runtime)); @@ -368,6 +373,9 @@ public class LocationClient { } break; default: + //wifi优先的话给20秒时间 + if (checktimes> 20) timeout=true; + if ((lbs_ok && timeout==true) ||(lbs_ok && wifi_ok )){ String AP01_CMD=protocolAPIHelper.AP01(runtime); @@ -478,7 +486,7 @@ public void updateCellInfo() { public void startLocationProcess(int mod){ - Logger.i("forceLocation="+forceLocation+", isLocating "+isLocating+", lastStep"+runtime.getLastStepCount()+", currentStep"+ runtime.getTotalStepCount()); + Logger.i("forceLocation="+forceLocation+", WorkingMod="+WorkingMod+", isLocating="+isLocating+", lastStep="+runtime.getLastStepCount()+", currentStep="+ runtime.getTotalStepCount()); if (isLocating ) { Logger.i("locating ,skip location!"); return; @@ -486,7 +494,8 @@ public void updateCellInfo() { - if ( forceLocation == 0 || runtime.getLastStepCount() == runtime.getTotalStepCount()){ + // 不强制定位 且 WorkingMod 不是紧急模式,且 没有移动过 + if ( !(( forceLocation == 1 ) || ( WorkingMod == 4 )) && ( runtime.getLastStepCount() == runtime.getTotalStepCount()) ){ Logger.i("No Move ,skip location!"); return ; @@ -559,6 +568,8 @@ public void updateCellInfo() { } + + public void triggerSendThread(){ this.mLock.lock(); try { diff --git a/app/src/main/java/com/ic/protocol/NMEAListener.java b/app/src/main/java/com/ic/protocol/NMEAListener.java index a270ebe5..4b8cbeba 100644 --- a/app/src/main/java/com/ic/protocol/NMEAListener.java +++ b/app/src/main/java/com/ic/protocol/NMEAListener.java @@ -289,17 +289,28 @@ public class NMEAListener implements NmeaListener, LocationListener { 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 ) { + + //log msg变量 + StringBuffer sb = new StringBuffer(); + // 经纬度 保留6位小数点 + DecimalFormat df = new DecimalFormat("#.000000"); + String strLatitude = df.format(latitude); + String strLongitude = df.format(longitude); + + sb.append(" orig lat=").append(strLatitude).append(", orig lon=").append(strLongitude); + // 转换单位,从度转换到分 + double intfen= ((longitude - (int)longitude))*60; //小数转换到分为单位 +// double miao= (longitude*100 - (int)(longitude*100)); // + double last= ((int)longitude)*100 +intfen; + longitude =last; + intfen= (latitude - (int)latitude)*60;//小数转换到分为单位 +// miao= (latitude*100 - (int)(latitude*100)); + last= ((int)latitude)*100 +intfen; + latitude=last; + //sucess long gpsTime = location.getTime(); @@ -315,17 +326,14 @@ public class NMEAListener implements NmeaListener, LocationListener { 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()); + // 经纬度 保留4位小数点 + df = new DecimalFormat("#.0000"); + strLatitude = df.format(latitude); + strLongitude = df.format(longitude); + 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()); @@ -356,10 +364,12 @@ public class NMEAListener implements NmeaListener, LocationListener { longitude=0; latitude=0; searchCout=0; - locationManager.addGpsStatusListener(statusListener);//搜星 + gpsMode = GPS_CURRENT_STATUS.GPS_LISTENING; + locationManager.addGpsStatusListener(statusListener);//监听搜星状态 // this.locationManager.addNmeaListener(this); - return true; + //做个热启动 + return gpsHotStart(); } 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 339425d9..a552804a 100644 --- a/app/src/main/java/com/ic/protocol/bean/Runtime.java +++ b/app/src/main/java/com/ic/protocol/bean/Runtime.java @@ -38,7 +38,7 @@ public class Runtime { private String currentCellInfo; - public String currentWifiInfo=""; +// public String currentWifiInfo=""; private DBHelper dbHelper; 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 8eb74f60..6df90294 100644 --- a/app/src/main/java/com/ic/protocol/service/protocolMainServer.java +++ b/app/src/main/java/com/ic/protocol/service/protocolMainServer.java @@ -18,7 +18,9 @@ import android.os.SystemClock; import android.util.Log; import android.widget.Toast; +import com.ic.jni.ICJniUtils; import com.ic.protocol.Constants; +import com.ic.protocol.GSensorListener; import com.ic.protocol.LocationClient; import com.ic.protocol.adapter.LBSHelper; import com.ic.protocol.adapter.protocolAPIHelper; @@ -466,6 +468,8 @@ public class protocolMainServer extends Service { batteryUtil = new BatteryUtil(this.runtime); batteryUtil.registerBroadReceiver(); + //保证获取正确的计步数据 + loadStepCount(); //设置计步清零时间。 setCleanStepCountAlarm(); @@ -789,52 +793,9 @@ public class protocolMainServer extends Service { Logger.log(TAG,funcName,msg); } - -// @Override -// public void onCreate() { -// -// log("开始监听网络协议状态"); -// -//// IntentFilter intentFilter = new IntentFilter(); -//// intentFilter.addAction(Intent.ACTION_BATTERY_LOW); // 低电量提示 -//// intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED); // 低电量变化 -//// intentFilter.addAction(Intent.ACTION_MANAGE_NETWORK_USAGE); -//// try { -////// registerReceiver(mIntentReceiver, intentFilter); -//// } catch (Exception ignored) { -//// } -// -// -//// telManager = (TelephonyManager) getApplicationContext().getSystemService(Service.TELEPHONY_SERVICE); -//// assert telManager != null; -//// telManager.listen(mCallStateListener, PhoneStateListener.LISTEN_CALL_STATE); -// -// -//// init_protocols(); -// -//// startTimer(); -// mProtocolServer=this; -// -// onCreateCore(); -// super.onCreate(); -// } - public static protocolMainServer getInstance(){ return mProtocolServer; } -// private void init_protocols(){ -// -// if (mDevStat == null) { -// mDevStat =new Runtime(); -// log("new mDevStat"); -// } -//// if (mProtocolAPI == null) mProtocolAPI = new protocolAPIHelper(); -// if (mWifiManager == null) mWifiManager = (WifiManager)this.getApplicationContext().getSystemService(Context.WIFI_SERVICE); -// if (lbshelper==null) lbshelper = new LBSHelper(this,mWifiManager,mDevStat); -// -// toast = new Toastc(this, Toast.LENGTH_SHORT); -// -// } public void startConnectionRetryTimer(){ if (mTimer_retry_connect == null) { @@ -879,6 +840,12 @@ public class protocolMainServer extends Service { + public void saveStepCount(){ + int i = runtime.getTotalStepCount(); + int j = runtime.getSaveStepCount(); + SharPreferenceUtil.setPrefInt(this, "KEY_STEP_COUNT", i); + SharPreferenceUtil.setPrefInt(this, "key_save_step_count", j); + } @Override public void onDestroy() { super.onDestroy(); @@ -886,14 +853,15 @@ public class protocolMainServer extends Service { unregisterReceiver(mIntentReceiver); } catch (Exception ignored) { } - this.connectionServiceChain.processDetach(this.connection, this.runtime); - this.invokeHandlerServiceChain.processDetach(this.connection, this.runtime); - this.locationClient.stop(); - this.connection.close(); - unregisterReceiver(this.broadcastReceiver); - unregisterReceiver(this.screenOnReceiver); - unregisterReceiver(this.AtCallbackBroadcastReceiver); - batteryUtil.unregisterBroadReceiver(); + saveStepCount(); + this.connectionServiceChain.processDetach(this.connection, this.runtime); + this.invokeHandlerServiceChain.processDetach(this.connection, this.runtime); + this.locationClient.stop(); + this.connection.close(); + unregisterReceiver(this.broadcastReceiver); + unregisterReceiver(this.screenOnReceiver); + unregisterReceiver(this.AtCallbackBroadcastReceiver); + batteryUtil.unregisterBroadReceiver(); }