completed wether cmd data parse.
authorTrillGates <williamtrillgates@gmail.com>
Wed, 7 Apr 2021 03:19:10 +0000 (11:19 +0800)
committerTrillGates <williamtrillgates@gmail.com>
Wed, 7 Apr 2021 03:19:10 +0000 (11:19 +0800)
app/src/main/java/com/enqualcomm/support/service/KeepAlive.java
app/src/main/java/com/ic/protocols/protocol_fzd.java

index f25e8d2..9377eb0 100644 (file)
@@ -62,14 +62,14 @@ public class KeepAlive extends AbstractConnectionService {
 
     //如果重试5次还没有连接上,则需要重新断开连接重新连接服务器。
     private int hearBeatResendCount = 0;
-    private int MaxHeartbeatResendTime = 6;
+    private static final int MaxHeartbeatResendTime = 6;
     //每次retry发送心跳的间隔为20秒
-    private int heartBeatRetryTimeout = 20;
+    private static final int heartBeatRetryTimeout = 20;
 
-    private Handler mHandler;
+    private final Handler mHandler;
     //监测 心跳服务器响应的timer
     private ScheduledThreadPoolExecutor scheduled = null;
-    private Runnable CheckSrvResponseTimerTask = new Runnable() {
+    private final Runnable CheckSrvResponseTimerTask = new Runnable() {
         @Override
         public void run() {
             checkSrvResponse();
@@ -94,9 +94,10 @@ public class KeepAlive extends AbstractConnectionService {
             //如果开始进行连接重
             // {
             // 试,证明网络断开的,那么KeepAlive也需要重连(心跳包)
-            if (scheduled != null) {
-                scheduled.scheduleAtFixedRate(CheckSrvResponseTimerTask, heartBeatRetryTimeout * 1000, heartBeatRetryTimeout * 1000, TimeUnit.MILLISECONDS); //delay 3秒先检查一次,然后每5秒重试一次
-            }
+            scheduled.scheduleAtFixedRate(CheckSrvResponseTimerTask,
+                    heartBeatRetryTimeout * 1000,
+                    heartBeatRetryTimeout * 1000,
+                    TimeUnit.MILLISECONDS); //delay 3秒先检查一次,然后每5秒重试一次
         }
     }
 
@@ -142,10 +143,10 @@ public class KeepAlive extends AbstractConnectionService {
                     ICLogger.i("Update IMEI " + ret);
 
                     //只有曾经login成功过,且上一次成功时间超过15分钟,才会自主断开网络。
-                    long currenttime = System.currentTimeMillis();
+                    long currentTime = System.currentTimeMillis();
                     ICLogger.i("只有曾经login或者心跳发送成功过,且上一次成功时间超过15分钟,才会自主断开网络! last longin time " +
-                            mRuntime.lastLoginSuccessTime + " ms from last login time " + (currenttime - mRuntime.lastLoginSuccessTime));
-                    if ((mRuntime.lastLoginSuccessTime > 0) && ((currenttime - mRuntime.lastLoginSuccessTime) > 15 * 60 * 1000)) {
+                            mRuntime.lastLoginSuccessTime + " ms from last login time " + (currentTime - mRuntime.lastLoginSuccessTime));
+                    if ((mRuntime.lastLoginSuccessTime > 0) && ((currentTime - mRuntime.lastLoginSuccessTime) > 15 * 60 * 1000)) {
                         ICLogger.i("超时自主断开网络!");
                         CoreService.getInstance().disconnect_server();
                     } else {
index af7fd9e..0a5e6b6 100644 (file)
@@ -1224,6 +1224,9 @@ public class protocol_fzd {
             case LK: //登录包
                 ICLogger.i("服务器收到登录包LK");
                 mConnection.DeliverCMDMessageToSystem("login", cmd);//通知下面线程状态变化
+                //测试一下获取天气消息
+                //TODO:
+                mConnection.send(WT(mRuntime));
                 break;
             case KA:
                 ICLogger.i("服务器收到心跳包KA");
@@ -1326,11 +1329,52 @@ public class protocol_fzd {
             case MESSAGE:
                 handleMESSAGE(mConnection, data);
                 break;
+            case WT:
+                ICLogger.d("收到请求的天气消息.. WT");
+                ICLogger.d("WT--> DATA--> " + data);
+                //处理消息
+                handleWT(data);
+                mConnection.DeliverCMDMessageToSystem("WT", cmd);//通知下面线程状态变化
+                break;
         }
         return ret;
 
     }
 
+    /**
+     * 处理天气结果,后面得通知到远程
+     * //TODO:
+     * 年-月-日,时:分:秒,天气描述,天气编号,当前温度,最低温,最高温,城 市名
+     * 21-04-07,11:08:10,b6e0d4c6,1,23,-1,40,6DF157335E02
+     *
+     * @param data
+     */
+    private void handleWT(String data) {
+        String[] split = data.split(CMDSPLIT);
+        if (split.length == 8) {
+            //获取数据
+            String date = split[0];
+            String time = split[1];
+            String wtDesc = Util.UrlGB2312ToUTF8(split[2]);
+            String wtCode = split[3];
+            String currentTemp = split[4];
+            String lowTemp = split[5];
+            String highTemp = split[6];
+            String cityName = Util.decodeUnicode2Utf8(split[7]);
+            ICLogger.d("date == > " + date);
+            ICLogger.d("time == > " + time);
+            ICLogger.d("wtDesc == > " + wtDesc);
+            ICLogger.d("wtCode == > " + wtCode);
+            ICLogger.d("currentTemp == > " + currentTemp);
+            ICLogger.d("lowTemp == > " + lowTemp);
+            ICLogger.d("highTemp == > " + highTemp);
+            ICLogger.d("cityName == > " + cityName);
+        } else {
+            ICLogger.d("data -- > split size " + split.length);
+            ICLogger.d("parse data error..." + data);
+        }
+    }
+
     private void handleMESSAGE(Connection mConnection, String data) {
         //解析数据
         String textData = Util.decodeUnicode2Utf8(data);
@@ -1604,20 +1648,4 @@ public class protocol_fzd {
         }
     }
 
-
-    public boolean handleCmd(CMD_TYPE type, String cmd, byte[] bytes) {
-        //只有需要传递二级制数据的才需要这个函数,目前只有BP28需要
-        boolean ret = true;
-        ICLogger.i("handleCmd " + type.name() + " " + cmd + " bytelen=" + bytes.length);
-        if (Config.LOG_TOFILE) ICLogger.logToFile("APILog", " recv " + new String(bytes));
-        switch (type) {
-            case LK:
-                //    handleBP28(mConnection,cmd, mRuntime,bytes);
-                ICLogger.i("收到服务器语音BP28");
-                mConnection.DeliverCMDMessageToSystem("BP28", "");//通知下面线程状态变化
-                break;
-        }
-        return ret;
-    }
-
 }