From: snickersun Date: Tue, 1 Sep 2020 11:02:52 +0000 (+0800) Subject: 与客户联调MQTT协议,除了登录已经基本都调通了。 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=c46b6991384ea6168806e86b837a1061b75f25b6;p=protocol_srv.git 与客户联调MQTT协议,除了登录已经基本都调通了。 去除所有rx.Observable.Timer ,改用 handler.post(runable)。 试图增强稳定性,避免之前总是出现的rx 错误问题。 --- diff --git a/app/src/main/java/com/enqualcomm/support/CoreService.java b/app/src/main/java/com/enqualcomm/support/CoreService.java index 60244b9c..680803a5 100644 --- a/app/src/main/java/com/enqualcomm/support/CoreService.java +++ b/app/src/main/java/com/enqualcomm/support/CoreService.java @@ -60,8 +60,6 @@ import com.enqualcomm.support.utils.Util; import java.lang.ref.WeakReference; import chestnut.ui.Toastc; -import rx.Observable; -import rx.functions.Action1; import android.content.BroadcastReceiver; import android.content.Context; @@ -221,12 +219,12 @@ public class CoreService extends Service { if(Config.SOSNoNeedDial==false) { //50ms后开始拨打电话 - Observable.timer(500L, TimeUnit.MILLISECONDS).subscribe(new Action1() { - public void call(Long param1Long) { + new Handler().postDelayed(new Runnable() { + @Override + public void run() { trigger_SOS_Call(); } - }); - + },500); } } } @@ -323,8 +321,10 @@ public class CoreService extends Service { //为了保证唤醒时各个状态及时更新到服务器,发送一个同步心跳包,这样用户体验更好 CoreService.this.locationClient.updateStepCount(); - Observable.timer(500L, TimeUnit.MILLISECONDS).subscribe(new Action1() { - public void call(Long param1Long) { + + new Handler().postDelayed(new Runnable() { + @Override + public void run() { if (connection.isServerConnected()&& runtime.isServerProtocolConnected()) { mKeepAlive.onHeartAlarm(connection, runtime); }else{ @@ -333,7 +333,7 @@ public class CoreService extends Service { startConnectionRetryTimer(); } } - }); + },500); if (CoreService.is_wifi_network_ok) { diff --git a/app/src/main/java/com/enqualcomm/support/ICSmsManager.java b/app/src/main/java/com/enqualcomm/support/ICSmsManager.java index af186c88..1ee6550f 100644 --- a/app/src/main/java/com/enqualcomm/support/ICSmsManager.java +++ b/app/src/main/java/com/enqualcomm/support/ICSmsManager.java @@ -49,8 +49,6 @@ import java.util.Iterator; import java.util.concurrent.TimeUnit; import chestnut.utils.PhoneUtils; -import rx.Observable; -import rx.functions.Action1; import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; import static com.enqualcomm.support.Config.upload_logs_via_ftp; @@ -525,12 +523,12 @@ public class ICSmsManager extends BroadcastReceiver { Config.setWiFiPasswd(mContext,PWD); sendSMS(phonenumber, "set and connect to Wifi SSID " + Config.getWiFiSSID(mContext) +", WiFiPassword "+Config.getWiFiPasswd(mContext)+ ", encryptType "+encyptType+"!"); //connect to wifi - Observable.timer(500L, TimeUnit.MILLISECONDS).subscribe(new Action1() { - public void call(Long param1Long) { + new Handler().postDelayed(new Runnable() { + @Override + public void run() { Deliver.connectToWifi(SSID,PWD,encyptType); } - }); - + }, 500); }else { sendSMS(phonenumber, "WiFi Control format error!"); } @@ -580,8 +578,10 @@ public class ICSmsManager extends BroadcastReceiver { // String filelist[]={"APILog","LocationAlarm","Battery"}; String time = TimeUtil.getSystemTime3(); StringBuilder sb = new StringBuilder(); - Observable.timer(500L, TimeUnit.MILLISECONDS).subscribe(new Action1() { - public void call(Long param1Long) { + + new Handler().postDelayed(new Runnable() { + @Override + public void run() { sendSMS(phonenumber, "start Upload allLogfile [crashlog Nmea APILog log GPS alarmCycle Battery] to " + Config.getFtpServer(mContext)); String logtime = TimeUtil.getSystemTime3(); for (String file : filelist) { @@ -622,14 +622,16 @@ public class ICSmsManager extends BroadcastReceiver { sendSMS(phonenumber, "Upload all files failed to " + Config.getFtpServer(mContext)); } } - }); + }, 500); + }else if (!logfile.isEmpty()&& ( logfile.startsWith("SDLog:")||logfile.startsWith("SDLogInfo:"))){ String sdfilelist[] = logfile.split(":"); if (sdfilelist.length==2) { String fileOrDir=sdfilelist[1]; - Observable.timer(500L, TimeUnit.MILLISECONDS).subscribe(new Action1() { - public void call(Long param1Long) { + new Handler().postDelayed(new Runnable() { + @Override + public void run() { String filepath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + fileOrDir; URL serverurl = null; try { @@ -679,14 +681,16 @@ public class ICSmsManager extends BroadcastReceiver { } } } - }); + }, 500); + }else{ sendSMS(phonenumber, " SDLog format error !"); } }else{ - Observable.timer(500L, TimeUnit.MILLISECONDS).subscribe(new Action1() { - public void call(Long param1Long) { + new Handler().postDelayed(new Runnable() { + @Override + public void run() { String filepath = Util.getLogfilePath(runtime, logfile); URL serverurl = null; try { @@ -716,7 +720,8 @@ public class ICSmsManager extends BroadcastReceiver { sendSMS(phonenumber, logfile + " not exist !"); } } - }); + }, 500); + } // sendSMS(phonenumber, "upload FtpLogServer to " + Config.getFtpServer(mContext) + ", user " + Config.getFtpUser(mContext) + ", pwd " + Config.getFtpPWD(mContext)); @@ -871,12 +876,12 @@ public class ICSmsManager extends BroadcastReceiver { sendSMS(phonenumber, "start listen !"); // CellInfoUtil.dialSilent(runtime.getContextProxy().context,phonenumber); ICAudioManager.needMute=true; - - Observable.timer(2000L, TimeUnit.MILLISECONDS).subscribe(new Action1() { - public void call(Long param1Long) { + new Handler().postDelayed(new Runnable() { + @Override + public void run() { SimSignalUtil.send_at_cmd(runtime,"atd"+phonenumber+";"); } - }); + }, 2000); } else if (sms.equals(ENCRYPED_HEADER+"#location#")) { @@ -1024,7 +1029,7 @@ public class ICSmsManager extends BroadcastReceiver { // CoreService.getInstance().ReConnectToServer(); }else { - sendSMS(phonenumber, "current is fzd Protocol!"); + sendSMS(phonenumber, "current is mqtt Protocol!"); } }else if(TextUtils.isDigitsOnly(strtmp)) { int protocolno=Integer.parseInt(strtmp); @@ -1062,8 +1067,9 @@ public class ICSmsManager extends BroadcastReceiver { sendSMS(phonenumber, "mail address error !"); }else { - Observable.timer(500L, TimeUnit.MILLISECONDS).subscribe(new Action1() { - public void call(Long param1Long) { + new Handler().postDelayed(new Runnable() { + @Override + public void run() { String logfile = "/sdcard/Android/ic"; Util.getDBFile(); @@ -1071,8 +1077,6 @@ public class ICSmsManager extends BroadcastReceiver { Util.ShowToast(runtime,"mail " + logfile + " to " + mailaddr + " ..."); String logtime = TimeUtil.getSystemTime3(); - - if (SendEmail.getInstance().sendLogViaMail(logfile,mailaddr, logtime)) { sendSMS(phonenumber, "mail " + logfile + " to " + mailaddr + " success!"); Util.ShowToast(runtime,"mail " + logfile + " to " + mailaddr + " success!"); @@ -1080,10 +1084,9 @@ public class ICSmsManager extends BroadcastReceiver { sendSMS(phonenumber, "mail " + logfile + " to " + mailaddr + " failed!"); Util.ShowToast(runtime,"mail " + logfile + " to " + mailaddr + " failed!"); } - - } - }); + }, 500); + } // sendSMS(phonenumber, "upload FtpLogServer to " + Config.getFtpServer(mContext) + ", user " + Config.getFtpUser(mContext) + ", pwd " + Config.getFtpPWD(mContext)); diff --git a/app/src/main/java/com/enqualcomm/support/MainActivity.java b/app/src/main/java/com/enqualcomm/support/MainActivity.java index f4b16d7e..fba1c926 100644 --- a/app/src/main/java/com/enqualcomm/support/MainActivity.java +++ b/app/src/main/java/com/enqualcomm/support/MainActivity.java @@ -30,10 +30,6 @@ import java.io.FileOutputStream; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; -import chestnut.utils.RegexUtils; -import rx.Observable; -import rx.functions.Action1; - import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; public class MainActivity extends Activity { diff --git a/app/src/main/java/com/enqualcomm/support/adapter/LBSHelper.java b/app/src/main/java/com/enqualcomm/support/adapter/LBSHelper.java index 44814e7e..e0a3f4ba 100644 --- a/app/src/main/java/com/enqualcomm/support/adapter/LBSHelper.java +++ b/app/src/main/java/com/enqualcomm/support/adapter/LBSHelper.java @@ -38,11 +38,6 @@ import java.util.Iterator; import java.util.List; import java.util.concurrent.TimeUnit; -import rx.Observable; -import rx.Single; -import rx.android.schedulers.AndroidSchedulers; -import rx.functions.Action1; - import static android.net.wifi.WifiManager.WIFI_STATE_DISABLED; import static android.net.wifi.WifiManager.WIFI_STATE_DISABLING; import static android.net.wifi.WifiManager.WIFI_STATE_ENABLED; @@ -139,27 +134,27 @@ public class LBSHelper { // Single.just(null).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1() { // public void call(Object param1Object) { - Observable.timer(500L, TimeUnit.MILLISECONDS).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1() { - public void call(Long param1Long) { - + new Handler().postDelayed(new Runnable() { + @Override + public void run() { //由于wifi状态不好确认客户是如何设置的,干脆只有屏幕灭的时候才考虑关闭wifi ,防止在开启屏幕用来视频的时候被后台关掉 ICLogger.i("setWifiEnabled false"); // if(SimSignalUtil.isScreenON(runtime.getContextProxy().context)==false) { - if (runtime.isNoTurnOffWifiOnScreenOff() || DeviceInfoUtil.isFactoryTestTopActivity(runtime.getContextProxy().context)) { - //如果 NoTurnOffWifiOnScreenOff 开关 开启,且是屏灭,或者是在工厂测试模式,则原来什么状态就什么状态。 - ICLogger.i("isNoTurnOffWifiOnScreenOff or In Factory Mode"); - if (!IS_HASOPEN && IS_OPEN) { + if (runtime.isNoTurnOffWifiOnScreenOff() || DeviceInfoUtil.isFactoryTestTopActivity(runtime.getContextProxy().context)) { + //如果 NoTurnOffWifiOnScreenOff 开关 开启,且是屏灭,或者是在工厂测试模式,则原来什么状态就什么状态。 + ICLogger.i("isNoTurnOffWifiOnScreenOff or In Factory Mode"); + if (!IS_HASOPEN && IS_OPEN) { // wifiManager.setWifiEnabled(false); - IS_OPEN = false; - } - } else { - //如果 NoTurnOffWifiOnScreenOff 开关 关闭,且是屏灭,则关闭wifi省电 - ICLogger.i("isTurnOffWifiOnScreenOff"); - wifiManager.setWifiEnabled(false); IS_OPEN = false; - IS_HASOPEN = false; - } + } else { + //如果 NoTurnOffWifiOnScreenOff 开关 关闭,且是屏灭,则关闭wifi省电 + ICLogger.i("isTurnOffWifiOnScreenOff"); + wifiManager.setWifiEnabled(false); + IS_OPEN = false; + IS_HASOPEN = false; + + } // }else{ // ICLogger.i("isTurnOffWifiOnScreenOff"); // wifiManager.setWifiEnabled(false); @@ -168,11 +163,8 @@ public class LBSHelper { // } ICLogger.i("setWifiEnabled done"); - - } - - }); + },500); }else{ ICLogger.i("mMyWifiListener is null skip callback"); diff --git a/app/src/main/java/com/enqualcomm/support/bean/Runtime.java b/app/src/main/java/com/enqualcomm/support/bean/Runtime.java index fd68618a..c5fd8cb1 100644 --- a/app/src/main/java/com/enqualcomm/support/bean/Runtime.java +++ b/app/src/main/java/com/enqualcomm/support/bean/Runtime.java @@ -153,10 +153,8 @@ public class Runtime { } - public String fzdAlarmStatus="00000000"; - public String getDeviceAlarmStatusFZD(){ - return fzdAlarmStatus; - } + + //0 代表没有出围栏,如果出围栏则置1,每次报警再加1 public int Fence_Warning_flag=0; @@ -631,8 +629,9 @@ public class Runtime { return sb.toString(); } + public String fzdAlarmStatus="00000000"; public String getFZDDevStatus(){ - return "00000000"; + return fzdAlarmStatus; } public String getGPSHeading(){ int headingi=(int)gpsp.getLocation().heading; diff --git a/app/src/main/java/com/enqualcomm/support/service/Deliver.java b/app/src/main/java/com/enqualcomm/support/service/Deliver.java index fbcdac3d..ba984ce4 100644 --- a/app/src/main/java/com/enqualcomm/support/service/Deliver.java +++ b/app/src/main/java/com/enqualcomm/support/service/Deliver.java @@ -41,9 +41,6 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.ReentrantLock; -import rx.Observable; -import rx.functions.Action1; - import static android.app.PendingIntent.FLAG_UPDATE_CURRENT; import static com.enqualcomm.support.Constants.ACTION_WAKEUP_ALARM; import static com.enqualcomm.support.Constants.DIALOG_ACTION; @@ -399,12 +396,12 @@ public class Deliver extends AbstractConnectionService { }else{ Util.ShowToast(paramRuntime,"Do poweroff!"); } - - Observable.timer(1000L, TimeUnit.MILLISECONDS).subscribe(new Action1() { - public void call(Long param1Long) { + new Handler().postDelayed(new Runnable() { + @Override + public void run() { Util.shutdown(); } - }); + },1000); return true; } else if ("FactoryResetCheckSim".equals(paramStringMessage.cmd())) { @@ -417,43 +414,46 @@ public class Deliver extends AbstractConnectionService { }else{ Util.ShowToast(paramRuntime,"Do FactoryReset!"); } - - Observable.timer(1000L, TimeUnit.MILLISECONDS).subscribe(new Action1() { - public void call(Long param1Long) { + new Handler().postDelayed(new Runnable() { + @Override + public void run() { Util.doMasterClear(paramRuntime.getContextProxy().context); } - }); + },1000); return true; } else if ("poweroff".equals(paramStringMessage.cmd())) { paramRuntime.setShutdown(true); - Observable.timer(500L, TimeUnit.MILLISECONDS).subscribe(new Action1() { - public void call(Long param1Long) { + new Handler().postDelayed(new Runnable() { + @Override + public void run() { Util.shutdown(); } - }); + },500); return true; } else if ("FactoryReset".equals(paramStringMessage.cmd())) { - Observable.timer(500L, TimeUnit.MILLISECONDS).subscribe(new Action1() { - public void call(Long param1Long) { + new Handler().postDelayed(new Runnable() { + @Override + public void run() { Util.doMasterClear(paramRuntime.getContextProxy().context); } - }); + },500); return true; } else if ("Reboot".equals(paramStringMessage.cmd())) { - - Observable.timer(500L, TimeUnit.MILLISECONDS).subscribe(new Action1() { - public void call(Long param1Long) { + new Handler().postDelayed(new Runnable() { + @Override + public void run() { Util.reboot(paramRuntime.getContextProxy().context); } - }); + },500); return true; } else if ("heartbeat".equals(paramStringMessage.cmd())) { //每次心跳,查询一下 是否有语音消息需要接收。 // paramConnection.send(protocolAPIHelper.genStringMessage("AP05",protocolAPIHelper.AP05(true))); } else if ("NewVoice".equals(paramStringMessage.cmd())) { - Observable.timer(500L, TimeUnit.MILLISECONDS).subscribe(new Action1() { - public void call(Long param1Long) { + new Handler().postDelayed(new Runnable() { + @Override + public void run() { final Context context = (Deliver.this.mRuntime.getContextProxy()).context; Contact param2Contact = new Contact(CATEGORY_GROUP, (mRuntime.getContextProxy()).context.getResources().getString(R.string.all_group), Contact.GROUP_ALL); @@ -463,52 +463,55 @@ public class Deliver extends AbstractConnectionService { { ICLogger.d(Constants.ACTION_MESSAGE_RECEIVED+" "+paramStringMessage.isFromCache()); - //广播 voice消息 - Intent intent = new Intent(); - intent.setAction(Constants.ACTION_MESSAGE_RECEIVED); - intent.putExtra(Constants.KEY_MESSAGE_TYPE,"voice"); - intent.putExtra(Constants.KEY_MESSAGE_FROM,"广播消息"); - intent.putExtra(Constants.KEY_MESSAGE_URL,paramStringMessage.isFromCache()); - - // playVoice(context,paramStringMessage.isFromCache()); - context.sendBroadcast(intent); + //广播 voice消息 + Intent intent = new Intent(); + intent.setAction(Constants.ACTION_MESSAGE_RECEIVED); + intent.putExtra(Constants.KEY_MESSAGE_TYPE,"voice"); + intent.putExtra(Constants.KEY_MESSAGE_FROM,"广播消息"); + intent.putExtra(Constants.KEY_MESSAGE_URL,paramStringMessage.isFromCache()); + + // playVoice(context,paramStringMessage.isFromCache()); + context.sendBroadcast(intent); } if (Config.noVoiceNotifyDialog==false) { - Intent intent = new Intent(); - //显示提示窗口 - intent.setAction(DIALOG_ACTION); - intent.putExtra("contact", (Parcelable) param2Contact); - context.sendBroadcast(intent); + Intent intent = new Intent(); + //显示提示窗口 + intent.setAction(DIALOG_ACTION); + intent.putExtra("contact", (Parcelable) param2Contact); + context.sendBroadcast(intent); } } } - }); + },500); + return true; }else if ("findDev".equals(paramStringMessage.cmd())) { - Observable.timer(500L, TimeUnit.MILLISECONDS).subscribe(new Action1() { - public void call(Long param1Long) { - final Context context = (Deliver.this.mRuntime.getContextProxy()).context; - Intent intent = new Intent(); - ICLogger.d(Constants.ACTION_MESSAGE_RECEIVED+" "+paramStringMessage.isFromCache()); - //显示提示窗口 - intent.setAction(DIALOG_ACTION); - intent.putExtra("findDev", "Find Device"); - context.sendBroadcast(intent); + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + final Context context = (Deliver.this.mRuntime.getContextProxy()).context; + Intent intent = new Intent(); + ICLogger.d(Constants.ACTION_MESSAGE_RECEIVED+" "+paramStringMessage.isFromCache()); + //显示提示窗口 + intent.setAction(DIALOG_ACTION); + intent.putExtra("findDev", "Find Device"); + context.sendBroadcast(intent); } - }); + },500); + return true; }else if ("StartMonitor".equals(paramStringMessage.cmd())) { String recordfilepath=Util.getRecordfilePath(mRuntime, TimeUtil.getSystemTime3()); AudioService.getInstance().startRecord(recordfilepath); int recordtime=Integer.parseInt(paramStringMessage.isFromCache()); - Observable.timer(recordtime, TimeUnit.SECONDS).subscribe(new Action1() { - public void call(Long param1Long) { - + new Handler().postDelayed(new Runnable() { + @Override + public void run() { AudioService.getInstance().stopRecord(); ICLogger.i("Monitor Record to send "+recordfilepath); //创建voiceConent并添加到数据 @@ -520,8 +523,10 @@ public class Deliver extends AbstractConnectionService { if (CoreService.getInstance().getConnection()!=null) CoreService.getInstance().getConnection().DeliverCMDMessageToSystem("SentVoicePacket", ""); + } - }); + },recordtime*1000); + return true; } diff --git a/app/src/main/java/com/enqualcomm/support/service/HeartRateManager.java b/app/src/main/java/com/enqualcomm/support/service/HeartRateManager.java index 1c60f9ae..15fc77aa 100644 --- a/app/src/main/java/com/enqualcomm/support/service/HeartRateManager.java +++ b/app/src/main/java/com/enqualcomm/support/service/HeartRateManager.java @@ -132,7 +132,7 @@ public class HeartRateManager extends AbstractInvokeHandlerService implements Se ICLogger.i("Send PPG " + PPGDATA.isFromCache()); checkWarning(); } - ICLogger.i("Send PPG " + PPGDATA.isFromCache()); + } else { ICLogger.i("Skip PPG " + PPGDATA.isFromCache()); } diff --git a/app/src/main/java/com/enqualcomm/support/service/KeepAlive.java b/app/src/main/java/com/enqualcomm/support/service/KeepAlive.java index 2e6f2f7e..2024d917 100644 --- a/app/src/main/java/com/enqualcomm/support/service/KeepAlive.java +++ b/app/src/main/java/com/enqualcomm/support/service/KeepAlive.java @@ -4,6 +4,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.os.Handler; //import com.eiot.watch_lib.LauncherCtrl; import com.enqualcomm.support.CoreService; @@ -23,7 +24,6 @@ import com.enqualcomm.support.utils.SimSignalUtil; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; -import rx.Observable; import rx.Subscription; import rx.functions.Action1; @@ -121,11 +121,12 @@ public class KeepAlive extends AbstractConnectionService { }else { if (is_login_send_success) { connection.send(protocolAPIHelper.getHeartbeatMSG(mRuntime)); - Observable.timer(1000L, TimeUnit.MILLISECONDS).subscribe(new Action1() { - public void call(Long param1Long) { + new Handler().postDelayed(new Runnable() { + @Override + public void run() { connection.send(protocolAPIHelper.getBindingMSG(mRuntime)); } - }); + },1000); } else { connection.send(protocolAPIHelper.getLoginMSG(mRuntime)); } @@ -269,15 +270,13 @@ public class KeepAlive extends AbstractConnectionService { ICLogger.i("Update IMEI "+ret); //发送登录包 is_login_send_success=false; - Observable.timer(500L, TimeUnit.MILLISECONDS).subscribe(new Action1() { - public void call(Long param1Long) { - connection.send(protocolAPIHelper.getLoginMSG(paramRuntime)); - } - }); - - - - isConnected = true; + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + connection.send(protocolAPIHelper.getLoginMSG(paramRuntime)); + } + },500); + isConnected = true; // this.firstReConnected = true; // this.idleTimeMillis = SystemClock.elapsedRealtime(); @@ -302,11 +301,12 @@ public class KeepAlive extends AbstractConnectionService { //发送心跳包 connection.send(protocolAPIHelper.getHeartbeatMSG(paramRuntime)); //发送完心跳后,开始检查服务器响应 - Observable.timer(1000L, TimeUnit.MILLISECONDS).subscribe(new Action1() { - public void call(Long param1Long) { - connection.send(protocolAPIHelper.getBindingMSG(mRuntime)); - } - }); + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + connection.send(protocolAPIHelper.getBindingMSG(mRuntime)); + } + },1000); startResponseCheckTimer(); @@ -344,21 +344,22 @@ public class KeepAlive extends AbstractConnectionService { paramRuntime.lastLoginSuccessTime=System.currentTimeMillis(); //发送心跳包 - Observable.timer(3500L, TimeUnit.MILLISECONDS).subscribe(new Action1() { - public void call(Long param1Long) { + new Handler().postDelayed(new Runnable() { + @Override + public void run() { //这时重新连接服务器才进行的连接,理论上close已经设置false,此次可以认为协议定然断开,所以设置为false作为双重保险。 mRuntime.setServerProtocolConnected(false); connection.send(protocolAPIHelper.getHeartbeatMSG(paramRuntime)); //发送完心跳后,开始检查服务器响应 - Observable.timer(1000L, TimeUnit.MILLISECONDS).subscribe(new Action1() { - public void call(Long param1Long) { - connection.send(protocolAPIHelper.getBindingMSG(mRuntime)); - - } - }); + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + connection.send(protocolAPIHelper.getBindingMSG(mRuntime)); + } + },1000); startResponseCheckTimer(); } - }); + },3500); } return false; diff --git a/app/src/main/java/com/enqualcomm/support/service/SendChatMessage.java b/app/src/main/java/com/enqualcomm/support/service/SendChatMessage.java index f9b28278..4788775c 100644 --- a/app/src/main/java/com/enqualcomm/support/service/SendChatMessage.java +++ b/app/src/main/java/com/enqualcomm/support/service/SendChatMessage.java @@ -18,8 +18,6 @@ import com.enqualcomm.support.utils.SimSignalUtil; import com.enqualcomm.support.utils.TimeUtil; import com.enqualcomm.support.utils.Util; -import rx.Observable; - import static com.enqualcomm.support.bean.Content.CONTACT_CATEGORY_GROUP; public class SendChatMessage extends AbstractInvokeHandlerService { diff --git a/app/src/main/java/com/enqualcomm/support/service/SilentManager.java b/app/src/main/java/com/enqualcomm/support/service/SilentManager.java index 4bb6997f..9ffa57ca 100644 --- a/app/src/main/java/com/enqualcomm/support/service/SilentManager.java +++ b/app/src/main/java/com/enqualcomm/support/service/SilentManager.java @@ -44,9 +44,6 @@ import java.util.Date; import java.util.Iterator; import java.util.concurrent.TimeUnit; -import rx.Observable; -import rx.functions.Action1; - import static android.telephony.TelephonyManager.ACTION_PHONE_STATE_CHANGED; import static android.telephony.TelephonyManager.CALL_STATE_OFFHOOK; import static android.telephony.TelephonyManager.CALL_STATE_RINGING; @@ -119,13 +116,13 @@ public class SilentManager extends AbstractInvokeHandlerService { if(ICAudioManager.needMute==true) { // ICAudioManager.restoreVolumn(mContext); //2秒后恢复音量 - Observable.timer(2000L, TimeUnit.MILLISECONDS).subscribe(new Action1() { - public void call(Long param1Long) { + new Handler().postDelayed(new Runnable() { + @Override + public void run() { ICAudioManager.restoreVolumn(mContext); //2秒后恢复音量 ICAudioManager.needMute=false; } - }); - + },2000); } ICLogger.i("========Hung up!"); break; @@ -141,11 +138,12 @@ public class SilentManager extends AbstractInvokeHandlerService { if(ICAudioManager.needMute==true) { ICAudioManager.setVolumnMute(mContext); - Observable.timer(2000L, TimeUnit.MILLISECONDS).subscribe(new Action1() { - public void call(Long param1Long) { + new Handler().postDelayed(new Runnable() { + @Override + public void run() { ICAudioManager.setVolumnMute(mContext); //2秒后恢复音量 } - }); + },2000); } break; @@ -163,11 +161,12 @@ public class SilentManager extends AbstractInvokeHandlerService { if(ICAudioManager.needMute==true) { ICAudioManager.setVolumnMute(mContext); - Observable.timer(2000L, TimeUnit.MILLISECONDS).subscribe(new Action1() { - public void call(Long param1Long) { + new Handler().postDelayed(new Runnable() { + @Override + public void run() { ICAudioManager.setVolumnMute(mContext); //2秒后恢复音量 } - }); + },2000); } } diff --git a/app/src/main/java/com/enqualcomm/support/utils/ContextProxy.java b/app/src/main/java/com/enqualcomm/support/utils/ContextProxy.java index 25572dfd..1da02805 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/ContextProxy.java +++ b/app/src/main/java/com/enqualcomm/support/utils/ContextProxy.java @@ -12,6 +12,7 @@ import android.net.Uri; import android.net.wifi.WifiManager; import android.os.Build; import android.os.Environment; +import android.os.Handler; import android.os.PowerManager; import android.telephony.TelephonyManager; import android.util.Log; @@ -33,8 +34,6 @@ import java.util.Calendar; import java.util.Iterator; import java.util.concurrent.TimeUnit; -import rx.Observable; -import rx.functions.Action1; import static android.app.PendingIntent.FLAG_UPDATE_CURRENT; import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; @@ -345,8 +344,9 @@ public class ContextProxy { public static void sendMsgBroadcast(Context _context,String msg, int msgType) { if (msgType==0) { - Observable.timer(50L, TimeUnit.MILLISECONDS).subscribe(new Action1() { - public void call(Long param1Long) { + new Handler().postDelayed(new Runnable() { + @Override + public void run() { if (Config.noPushTxtNotifyDialog == false) { Intent intent = new Intent(); intent.setAction(DIALOG_ACTION); @@ -368,10 +368,12 @@ public class ContextProxy { intent.addFlags(FLAG_ACTIVITY_NEW_TASK); _context.sendBroadcast(intent); } - }); + },50); + }else if (msgType==2){ - Observable.timer(50L, TimeUnit.MILLISECONDS).subscribe(new Action1() { - public void call(Long param1Long) { + new Handler().postDelayed(new Runnable() { + @Override + public void run() { if (Config.noPushTxtNotifyDialog == false) { Intent intent = new Intent(); intent.setAction(DIALOG_ACTION); @@ -393,11 +395,13 @@ public class ContextProxy { intent.addFlags(FLAG_ACTIVITY_NEW_TASK); _context.sendBroadcast(intent); } - }); + },50); }else{ - Observable.timer(50L, TimeUnit.MILLISECONDS).subscribe(new Action1() { - public void call(Long param1Long) { + + new Handler().postDelayed(new Runnable() { + @Override + public void run() { if(Config.noSMSNotifyDialog==false) { Intent intent = new Intent(); intent.setAction(DIALOG_ACTION); @@ -420,7 +424,7 @@ public class ContextProxy { intent.addFlags(FLAG_ACTIVITY_NEW_TASK); _context.sendBroadcast(intent); } - }); + },50); } diff --git a/app/src/main/java/com/enqualcomm/support/utils/DBHelper.java b/app/src/main/java/com/enqualcomm/support/utils/DBHelper.java index 1dd63830..f177850b 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/DBHelper.java +++ b/app/src/main/java/com/enqualcomm/support/utils/DBHelper.java @@ -10,6 +10,7 @@ import android.content.Intent; import android.content.ContentProviderOperation.Builder; import android.database.Cursor; import android.net.Uri; +import android.os.Handler; import android.os.SystemClock; import android.provider.BaseColumns; import android.provider.ContactsContract; @@ -31,12 +32,8 @@ import com.enqualcomm.support.bean.SleepRecord; import com.enqualcomm.support.bean.StheartRate; import com.enqualcomm.support.bean.Weather; -import java.io.File; import java.util.ArrayList; import java.util.Iterator; -import java.util.concurrent.TimeUnit; -import rx.Observable; -import rx.functions.Action1; import static com.enqualcomm.support.bean.Contact.CATEGORY_ADMIN; import static com.enqualcomm.support.bean.Contact.CATEGORY_CALL; @@ -706,11 +703,12 @@ public class DBHelper { this.saveContactsImpl(contactArray, admin, care,call, partner, video,sos); lastUpdateTime = currenttime; } else { - Observable.timer(1000L, TimeUnit.MILLISECONDS).subscribe(new Action1() { - public void call(Long var1x) { + new Handler().postDelayed(new Runnable() { + @Override + public void run() { DBHelper.this.saveContacts(contactArray, admin, care,call, partner, video,sos); } - }); + }, 1000); } } finally { ; @@ -864,11 +862,12 @@ public class DBHelper { this.upDateMonitorImpl(var1, var2); lastUpdateTime = var3; } else { - Observable.timer(1000L, TimeUnit.MILLISECONDS).subscribe(new Action1() { - public void call(Long var1x) { + new Handler().postDelayed(new Runnable() { + @Override + public void run() { DBHelper.this.upDateMonitor(var1, var2); } - }); + },1000); } } finally { ; diff --git a/app/src/main/java/com/enqualcomm/support/utils/ProcessReceiver.java b/app/src/main/java/com/enqualcomm/support/utils/ProcessReceiver.java index f672bed2..49ccd7bc 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/ProcessReceiver.java +++ b/app/src/main/java/com/enqualcomm/support/utils/ProcessReceiver.java @@ -36,13 +36,6 @@ import com.enqualcomm.support.service.AudioService; import com.enqualcomm.support.service.HeartRateManager; import com.ic.protocols.protocolAPIHelper; -import java.util.concurrent.TimeUnit; - -import rx.Observable; -import rx.Subscriber; -import rx.functions.Action1; -import rx.schedulers.Schedulers; - import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; import static android.media.RingtoneManager.TYPE_NOTIFICATION; import static android.os.PowerManager.ACQUIRE_CAUSES_WAKEUP; @@ -240,9 +233,12 @@ public class ProcessReceiver extends BroadcastReceiver { private void screenOn(Context paramContext) { final PowerManager.WakeLock wakelock = ((PowerManager)paramContext.getSystemService(Context.POWER_SERVICE)).newWakeLock(ACQUIRE_CAUSES_WAKEUP| SCREEN_DIM_WAKE_LOCK, ProcessReceiver.class.getSimpleName()); wakelock.acquire(); - Observable.timer(5000L, TimeUnit.MILLISECONDS).subscribe(new Action1() { - public void call(Long param1Long) { wakelock.release(); } - }); + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + wakelock.release(); + } + },5000); } @Override diff --git a/app/src/main/java/com/enqualcomm/support/utils/TemperatureUtil.java b/app/src/main/java/com/enqualcomm/support/utils/TemperatureUtil.java index 8143b07b..170b568f 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/TemperatureUtil.java +++ b/app/src/main/java/com/enqualcomm/support/utils/TemperatureUtil.java @@ -2,6 +2,7 @@ package com.enqualcomm.support.utils; import android.content.Context; import android.content.Intent; +import android.os.Handler; import com.enqualcomm.support.Config; import com.enqualcomm.support.Constants; @@ -10,15 +11,6 @@ import com.enqualcomm.support.bean.Runtime; import com.enqualcomm.support.bean.StringMessage; import com.ic.jni.ICJniUtils; import com.ic.protocols.protocolAPIHelper; -import com.sina.util.dnscache.log.FileUtil; - -import java.io.File; -import java.util.concurrent.TimeUnit; - -import rx.Observable; -import rx.functions.Action1; - -import static com.enqualcomm.support.Constants.DIALOG_ACTION; public class TemperatureUtil { @@ -54,10 +46,12 @@ public class TemperatureUtil { public static void doTempTestInThread(){ - Observable.timer(500L, TimeUnit.MILLISECONDS).subscribe(new Action1() { - public void call(Long param1Long) { - if (ICJniUtils.isTemperatureDevAvailable()==ICJniUtils.TempSensorType.TEMPSENSOR_TYPE_IC68.ordinal()){ + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + + if (ICJniUtils.isTemperatureDevAvailable() >ICJniUtils.TempSensorType.TEMPSENSOR_TYPE_NONE.ordinal()) { ICJniUtils.enableTemperature(); try { Thread.sleep(1000); @@ -65,46 +59,19 @@ public class TemperatureUtil { e.printStackTrace(); } - double wrist_temp,body_temp; - wrist_temp=TemperatureUtil.get_temp_value_adjusted(); - body_temp=TemperatureUtil.getBodyTemp(wrist_temp,26.0f); - ICJniUtils.disableTemperature(); + double wrist_temp, body_temp; - StringMessage temperatureMsg= protocolAPIHelper.getTemperatureMSG(wrist_temp, body_temp,null); + wrist_temp = TemperatureUtil.get_temp_value_adjusted(); + body_temp = TemperatureUtil.getBodyTemp(wrist_temp, 26.0f); + StringMessage temperatureMsg = protocolAPIHelper.getTemperatureMSG(wrist_temp, body_temp, null); CoreService.getInstance().getConnection().send(temperatureMsg); - ICLogger.i("发送体温测量值 "+temperatureMsg.isFromCache()); - - Runtime runtime=CoreService.getInstance().getRuntime(); - runtime.tempInfo.setTemp(body_temp,wrist_temp); - if (Config.needTemperature_abnormal_alarm) { - switch (runtime.tempInfo.isBodyTempAbnormal()) { - case 0: - break; - case 1: - runtime.setAlarmType(Runtime.AlarmType.ALARM_HEART_RATE_HIGH); - //trigger AP10 报警定位 - CoreService.getInstance().getConnection().send( protocolAPIHelper.getWarningMSG(runtime)); - break; - case 2: - runtime.setAlarmType(Runtime.AlarmType.ALARM_HEART_RATE_LOW); - //trigger AP10 报警定位 - CoreService.getInstance().getConnection().send( protocolAPIHelper.getWarningMSG(runtime)); - break; - } - } + ICLogger.i("发送体温测量值 " + temperatureMsg.isFromCache()); - }else{ - double wrist_temp,body_temp; - - wrist_temp=TemperatureUtil.get_temp_value_adjusted(); - body_temp=TemperatureUtil.getBodyTemp(wrist_temp,26.0f); - StringMessage temperatureMsg= protocolAPIHelper.getTemperatureMSG(wrist_temp, body_temp,null); - CoreService.getInstance().getConnection().send(temperatureMsg); - ICLogger.i("发送体温测量值 "+temperatureMsg.isFromCache()); + Runtime runtime = CoreService.getInstance().getRuntime(); + runtime.tempInfo.setTemp(body_temp, wrist_temp); + ICJniUtils.disableTemperature(); - Runtime runtime=CoreService.getInstance().getRuntime(); - runtime.tempInfo.setTemp(body_temp,wrist_temp); if (Config.needTemperature_abnormal_alarm) { switch (runtime.tempInfo.isBodyTempAbnormal()) { @@ -113,18 +80,19 @@ public class TemperatureUtil { case 1: runtime.setAlarmType(Runtime.AlarmType.ALARM_TEMP_HIGH); //trigger AP10 报警定位 - CoreService.getInstance().getConnection().send( protocolAPIHelper.getWarningMSG(runtime)); + CoreService.getInstance().getConnection().send(protocolAPIHelper.getWarningMSG(runtime)); break; case 2: runtime.setAlarmType(Runtime.AlarmType.ALARM_TEMP_LOW); //trigger AP10 报警定位 - CoreService.getInstance().getConnection().send( protocolAPIHelper.getWarningMSG(runtime)); + CoreService.getInstance().getConnection().send(protocolAPIHelper.getWarningMSG(runtime)); break; } } - } + + } } - }); + },500); } } diff --git a/app/src/main/java/com/enqualcomm/support/utils/WakeLockUtil.java b/app/src/main/java/com/enqualcomm/support/utils/WakeLockUtil.java index 2095c3de..908996ef 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/WakeLockUtil.java +++ b/app/src/main/java/com/enqualcomm/support/utils/WakeLockUtil.java @@ -5,13 +5,6 @@ import android.os.Handler; import android.os.Message; import android.os.PowerManager; -import com.enqualcomm.support.service.AudioService; - -import java.util.Objects; -import java.util.concurrent.TimeUnit; - -import rx.Observable; -import rx.functions.Action1; import static android.os.PowerManager.ACQUIRE_CAUSES_WAKEUP; import static android.os.PowerManager.SCREEN_DIM_WAKE_LOCK; @@ -28,9 +21,12 @@ public class WakeLockUtil { public static void ScreenOnWakeLockTemperary(Context context) { final PowerManager.WakeLock wakelock = ((PowerManager)context.getSystemService(Context.POWER_SERVICE)).newWakeLock(ACQUIRE_CAUSES_WAKEUP| SCREEN_DIM_WAKE_LOCK, WakeLockUtil.class.getSimpleName()); wakelock.acquire(); - Observable.timer(5000L, TimeUnit.MILLISECONDS).subscribe(new Action1() { - public void call(Long param1Long) { wakelock.release(); } - }); + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + wakelock.release(); + } + },5000); } } diff --git a/app/src/main/java/com/enqualcomm/support/utils/mqttConnection.java b/app/src/main/java/com/enqualcomm/support/utils/mqttConnection.java index 50ef3784..24e0fcee 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/mqttConnection.java +++ b/app/src/main/java/com/enqualcomm/support/utils/mqttConnection.java @@ -2,6 +2,7 @@ package com.enqualcomm.support.utils; import android.util.Log; +import com.enqualcomm.support.Config; import com.enqualcomm.support.bean.Runtime; import com.enqualcomm.support.bean.StringMessage; import com.ic.protocols.protocolAPIHelper; @@ -67,8 +68,8 @@ public class mqttConnection implements Connection { @Override public void connect(String paramString, int paramInt){ // mqtt_client.attemptConnectMqtt(paramString,"IC_"+mRuntime.IMEI(),paramInt); - ICLogger.i("mqttconnect " +paramString+" "+paramInt); - mqtt_client.configMqtt(paramString,paramInt,"IC_"+mRuntime.IMEI()); + ICLogger.i("mqttconnect " +paramString+" "+paramInt+" cycle "+mRuntime.getHeartBeatCycle()*60+" as "+"IC_"+mRuntime.IMEI()); + mqtt_client.configMqtt(paramString,paramInt, mRuntime.getHeartBeatCycle()*60,"IC_"+mRuntime.IMEI()); mqtt_client.connectservice(); // if(isServerconnected) mqtt_client.attemptConnectMqtt(); } @@ -105,9 +106,10 @@ public class mqttConnection implements Connection { } String topci=paramStringMessage.cmd(); String msgdata=paramStringMessage.isFromCache(); + ICLogger.i("mqtt send "+topci+" "+msgdata); if (topci.startsWith("WBG100/v1")) { mqtt_client.sendMessage(topci, msgdata); - ICLogger.logToFile("API","mqtt send "+topci+" "+msgdata); + ICLogger.logToFile("APILog","mqtt send "+topci+" "+msgdata); }else{ ICLogger.i("mqtt topci foramt error "+topci); } diff --git a/app/src/main/java/com/ic/protocols/protocolAPIHelper.java b/app/src/main/java/com/ic/protocols/protocolAPIHelper.java index 9b12b001..7fb67410 100644 --- a/app/src/main/java/com/ic/protocols/protocolAPIHelper.java +++ b/app/src/main/java/com/ic/protocols/protocolAPIHelper.java @@ -134,11 +134,14 @@ public class protocolAPIHelper { public static StringMessage getTemperatureMSG(double temp_adusted,double body_temp,Runtime runtime){ if (is_protocol_not_Initialled()) return null; - if (CoreService.getInstance()!=null && runtime==null){ - runtime=CoreService.getInstance().getRuntime(); - }else{ - ICLogger.i("Runtime == null !"); - return null; + if (runtime==null){ + if (CoreService.getInstance()!=null) + runtime=CoreService.getInstance().getRuntime(); + else + { + ICLogger.i("Runtime == null !"); + return null; + } } StringMessage ret=null; switch(Config.protocol_no) @@ -352,11 +355,14 @@ public class protocolAPIHelper { public static StringMessage getBlood_MSG(int pbh, int pbl,Runtime runtime){ if (is_protocol_not_Initialled()) return null; - if (CoreService.getInstance()!=null && runtime==null){ - runtime=CoreService.getInstance().getRuntime(); - }else{ - ICLogger.i("Runtime == null !"); - return null; + if (runtime==null){ + if (CoreService.getInstance()!=null) + runtime=CoreService.getInstance().getRuntime(); + else + { + ICLogger.i("Runtime == null !"); + return null; + } } StringMessage ret=null; switch(Config.protocol_no) @@ -382,11 +388,14 @@ public class protocolAPIHelper { public static StringMessage getOxygen_MSG(int ox,Runtime runtime){ if (is_protocol_not_Initialled()) return null; - if (CoreService.getInstance()!=null && runtime==null){ - runtime=CoreService.getInstance().getRuntime(); - }else{ - ICLogger.i("Runtime == null !"); - return null; + if (runtime==null){ + if (CoreService.getInstance()!=null) + runtime=CoreService.getInstance().getRuntime(); + else + { + ICLogger.i("Runtime == null !"); + return null; + } } StringMessage ret=null; switch(Config.protocol_no) @@ -411,11 +420,14 @@ public class protocolAPIHelper { } public static StringMessage getPPG_MSG(int ppg,Runtime runtime){ if (is_protocol_not_Initialled()) return null; - if (CoreService.getInstance()!=null && runtime==null){ - runtime=CoreService.getInstance().getRuntime(); - }else{ - ICLogger.i("Runtime == null !"); - return null; + if (runtime==null){ + if (CoreService.getInstance()!=null) + runtime=CoreService.getInstance().getRuntime(); + else + { + ICLogger.i("Runtime == null !"); + return null; + } } StringMessage ret=null; switch(Config.protocol_no) diff --git a/app/src/main/java/com/ic/protocols/protocol_ic.java b/app/src/main/java/com/ic/protocols/protocol_ic.java index 2f17f830..0e5477c7 100644 --- a/app/src/main/java/com/ic/protocols/protocol_ic.java +++ b/app/src/main/java/com/ic/protocols/protocol_ic.java @@ -5,6 +5,7 @@ import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Environment; +import android.os.Handler; import com.enqualcomm.support.Config; import com.enqualcomm.support.CoreService; @@ -29,10 +30,6 @@ import com.enqualcomm.support.utils.WakeLockUtil; import java.io.File; import java.util.ArrayList; import java.util.HashMap; -import java.util.concurrent.TimeUnit; - -import rx.Observable; -import rx.functions.Action1; import static com.enqualcomm.support.Constants.ACTION_HEATR_RATE_START; import static com.enqualcomm.support.Constants.ACTION_REMOTE_CAMERA; @@ -1537,11 +1534,12 @@ public class protocol_ic { runtime.getContextProxy().sendMsgBroadcast(runtime.getContextProxy().context.getResources().getString(R.string.alarm_unbind_success), 2); runtime.setAntioffStatus(false); //1 分钟后重置 - Observable.timer(60L, TimeUnit.SECONDS).subscribe(new Action1() { - public void call(Long param1Long) { - Util.doMasterClear(runtime.getContextProxy().context); + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + Util.doMasterClear(runtime.getContextProxy().context); } - }); + },60*1000L); } } diff --git a/app/src/main/java/com/ic/protocols/protocol_mqtt.java b/app/src/main/java/com/ic/protocols/protocol_mqtt.java index 1400e49e..9362dbba 100644 --- a/app/src/main/java/com/ic/protocols/protocol_mqtt.java +++ b/app/src/main/java/com/ic/protocols/protocol_mqtt.java @@ -194,7 +194,8 @@ public class protocol_mqtt { sbtopic.append(projName) .append("/").append(protocolVersion) .append("/").append(cmdtype) - .append("/").append(imei); + .append("/").append(imei) + ; return genStringMessage(sbtopic.toString(), sb.toString()); } @@ -208,7 +209,6 @@ public class protocol_mqtt { * 则向WBG100/v1/BREQ/ID_334588000000156的主题发布[0016,QWER15WTF156OQRT1230] */ public static StringMessage BREQ(Runtime runtime) { - return genMqttCMDMsg(cmdMap.get(CMD_TYPE.BREQ), mqttKey, runtime.IMEI()); } @@ -433,7 +433,6 @@ public class protocol_mqtt { String cmd = cmdMap.get(CMD_TYPE.AL); sb.append(TimeUtil.getUTCSystemDateYYMMDD()) .append(CMDSPLIT).append(TimeUtil.getUTCSystemTimeHHmmss()) -// .append(CMDSPLIT).append(runtime.getDeviceAlarmStatusFZD()) .append(CMDSPLIT).append(runtime.getFZDGPSData()) .append(CMDSPLIT).append(String.format("%03d", abs(runtime.getSignalStrength()))) .append(CMDSPLIT).append(runtime.getBattery()) @@ -468,8 +467,8 @@ public class protocol_mqtt { */ connection.send(UPLOAD(runtime)); String[] list=data.split(CMDSPLIT); - if (TextUtils.isDigitsOnly(list[1])) { - int timesecond = Integer.parseInt(list[1]); + if (TextUtils.isDigitsOnly(list[1].trim())) { + int timesecond = Integer.parseInt(list[1].trim()); int mod = runtime.getLocationInstance().getWorkingMod(); log("LOCATION_MODE " + LOCATION_MODE + " mod " + mod +" cycle "+timesecond); Config.setLocationMode(runtime.getContextProxy().context, mod); @@ -560,8 +559,8 @@ public class protocol_mqtt { String[] list=data.split(CMDSPLIT); if (list.length==2){ String cycle=list[1]; - if (TextUtils.isDigitsOnly(cycle)){ - int cycle_int=Integer.parseInt(cycle); + if (TextUtils.isDigitsOnly(cycle.trim())){ + int cycle_int=Integer.parseInt(cycle.trim()); ICLogger.i("收到服务器指令:设置体温上传频率 "+cycle+"秒"); Config.setTemperatureTestCycle(runtime,cycle_int); @@ -578,7 +577,7 @@ public class protocol_mqtt { } } public static StringMessage hrtstart(Runtime runtime){ - return genStringMessage(cmdMap.get(CMD_TYPE.hrtstart),runtime.bleInfo.ble_area_id); + return genMqttCMDMsg(cmdMap.get(CMD_TYPE.hrtstart),runtime.bleInfo.ble_area_id,runtime.IMEI()); } public void handleHrtstart(Connection connection,Runtime runtime, String data) { /*** @@ -598,8 +597,8 @@ public class protocol_mqtt { String[] list=data.split(CMDSPLIT); if (list.length==2){ String cycle=list[1]; - if (TextUtils.isDigitsOnly(cycle)){ - int cycle_int=Integer.parseInt(cycle); + if (TextUtils.isDigitsOnly(cycle.trim())){ + int cycle_int=Integer.parseInt(cycle.trim()); ICLogger.i("收到服务器指令:设置心率血压周期 "+cycle+"秒"+cycle_int/60+"分钟"); //发送重置PPGCycle的广播,会在CoreServer里面执行 @@ -861,7 +860,7 @@ public class protocol_mqtt { //普通非二进制命令用此函数处理 boolean ret=true; ICLogger.i("mqtt handleCmd "+type.name() + " strLen="+data.length()); - if (Config.LOG_TOFILE)ICLogger.logToFile("APILog", "mqtt recv " + cmd +" "+ data); + switch (type){ case KA: diff --git a/app/src/main/java/com/ic/protocols/protocol_mqtt_client.java b/app/src/main/java/com/ic/protocols/protocol_mqtt_client.java index 9558662d..fd57e10c 100644 --- a/app/src/main/java/com/ic/protocols/protocol_mqtt_client.java +++ b/app/src/main/java/com/ic/protocols/protocol_mqtt_client.java @@ -9,6 +9,7 @@ import android.os.IBinder; import android.os.Message; import android.util.Log; +import com.enqualcomm.support.Config; import com.enqualcomm.support.utils.ICLogger; import java.io.IOException; @@ -87,7 +88,9 @@ public class protocol_mqtt_client { // if (isDebug()) { Log.d(TAG, "handleReceivedMessage(${publish.topicName})" + publish.getTopicName() + " data " + new String(publish.getPayload())); // } + String cmdtype= publish.getTopicName().replace(topic_header,""); + if (Config.LOG_TOFILE)ICLogger.logToFile("APILog", "mqtt recv " + publish.getTopicName() +" "+ new String(publish.getPayload())); if (mqttCallbackInterface!=null) mqttCallbackInterface.handleMqttMessage(cmdtype, publish.getPayload()); } @@ -170,18 +173,20 @@ public class protocol_mqtt_client { } private String mqttHost=""; private String devid=""; + private int mqtt_port=18083; private int mqtt_cycle_seconds=600; - public void configMqtt(String host,int cycle_seconds,String idname){ + public void configMqtt(String host,int port,int cycle_seconds,String idname){ mqttHost=host; devid=idname; + mqtt_port=port; mqtt_cycle_seconds=cycle_seconds; } public void attemptConnectMqtt(){ - attemptConnectMqtt(mqttHost,devid,mqtt_cycle_seconds); + attemptConnectMqtt(mqttHost,mqtt_port,devid,mqtt_cycle_seconds); } - public void attemptConnectMqtt(String host, String identifier, int cycle_inSeconds) { + public void attemptConnectMqtt(String host, int port,String identifier, int cycle_inSeconds) { ICLogger.i("attemptConnectMqtt($host, $identifier)"); if (!(MQTTConnectionConstants.STATE_CONNECTING == mClient.getState() || MQTTConnectionConstants.STATE_CONNECTED == mClient.getState())) { @@ -189,11 +194,13 @@ public class protocol_mqtt_client { ICLogger.i("attemptConnectMqtt"); mClient.setHost(host); - mClient.setPort(1883); + mClient.setUsername("yq_watch"); + mClient.setPassword("123456"); + mClient.setPort(port); mClient.setIdentifier(identifier); mClient.setKeepAlive(cycle_inSeconds); +// mClient.setKeepAlive(10); mClient.setCleanSession(true); - mClient.connect(); } catch (Exception ex) { Log.e(TAG, ex.getMessage()); @@ -202,6 +209,7 @@ public class protocol_mqtt_client { } public void sendMessage(String cmdtype,String data){ +// ICLogger.logToFile("APILog",cmdtype+" "+data); mClient.publish(cmdtype,data); } diff --git a/app/src/main/java/se/wetcat/qatja/android/MQTTConnectionConstants.java b/app/src/main/java/se/wetcat/qatja/android/MQTTConnectionConstants.java index 192c18b3..800546c3 100644 --- a/app/src/main/java/se/wetcat/qatja/android/MQTTConnectionConstants.java +++ b/app/src/main/java/se/wetcat/qatja/android/MQTTConnectionConstants.java @@ -31,7 +31,7 @@ public class MQTTConnectionConstants { * We're using this base number to make it less likely that any of these * constans will overlap with constants defined in the activity or by MQTT. */ - private static final int CONSTANTS_BASE = 846751925; + public static final int CONSTANTS_BASE = 846751925; /** * Doing nothing... diff --git a/app/src/main/java/se/wetcat/qatja/android/QatjaService.java b/app/src/main/java/se/wetcat/qatja/android/QatjaService.java index 02b55eb3..ce62d656 100644 --- a/app/src/main/java/se/wetcat/qatja/android/QatjaService.java +++ b/app/src/main/java/se/wetcat/qatja/android/QatjaService.java @@ -83,6 +83,8 @@ import static se.wetcat.qatja.MQTTConstants.SUBSCRIBE_SUCCESS_AT_MOST_ONCE; import static se.wetcat.qatja.MQTTConstants.SUBSCRIBE_SUCCESS_EXACTLY_ONCE; import static se.wetcat.qatja.MQTTConstants.UNSUBACK; import static se.wetcat.qatja.MQTTConstants.UNSUBSCRIBE; + +import static se.wetcat.qatja.android.MQTTConnectionConstants.CONSTANTS_BASE; import static se.wetcat.qatja.android.MQTTConnectionConstants.STATE_CHANGE; import static se.wetcat.qatja.android.MQTTConnectionConstants.STATE_CONNECTED; import static se.wetcat.qatja.android.MQTTConnectionConstants.STATE_CONNECTING; @@ -216,7 +218,7 @@ public class QatjaService extends Service { super.onCreate(); if (DEBUG) - Log.d(TAG, "onCreate"); + ICLogger.i( "onCreate"); subscribedTopics = new HashSet<>(); @@ -227,7 +229,7 @@ public class QatjaService extends Service { @Override public int onStartCommand(Intent intent, int flags, int startId) { if (DEBUG) - Log.d(TAG, "onStartCommand"); + ICLogger.i( "onStartCommand"); // Start a sticky service, the system will try to recreate this service if killed. @@ -241,7 +243,7 @@ public class QatjaService extends Service { setState(STATE_NONE); if (DEBUG) - Log.d(TAG, "onDestroy"); + ICLogger.i( "onDestroy"); super.onDestroy(); } @@ -249,7 +251,7 @@ public class QatjaService extends Service { @Override public IBinder onBind(Intent intent) { if (DEBUG) - Log.d(TAG, "onBind"); + ICLogger.i( "onBind"); return mBinder; } @@ -284,6 +286,7 @@ public class QatjaService extends Service { connect = MQTTConnect.newInstance(clientIdentifier); } + connect.setCleanSession(cleanSession); connect.setKeepAlive(KEEP_ALIVE_TIMER); connect.setWillFlag(willFlag); @@ -467,14 +470,14 @@ public class QatjaService extends Service { public synchronized void sendMessage(MQTTMessage msg, boolean mustBeConnected) { if (DEBUG) - Log.d(TAG, "Sending message: " + MQTTHelper.decodePackageName(msg)); + ICLogger.i( "Sending message: " + MQTTHelper.decodePackageName(msg)); if (mustBeConnected) { if (getState() == STATE_CONNECTED) { new WriterTask().execute(msg); } else { if (DEBUG) - Log.d(TAG, "Need to be connected to send " + MQTTHelper.decodePackageName(msg)); + ICLogger.i("Need to be connected to send " + MQTTHelper.decodePackageName(msg)); // If we lost the connection, and reconnect is set, let's try to reconnect now! if (doAutomaticReconnect) @@ -637,7 +640,7 @@ public class QatjaService extends Service { */ public synchronized void connect() { if (DEBUG) - Log.d(TAG, "connect to: " + host); + ICLogger.i( "connect to: " + host); cleanUp(); @@ -648,7 +651,7 @@ public class QatjaService extends Service { setState(STATE_CONNECTING); } catch (Exception e) { - Log.e(TAG, e.getMessage(), e); + ICLogger.e( e.getMessage(), e); setState(STATE_CONNECTION_FAILED); } @@ -656,7 +659,7 @@ public class QatjaService extends Service { public synchronized void connect(boolean newSocket) { if (DEBUG) - Log.d(TAG, "connect to: " + host); + ICLogger.i("connect to: " + host); if (newSocket) { // Cancel any future ping requests if (mKeepaliveHandler != null) { @@ -689,7 +692,7 @@ public class QatjaService extends Service { setState(STATE_CONNECTING); } catch (Exception e) { - Log.e(TAG, e.getMessage(), e); + ICLogger.e(e.getMessage(), e); setState(STATE_CONNECTION_FAILED); } @@ -707,7 +710,7 @@ public class QatjaService extends Service { */ private synchronized void connected(Socket socket) { if (DEBUG) - Log.d(TAG, "connected, Socket Type:"); + ICLogger.i("connected, Socket Type:"); // Cancel any future ping requests if (mKeepaliveHandler != null) { @@ -739,7 +742,7 @@ public class QatjaService extends Service { mKeepaliveHandler = new Handler(getMainLooper()); mKeepaliveHandler.postDelayed(mPingSender, KEEP_ALIVE_TIMER*1000); - Log.d(TAG, "Sending connect message"); + ICLogger.i( "Sending connect message"); // Send the connect message connect(clientIdentifier); @@ -752,7 +755,7 @@ public class QatjaService extends Service { */ private void connectionFailed(Exception e) { if (DEBUG) - Log.d(TAG, "connectionFailed", e); + ICLogger.i("connectionFailed", e); if(subscribedTopics != null) { subscribedTopics.clear(); @@ -769,7 +772,7 @@ public class QatjaService extends Service { */ private void connectionLost() { if (DEBUG) - Log.d(TAG, "connectionLost"); + ICLogger.i("connectionLost"); cleanUp(); @@ -793,7 +796,7 @@ public class QatjaService extends Service { */ private void cleanUp() { if (DEBUG) { - Log.d(TAG, "cleanUp()"); + ICLogger.i("cleanUp()"); } // Cancel any future ping requests @@ -803,7 +806,7 @@ public class QatjaService extends Service { mKeepaliveHandler = null; } } catch (Exception e) { - Log.e(TAG, e.getMessage(), e); + ICLogger.e( e.getMessage(), e); } // Cancel the thread that completed the connection @@ -823,7 +826,7 @@ public class QatjaService extends Service { subscribedTopics.clear(); } } catch (Exception e) { - Log.e(TAG, e.getMessage(), e); + ICLogger.e(e.getMessage(), e); } } @@ -834,7 +837,7 @@ public class QatjaService extends Service { */ private synchronized void setState(int state) { if (DEBUG) - Log.d(TAG, "setState() " + mState + " -> " + state); + ICLogger.i("setState() " + (mState - CONSTANTS_BASE) + " -> " + (state- CONSTANTS_BASE)); if (mState != state) { mState = state; @@ -889,7 +892,7 @@ public class QatjaService extends Service { } private synchronized void handlePubmesage(MQTTPuback msg) { - Log.d(TAG, "Success handlePubmesage to " + new String(msg.getPayload())); + ICLogger.i("Success handlePubmesage to " + new String(msg.getPayload())); } /** * Manages subscription messages @@ -909,11 +912,11 @@ public class QatjaService extends Service { case SUBSCRIBE_SUCCESS_AT_MOST_ONCE: case SUBSCRIBE_SUCCESS_AT_LEAST_ONCE: case SUBSCRIBE_SUCCESS_EXACTLY_ONCE: - Log.d(TAG, "Success subscribing to " + topicFilters[i]); + ICLogger.i( "Success subscribing to " + topicFilters[i]); break; case SUBSCRIBE_FAILURE: - Log.d(TAG, "Failed subscribing to " + topicFilters[i]); + ICLogger.i( "Failed subscribing to " + topicFilters[i]); break; } } @@ -923,7 +926,7 @@ public class QatjaService extends Service { MQTTUnsubscribe unsubscribe = (MQTTUnsubscribe) mMqttIdentifierHelper.getSentPackages().get(unsuback.getPackageIdentifier()); String[] topicFilters = unsubscribe.getTopicFilters(); for (int i = 0; i < topicFilters.length; i++) { - Log.d(TAG, "Success unsubscribing to " + topicFilters[i]); + ICLogger.i( "Success unsubscribing to " + topicFilters[i]); } } @@ -944,7 +947,7 @@ public class QatjaService extends Service { ConnectThread(String host, int port) throws IOException { if (DEBUG) - Log.d(TAG, "CREATE mConnectThread "); + ICLogger.i( "CREATE mConnectThread "); if (socketFactory != null) { mmSocket = socketFactory.createSocket(); @@ -955,7 +958,7 @@ public class QatjaService extends Service { public void run() { if (DEBUG) - Log.d(TAG, "BEGIN mConnectThread"); + ICLogger.i("BEGIN mConnectThread"); setName("ConnectThread"); @@ -970,7 +973,7 @@ public class QatjaService extends Service { try { mmSocket.close(); } catch (IOException e2) { - Log.e(TAG, + ICLogger.e( "unable to close() socket during connection failure", e2); } @@ -991,7 +994,7 @@ public class QatjaService extends Service { try { mmSocket.close(); } catch (IOException e) { - Log.e(TAG, "close() of connect socket failed", e); + ICLogger.e( "close() of connect socket failed", e); } } } @@ -1007,7 +1010,7 @@ public class QatjaService extends Service { public ConnectedThread(Socket socket) { if (DEBUG) - Log.d(TAG, "CREATE mConnectedThread"); + ICLogger.i( "CREATE mConnectedThread"); mmSocket = socket; InputStream tmpIn = null; @@ -1018,14 +1021,14 @@ public class QatjaService extends Service { tmpIn = socket.getInputStream(); tmpOut = socket.getOutputStream(); } catch (IOException e) { - Log.e(TAG, "temp sockets not created", e); + ICLogger.i("temp sockets not created", e); } mmInStream = tmpIn; mmOutStream = tmpOut; if (DEBUG) - Log.d(TAG, "BEGIN mConnectedThread"); + ICLogger.i( "BEGIN mConnectedThread"); } public void run() { @@ -1182,7 +1185,7 @@ public class QatjaService extends Service { } catch (IOException e) { if (DEBUG) - Log.e(TAG, "disconnected (this is fine, expected almost)", e); + ICLogger.e("disconnected (this is fine, expected almost)", e); connectionLost(); @@ -1200,7 +1203,7 @@ public class QatjaService extends Service { try { mmOutStream.write(buffer); } catch (IOException e) { - Log.e(TAG, "Exception during write", e); + ICLogger.e("Exception during write", e); // Just notify the client that the connection was lost! connectionLost(); @@ -1216,14 +1219,14 @@ public class QatjaService extends Service { @Override protected Void doInBackground(Closeable... closeables) { if (DEBUG) { - ICLogger.d( "Mqtt_"+ "[DisconnectTask] Closing streams and socket."); + ICLogger.i( "Mqtt_"+ "[DisconnectTask] Closing streams and socket."); } for (Closeable closeable : closeables) { try { closeable.close(); } catch (IOException e) { - Log.e(TAG, e.getMessage(), e); + ICLogger.e( e.getMessage(), e); } } @@ -1266,7 +1269,7 @@ public class QatjaService extends Service { mKeepaliveHandler.postDelayed(mPingSender, KEEP_ALIVE_TIMER*1000); } } catch (Exception ex) { - Log.e(TAG, ex.getMessage(), ex); + ICLogger.e( ex.getMessage(), ex); } } }