启动初始化计步,
authorsnickersun <scy@incartech.cn>
Sat, 18 Jan 2020 08:42:36 +0000 (16:42 +0800)
committersnickersun <scy@incartech.cn>
Sat, 18 Jan 2020 08:42:36 +0000 (16:42 +0800)
WifiInfo为Null 处理
修复GPS坐标转换错误

app/src/main/java/com/ic/protocol/LocationClient.java
app/src/main/java/com/ic/protocol/NMEAListener.java
app/src/main/java/com/ic/protocol/bean/Runtime.java
app/src/main/java/com/ic/protocol/service/protocolMainServer.java

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