mqtt 测试版本第一版,
authorsnickersun <scy@incartech.cn>
Thu, 27 Aug 2020 12:33:51 +0000 (20:33 +0800)
committersnickersun <scy@incartech.cn>
Thu, 27 Aug 2020 12:33:51 +0000 (20:33 +0800)
加入mqtt到原来的逻辑中,添加mqtt_connection,QatjaService,等一系列类
目前只有BREQ,KA,UD完成了,还有其他接口没有需改,另外和以前的协议的兼容性也需要测试。

23 files changed:
app/release/ICSer_V504_2008212009_release.apk [deleted file]
app/release/output.json [deleted file]
app/src/main/java/com/enqualcomm/support/CoreService.java
app/src/main/java/com/enqualcomm/support/LocationClient.java
app/src/main/java/com/enqualcomm/support/bean/BLEInfo.java [new file with mode: 0644]
app/src/main/java/com/enqualcomm/support/bean/Runtime.java
app/src/main/java/com/enqualcomm/support/service/Deliver.java
app/src/main/java/com/enqualcomm/support/service/HeartRateManager.java
app/src/main/java/com/enqualcomm/support/service/Initialize.java
app/src/main/java/com/enqualcomm/support/service/KeepAlive.java
app/src/main/java/com/enqualcomm/support/service/SendChatMessage.java
app/src/main/java/com/enqualcomm/support/utils/Connection.java
app/src/main/java/com/enqualcomm/support/utils/NettyConnection.java
app/src/main/java/com/enqualcomm/support/utils/mqttConnection.java [new file with mode: 0644]
app/src/main/java/com/ic/protocols/protocolAPIHelper.java
app/src/main/java/com/ic/protocols/protocol_beehome.java
app/src/main/java/com/ic/protocols/protocol_fzd.java
app/src/main/java/com/ic/protocols/protocol_ic.java
app/src/main/java/com/ic/protocols/protocol_jiai.java
app/src/main/java/com/ic/protocols/protocol_mqtt.java
app/src/main/java/com/ic/protocols/protocol_mqtt_client.java
app/src/main/java/se/wetcat/qatja/android/QatjaService.java
app/version_code.properties

diff --git a/app/release/ICSer_V504_2008212009_release.apk b/app/release/ICSer_V504_2008212009_release.apk
deleted file mode 100644 (file)
index cf14047..0000000
Binary files a/app/release/ICSer_V504_2008212009_release.apk and /dev/null differ
diff --git a/app/release/output.json b/app/release/output.json
deleted file mode 100644 (file)
index e48e91c..0000000
+++ /dev/null
@@ -1 +0,0 @@
-[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":504,"versionName":"2008212009","enabled":true,"outputFile":"ICSer_V504_2008212009_release.apk","fullName":"release","baseName":"release"},"path":"ICSer_V504_2008212009_release.apk","properties":{}}]
\ No newline at end of file
index 78fadad..a704cd8 100644 (file)
@@ -20,6 +20,8 @@ import com.enqualcomm.support.bean.ICLocation;
 import com.enqualcomm.support.bean.SleepInfo;\r
 import com.enqualcomm.support.bean.SleepRecord;\r
 import com.enqualcomm.support.service.AntiMonitorService;\r
+import com.enqualcomm.support.utils.CellInfoUtil;\r
+import com.enqualcomm.support.utils.Connection;\r
 import com.enqualcomm.support.utils.DeviceInfoUtil;\r
 import com.enqualcomm.support.utils.LedUtil;\r
 import com.enqualcomm.support.utils.StorageUtils;\r
@@ -27,6 +29,7 @@ import com.enqualcomm.support.utils.TemperatureUtil;
 import com.enqualcomm.support.utils.TimeUtil;\r
 import com.enqualcomm.support.utils.VibrateUtil;\r
 import com.enqualcomm.support.utils.WakeLockUtil;\r
+import com.enqualcomm.support.utils.mqttConnection;\r
 import com.ic.jni.ICJniUtils;\r
 import com.enqualcomm.support.adapter.LBSHelper;\r
 import com.ic.protocols.protocolAPIHelper;\r
@@ -271,7 +274,7 @@ public class CoreService extends Service {
             coreService.locationClient.onReceive(param1StringMessage);\r
         }\r
     }\r
-    NettyConnection connection = null;\r
+    Connection connection = null;\r
     AbstractConnectionService connectionServiceChain;\r
 \r
     AbstractInvokeHandlerService invokeHandlerServiceChain;\r
@@ -494,7 +497,7 @@ public class CoreService extends Service {
     public Runtime getRuntime(){\r
         return runtime;\r
     }\r
-    public NettyConnection getConnection(){\r
+    public Connection getConnection(){\r
         return connection;\r
     }\r
 \r
@@ -516,7 +519,12 @@ public class CoreService extends Service {
         this.runtime.initDnsUtil(ICApplication.getInstance().getApplicationContext());\r
 \r
 \r
-        connection=new NettyConnection(new ServerHandler(this),runtime);\r
+        if (Config.protocol_no==Config.PROTOCOL_MQTT)\r
+        {\r
+            connection = new mqttConnection(new ServerHandler(this), runtime);\r
+        }else {\r
+            connection = new NettyConnection(new ServerHandler(this), runtime);\r
+        }\r
         this.connectionServiceChain = getConnectionServiceChain();\r
         this.invokeHandlerServiceChain = getInvokeHandlerServiceChain();\r
 //        if (cmcm_call_eiot_into_powersave_mode() == 1) {\r
@@ -607,7 +615,7 @@ public class CoreService extends Service {
         //启动inner Service\r
         startService(new Intent(this, InnerService.class));\r
 \r
-        ReConnectToServer();\r
+\r
         this.locationClient.init();\r
 \r
 \r
@@ -703,6 +711,11 @@ public class CoreService extends Service {
         //备份DB数据到sd cache目录,为调试方便\r
         Util.getDBFile();\r
 //        test(); //test function\r
+\r
+        //更新IMEI\r
+        DeviceInfoUtil.updateImei(runtime);\r
+\r
+        ReConnectToServer();\r
     }\r
 \r
     private void test(){\r
@@ -812,8 +825,8 @@ public class CoreService extends Service {
                             + " light " + si.getLightsleep_minutes()\r
                             + " score " + si.getScore()\r
                     );\r
-                    Observable.timer(randomint * 60 * 1000L, TimeUnit.MILLISECONDS).subscribe(new Action1<Long>() {\r
-                        public void call(Long param1Long) {\r
+//                    Observable.timer(randomint * 60 * 1000L, TimeUnit.MILLISECONDS).subscribe(new Action1<Long>() {\r
+//                        public void call(Long param1Long) {\r
 //                        connection.send(protocolAPIHelper);\r
                             ICLogger.i("Send  sleep info " + si.getCurrentDate()\r
                                     + " deep " + si.getDeepsleep_minutes()\r
@@ -821,8 +834,8 @@ public class CoreService extends Service {
                                     + " score " + si.getScore()\r
                             );\r
                             Deliver.sendLocationMSG(protocolAPIHelper.getSleepMSG(SleepInfo.getInstance()));\r
-                        }\r
-                    });\r
+//                        }\r
+//                    });\r
 \r
                 }\r
             }\r
index a5b917e..9030867 100644 (file)
@@ -11,6 +11,7 @@ import android.os.SystemClock;
 \r
 import com.enqualcomm.support.utils.AlarmHelper;\r
 import com.enqualcomm.support.adapter.LBSHelper;\r
+import com.enqualcomm.support.utils.Connection;\r
 import com.ic.protocols.protocolAPIHelper;\r
 import com.enqualcomm.support.bean.ICLocation;\r
 import com.enqualcomm.support.bean.StringMessage;\r
@@ -56,7 +57,7 @@ public class LocationClient {
   \r
   private static final int TIME_OUT = 30000;\r
 \r
-  private static NettyConnection connection;\r
+  private static Connection connection;\r
 \r
   private static boolean isLocationCallBack = false;\r
 \r
@@ -113,7 +114,7 @@ public class LocationClient {
   public static LocationClient getInstance(){\r
     return gLocationCline;\r
   }\r
-  public LocationClient(NettyConnection paramNettyConnection, Runtime paramRuntime) {\r
+  public LocationClient(Connection paramNettyConnection, Runtime paramRuntime) {\r
     connection = paramNettyConnection;\r
     runtime = paramRuntime;\r
 \r
@@ -363,10 +364,10 @@ public class LocationClient {
               }else {\r
 \r
                 if (gps_ok) {\r
-                  String AP01_CMD = protocolAPIHelper.getGPSLocationMSG(runtime);\r
+                  StringMessage AP01_CMD = protocolAPIHelper.getGPSLocationMSG(runtime);\r
                   Deliver.sendLocationMSG(AP01_CMD);\r
                 }else{\r
-                  String AP02_CMD = protocolAPIHelper.getLBSLocationMSG(runtime);\r
+                  StringMessage AP02_CMD = protocolAPIHelper.getLBSLocationMSG(runtime);\r
                   Deliver.sendLocationMSG(AP02_CMD);\r
                 }\r
 \r
@@ -436,7 +437,7 @@ public class LocationClient {
                 startSOSLocation=false;\r
 \r
               }else {\r
-                String AP02_CMD = protocolAPIHelper.getLBSLocationMSG(runtime);\r
+                StringMessage AP02_CMD = protocolAPIHelper.getLBSLocationMSG(runtime);\r
                 Deliver.sendLocationMSG(AP02_CMD);\r
               }\r
 \r
diff --git a/app/src/main/java/com/enqualcomm/support/bean/BLEInfo.java b/app/src/main/java/com/enqualcomm/support/bean/BLEInfo.java
new file mode 100644 (file)
index 0000000..7f09f53
--- /dev/null
@@ -0,0 +1,16 @@
+package com.enqualcomm.support.bean;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+public class BLEInfo {\r
+    public String ble_area_id="";\r
+\r
+    public ArrayList<String> btMacList=new ArrayList<>();\r
+\r
+    public String gps_n="";\r
+    public String gps_e="";\r
+    public boolean is_in_area=false;\r
+\r
+\r
+}\r
index feb4951..6347e1e 100644 (file)
@@ -26,6 +26,7 @@ public class Runtime {
 \r
     public TemperatureInfo tempInfo=new TemperatureInfo();\r
   public boolean BindingStatus=false;\r
+  public BLEInfo bleInfo=new BLEInfo();\r
   private String battery="000";\r
 \r
   private int batteryVoltage=0;\r
index 7de4705..4618156 100644 (file)
@@ -71,7 +71,7 @@ public class Deliver extends AbstractConnectionService {
   public static LinkedBlockingDeque<StringMessage> queue = new LinkedBlockingDeque(200);\r
 \r
   private static FileCache fileCache;\r
-  private static NettyConnection connection;\r
+  private static Connection connection;\r
 \r
   public static boolean is_active_location = false;\r
   \r
@@ -111,7 +111,7 @@ public class Deliver extends AbstractConnectionService {
       }\r
     };\r
   }\r
-  public Deliver(NettyConnection paramNettyConnection, Runtime paramRuntime) {\r
+  public Deliver(Connection paramNettyConnection, Runtime paramRuntime) {\r
     connection = paramNettyConnection;\r
     mRuntime = paramRuntime;\r
     //把queue 保存在磁盘中的缓存文件\r
@@ -149,10 +149,11 @@ public class Deliver extends AbstractConnectionService {
   }\r
   private static boolean NeedCheckServerResponse=true;\r
   private static boolean ServerResponsed=false;\r
-  private static String needCheckResponseCMD=null;\r
+  private static StringMessage needCheckResponseCMD=null;\r
   private static int CheckCount=0;\r
 \r
-  private static void checkNeedServerResponse(String cmd){\r
+  private static void checkNeedServerResponse(StringMessage cmd){\r
+\r
       if (cmd!=null && Config.protocol_no==Config.PROTOCOL_FZD  &&\r
               (protocolAPIHelper.isCmdStr(cmd).equals("UD") || protocolAPIHelper.isCmdStr(cmd).equals("UD2"))){\r
         NeedCheckServerResponse=false;\r
@@ -182,20 +183,20 @@ public class Deliver extends AbstractConnectionService {
           //刚刚发送的包不为空,且检测次数小于3,则保留数据,进行下一次重试。\r
           if (needCheckResponseCMD!=null && CheckCount < 3) {\r
             //如果cmd有效,且尝试次数小于3, 没有收到反馈的情况下,可以重新插入queue进行下一次尝试!\r
-            ICLogger.i("checkSrvResponse "+CheckCount+" times for "+needCheckResponseCMD);\r
-            if (!ServiceUtil.offerQueue(new StringMessage(needCheckResponseCMD), true)) {\r
-              ICLogger.i("checkSrvResponse failed ,重新添加MessageQueue 已满,数据将被丢弃!" + needCheckResponseCMD);\r
+            ICLogger.i("checkSrvResponse "+CheckCount+" times for "+needCheckResponseCMD.cmd()+ " "+needCheckResponseCMD.isFromCache());\r
+            if (!ServiceUtil.offerQueue(needCheckResponseCMD, true)) {\r
+              ICLogger.i("checkSrvResponse failed ,重新添加MessageQueue 已满,数据将被丢弃!" + needCheckResponseCMD.cmd()+ " "+needCheckResponseCMD.isFromCache());\r
               if (Config.LOG_TOFILE)\r
-                ICLogger.logToFile("APILog", "response failed queueFullskip!  " + needCheckResponseCMD);\r
+                ICLogger.logToFile("APILog", "response failed queueFullskip!  " + needCheckResponseCMD.cmd()+ " "+needCheckResponseCMD.isFromCache());\r
             }else{\r
               if (Config.LOG_TOFILE)\r
-                ICLogger.logToFile("APILog", "response failed retry !  " +CheckCount+" " + needCheckResponseCMD);\r
+                ICLogger.logToFile("APILog", "response failed retry !  " +CheckCount+" " + needCheckResponseCMD.cmd()+ " "+needCheckResponseCMD.isFromCache());\r
             }\r
             CheckCount++;\r
           }else{ //否则 可能是还没有发送过数据,或者超过重试次数,继续提取queue中数据进行发送\r
             ICLogger.i("checkSrvResponse CheckCount="+CheckCount+" Timeout or cmd is null, skip ");\r
             if (Config.LOG_TOFILE)\r
-              ICLogger.logToFile("APILog", "response timeout skip!  " + needCheckResponseCMD);\r
+              ICLogger.logToFile("APILog", "response timeout skip!  " );\r
             CheckCount=0;\r
           }\r
         }\r
@@ -206,12 +207,15 @@ public class Deliver extends AbstractConnectionService {
             StringMessage stringMessage = queue.poll();\r
             if (stringMessage != null) {\r
               String cmd = stringMessage.isFromCache();\r
+              String topci = stringMessage.cmd();\r
+              stringBuilder.append(topci);\r
+              stringBuilder.append(" ");\r
               stringBuilder.append(cmd);\r
               stringBuilder.append("\n");\r
               if (checkNetwork()) {\r
-                connection.sendMsg(cmd);\r
+                connection.send(stringMessage);\r
 //                stringMessage = queue.poll();\r
-                needCheckResponseCMD=cmd;\r
+                needCheckResponseCMD=stringMessage;\r
                 //如果需要Check\r
                 if (NeedCheckServerResponse==true){\r
                     ICLogger.i("checkSrvResponse "+cmd);\r
@@ -245,26 +249,35 @@ public class Deliver extends AbstractConnectionService {
     return ret;\r
   }\r
 \r
-public static void sendLocationMSG( String Msg){\r
+\r
+  public static void sendLocationMSG( String Msg){\r
 \r
     if(Msg==null ||Msg.trim().isEmpty()){\r
       ICLogger.i("命令为空,跳过发送!");\r
       return ;\r
     }\r
+    sendLocationMSG(protocolAPIHelper.genStringMessage("queue",Msg));\r
+  }\r
+  public static void sendLocationMSG( StringMessage Msg){\r
+    if(Msg==null ){\r
+      ICLogger.i("命令为空,跳过发送!");\r
+      return ;\r
+    }\r
+\r
     if(mRuntime.getUseQueue()){\r
-      if(!ServiceUtil.offerQueue(protocolAPIHelper.genStringMessage("queue",Msg))) {\r
-        ICLogger.i(" MessageQueue 已满,数据将被丢弃," + Msg);\r
-        if (Config.LOG_TOFILE)ICLogger.logToFile( "APILog", " queueFullskip  " + Msg);\r
+      if(!ServiceUtil.offerQueue(Msg)) {\r
+        ICLogger.i(" MessageQueue 已满,数据将被丢弃," + Msg.cmd()+" "+Msg.isFromCache());\r
+        if (Config.LOG_TOFILE)ICLogger.logToFile( "APILog", " queueFullskip  " + Msg.cmd()+" "+Msg.isFromCache());\r
       }\r
 //      if(queue.size()>5) //测试queue 发送逻辑用\r
         triggerSendThread();\r
     }else {\r
       if (checkNetwork()) {\r
         ICLogger.i(" first send " + Msg);\r
-        connection.send(protocolAPIHelper.genStringMessage("queue",Msg));\r
+        connection.send(Msg);\r
       } else {\r
         ICLogger.i("offline skip  " + Msg);\r
-        if (Config.LOG_TOFILE) ICLogger.logToFile( "APILog", " offlineskip  " + Msg);\r
+        if (Config.LOG_TOFILE) ICLogger.logToFile( "APILog", " offlineskip  " + Msg.cmd()+" "+Msg.isFromCache());\r
       }\r
     }\r
 }\r
@@ -344,13 +357,15 @@ public static void sendLocationMSG( String Msg){
       voicePacket voicepacket = voicePacket.getInstanceSent();\r
       if (voicepacket.getCurrentIndexToSent() < voicepacket.getPacketCount()) {\r
         ICLogger.i("voicepacket " + voicepacket.getName() + " filetype " + voicepacket.getFiletype() + " , datatype " + voicepacket.getDateType() + voicepacket.getPacketTime() + " send " + (voicepacket.getCurrentIndexToSent() + 1) + "/" + voicepacket.getPacketCount());\r
-        ((NettyConnection) mConnection).sendMsg(\r
-                protocolAPIHelper.getVoicePacketItem(voicepacket.getPacketTime(),\r
-                        voicepacket.getPacketCount(),\r
-                        (voicepacket.getCurrentIndexToSent() + 1),\r
-                        voicepacket.getVoicePacketWithIndex(voicepacket.getCurrentIndexToSent()).getPacketLen(),\r
-                        voicepacket.getVoicePacketWithIndex(voicepacket.getCurrentIndexToSent()).getPacketData(), voicepacket.getFiletype(), voicepacket.getDateType())\r
-        );\r
+        if(mConnection instanceof  NettyConnection) {\r
+          ((NettyConnection) mConnection).sendMsg("RAWPACKET",\r
+                  protocolAPIHelper.getVoicePacketItem(voicepacket.getPacketTime(),\r
+                          voicepacket.getPacketCount(),\r
+                          (voicepacket.getCurrentIndexToSent() + 1),\r
+                          voicepacket.getVoicePacketWithIndex(voicepacket.getCurrentIndexToSent()).getPacketLen(),\r
+                          voicepacket.getVoicePacketWithIndex(voicepacket.getCurrentIndexToSent()).getPacketData(), voicepacket.getFiletype(), voicepacket.getDateType())\r
+          );\r
+        }\r
       } else {\r
         ICLogger.i("voicepacket " + voicepacket.getName() + " filetype " + voicepacket.getFiletype() + " , datatype " + voicepacket.getDateType() + " " + voicepacket.getPacketTime() + " sent Done!");\r
       }\r
index 6168d7e..67639c6 100644 (file)
@@ -48,7 +48,7 @@ public class HeartRateManager extends AbstractInvokeHandlerService implements Se
   private SimSignalUtil mSignalUtil;\r
 \r
   private Runtime runtime;\r
-  private NettyConnection connection;\r
+  private Connection connection;\r
 \r
   private ScheduledThreadPoolExecutor timerPPG=null;\r
   private static Handler mHandler=null;\r
@@ -95,7 +95,7 @@ public class HeartRateManager extends AbstractInvokeHandlerService implements Se
 \r
     }\r
   }\r
-  public HeartRateManager(Runtime _runtime,NettyConnection _connection){\r
+  public HeartRateManager(Runtime _runtime,Connection _connection){\r
     runtime=_runtime;\r
     connection=_connection;\r
     currentStat= heartRateStatus.HEARTRATE_WORKINGSTAT.HEARTRATE_CLOSED;\r
@@ -414,7 +414,7 @@ public static void triggerPPGtest(){
           }\r
 \r
 \r
-            if (((NettyConnection) connection).isServerConnected()) {\r
+            if (connection.isServerConnected()) {\r
               String PPGDATA = protocolAPIHelper.getPPG_ECG_MSG(Integer.parseInt(ppg), Integer.parseInt(bph), Integer.parseInt(bpl), Integer.parseInt(spo2));\r
               if(PPGDATA.isEmpty()){\r
                 String ppgd=protocolAPIHelper.getPPG_MSG(Integer.parseInt(ppg));\r
index 9a6884c..9cd1b7f 100644 (file)
@@ -76,7 +76,7 @@ public class Initialize extends AbstractConnectionService {
     Config.loadServerSettings(paramRuntime);\r
 \r
     //发送登录包\r
-    paramConnection.send(new StringMessage(protocolAPIHelper.getLoginMSG(paramRuntime)));\r
+    paramConnection.send(protocolAPIHelper.getLoginMSG(paramRuntime));\r
 \r
 \r
     return false;\r
index f11fb3f..c123011 100644 (file)
@@ -111,16 +111,16 @@ public class KeepAlive extends AbstractConnectionService {
           boolean ret=DeviceInfoUtil.updateImei(mRuntime);\r
           ICLogger.i("Update IMEI "+ret);\r
           if (is_login_send_success) {\r
-              connection.send(protocolAPIHelper.genStringMessage("heartbeat", protocolAPIHelper.getHeartbeatMSG(mRuntime)));\r
+              connection.send(protocolAPIHelper.getHeartbeatMSG(mRuntime));\r
               Observable.timer(1000L, TimeUnit.MILLISECONDS).subscribe(new Action1<Long>() {\r
                   public void call(Long param1Long) {\r
-                      connection.send(protocolAPIHelper.genStringMessage("binding", protocolAPIHelper.getBindingMSG()));\r
+                      connection.send(protocolAPIHelper.getBindingMSG(mRuntime));\r
 \r
                   }\r
               });\r
           }\r
           else\r
-            connection.send(protocolAPIHelper.genStringMessage("heartbeat", protocolAPIHelper.getLoginMSG(mRuntime)));\r
+            connection.send(protocolAPIHelper.getLoginMSG(mRuntime));\r
 \r
         }\r
       }\r
@@ -263,7 +263,7 @@ public class KeepAlive extends AbstractConnectionService {
     is_login_send_success=false;\r
     Observable.timer(500L, TimeUnit.MILLISECONDS).subscribe(new Action1<Long>() {\r
       public void call(Long param1Long) {\r
-        connection.send(protocolAPIHelper.genStringMessage("login",protocolAPIHelper.getLoginMSG(paramRuntime)));\r
+        connection.send(protocolAPIHelper.getLoginMSG(paramRuntime));\r
       }\r
     });\r
 \r
@@ -283,7 +283,7 @@ public class KeepAlive extends AbstractConnectionService {
     this.mContext.unregisterReceiver(this.mShutDownReceiver);\r
   }\r
   \r
-  public void onHeartAlarm(NettyConnection paramNettyConnection, Runtime paramRuntime) {\r
+  public void onHeartAlarm(Connection paramNettyConnection, Runtime paramRuntime) {\r
     ICLogger.i("onHeartAlarm");\r
 \r
     stopResponseCheckTimer();\r
@@ -292,11 +292,11 @@ public class KeepAlive extends AbstractConnectionService {
 \r
     //这个是正常心跳包,暂时不能认为服务器连接时失败的,所以正常发送检测。\r
     //发送心跳包\r
-    connection.send(protocolAPIHelper.genStringMessage("heartbeat",protocolAPIHelper.getHeartbeatMSG(paramRuntime)));\r
+    connection.send(protocolAPIHelper.getHeartbeatMSG(paramRuntime));\r
         //发送完心跳后,开始检查服务器响应\r
       Observable.timer(1000L, TimeUnit.MILLISECONDS).subscribe(new Action1<Long>() {\r
           public void call(Long param1Long) {\r
-              connection.send(protocolAPIHelper.genStringMessage("binding", protocolAPIHelper.getBindingMSG()));\r
+              connection.send(protocolAPIHelper.getBindingMSG(mRuntime));\r
           }\r
       });\r
     startResponseCheckTimer();\r
@@ -338,11 +338,11 @@ public class KeepAlive extends AbstractConnectionService {
         public void call(Long param1Long) {\r
           //这时重新连接服务器才进行的连接,理论上close已经设置false,此次可以认为协议定然断开,所以设置为false作为双重保险。\r
           mRuntime.setServerProtocolConnected(false);\r
-          connection.send(protocolAPIHelper.genStringMessage("heartbeat",protocolAPIHelper.getHeartbeatMSG(paramRuntime)));\r
+          connection.send(protocolAPIHelper.getHeartbeatMSG(paramRuntime));\r
           //发送完心跳后,开始检查服务器响应\r
             Observable.timer(1000L, TimeUnit.MILLISECONDS).subscribe(new Action1<Long>() {\r
                 public void call(Long param1Long) {\r
-                    connection.send(protocolAPIHelper.genStringMessage("binding", protocolAPIHelper.getBindingMSG()));\r
+                    connection.send(protocolAPIHelper.getBindingMSG(mRuntime));\r
 \r
                 }\r
             });\r
index 637e3be..f9b2827 100644 (file)
@@ -154,7 +154,7 @@ public class SendChatMessage extends AbstractInvokeHandlerService {
           // 把voiceContent拆解成1024的分包\r
             Util.parseToVoicePacketSent(voiceContent);\r
             //trigger 分包发送\r
-            ((NettyConnection) paramConnection).DeliverCMDMessageToSystem("SentVoicePacket", "");\r
+            paramConnection.DeliverCMDMessageToSystem("SentVoicePacket", "");\r
 \r
       case 1000:\r
         break;\r
index 2106dd0..046eeba 100644 (file)
@@ -8,7 +8,8 @@ public interface Connection {
   void connect(String paramString, int paramInt);\r
   \r
   void disconnect();\r
-  \r
+  boolean disconnectServer();\r
+\r
   int getTimeout();\r
   \r
   void open();\r
@@ -18,5 +19,9 @@ public interface Connection {
   boolean sendBlocking(StringMessage paramStringMessage);\r
   \r
   void setTimeout(int paramInt);\r
+\r
+  void DeliverCMDMessageToSystem(String cmd,String msg);\r
+\r
+  boolean isServerConnected();\r
 }\r
 \r
index 564a43e..3674458 100644 (file)
@@ -4,6 +4,7 @@ import android.os.Bundle;
 import android.os.Handler;\r
 import android.os.Message;\r
 import android.os.SystemClock;\r
+import android.util.Log;\r
 \r
 \r
 import com.enqualcomm.support.Config;\r
@@ -35,9 +36,10 @@ public class NettyConnection implements Connection {
   private int timeout = 60;\r
   \r
   public NettyConnection(ConnectionListener paramConnectionListener,Runtime runtime) {\r
+      Log.i(TAG, "NettyConnection ");\r
     this.listener = paramConnectionListener;\r
 \r
-    if (API == null) API=new protocolAPIHelper(NettyConnection.this,runtime );\r
+    if (API == null) API=new protocolAPIHelper(this,runtime );\r
 \r
       initReadListener();\r
       init_connection_listener();\r
@@ -168,7 +170,13 @@ public class NettyConnection implements Connection {
 \r
     return true;\r
   }\r
-    public boolean sendMsg(byte[]  cmdArray) {\r
+\r
+    public boolean sendMsg(String cmdtype,byte[]  cmdArray) {\r
+      log(cmdtype);\r
+      return sendMsg(cmdArray);\r
+\r
+    }\r
+        public boolean sendMsg(byte[]  cmdArray) {\r
 \r
         if( cmdArray==null || cmdArray.length==0)\r
         {\r
@@ -209,11 +217,11 @@ public class NettyConnection implements Connection {
 \r
 \r
   public void DeliverCMDMessageToSystem(String cmd,String msg){\r
-      if (NettyConnection.this.listener!=null){\r
+      if (this.listener!=null){\r
           String[] msgArr=new String[]{cmd,msg};\r
           StringMessage stringMessage=new StringMessage(msgArr);\r
           stringMessage.refresh(msg);\r
-          NettyConnection.this.listener.onReceive(stringMessage );\r
+          this.listener.onReceive(stringMessage );\r
       }\r
   }\r
 \r
@@ -265,7 +273,7 @@ public class NettyConnection implements Connection {
               String msg=  new String(bytes);\r
 \r
               log("get Msg :"+msg+" (size) byteslen" + bytes.length +" strlen"+ msg.length());\r
-              API.parserCmd(bytes);\r
+              API.parserCmd("",bytes);\r
 \r
           }\r
           return false;\r
@@ -281,12 +289,12 @@ public class NettyConnection implements Connection {
               .subscribe(socketStatus -> {\r
                   log("socketStatusListener socketStatus:" + socketStatus.name());\r
                   if (socketStatus.name().equals("CONNECTED")){\r
-                      if (NettyConnection.this.listener!=null){\r
-                          NettyConnection.this.listener.onConnectionOpen();\r
+                      if (this.listener!=null){\r
+                          this.listener.onConnectionOpen();\r
                       }\r
                   }else if (socketStatus.name().equals("DIS_CONNECT") || socketStatus.name().equals("DIS_CONNECT_BY_SERVERSIDE")) {\r
-                      if (NettyConnection.this.listener!=null){\r
-                          NettyConnection.this.listener.onConnectionClose(socketStatus.name());\r
+                      if (this.listener!=null){\r
+                          this.listener.onConnectionClose(socketStatus.name());\r
                       }\r
                       disconnectServer();\r
                   }\r
diff --git a/app/src/main/java/com/enqualcomm/support/utils/mqttConnection.java b/app/src/main/java/com/enqualcomm/support/utils/mqttConnection.java
new file mode 100644 (file)
index 0000000..c44a006
--- /dev/null
@@ -0,0 +1,142 @@
+package com.enqualcomm.support.utils;\r
+\r
+import android.util.Log;\r
+\r
+import com.enqualcomm.support.bean.Runtime;\r
+import com.enqualcomm.support.bean.StringMessage;\r
+import com.ic.protocols.protocolAPIHelper;\r
+import com.ic.protocols.protocol_mqtt_client;\r
+\r
+public class mqttConnection implements Connection {\r
+    private String topic_header="";\r
+    private protocol_mqtt_client.MqttCallbackInterface mqttcallback=new protocol_mqtt_client.MqttCallbackInterface() {\r
+        @Override\r
+        public void onMqttConnected() {\r
+            ICLogger.i( "onMqttConnected");\r
+            topic_header="WBG100/v1/"+mRuntime.IMEI()+"/";\r
+            ICLogger.i( "topic_header "+topic_header);\r
+            mqtt_client.setSubscriptTopicHeader(topic_header);\r
+            mqtt_client.attemptSubscribeToTopic(topic_header+"+");\r
+            isServerconnected=true;\r
+            mRuntime.setServerProtocolConnected(true);\r
+            if (listener!=null)\r
+                listener.onConnectionOpen();\r
+\r
+        }\r
+\r
+        @Override\r
+        public void onMqttDisconnected() {\r
+            ICLogger.i( "onMqttDisconnected");\r
+            isServerconnected=false;\r
+            mRuntime.setServerProtocolConnected(false);\r
+            if (listener!=null)\r
+                listener.onConnectionClose("");\r
+        }\r
+\r
+        @Override\r
+        public void handleMqttMessage(String cmdtype, byte[] msgdata) {\r
+            ICLogger.i( "handleMqttMessage "+cmdtype+" " +new String(msgdata));\r
+            API.parserCmd(cmdtype,msgdata);\r
+        }\r
+\r
+        @Override\r
+        public void handleMqttMessage(String cmdtype, String msgdata) {\r
+            ICLogger.i( "handleMqttMessage "+cmdtype+" "+ msgdata);\r
+            API.parserCmd(cmdtype,msgdata.getBytes());\r
+        }\r
+    };\r
+    public mqttConnection(ConnectionListener paramConnectionListener, Runtime runtime) {\r
+        ICLogger.i("mqttConnection ");\r
+        mqtt_client=new protocol_mqtt_client(runtime.getContextProxy().context,mqttcallback);\r
+        listener=paramConnectionListener;\r
+        mRuntime=runtime;\r
+        if (API == null) API=new protocolAPIHelper(this,runtime );\r
+\r
+    }\r
+    private Runtime mRuntime=null;\r
+    private protocol_mqtt_client mqtt_client=null;\r
+\r
+    private static boolean isServerconnected=false;\r
+    private protocolAPIHelper API=null;\r
+    private ConnectionListener listener=null;\r
+    @Override\r
+    public void close(){\r
+\r
+    }\r
+\r
+    @Override\r
+    public void connect(String paramString, int paramInt){\r
+//        mqtt_client.attemptConnectMqtt(paramString,"IC_"+mRuntime.IMEI(),paramInt);\r
+        ICLogger.i("mqttconnect " +paramString+" "+paramInt);\r
+        mqtt_client.configMqtt(paramString,paramInt,"IC_"+mRuntime.IMEI());\r
+        mqtt_client.connectservice();\r
+       // if(isServerconnected) mqtt_client.attemptConnectMqtt();\r
+    }\r
+\r
+    @Override\r
+    public void disconnect(){\r
+        disconnectServer();\r
+    }\r
+\r
+    @Override\r
+    public boolean disconnectServer() {\r
+        mqtt_client.disconnect();\r
+        return true;\r
+    }\r
+\r
+    @Override\r
+    public int getTimeout(){\r
+\r
+        return 0;\r
+    }\r
+\r
+    @Override\r
+    public void open(){\r
+\r
+    }\r
+\r
+    @Override\r
+    public void send(StringMessage paramStringMessage){\r
+\r
+        if(paramStringMessage==null)\r
+        {\r
+            ICLogger.i("send StringMessage Null skip!");\r
+            return;\r
+        }\r
+        String topci=paramStringMessage.cmd();\r
+        String msgdata=paramStringMessage.isFromCache();\r
+        if (topci.startsWith("WBG100/v1")) {\r
+            mqtt_client.sendMessage(topci, msgdata);\r
+            ICLogger.logToFile("API","send "+topci+" "+msgdata);\r
+        }else{\r
+            ICLogger.i("topci foramt error "+topci);\r
+        }\r
+    }\r
+\r
+    @Override\r
+    public boolean sendBlocking(StringMessage paramStringMessage){\r
+        send(paramStringMessage);\r
+        return true;\r
+    }\r
+\r
+    @Override\r
+    public void setTimeout(int paramInt){\r
+\r
+    }\r
+\r
+    @Override\r
+    public void DeliverCMDMessageToSystem(String cmd, String msg) {\r
+        if (this.listener!=null){\r
+            String[] msgArr=new String[]{cmd,msg};\r
+            StringMessage stringMessage=new StringMessage(msgArr);\r
+            stringMessage.refresh(msg);\r
+            this.listener.onReceive(stringMessage );\r
+        }\r
+    }\r
+\r
+    @Override\r
+    public boolean isServerConnected() {\r
+        return isServerconnected;\r
+    }\r
+\r
+}\r
index f1d52de..40a1ba1 100644 (file)
@@ -4,8 +4,8 @@ import com.enqualcomm.support.Config;
 import com.enqualcomm.support.bean.Runtime;\r
 import com.enqualcomm.support.bean.SleepInfo;\r
 import com.enqualcomm.support.bean.StringMessage;\r
+import com.enqualcomm.support.utils.Connection;\r
 import com.enqualcomm.support.utils.ICLogger;\r
-import com.enqualcomm.support.utils.NettyConnection;\r
 \r
 \r
 public class protocolAPIHelper {\r
@@ -16,7 +16,7 @@ public class protocolAPIHelper {
     private static protocol_fzd protocolfzd_handler=null;\r
     private static protocol_mqtt protocolmqtt_handler=null;\r
 \r
-    public protocolAPIHelper(NettyConnection connect,Runtime runtime) {\r
+    public protocolAPIHelper(Connection connect, Runtime runtime) {\r
         ICLogger.i("init Protocol "+Config.getProtocolNumber());\r
         if (protocolbeehome_handler==null)\r
             protocolbeehome_handler=new protocol_beehome(connect,runtime);\r
@@ -40,7 +40,7 @@ public class protocolAPIHelper {
        字符串通过#号进行识别。\r
        每个字符串如果发现 #,却又没有Header,“IW”则会被丢弃\r
         */\r
-    public boolean parserCmd(byte[] bytes) {\r
+    public boolean parserCmd(String cmd_type,byte[] bytes) {\r
         if (is_protocol_not_Initialled()) return false;\r
         switch(Config.protocol_no)\r
         {\r
@@ -57,11 +57,16 @@ public class protocolAPIHelper {
                 protocolfzd_handler.parserCmd(bytes);\r
                 break;\r
             case Config.PROTOCOL_MQTT:\r
-                protocolmqtt_handler.parserCmd(bytes);\r
+                protocolmqtt_handler.parserCmd(cmd_type,bytes);\r
                 break;\r
         }\r
         return true;\r
     }\r
+    public static StringMessage genStringMessage(String cmdName, byte[] rawdata){\r
+        StringMessage sm=new StringMessage(new String[]{cmdName,new String(rawdata) });\r
+\r
+        return sm;\r
+    }\r
     public static StringMessage genStringMessage(String cmdName, String msg){\r
         StringMessage sm=new StringMessage(new String[]{cmdName,msg});\r
         sm.refresh(msg);\r
@@ -69,22 +74,22 @@ public class protocolAPIHelper {
     }\r
 \r
 \r
-    public static String isCmdStr(String msg){\r
+    public static String isCmdStr(StringMessage msg){\r
         if (is_protocol_not_Initialled()) return "";\r
         String ret="";\r
         switch(Config.protocol_no)\r
         {\r
             case Config.PROTOCOL_JIAI:\r
-                ret=protocol_jiai.isCmdStr(msg);\r
+                ret=protocol_jiai.isCmdStr(msg.isFromCache());\r
                 break;\r
             case Config.PROTOCOL_BEEHOME:\r
-                ret=protocol_beehome.isCmdStr(msg);\r
+                ret=protocol_beehome.isCmdStr(msg.isFromCache());\r
                 break;\r
             case Config.PROTOCOL_IC:\r
-                ret=protocol_ic.isCmdStr(msg);\r
+                ret=protocol_ic.isCmdStr(msg.isFromCache());\r
                 break;\r
             case Config.PROTOCOL_FZD:\r
-                ret=protocol_fzd.isCmdStr(msg);\r
+                ret=protocol_fzd.isCmdStr(msg.isFromCache());\r
                 break;\r
             case Config.PROTOCOL_MQTT:\r
                 ret=protocol_mqtt.isCmdStr(msg);\r
@@ -93,25 +98,25 @@ public class protocolAPIHelper {
         return ret;\r
     }\r
 \r
-    public static String getBindingMSG(){\r
-        if (is_protocol_not_Initialled()) return "";\r
-        String ret="";\r
+    public static StringMessage getBindingMSG(Runtime runtime){\r
+        if (is_protocol_not_Initialled()) return null;\r
+        StringMessage ret=null;\r
         switch(Config.protocol_no)\r
         {\r
             case Config.PROTOCOL_JIAI:\r
-                ret="";\r
+                ret=null;\r
                 break;\r
             case Config.PROTOCOL_BEEHOME:\r
-                ret="";\r
+                ret=null;\r
                 break;\r
             case Config.PROTOCOL_IC:\r
-                ret="";\r
+                ret=null;\r
                 break;\r
             case Config.PROTOCOL_FZD:\r
-                ret=protocol_fzd.PING();\r
+                ret=genStringMessage("PING",protocol_fzd.PING());\r
                 break;\r
             case Config.PROTOCOL_MQTT:\r
-                ret="";\r
+                ret=null;\r
                 break;\r
         }\r
         return ret;\r
@@ -135,7 +140,7 @@ public class protocolAPIHelper {
                 ret=protocol_fzd.temp(body_temp);\r
                 break;\r
             case Config.PROTOCOL_MQTT:\r
-                ret=protocol_mqtt.temp(body_temp);\r
+                ret="";\r
                 break;\r
         }\r
         return ret;\r
@@ -164,46 +169,46 @@ public class protocolAPIHelper {
         return ret;\r
     }\r
 \r
-    public static String getLoginMSG(Runtime runtime){\r
-        if (is_protocol_not_Initialled()) return "";\r
-        String ret="";\r
+    public static StringMessage getLoginMSG(Runtime runtime){\r
+        if (is_protocol_not_Initialled()) return null;\r
+        StringMessage ret=null;\r
         switch(Config.protocol_no)\r
         {\r
             case Config.PROTOCOL_JIAI:\r
-                ret=protocol_jiai.AP00(runtime);\r
+                ret=genStringMessage("AP00",protocol_jiai.AP00(runtime));\r
                 break;\r
             case Config.PROTOCOL_BEEHOME:\r
-                ret=protocol_beehome.AP00(runtime);\r
+                ret=genStringMessage("AP00",protocol_beehome.AP00(runtime));\r
                 break;\r
             case Config.PROTOCOL_IC:\r
-                ret=protocol_ic.AP00(runtime);\r
+                ret=genStringMessage("AP00",protocol_ic.AP00(runtime));\r
                 break;\r
             case Config.PROTOCOL_FZD:\r
-                ret=protocol_fzd.LK();\r
+                ret=genStringMessage("AP00",protocol_fzd.LK());\r
                 break;\r
             case Config.PROTOCOL_MQTT:\r
-                ret="";\r
+                ret=protocol_mqtt.BREQ(runtime);\r
                 break;\r
         }\r
         return ret;\r
     }\r
 \r
-    public static String getHeartbeatMSG(Runtime runtime){\r
-        if (is_protocol_not_Initialled()) return "";\r
-        String ret="";\r
+    public static StringMessage getHeartbeatMSG(Runtime runtime){\r
+        if (is_protocol_not_Initialled()) return null;\r
+        StringMessage ret=null;\r
         switch(Config.protocol_no)\r
         {\r
             case Config.PROTOCOL_JIAI:\r
-                ret=protocol_jiai.AP03(runtime);\r
+                ret=genStringMessage("AP03",protocol_jiai.AP03(runtime));\r
                 break;\r
             case Config.PROTOCOL_BEEHOME:\r
-                ret=protocol_beehome.AP03(runtime);\r
+                ret=genStringMessage("AP03",protocol_beehome.AP03(runtime));\r
                 break;\r
             case Config.PROTOCOL_IC:\r
-                ret=protocol_ic.AP03(runtime);\r
+                ret=genStringMessage("AP03",protocol_ic.AP03(runtime));\r
                 break;\r
             case Config.PROTOCOL_FZD:\r
-                ret=protocol_fzd.KA(runtime);\r
+                ret=genStringMessage("KA",protocol_fzd.KA(runtime));\r
                 break;\r
             case Config.PROTOCOL_MQTT:\r
                 ret=protocol_mqtt.KA(runtime);\r
@@ -212,22 +217,22 @@ public class protocolAPIHelper {
         return ret;\r
     }\r
 \r
-    public static String getGPSLocationMSG(Runtime runtime){\r
-        if (is_protocol_not_Initialled()) return "";\r
-        String ret="";\r
+    public static StringMessage getGPSLocationMSG(Runtime runtime){\r
+        if (is_protocol_not_Initialled()) return null;\r
+        StringMessage ret=null;\r
         switch(Config.protocol_no)\r
         {\r
             case Config.PROTOCOL_JIAI:\r
-                ret=protocol_jiai.AP01(runtime);\r
+                ret=genStringMessage("AP01",protocol_jiai.AP01(runtime));\r
                 break;\r
             case Config.PROTOCOL_BEEHOME:\r
-                ret=protocol_beehome.AP01(runtime);\r
+                ret=genStringMessage("AP01",protocol_beehome.AP01(runtime));\r
                 break;\r
             case Config.PROTOCOL_IC:\r
-                ret=protocol_ic.AP01(runtime);\r
+                ret=genStringMessage("AP01",protocol_ic.AP01(runtime));\r
                 break;\r
             case Config.PROTOCOL_FZD:\r
-                ret=protocol_fzd.UD(runtime);\r
+                ret=genStringMessage("UD",protocol_fzd.UD(runtime));\r
                 break;\r
             case Config.PROTOCOL_MQTT:\r
                 ret=protocol_mqtt.UD(runtime);\r
@@ -235,22 +240,22 @@ public class protocolAPIHelper {
         }\r
         return ret;\r
     }\r
-    public static String getLBSLocationMSG(Runtime runtime){\r
-        if (is_protocol_not_Initialled()) return "";\r
-        String ret="";\r
+    public static StringMessage getLBSLocationMSG(Runtime runtime){\r
+        if (is_protocol_not_Initialled()) return null;\r
+        StringMessage ret=null;\r
         switch(Config.protocol_no)\r
         {\r
             case Config.PROTOCOL_JIAI:\r
-                ret=protocol_jiai.AP02(runtime);\r
+                ret=genStringMessage("AP02",protocol_jiai.AP02(runtime));\r
                 break;\r
             case Config.PROTOCOL_BEEHOME:\r
-                ret=protocol_beehome.AP02(runtime);\r
+                ret=genStringMessage("AP02",protocol_beehome.AP02(runtime));\r
                 break;\r
             case Config.PROTOCOL_IC:\r
-                ret=protocol_ic.AP02(runtime);\r
+                ret=genStringMessage("AP02",protocol_ic.AP02(runtime));\r
                 break;\r
             case Config.PROTOCOL_FZD:\r
-                ret=protocol_fzd.UD(runtime);\r
+                ret=genStringMessage("UD",protocol_fzd.UD(runtime));\r
                 break;\r
             case Config.PROTOCOL_MQTT:\r
                 ret=protocol_mqtt.UD(runtime);\r
@@ -347,7 +352,7 @@ public class protocolAPIHelper {
                 ret=protocol_fzd.blood(pbl,pbh);\r
                 break;\r
             case Config.PROTOCOL_MQTT:\r
-                ret=protocol_mqtt.blood(pbl,pbh);\r
+                ret="";//protocol_mqtt.blood(pbl,pbh);\r
                 break;\r
         }\r
         return ret;\r
@@ -371,7 +376,7 @@ public class protocolAPIHelper {
                 ret=protocol_fzd.oxygen(ox);\r
                 break;\r
             case Config.PROTOCOL_MQTT:\r
-                ret=protocol_mqtt.oxygen(ox);\r
+                ret="";//protocol_mqtt.oxygen(ox);\r
                 break;\r
         }\r
         return ret;\r
@@ -394,7 +399,7 @@ public class protocolAPIHelper {
                 ret=protocol_fzd.heart(ppg);\r
                 break;\r
             case Config.PROTOCOL_MQTT:\r
-                ret=protocol_mqtt.heart(ppg);\r
+                ret="";//protocol_mqtt.heart(ppg);\r
                 break;\r
         }\r
         return ret;\r
index a8ff2bb..1d1d37d 100644 (file)
@@ -18,7 +18,6 @@ import com.enqualcomm.support.bean.voicePacket;
 import com.enqualcomm.support.service.HeartRateManager;\r
 import com.enqualcomm.support.utils.Connection;\r
 import com.enqualcomm.support.utils.ICLogger;\r
-import com.enqualcomm.support.utils.NettyConnection;\r
 import com.enqualcomm.support.utils.TemperatureUtil;\r
 import com.enqualcomm.support.utils.TimeUtil;\r
 import com.enqualcomm.support.utils.Util;\r
@@ -203,10 +202,10 @@ public class protocol_beehome {
     }\r
 \r
 \r
-    private NettyConnection mConnection=null;\r
+    private Connection mConnection=null;\r
     private Runtime mRuntime=null;\r
 \r
-    public protocol_beehome(NettyConnection connect,Runtime runtime) {\r
+    public protocol_beehome(Connection connect,Runtime runtime) {\r
             mConnection=connect;\r
             mRuntime=runtime;\r
 \r
@@ -970,7 +969,7 @@ public class protocol_beehome {
     }\r
 \r
 \r
-    public void handleBP07(String cmd , NettyConnection connection ){\r
+    public void handleBP07(String cmd , Connection connection ){\r
 //平台响应:      IWBP07,20140818064408,6,1,1#\r
 //20140818064408:设备语音时间,yyyyMMddHHmmss 格式的年月日时分秒\r
 //6:语音包分包总数\r
@@ -1316,7 +1315,7 @@ public class protocol_beehome {
     }\r
 \r
     //处理 BP28 语音消息\r
-    public void handleBP28(NettyConnection connection,String cmd,Runtime runtime,byte[] bytes) {\r
+    public void handleBP28(Connection connection,String cmd,Runtime runtime,byte[] bytes) {\r
         //log("handleBP28 msg"+cmd);\r
 /**\r
  * IWBP28, D3590D54,XXXX,6,1,1024,XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX#\r
index 3cb2633..0594505 100644 (file)
@@ -21,7 +21,6 @@ import com.enqualcomm.support.service.HeartRateManager;
 import com.enqualcomm.support.utils.Connection;\r
 import com.enqualcomm.support.utils.ICLogger;\r
 import com.enqualcomm.support.utils.MD5;\r
-import com.enqualcomm.support.utils.NettyConnection;\r
 import com.enqualcomm.support.utils.TemperatureUtil;\r
 import com.enqualcomm.support.utils.TimeUtil;\r
 import com.enqualcomm.support.utils.Util;\r
@@ -145,10 +144,10 @@ public class protocol_fzd {
         cmdMap.put(CMD_TYPE.heart, "heart");\r
     }\r
 \r
-    private NettyConnection mConnection=null;\r
+    private Connection mConnection=null;\r
     private Runtime mRuntime=null;\r
 \r
-    public protocol_fzd(NettyConnection connect, Runtime runtime) {\r
+    public protocol_fzd(Connection connect, Runtime runtime) {\r
         mConnection=connect;\r
         mRuntime=runtime;\r
 \r
index b056e68..ba69aa5 100644 (file)
@@ -21,7 +21,6 @@ import com.enqualcomm.support.service.HeartRateManager;
 import com.enqualcomm.support.utils.CameraUtil;\r
 import com.enqualcomm.support.utils.Connection;\r
 import com.enqualcomm.support.utils.ICLogger;\r
-import com.enqualcomm.support.utils.NettyConnection;\r
 import com.enqualcomm.support.utils.TemperatureUtil;\r
 import com.enqualcomm.support.utils.TimeUtil;\r
 import com.enqualcomm.support.utils.Util;\r
@@ -240,10 +239,10 @@ public class protocol_ic {
     }\r
 \r
 \r
-    private NettyConnection mConnection=null;\r
+    private Connection mConnection=null;\r
     private Runtime mRuntime=null;\r
 \r
-    public protocol_ic(NettyConnection connect, Runtime runtime) {\r
+    public protocol_ic(Connection connect, Runtime runtime) {\r
             mConnection=connect;\r
             mRuntime=runtime;\r
 \r
@@ -1016,7 +1015,7 @@ public class protocol_ic {
     }\r
 \r
 \r
-    public void handleBP07(String cmd , NettyConnection connection ){\r
+    public void handleBP07(String cmd , Connection connection ){\r
 //平台响应:      IWBP07,20140818064408,6,1,1#\r
 //20140818064408:设备语音时间,yyyyMMddHHmmss 格式的年月日时分秒\r
 //6:语音包分包总数\r
@@ -1362,7 +1361,7 @@ public class protocol_ic {
     }\r
 \r
     //处理 BP28 语音消息\r
-    public void handleBP28(NettyConnection connection,String cmd,Runtime runtime,byte[] bytes) {\r
+    public void handleBP28(Connection connection,String cmd,Runtime runtime,byte[] bytes) {\r
         //log("handleBP28 msg"+cmd);\r
 /**\r
  * IWBP28, D3590D54,XXXX,6,1,1024,XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX#\r
@@ -1916,7 +1915,7 @@ public class protocol_ic {
                 .append(CMDEND).toString();\r
     }\r
 \r
-    public void handleBPDE(NettyConnection connection,String cmd,Runtime runtime){\r
+    public void handleBPDE(Connection connection,String cmd,Runtime runtime){\r
 /***\r
  * 示例:\r
  * IWBPDE,867400020316612,853676,0\r
@@ -1960,7 +1959,7 @@ public class protocol_ic {
                 .append(CMDEND).toString();\r
     }\r
 \r
-    public void handleBPDG(NettyConnection connection,String cmd,Runtime runtime){\r
+    public void handleBPDG(Connection connection,String cmd,Runtime runtime){\r
 /**\r
  * 示例:\r
  * IWBPDG,353456789012345,1,30.0,37.3 #\r
@@ -2051,7 +2050,7 @@ public class protocol_ic {
     }\r
 \r
 \r
-    public void handleBPTU(String cmd , NettyConnection connection ){\r
+    public void handleBPTU(String cmd , Connection connection ){\r
 /***\r
  * 平台响应\r
  * IWBPTU,6654111,080835,1,1,6,1,1#\r
@@ -2128,7 +2127,7 @@ public class protocol_ic {
                 .append(CMDEND).toString();\r
     }\r
 \r
-    public void handleBP46(String cmd , NettyConnection connection,Runtime runtime) {\r
+    public void handleBP46(String cmd , Connection connection,Runtime runtime) {\r
 /***\r
  * IWBP46,353456789012345,080835,1,[参数]#\r
  * 说明:\r
@@ -2181,7 +2180,7 @@ public class protocol_ic {
     }\r
 \r
 \r
-    public void handleBPDH( NettyConnection connection,Runtime runtime,String cmd) {\r
+    public void handleBPDH( Connection connection,Runtime runtime,String cmd) {\r
         /***\r
          * IWBPDH,353456789012345,080835,1,[参数]#\r
          * 说明:\r
index 77a92fe..a0f094b 100644 (file)
@@ -18,7 +18,6 @@ import com.enqualcomm.support.bean.voicePacket;
 import com.enqualcomm.support.service.HeartRateManager;\r
 import com.enqualcomm.support.utils.Connection;\r
 import com.enqualcomm.support.utils.ICLogger;\r
-import com.enqualcomm.support.utils.NettyConnection;\r
 import com.enqualcomm.support.utils.TimeUtil;\r
 import com.enqualcomm.support.utils.Util;\r
 \r
@@ -169,10 +168,10 @@ public class protocol_jiai {
         cmdMap.put(CMD_TYPE.BP89, "BP89");\r
     }\r
 \r
-    private NettyConnection mConnection=null;\r
+    private Connection mConnection=null;\r
     private Runtime mRuntime=null;\r
 \r
-    public protocol_jiai(NettyConnection connect,Runtime runtime) {\r
+    public protocol_jiai(Connection connect,Runtime runtime) {\r
         mConnection=connect;\r
         mRuntime=runtime;\r
 \r
@@ -931,7 +930,7 @@ public class protocol_jiai {
     }\r
 \r
 \r
-    public void handleBP07(String cmd , NettyConnection connection ){\r
+    public void handleBP07(String cmd , Connection connection ){\r
 //平台响应:      IWBP07,20140818064408,6,1,1#\r
 //20140818064408:设备语音时间,yyyyMMddHHmmss 格式的年月日时分秒\r
 //6:语音包分包总数\r
@@ -1240,7 +1239,7 @@ public class protocol_jiai {
     }\r
 \r
     //处理 BP28 语音消息\r
-    public void handleBP28(NettyConnection connection,String cmd,Runtime runtime,byte[] bytes) {\r
+    public void handleBP28(Connection connection,String cmd,Runtime runtime,byte[] bytes) {\r
         //log("handleBP28 msg"+cmd);\r
 /**\r
  * IWBP28, D3590D54,XXXX,6,1,1024,XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX#\r
index 02c30f8..ddbc8ec 100644 (file)
@@ -2,6 +2,7 @@ package com.ic.protocols;
 \r
 import android.content.ComponentName;\r
 import android.content.Intent;\r
+import android.text.TextUtils;\r
 \r
 import com.enqualcomm.support.Config;\r
 import com.enqualcomm.support.CoreService;\r
@@ -12,7 +13,6 @@ import com.enqualcomm.support.service.HeartRateManager;
 import com.enqualcomm.support.utils.Connection;\r
 import com.enqualcomm.support.utils.ICLogger;\r
 import com.enqualcomm.support.utils.MD5;\r
-import com.enqualcomm.support.utils.NettyConnection;\r
 import com.enqualcomm.support.utils.TemperatureUtil;\r
 import com.enqualcomm.support.utils.TimeUtil;\r
 import com.enqualcomm.support.utils.Util;\r
@@ -30,9 +30,7 @@ import static java.lang.Math.abs;
 public class protocol_mqtt {\r
     private static final String TAG = "ICSrv." + protocol_mqtt.class.getSimpleName();\r
     private static final String CMDHEADER = "[";\r
-    private static final String CMDCOMPANY="IC";\r
     private static final String CMDEND = "]";\r
-    private static final String CMDHEADERSPLIT = "*";\r
     private static final String CMDSPLIT = ",";\r
 \r
     public static final String defaultServerIP="47.106.237.76";\r
@@ -94,10 +92,10 @@ public class protocol_mqtt {
 \r
     }\r
 \r
-    private NettyConnection mConnection=null;\r
+    private Connection mConnection=null;\r
     private Runtime mRuntime=null;\r
 \r
-    public protocol_mqtt(NettyConnection connect, Runtime runtime) {\r
+    public protocol_mqtt(Connection connect, Runtime runtime) {\r
         mConnection=connect;\r
         mRuntime=runtime;\r
 \r
@@ -122,38 +120,14 @@ public class protocol_mqtt {
         return sm;\r
     }\r
 \r
-    /*\r
-    输入的字符串,如果有完整命令,返回 命令名\r
-    否则返回 空字符串\r
-     */\r
-    public static String isCmdStr(String msg) {\r
-        String cmd_msgbuf=msg;\r
-        int  cmdindex =cmd_msgbuf.indexOf(CMDCOMPANY+CMDHEADERSPLIT);\r
-        if (cmdindex>0) { //如果开头不是CMDHEADER但是包含CMDHEADER则删除前面的数据\r
-            String cmd=cmd_msgbuf.substring(cmdindex);\r
-            cmd_msgbuf=cmd;\r
-        }\r
-        cmdindex=cmd_msgbuf.indexOf(CMDEND);\r
-        if(cmdindex>0){\r
-            String cmd=cmd_msgbuf.substring(0,cmdindex);\r
-            cmd_msgbuf=cmd;\r
-        }\r
-        cmdindex=cmd_msgbuf.indexOf(CMDSPLIT);\r
-        if(cmdindex>0){\r
-            String cmd=cmd_msgbuf.substring(0,cmdindex);\r
-            cmd_msgbuf=cmd;\r
-        }\r
 \r
-        if (regexUtil.isFZDCMD(cmd_msgbuf)) {\r
-            for (CMD_TYPE key : cmdMap.keySet()) {\r
-                if (regexUtil.isFZDCMD(cmdMap.get(key), cmd_msgbuf)) { //如果是FZD命令,则进行处理,否则保留数据动\r
-                    ICLogger.i("found cmd keyid=" + key + " ,keyname=" + cmdMap.get(key));\r
-                    return cmdMap.get(key);\r
-                }\r
+    public static String isCmdStr(StringMessage msg){\r
+        for (CMD_TYPE key : cmdMap.keySet()) {\r
+            if (cmdMap.get(key).toString().equals(msg.cmd())){\r
+                return msg.cmd();\r
             }\r
-            return "";\r
-        }else\r
-            return "";\r
+        }\r
+        return "";\r
     }\r
     /*\r
     返回true 表示 cmd 全部解析成功\r
@@ -161,50 +135,19 @@ public class protocol_mqtt {
     字符串通过#号进行识别。\r
     每个字符串如果发现 #,却又没有Header,“IW”则会被丢弃\r
      */\r
-    public boolean parserCmd(byte[] bytes) {\r
+    public boolean parserCmd(String cmdtype,byte[] bytes) {\r
         String cmd_msgbuf=new String(bytes);\r
         log("bytes.size "+bytes.length);\r
         cmdbuf.append(cmd_msgbuf);\r
         log("cmdbuf.size "+cmdbuf.length() +" "+cmdbuf.toString());\r
-        int  cmdindex =cmd_msgbuf.indexOf(CMDCOMPANY+CMDHEADERSPLIT);\r
-        if (cmdindex>0) { //如果开头不是CMDHEADER但是包含CMDHEADER则删除前面的数据\r
-            String cmd=cmd_msgbuf.substring(cmdindex);\r
-            cmd_msgbuf=cmd;\r
-        }\r
-        cmdindex=cmd_msgbuf.indexOf(CMDEND);\r
-        if(cmdindex>0){\r
-            String cmd=cmd_msgbuf.substring(0,cmdindex);\r
-            cmd_msgbuf=cmd;\r
-        }\r
-        cmdindex=cmd_msgbuf.indexOf(CMDSPLIT);\r
-        if(cmdindex>0){\r
-            String cmd=cmd_msgbuf.substring(0,cmdindex);\r
-            cmd_msgbuf=cmd;\r
-        }\r
-        if (cmdbuf.toString().split(CMDCOMPANY+CMDHEADERSPLIT).length>1)\r
-        {\r
-            ICLogger.i("More than 1 cmd in buffer ! just log it");\r
-        }\r
-            for (CMD_TYPE key : cmdMap.keySet()) {\r
-               // ICLogger.i("key "+cmdMap.get(key)+" cmdbuf "+cmd_msgbuf);\r
-                if (regexUtil.isFZDCMD(cmdMap.get(key),cmd_msgbuf)) { //如果是FZD命令,则进行处理,否则保留数据动\r
-                    String data=cmdbuf.toString().replace(CMDHEADER,"").replace(cmd_msgbuf,"").replace(CMDEND,"");\r
-//                    ICLogger.i("found cmd keyid=" + key + " ,keyname=" + cmdMap.get(key) + " ,  " + cmdbuf.toString() + "  "+cmd_msgbuf  + " data "+data );\r
-//                    if (key == CMD_TYPE.TK) {\r
-//                        //如果是BP28则 后面的数据是音频,需要保留\r
-//                        byte[] amrBuf;\r
-//                        int amrLen = getBP28Amrlen(cmdlist[i] );\r
-//                        if (bytes.length > amrLen) {\r
-//                            handleCmd(key, cmdlist[i], bytes);\r
-//                        }\r
-//                    } else {\r
-                        if (data.startsWith(CMDSPLIT)) data=data.substring(1);\r
-                        handleCmd(key, cmd_msgbuf,data);\r
-                        cmdbuf.delete(0,cmdbuf.length());//处理后清空\r
-//                    }\r
-                }\r
+        cmd_msgbuf=cmd_msgbuf.replace(CMDHEADER,"").replace(CMDEND,"");\r
+        for (CMD_TYPE key : cmdMap.keySet()) {\r
+            if (cmdMap.get(key).toString().equals(cmdtype)){\r
+                handleCmd(key, cmdtype,cmd_msgbuf);\r
+                return true;\r
             }\r
-        return true;\r
+        }\r
+        return false;\r
     }\r
 \r
     private static String getHexLen(int len){\r
@@ -221,110 +164,111 @@ public class protocol_mqtt {
         sb.append(hv);\r
         return sb.toString();\r
     }\r
-    private static String genHeader(int len,String cmd){\r
-\r
-        if (CoreService.getInstance()==null)\r
-            return "";\r
-\r
-        String imei =CoreService.getInstance().getRuntime().IMEI();\r
-        return new StringBuilder().append(CMDCOMPANY).append(CMDHEADERSPLIT)\r
-                .append(imei).append(CMDHEADERSPLIT)\r
-                .append(getHexLen(len)).append(CMDHEADERSPLIT).append(cmd).toString();\r
-    }\r
-\r
-    private static String keyheader(String cmd,int len){\r
-        String header=genHeader(len,cmd);\r
-        String key= MD5.getCMDStringMD5(header);\r
-        return key;\r
-    }\r
-\r
-    public static String genFZDCMD( String CMD){\r
-        StringBuilder sb=new StringBuilder();\r
-        int len=CMD.length();\r
-        String header=genHeader(len,CMD);\r
-        String keyheader=keyheader(CMD,len);\r
-        sb.append(CMDHEADER).append(keyheader).append(header).append(CMDEND);\r
-        return sb.toString();\r
-    }\r
-    public static String genFZDCMD( String CMD,String data){\r
+     public static StringMessage genMqttCMDMsg(String cmdtype, String data,String imei){\r
         StringBuilder sb=new StringBuilder();\r
-        String data_buf=CMD+CMDSPLIT+data;\r
-        int data_buf_len=data_buf.length();\r
-        String header=genHeader(data_buf_len,CMD);\r
-        String keyheader=keyheader(CMD,data_buf_len);//计算header md5值\r
-        sb.append(CMDHEADER).append(keyheader).append(header).append(CMDSPLIT).append(data).append(CMDEND);\r
-        return sb.toString();\r
+        int len=data.length()+1;//长度计算要包括逗号\r
+        sb.append(CMDHEADER).append(getHexLen(len)).append(CMDSPLIT).append(data).append(CMDEND);\r
+         StringBuilder sbtopic=new StringBuilder();\r
+         sbtopic.append(projName)\r
+                 .append("/").append(protocolVersion)\r
+                 .append("/").append(cmdtype)\r
+                 .append("/").append(imei);\r
+        return genStringMessage(sbtopic.toString(),sb.toString());\r
     }\r
 \r
 \r
     /**\r
-     * 绑定\r
+     * 终端发布(平台订阅):\r
+     * 终端向“WBG100/v1/BREQ/ID_手表IMEI”的主题发布   [LEN,MQTT注册时的账号及密码的密文]\r
+     *\r
+     * 实例: 若手表IMEI号为334588000000156,\r
+     * MQTT注册时的账号及密码的密文为:QWER15WTF156OQRT1230\r
+     * 则向WBG100/v1/BREQ/ID_334588000000156的主题发布[0016,QWER15WTF156OQRT1230]\r
      * */\r
-    public static String BREQ(){\r
-//        IC*YYYYYYYYYYYYYYY*LEN*PING\r
-        return genFZDCMD(cmdMap.get(CMD_TYPE.BREQ));\r
+    public static StringMessage BREQ(Runtime runtime){\r
+\r
+        return genMqttCMDMsg(cmdMap.get(CMD_TYPE.BREQ), mqttKey,runtime.IMEI());\r
     }\r
 \r
 \r
     public static void handleBREQ(Runtime runtime,String data){\r
-//        [IC*YYYYYYYYYYYYYYY*LEN*PING,是否绑定(0 表示未绑定,1 表示绑定)]\r
-//        实例:[IC*334588000000156*0006*PING,0]或[IC*334588000000156*0006*PING,1]\r
-        int bind=Integer.parseInt(data);\r
-        if (bind==0){\r
-            ICLogger.i("设备未绑定!");\r
-            runtime.BindingStatus=false;\r
-        }else{\r
-            ICLogger.i("设备已绑定!");\r
-            runtime.BindingStatus=true;\r
+/***\r
+ * 回应的消息为:[LEN,区域id,绑定的区域纬度,N/S,经度,E/W,beacon mac_1,beacon mac_2,beacon mac_3,…,beacon mac_n]\r
+ *\r
+ * 实例: 若手表IMEI号为334588000000156,绑定的区域为123456789,\r
+ * 经纬度为:22.570512,N,113.8623267,E,\r
+ * beacon  mac:0x5947ffff0001, 5947ffff0002\r
+ * 则终端订阅“WBG100/v1/ID_334588000000156/+”的主题列表,会收到平台的回应\r
+ * 先判断子主题是否为:BREQ\r
+ * 是,则消息为:[003F,123456789,22.570512,N,113.8623267,E,5947ffff0001, 5947ffff0002]\r
+ */\r
+        String[] list=data.split(CMDSPLIT);\r
+        if (list.length>=8){\r
+\r
+            runtime.bleInfo.ble_area_id=list[1];\r
+            runtime.bleInfo.gps_n=list[2];\r
+            runtime.bleInfo.gps_e=list[4];\r
+            runtime.bleInfo.btMacList.clear();\r
+            for (int i=6;i< list.length;i++){\r
+                runtime.bleInfo.btMacList.add(list[i]);\r
+            }\r
         }\r
-\r
     }\r
 \r
-    public static String KA(Runtime runtime){\r
-//[IC*YYYYYYYYYYYYYYY*LEN*KA,日期,步数,翻滚次数,电量百分数] 实例:[IC*334588000000156*0014*KA,120414,50,100,100]\r
+    public static StringMessage KA(Runtime runtime){\r
+\r
+        /***\r
+         * 终端向“WBG100/v1/KA/ID_手表IMEI”的主题发布   [LEN, 日期,步数,翻滚次数,电量百分数,区域id]\r
+         *\r
+         * 实例:若手表IMEI号为334588000000156,请求绑定时下发的区域id为123456789,\r
+         * 则向WBG100/v1/KA/ID_334588000000156的主题发布 [001B,120414,50,100,100, 123456789]\r
+         *\r
+         * 终端订阅(平台发布):\r
+         * 终端订阅“WBG100/v1/ID_手表IMEI/+”的主题列表,会收到平台的回应\r
+         * 平台发布的子主题为:KA\r
+         * 回应的消息为:[LEN,KA]\r
+         */\r
         StringBuilder sb=new StringBuilder();\r
         String cmd=cmdMap.get(CMD_TYPE.KA);\r
         sb.append(TimeUtil.getSystemDateYYMMDD()).append(CMDSPLIT)\r
         .append(runtime.getTotalStepCount()).append(CMDSPLIT)\r
         .append(runtime.getRolltimes()).append(CMDSPLIT)\r
-        .append(runtime.getBattery());\r
-        return genFZDCMD(cmd,sb.toString());\r
-    }\r
-\r
-\r
-    public void handleKA(Runtime runtime,String data){\r
-\r
+        .append(runtime.getBattery()).append(CMDSPLIT)\r
+        .append(runtime.bleInfo.ble_area_id);\r
+        return genMqttCMDMsg(cmd,sb.toString(),runtime.IMEI());\r
     }\r
 \r
     /*LBS+GPS混合定位*/\r
-    public static String UD(Runtime runtime) {\r
+    public static StringMessage UD(Runtime runtime) {\r
         /***\r
-         * [IC*334588000000156*00CD*UD,180916,025723,A,22.570733,N,113.8626083,E,0.00,249.5,0.0,6,100, 60,0,0,00000010,7,255,460,1,9529,21809,158,9529,63555,133,9529,63554,129,9529,21405,126,95\r
-         * 29,21242,124,9529,21151,120,9529,63556,119,0]\r
+         * [LEN,定位数据,区域id]\r
+         *\r
+         * 实例:若手表IMEI号为334588000000156,请求绑定时下发的区域id为123456789,\r
+         * 则向WBG100/v1/LGZONE/ID_334588000000156的主题发布\r
+         * [00D7,180916,025723,A,22.570733,N,113.8626083,E,0.00,249.5,0.0,6,100,\r
+         * 60,0,0,00000010,7,255,460,1,9529,21809,158,9529,63555,133,9529,63554,129,9529,21405,126,9529,21242,124,9529,21151,120,9529,63556,119,0,123456789]\r
          * 说明:\r
          * 数据内容:\r
-         * UD,命令号\r
-         * 180916,日期(年月日)(0 时区),表示 0 时区的二零一八年九月十六号\r
-         *\r
-         * 025723,时间(时分秒)(0 时区),表示 0 时区的两点五十七分二十三秒A,gps 定位有效\r
+         * 180916,日期(年月日)(0 时区),表示0 时区的二零一八年九月十六号\r
+         * 025723,时间(时分秒)(0 时区),表示0 时区的两点五十七分二十三秒\r
+         * A,gps 定位有效\r
          * 22.570733,纬度\r
-         * N,纬度表示113.8626083,经度\r
-         * E,经度表示0.00,速度\r
+         * N,纬度表示\r
+         * 113.8626083,经度\r
+         * E,经度表示\r
+         * 0.00,速度\r
          * 249.5,方向\r
          * 0.0,海拔\r
          * 6,卫星个数\r
-         *\r
          * 100,gsm 信号强度\r
          * 60,电量\r
          * 0,计步数\r
          * 0,翻转次数\r
-         * 00000010,终端状态,数据为 16 进制,解析成二进制为 0000 0000 0000 0000 0000 0000 0001 0000\r
-         * 前面 4 个字节表示状态,后面 4 个字节表示报警,数据中第 4 位为 1,对照文档最后的数据解析,表示手表静止状态。详细可参看文档最后部分。\r
+         * 00000010,终端状态,数据为16 进制,解析成二进制为0000 0000 0000 0000 0000 0000 0001 0000  前面4 个字节表示状态,后面4 个字节表示报警,数据中第4 位为1,对照文档最后的数据解析,表示手表静止状态。详细可参看文档最后部分。\r
          * 7,基站个数\r
-         * 255,460,1,9529,21809,158,9529,63555,133,9529,63554,129,9529,21405,126,9529,21242,124,9529,\r
-         * 21151,120,9529,63556,119,基站信息\r
+         * 255,460,1,9529,21809,158,9529,63555,133,9529,63554,129,9529,21405,126,9529,21242,124,9529,21151,120,9529,63556,119,基站信息\r
          * 0,WiFi 个数\r
-         *\r
+         * 123456789,为区域id\r
          */\r
 \r
 \r
@@ -339,9 +283,10 @@ public class protocol_mqtt {
                 .append(runtime.getRolltimes()).append(CMDSPLIT)\r
                 .append(runtime.getFZDDevStatus()).append(CMDSPLIT)\r
                 .append(runtime.getFZDLBSMultiStationData()).append(CMDSPLIT)\r
-                .append(runtime.getFZDWifiData());\r
-\r
-        return genFZDCMD(cmd,sb.toString());\r
+                .append(runtime.getFZDWifiData()).append(CMDSPLIT)\r
+                .append(runtime.bleInfo.is_in_area?"1":"0").append(CMDSPLIT)\r
+                .append(runtime.bleInfo.ble_area_id);\r
+        return genMqttCMDMsg(cmd,sb.toString(),runtime.IMEI());\r
     }\r
 \r
 \r
@@ -350,108 +295,108 @@ public class protocol_mqtt {
         log("BP02定位接收成功");\r
     }\r
 \r
-\r
-    public static String UPLOAD(){\r
-\r
-        return  genFZDCMD(cmdMap.get(CMD_TYPE.UPLOAD));\r
-    }\r
-\r
-    public void handleUPLOAD(Connection connection,Runtime runtime,String cmd,String data){\r
-            connection.send(genStringMessage("UPLOAD",UPLOAD()));\r
-            int timesecond=Integer.parseInt(data);\r
-            int mod=runtime.getLocationInstance().getWorkingMod();\r
-        log("LOCATION_MODE  "+LOCATION_MODE+" mod "+ mod);\r
-        Config.setLocationMode(runtime.getContextProxy().context,mod);\r
-        Config.setLocationCycle(runtime.getContextProxy().context,timesecond);\r
-        runtime.getLocationInstance().setLocation_cycle(timesecond);\r
-        runtime.getLocationInstance().setWorkingMod(mod);\r
-//            CoreService.getInstance().setLocationAlarm(runtime.getLocationInstance().getWorkingMod());\r
-        //此处设置好配置后,会在LocationClient通过消息开始执行及时定位操作。\r
-\r
-    }\r
-\r
-    public static String heart(int hrt){\r
-        return genFZDCMD(cmdMap.get(CMD_TYPE.heart),String.valueOf(hrt));\r
-    }\r
-    public static String oxygen(int ox){\r
-        return genFZDCMD(cmdMap.get(CMD_TYPE.oxygen),String.valueOf(ox));\r
-    }\r
-\r
-    public static String blood(int pbl,int pbh){\r
-        String data=pbh+CMDSPLIT+pbl;\r
-        return genFZDCMD(cmdMap.get(CMD_TYPE.blood),data);\r
-    }\r
-\r
-    public static String temp(double temp){\r
-        return genFZDCMD(cmdMap.get(CMD_TYPE.temp),String.format("%.1f",temp));\r
-    }\r
-\r
-    public static String wdstart(){\r
-        return genFZDCMD(cmdMap.get(CMD_TYPE.wdstart));\r
-    }\r
-    public void handleWdstart(Connection connection,Runtime runtime ,String data) {\r
-\r
-        connection.send(genStringMessage("wdstart",wdstart()));\r
-        int freq=Integer.parseInt(data);\r
-\r
-\r
-        Config.setTemperatureTestCycle(runtime,freq);\r
-        CoreService.getInstance().setTempAlarm();\r
-\r
-        TemperatureUtil.doTempTestInThread();\r
 //\r
-//        double wrist_temp,body_temp;\r
-//        wrist_temp= TemperatureUtil.get_temp_value_adjusted();\r
-//        body_temp=TemperatureUtil.getBodyTemp(wrist_temp,26.0f);\r
-//        String temperatureMsg=temp(body_temp);\r
-//        connection.send(genStringMessage("temp",temperatureMsg));\r
-    }\r
-    public static String hrtstart(){\r
-        return genFZDCMD(cmdMap.get(CMD_TYPE.hrtstart));\r
-    }\r
-    public void handleHrtstart(Connection connection) {\r
-\r
-        connection.send(genStringMessage("hrtstart",hrtstart()));\r
-    }\r
-\r
-    public static String SOS(){\r
-        return genFZDCMD(cmdMap.get(CMD_TYPE.SOS));\r
-    }\r
-\r
-\r
-    public void handleSOS(Connection connection,Runtime runtime,String cmd,String data) {\r
-\r
-        connection.send(genStringMessage("SOS",SOS()));\r
-        if (data!=null && data.length()>0) {\r
-            String list[] = data.split(CMDSPLIT);\r
-            if (list.length==1){\r
-                ArrayList<Contact> contactArray=new ArrayList<Contact>();\r
-                if (regexUtil.isMobileNumber( list[0]) || regexUtil.isPhoneNumber(list[0]))\r
-               {\r
-                   contactArray.add(new Contact(Contact.CATEGORY_SOS,"sos1",list[0]));\r
-                   ICLogger.i("find SOS1 number "+list[0]);\r
-               }\r
-            }else if (list.length==2){\r
-\r
-                ArrayList<Contact> contactArray=new ArrayList<Contact>();\r
-                if (regexUtil.isMobileNumber( list[0]) || regexUtil.isPhoneNumber(list[0]))\r
-                {\r
-                    contactArray.add(new Contact(Contact.CATEGORY_SOS,"sos1",list[0]));\r
-                    ICLogger.i("find SOS1 number "+list[0]);\r
-                }\r
-                if (regexUtil.isMobileNumber( list[1]) || regexUtil.isPhoneNumber(list[1]))\r
-                {\r
-                    contactArray.add(new Contact(Contact.CATEGORY_SOS,"sos2",list[1]));\r
-                    ICLogger.i("find SOS2 number "+list[1]);\r
-                }\r
-\r
-                runtime.getDbHelper().saveContacts(contactArray,false,false,false,false,false,true);\r
-\r
-            }\r
-        }\r
-\r
-\r
-    }\r
+//    public static String UPLOAD(){\r
+//\r
+//        return  genFZDCMD(cmdMap.get(CMD_TYPE.UPLOAD));\r
+//    }\r
+//\r
+//    public void handleUPLOAD(Connection connection,Runtime runtime,String cmd,String data){\r
+//            connection.send(genStringMessage("UPLOAD",UPLOAD()));\r
+//            int timesecond=Integer.parseInt(data);\r
+//            int mod=runtime.getLocationInstance().getWorkingMod();\r
+//        log("LOCATION_MODE  "+LOCATION_MODE+" mod "+ mod);\r
+//        Config.setLocationMode(runtime.getContextProxy().context,mod);\r
+//        Config.setLocationCycle(runtime.getContextProxy().context,timesecond);\r
+//        runtime.getLocationInstance().setLocation_cycle(timesecond);\r
+//        runtime.getLocationInstance().setWorkingMod(mod);\r
+////            CoreService.getInstance().setLocationAlarm(runtime.getLocationInstance().getWorkingMod());\r
+//        //此处设置好配置后,会在LocationClient通过消息开始执行及时定位操作。\r
+//\r
+//    }\r
+//\r
+//    public static String heart(int hrt){\r
+//        return genFZDCMD(cmdMap.get(CMD_TYPE.heart),String.valueOf(hrt));\r
+//    }\r
+//    public static String oxygen(int ox){\r
+//        return genFZDCMD(cmdMap.get(CMD_TYPE.oxygen),String.valueOf(ox));\r
+//    }\r
+//\r
+//    public static String blood(int pbl,int pbh){\r
+//        String data=pbh+CMDSPLIT+pbl;\r
+//        return genFZDCMD(cmdMap.get(CMD_TYPE.blood),data);\r
+//    }\r
+//\r
+//    public static String temp(double temp){\r
+//        return genFZDCMD(cmdMap.get(CMD_TYPE.temp),String.format("%.1f",temp));\r
+//    }\r
+//\r
+//    public static String wdstart(){\r
+//        return genFZDCMD(cmdMap.get(CMD_TYPE.wdstart));\r
+//    }\r
+//    public void handleWdstart(Connection connection,Runtime runtime ,String data) {\r
+//\r
+//        connection.send(genStringMessage("wdstart",wdstart()));\r
+//        int freq=Integer.parseInt(data);\r
+//\r
+//\r
+//        Config.setTemperatureTestCycle(runtime,freq);\r
+//        CoreService.getInstance().setTempAlarm();\r
+//\r
+//        TemperatureUtil.doTempTestInThread();\r
+////\r
+////        double wrist_temp,body_temp;\r
+////        wrist_temp= TemperatureUtil.get_temp_value_adjusted();\r
+////        body_temp=TemperatureUtil.getBodyTemp(wrist_temp,26.0f);\r
+////        String temperatureMsg=temp(body_temp);\r
+////        connection.send(genStringMessage("temp",temperatureMsg));\r
+//    }\r
+//    public static String hrtstart(){\r
+//        return genFZDCMD(cmdMap.get(CMD_TYPE.hrtstart));\r
+//    }\r
+//    public void handleHrtstart(Connection connection) {\r
+//\r
+//        connection.send(genStringMessage("hrtstart",hrtstart()));\r
+//    }\r
+//\r
+//    public static String SOS(){\r
+//        return genFZDCMD(cmdMap.get(CMD_TYPE.SOS));\r
+//    }\r
+//\r
+//\r
+//    public void handleSOS(Connection connection,Runtime runtime,String cmd,String data) {\r
+//\r
+//        connection.send(genStringMessage("SOS",SOS()));\r
+//        if (data!=null && data.length()>0) {\r
+//            String list[] = data.split(CMDSPLIT);\r
+//            if (list.length==1){\r
+//                ArrayList<Contact> contactArray=new ArrayList<Contact>();\r
+//                if (regexUtil.isMobileNumber( list[0]) || regexUtil.isPhoneNumber(list[0]))\r
+//               {\r
+//                   contactArray.add(new Contact(Contact.CATEGORY_SOS,"sos1",list[0]));\r
+//                   ICLogger.i("find SOS1 number "+list[0]);\r
+//               }\r
+//            }else if (list.length==2){\r
+//\r
+//                ArrayList<Contact> contactArray=new ArrayList<Contact>();\r
+//                if (regexUtil.isMobileNumber( list[0]) || regexUtil.isPhoneNumber(list[0]))\r
+//                {\r
+//                    contactArray.add(new Contact(Contact.CATEGORY_SOS,"sos1",list[0]));\r
+//                    ICLogger.i("find SOS1 number "+list[0]);\r
+//                }\r
+//                if (regexUtil.isMobileNumber( list[1]) || regexUtil.isPhoneNumber(list[1]))\r
+//                {\r
+//                    contactArray.add(new Contact(Contact.CATEGORY_SOS,"sos2",list[1]));\r
+//                    ICLogger.i("find SOS2 number "+list[1]);\r
+//                }\r
+//\r
+//                runtime.getDbHelper().saveContacts(contactArray,false,false,false,false,false,true);\r
+//\r
+//            }\r
+//        }\r
+//\r
+//\r
+//    }\r
 \r
     public void sendBroadcast(String cmd, Runtime dev) {\r
 \r
@@ -479,7 +424,9 @@ public class protocol_mqtt {
 \r
             case BREQ:\r
                 handleBREQ(mRuntime,data);\r
-                ICLogger.i("服务器返回Ping绑定信息");\r
+                //ICLogger.i("服务器返回Ping绑定信息");\r
+                ICLogger.i("服务器收到登录包BREQ");\r
+                mConnection.DeliverCMDMessageToSystem("login",cmd);//通知下面线程状态变化\r
                 break;\r
 //            case CR:\r
 //                //立即定位指令(长链接有效)\r
@@ -507,10 +454,10 @@ public class protocol_mqtt {
 //                ICLogger.i("收到服务器设置闹钟命令BP85");\r
 //                mConnection.DeliverCMDMessageToSystem("AP85",cmd);//通知下面线程状态变化\r
 //                break;\r
-            case UPLOAD:\r
-                //设置工作模式\r
-                handleUPLOAD(mConnection,mRuntime,cmd,data);\r
-                mConnection.DeliverCMDMessageToSystem("setWorkMod",cmd);//通知下面线程状态变化\r
+//            case UPLOAD:\r
+//                //设置工作模式\r
+//                handleUPLOAD(mConnection,mRuntime,cmd,data);\r
+//                mConnection.DeliverCMDMessageToSystem("setWorkMod",cmd);//通知下面线程状态变化\r
 //\r
 //                break;\r
 //            case BP34:\r
@@ -524,11 +471,11 @@ public class protocol_mqtt {
 ////                                API.handleBP05(cmd);\r
 ////                                break;\r
 //\r
-            case SOS:\r
-                //收到设置SOS号码\r
-                handleSOS(mConnection,mRuntime,cmd,data);\r
-                ICLogger.i("收到服务器设置SOS号码命令BP12");\r
-                break;\r
+//            case SOS:\r
+//                //收到设置SOS号码\r
+//                handleSOS(mConnection,mRuntime,cmd,data);\r
+//                ICLogger.i("收到服务器设置SOS号码命令BP12");\r
+//                break;\r
 //            case PHL:\r
 //                //收到设置白名单号码\r
 //                ICLogger.i("收到服务器设置白名单号码命令BP14");\r
@@ -560,32 +507,32 @@ public class protocol_mqtt {
 //                mConnection.DeliverCMDMessageToSystem("showTxt",cmd);//通知下面线程状态变化\r
 //                break;\r
 //\r
-            case hrtstart:\r
-                handleHrtstart(mConnection);\r
-                ICLogger.i("收到服务器心率检测命令");\r
-                HeartRateManager.triggerPPGtest();\r
-                break;\r
-\r
-            case wdstart:\r
-                handleWdstart(mConnection,mRuntime,data);\r
-                ICLogger.i("收到服务器体温测试及设置命令");\r
-                break;\r
-            case blood:\r
-                ICLogger.i("服务器收到上传的血压");\r
-                mConnection.DeliverCMDMessageToSystem("blood",cmd);//通知下面线程状态变化\r
-                break;\r
-            case oxygen:\r
-                ICLogger.i("服务器收到上传的血氧");\r
-                mConnection.DeliverCMDMessageToSystem("oxygen",cmd);//通知下面线程状态变化\r
-                break;\r
-            case temp:\r
-                ICLogger.i("服务器收到上传的体温");\r
-                mConnection.DeliverCMDMessageToSystem("temp",cmd);//通知下面线程状态变化\r
-                break;\r
-            case heart:\r
-                ICLogger.i("服务器收到上传的心率heart");\r
-                mConnection.DeliverCMDMessageToSystem("heart",cmd);//通知下面线程状态变化\r
-                break;\r
+//            case hrtstart:\r
+//                handleHrtstart(mConnection);\r
+//                ICLogger.i("收到服务器心率检测命令");\r
+//                HeartRateManager.triggerPPGtest();\r
+//                break;\r
+//\r
+//            case wdstart:\r
+//                handleWdstart(mConnection,mRuntime,data);\r
+//                ICLogger.i("收到服务器体温测试及设置命令");\r
+//                break;\r
+//            case blood:\r
+//                ICLogger.i("服务器收到上传的血压");\r
+//                mConnection.DeliverCMDMessageToSystem("blood",cmd);//通知下面线程状态变化\r
+//                break;\r
+//            case oxygen:\r
+//                ICLogger.i("服务器收到上传的血氧");\r
+//                mConnection.DeliverCMDMessageToSystem("oxygen",cmd);//通知下面线程状态变化\r
+//                break;\r
+//            case temp:\r
+//                ICLogger.i("服务器收到上传的体温");\r
+//                mConnection.DeliverCMDMessageToSystem("temp",cmd);//通知下面线程状态变化\r
+//                break;\r
+//            case heart:\r
+//                ICLogger.i("服务器收到上传的心率heart");\r
+//                mConnection.DeliverCMDMessageToSystem("heart",cmd);//通知下面线程状态变化\r
+//                break;\r
 //            case BP84:\r
 //                handleBP84(cmd,mConnection);\r
 //                ICLogger.i("收到服务器白名单命令");\r
index 8f4c96a..7b01983 100644 (file)
@@ -9,6 +9,8 @@ import android.os.IBinder;
 import android.os.Message;\r
 import android.util.Log;\r
 \r
+import com.enqualcomm.support.utils.ICLogger;\r
+\r
 import java.io.IOException;\r
 \r
 import se.wetcat.qatja.MQTTConstants;\r
@@ -20,74 +22,87 @@ import se.wetcat.qatja.messages.MQTTPublish;
 \r
 public class protocol_mqtt_client {\r
 \r
-    private String TAG=protocol_mqtt_client.class.getSimpleName();\r
+    private String TAG = protocol_mqtt_client.class.getSimpleName();\r
     private Handler mHandler = new Handler(new MqttCallback());\r
-    QatjaService mClient=null;\r
+    QatjaService mClient = null;\r
     private Context mContext;\r
     private boolean isBound = false;\r
     private boolean isBinding = false;\r
+    public static String topic_header="";\r
 \r
+    public void setSubscriptTopicHeader(String header){\r
+        topic_header=header;\r
+    }\r
     private class MqttCallback implements Handler.Callback {\r
         @Override\r
-        public boolean handleMessage(Message msg)\r
-             {\r
+        public boolean handleMessage(Message msg) {\r
 \r
-                switch (msg.what) {\r
-                    case MQTTConnectionConstants.STATE_CHANGE:\r
-                        handleStateChange(msg);\r
+            ICLogger.i("MqttCallback handleMessage "+msg.what);\r
+            switch (msg.what) {\r
+                case MQTTConnectionConstants.STATE_CHANGE:\r
+                    handleStateChange(msg);\r
+                    break;\r
+                case 3:\r
+                    handleReceivedMessage(msg);\r
                     break;\r
-                    case 3:\r
-                        handleReceivedMessage(msg);\r
-                        break;\r
-                    }\r
-                 return true;\r
             }\r
+            return true;\r
+        }\r
 \r
     }\r
+    MqttCallbackInterface mqttCallbackInterface=null;\r
+    public protocol_mqtt_client(Context context,MqttCallbackInterface _mqttCallbackInterface) {\r
 \r
-    public protocol_mqtt_client(Context context ) {\r
-\r
-        mContext=context;\r
+        mqttCallbackInterface=_mqttCallbackInterface;\r
+        mContext = context;\r
     }\r
+\r
     private void handleStateChange(Message msg) {\r
-        Log.e(TAG, MQTTConnectionConstants.resolveStateName(msg.arg1));\r
+        ICLogger.i(MQTTConnectionConstants.resolveStateName(msg.arg1));\r
 \r
         switch (msg.arg1) {\r
             case MQTTConnectionConstants.STATE_NONE:\r
-                onMqttDisconnected();\r
+                if (mqttCallbackInterface!= null)\r
+                    mqttCallbackInterface.onMqttDisconnected();\r
                 break;\r
-\r
             case MQTTConnectionConstants.STATE_CONNECTING:\r
                 break;\r
             case MQTTConnectionConstants.STATE_CONNECTED:\r
-                onMqttConnected();\r
+                if (mqttCallbackInterface!=null)\r
+                    mqttCallbackInterface.onMqttConnected();\r
                 break;\r
             case MQTTConnectionConstants.STATE_CONNECTION_FAILED:\r
-                onMqttDisconnected();\r
+                if (mqttCallbackInterface!=null)\r
+                    mqttCallbackInterface.onMqttDisconnected();\r
                 break;\r
             default:\r
                 Log.e(TAG, "Unhandled MQTT state change");\r
-            break;\r
+                break;\r
         }\r
     }\r
 \r
     private void handleReceivedMessage(Message msg) {\r
-        MQTTPublish publish    = (MQTTPublish)msg.obj;\r
+        MQTTPublish publish = (MQTTPublish) msg.obj;\r
 \r
 //        if (isDebug()) {\r
-            Log.d(TAG, "handleReceivedMessage(${publish.topicName})"+publish.getTopicName()+" data "+new String(publish.getPayload()));\r
+        Log.d(TAG, "handleReceivedMessage(${publish.topicName})" + publish.getTopicName() + " data " + new String(publish.getPayload()));\r
 //        }\r
+        String cmdtype= publish.getTopicName().replace(topic_header,"");\r
+        if (mqttCallbackInterface!=null)\r
+            mqttCallbackInterface.handleMqttMessage(cmdtype, publish.getPayload());\r
     }\r
 \r
     private ServiceConnection mConnection = new ServiceConnection() {\r
         @Override\r
         public void onServiceConnected(ComponentName componentName, IBinder iBinder) {\r
-            mClient = ((QatjaService.QatjaBinder)iBinder).getService();\r
+            mClient = ((QatjaService.QatjaBinder) iBinder).getService();\r
 \r
             isBound = true;\r
             isBinding = false;\r
 \r
             mClient.setHandler(mHandler);\r
+\r
+            attemptBindService();\r
         }\r
 \r
         @Override\r
@@ -98,7 +113,7 @@ public class protocol_mqtt_client {
     };\r
 \r
 \r
-   public void Resume() {\r
+    public void Resume() {\r
         attemptBindService();\r
     }\r
 \r
@@ -110,7 +125,7 @@ public class protocol_mqtt_client {
 \r
             isBinding = false;\r
             isBound = false;\r
-        } catch ( IllegalArgumentException ex) {\r
+        } catch (IllegalArgumentException ex) {\r
             Log.e(TAG, "Couldn't unbind the service, this is probably fine considering the state changes in the app... can probably ignore this.", ex);\r
         }\r
 \r
@@ -118,14 +133,14 @@ public class protocol_mqtt_client {
     }\r
 \r
     public void attemptSubscribeToTopic(String topic) {\r
-        Log.d(TAG, "attemptSubscribeToTopic($topic)"+topic);\r
+        Log.d(TAG, "attemptSubscribeToTopic($topic)" + topic);\r
 \r
 \r
-            try {\r
-                mClient.subscribe(topic, MQTTConstants.AT_MOST_ONCE);\r
-            } catch (Exception ex) {\r
-                Log.e(TAG, ex.getMessage());\r
-            }\r
+        try {\r
+            mClient.subscribe(topic, MQTTConstants.AT_MOST_ONCE);\r
+        } catch (Exception ex) {\r
+            Log.e(TAG, ex.getMessage());\r
+        }\r
 \r
     }\r
 \r
@@ -135,7 +150,7 @@ public class protocol_mqtt_client {
 \r
     public void connectservice() {\r
         if (isBound) {\r
-//            attemptConnectMqtt()\r
+            attemptConnectMqtt();\r
         } else if (!isBound && !isBinding) {\r
             attemptBindService();\r
         }\r
@@ -143,7 +158,7 @@ public class protocol_mqtt_client {
 \r
     private void attemptBindService() {\r
 //        if (isDebug()) {\r
-            Log.d(TAG, "attemptBindService()  [isBound: $isBound, isBinding: $isBinding]");\r
+        Log.d(TAG, "attemptBindService()  [isBound: $isBound, isBinding: $isBinding]");\r
 //        }\r
         if (!isBound && !isBinding) {\r
             isBinding = true;\r
@@ -153,17 +168,30 @@ public class protocol_mqtt_client {
         }\r
 \r
     }\r
+    private String mqttHost="";\r
+    private String devid="";\r
+    private int mqtt_cycle_seconds=600;\r
+    public void configMqtt(String host,int cycle_seconds,String idname){\r
+        mqttHost=host;\r
+        devid=idname;\r
+        mqtt_cycle_seconds=cycle_seconds;\r
+    }\r
 \r
-    public void attemptConnectMqtt(String host,String identifier, int cycle_inSeconds) {\r
-        Log.d(TAG, "attemptConnectMqtt($host, $identifier)");\r
 \r
-        if (!(MQTTConnectionConstants.STATE_CONNECTING== mClient.getState() || MQTTConnectionConstants.STATE_CONNECTED == mClient.getState()))\r
-        {\r
+    public void attemptConnectMqtt(){\r
+        attemptConnectMqtt(mqttHost,devid,mqtt_cycle_seconds);\r
+    }\r
+    public void attemptConnectMqtt(String host, String identifier, int cycle_inSeconds) {\r
+        ICLogger.i("attemptConnectMqtt($host, $identifier)");\r
+\r
+        if (!(MQTTConnectionConstants.STATE_CONNECTING == mClient.getState() || MQTTConnectionConstants.STATE_CONNECTED == mClient.getState())) {\r
             try {\r
+\r
+                ICLogger.i("attemptConnectMqtt");\r
                 mClient.setHost(host);\r
                 mClient.setPort(1883);\r
                 mClient.setIdentifier(identifier);\r
-                mClient.setKeepAlive(cycle_inSeconds*1000);\r
+                mClient.setKeepAlive(cycle_inSeconds);\r
                 mClient.setCleanSession(true);\r
 \r
                 mClient.connect();\r
@@ -173,19 +201,18 @@ public class protocol_mqtt_client {
         }\r
     }\r
 \r
-    void onMqttConnected() {\r
-        Log.i(TAG,"onMqttConnected");\r
-        attemptSubscribeToTopic("WBG100/v1/1/+");\r
-\r
+    public void sendMessage(String cmdtype,String data){\r
+       mClient.publish(topic_header+cmdtype,data);\r
     }\r
-    void onMqttDisconnected() {\r
-        Log.i(TAG,"onMqttDisconnected");\r
 \r
-    }\r
+    public interface MqttCallbackInterface\r
+    {\r
+        void onMqttConnected() ;\r
 \r
+        void onMqttDisconnected();\r
 \r
-    public void sendMessage(String topic,String data){\r
+        void handleMqttMessage(String cmdtype,byte[] msgdata);\r
+        void handleMqttMessage(String cmdtype,String msgdata);\r
 \r
-       mClient.publish(topic,data);\r
     }\r
 }\r
index d6aa41d..02b55eb 100644 (file)
@@ -25,6 +25,8 @@ import android.os.IBinder;
 import android.text.TextUtils;
 import android.util.Log;
 
+import com.enqualcomm.support.utils.ICLogger;
+
 import java.io.Closeable;
 import java.io.IOException;
 import java.io.InputStream;
@@ -101,7 +103,7 @@ public class QatjaService extends Service {
 
   private static final boolean DEBUG = true;
 
-  private static final String TAG = QatjaService.class.getSimpleName();
+  private static final String TAG = "mqtt_"+QatjaService.class.getSimpleName();
 
   /**
    * Current state of the connection
@@ -283,7 +285,7 @@ public class QatjaService extends Service {
     }
 
     connect.setCleanSession(cleanSession);
-    connect.setKeepAlive(60);
+    connect.setKeepAlive(KEEP_ALIVE_TIMER);
     connect.setWillFlag(willFlag);
     if (willFlag) {
       connect.setWillTopic(willTopic);
@@ -626,7 +628,7 @@ public class QatjaService extends Service {
       sendMessage(MQTTPingreq.newInstance());
 
       // Make sure to auto-queue the runnable again when the message has been sent.
-      mKeepaliveHandler.postDelayed(mPingSender, KEEP_ALIVE_TIMER);
+      mKeepaliveHandler.postDelayed(mPingSender, KEEP_ALIVE_TIMER*1000);
     }
   };
 
@@ -735,7 +737,7 @@ public class QatjaService extends Service {
 
     // Start the PINGREQ handler
     mKeepaliveHandler = new Handler(getMainLooper());
-    mKeepaliveHandler.postDelayed(mPingSender, KEEP_ALIVE_TIMER);
+    mKeepaliveHandler.postDelayed(mPingSender, KEEP_ALIVE_TIMER*1000);
 
     Log.d(TAG, "Sending connect message");
 
@@ -861,10 +863,10 @@ public class QatjaService extends Service {
   /**
    * Set keep alive timer in milliseconds
    *
-   * @param milliseconds the time
+   * @param seconds the time
    */
-  public void setKeepAlive(int milliseconds) {
-    KEEP_ALIVE_TIMER = milliseconds;
+  public void setKeepAlive(int seconds) {
+    KEEP_ALIVE_TIMER = seconds;
   }
 
   /**
@@ -1042,7 +1044,7 @@ public class QatjaService extends Service {
               byte type = MQTTHelper.decodeType(buffer);
 
               if (DEBUG)
-                Log.d(TAG, "Received " + MQTTHelper.decodePackageName(type));
+                ICLogger.d( "Mqtt_"+"Received " + MQTTHelper.decodePackageName(type));
 
               // Handle automatic responses here
               switch (type) {
@@ -1056,37 +1058,37 @@ public class QatjaService extends Service {
                   switch (connack.getReturnCode()) {
                     case CONNECTION_ACCEPTED:
                       if (DEBUG)
-                        Log.d(TAG, "Connected");
+                        ICLogger.d( "Mqtt_"+ "Connected");
                       setState(STATE_CONNECTED);
                       break;
 
                     case CONNECTION_REFUSED_VERSION:
                       if (DEBUG)
-                        Log.d(TAG, "Failed to connect, unaccebtable protocol version");
+                        ICLogger.d( "Mqtt_"+ "Failed to connect, unaccebtable protocol version");
                       setState(STATE_CONNECTION_FAILED);
                       break;
 
                     case CONNECTION_REFUSED_IDENTIFIER:
                       if (DEBUG)
-                        Log.d(TAG, "Failed to connect, identifier rejected");
+                        ICLogger.d( "Mqtt_"+ "Failed to connect, identifier rejected");
                       setState(STATE_CONNECTION_FAILED);
                       break;
 
                     case CONNECTION_REFUSED_SERVER:
                       if (DEBUG)
-                        Log.d(TAG, "Failed to connect, server unavailable");
+                        ICLogger.d( "Mqtt_"+ "Failed to connect, server unavailable");
                       setState(STATE_CONNECTION_FAILED);
                       break;
 
                     case CONNECTION_REFUSED_USER:
                       if (DEBUG)
-                        Log.d(TAG, "Failed to connect, bad username or password");
+                        ICLogger.d( "Mqtt_"+ "Failed to connect, bad username or password");
                       setState(STATE_CONNECTION_FAILED);
                       break;
 
                     case CONNECTION_REFUSED_AUTH:
                       if (DEBUG)
-                        Log.d(TAG, "Failed to connect, not authorized");
+                        ICLogger.d( "Mqtt_"+ "Failed to connect, not authorized");
                       setState(STATE_CONNECTION_FAILED);
                       break;
                   }
@@ -1214,7 +1216,7 @@ public class QatjaService extends Service {
     @Override
     protected Void doInBackground(Closeable... closeables) {
       if (DEBUG) {
-        Log.d(TAG, "[DisconnectTask] Closing streams and socket.");
+        ICLogger.d( "Mqtt_"+ "[DisconnectTask] Closing streams and socket.");
       }
 
       for (Closeable closeable : closeables) {
@@ -1261,7 +1263,7 @@ public class QatjaService extends Service {
           try {
             if (mKeepaliveHandler != null) {
               mKeepaliveHandler.removeCallbacks(mPingSender);
-              mKeepaliveHandler.postDelayed(mPingSender, KEEP_ALIVE_TIMER);
+              mKeepaliveHandler.postDelayed(mPingSender, KEEP_ALIVE_TIMER*1000);
             }
           } catch (Exception ex) {
             Log.e(TAG, ex.getMessage(), ex);
index e9912a8..d5c8d3c 100644 (file)
@@ -1,2 +1,2 @@
-#Fri Aug 21 20:09:36 CST 2020\r
-VERSION_CODE=504\r
+#Thu Aug 27 00:06:54 CST 2020\r
+VERSION_CODE=505\r