From 5a5a2b696866f947b6025d26c3302e8ffef46435 Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期一, 11 一月 2021 16:11:20 +0800
Subject: [PATCH] 2021-01-11 1.更新MQTT连接和本地搜索网关方法。2.子账号相关接口完善

---
 Crabtree/SmartHome/HDL/Operation/Control.cs |   61 +++++++++++++++++++++++-------
 1 files changed, 46 insertions(+), 15 deletions(-)

diff --git a/Crabtree/SmartHome/HDL/Operation/Control.cs b/Crabtree/SmartHome/HDL/Operation/Control.cs
index ded44d4..8bbe6cf 100644
--- a/Crabtree/SmartHome/HDL/Operation/Control.cs
+++ b/Crabtree/SmartHome/HDL/Operation/Control.cs
@@ -8,6 +8,7 @@
 {
     public class Control
     {
+        public static bool IsEnterBackground = false;
         public bool IsCanShowTip;
         public System.DateTime LatestDateTime = System.DateTime.Now;
 
@@ -62,7 +63,7 @@
                 AddData = gatewayBytes,
             }, sendCount, false);
             CommonPage.FindGateway = false;
-            System.Console.WriteLine (command.ToString () + "::" + CommonPage.EndPoint.ToString ());
+            Utlis.WriteLine (command.ToString () + "::" + CommonPage.EndPoint.ToString ());
         }
 
         /// <summary>
@@ -164,6 +165,8 @@
                 case Command.SetGateWayTopicACK:
                 case Command.ReadGateWayAdminInfoACK:
                 case Command.SetGateWayAdminInfoACK:
+                case Command.ReadGateWayLocalEncryptionACK:
+                case Command.SetReadGateWayLocalEncryptionACK:
                 //************************************
                 case Command.ReadGateWayModelInfoACK:
                 case Command.ReadGatewayServerIPACK:
@@ -216,6 +219,7 @@
                 case Command.READ_JOG_OPEN_TIME_ACK:
                 case Command.SET_JOG_CLOSE_TIME_ACK:
                 case Command.READ_JOG_CLOSE_TIME_ACK:
+                case Command.ReadRemarkACK:
                     receiveFlag += "";
                     break;
                 case Command.ControlMusicModel1ACK:
@@ -283,7 +287,7 @@
                 default:
                     break;
                 }
-                //System.Console.WriteLine ("鎺ユ敹鍒版暟鎹細" + receiveFlag);
+                //Utlis.WriteLine ("鎺ユ敹鍒版暟鎹細" + receiveFlag);
 
                 for (int i = 0; i < controlList.Count; i++) {
                     try {
@@ -298,7 +302,7 @@
                     }
                 }
             } catch (Exception ex) {
-                Console.WriteLine ("ManagerReceive鎶涘嚭寮傚父锛�" + ex.ToString ());
+                Utlis.WriteLine ("ManagerReceive鎶涘嚭寮傚父锛�" + ex.ToString ());
             }
         }
 
@@ -321,7 +325,7 @@
                     }
 
                 }
-                //System.Console.WriteLine ("++++++++"+controlList.Count.ToString ());
+                //Utlis.WriteLine ("++++++++"+controlList.Count.ToString ());
             }
             controlList.Add (this);
         }
@@ -383,37 +387,61 @@
         void managerSendCount (object o)
         {
             add ();
-            if (Shared.SimpleControl.CommonPage.IsRemote && !isLocal) {
-                System.Console.WriteLine ("杩滅▼鍙戦�佹暟鎹�:" + SendFlag);
+            if (CommonPage.IsRemote && !isLocal) {
+                //if (!SmartHome.MqttCommon.IsGatewayOnline) {
+                //    System.Threading.Thread.Sleep (500);
+                //    Utlis.WriteLine ($"缃戝叧涓嶅湪绾� 鍙栨秷鍙戦��:" + SendFlag);
+                //    Packet.HaveSendCount = 3;
+                //    allDone.Set ();
+                //    return;
+                //}
+                if (IsEnterBackground) {
+                    System.Threading.Thread.Sleep (500);
+                    Utlis.WriteLine ("宸茶繘鍏ュ悗鍙� 鍙栨秷鍙戦��");
+                    Packet.HaveSendCount = 3;
+                    allDone.Set ();
+                    return;
+                }
+                Utlis.WriteLine ("杩滅▼鍙戦�佹暟鎹�:" + SendFlag);
                 SmartHome.MqttCommon.MqttRemoteSend (Packet.Bytes);
                 Packet.FlagDateTime = DateTime.Now;
                 Packet.HaveSendCount--;
                 //杩欓噷鏄噸鍙戜袱娆�
                 while (Packet.HaveSendCount < 3) {
-                    if (Packet.FlagDateTime.AddMilliseconds (1000).Ticks <= System.DateTime.Now.Ticks) {
-                        SmartHome.MqttCommon.MqttRemoteSend (Packet.Bytes);
-                        System.Console.WriteLine ("閲嶅彂杩滅▼鍙戦�佹暟鎹�:" + SendFlag);
-                        Packet.FlagDateTime = DateTime.Now;
-                        Packet.HaveSendCount++;
+                    if (Packet.HaveSendCount < 2) {
+                        if (Packet.FlagDateTime.AddMilliseconds (2000).Ticks <= System.DateTime.Now.Ticks) {
+                            SmartHome.MqttCommon.MqttRemoteSend (Packet.Bytes);
+                            Utlis.WriteLine ("閲嶅彂杩滅▼鍙戦�佹暟鎹�:" + SendFlag);
+                            Packet.FlagDateTime = DateTime.Now;
+                            Packet.HaveSendCount++;
+                        }
+                    } else {
+                        if (Packet.FlagDateTime.AddMilliseconds (5000).Ticks <= System.DateTime.Now.Ticks) {
+                            Utlis.WriteLine ("杩滅▼鍙戦�佹暟鎹�: 绛夊緟5s瓒呮椂");
+                            Packet.FlagDateTime = DateTime.Now;
+                            Packet.HaveSendCount++;
+                        }
                     }
                     System.Threading.Thread.Sleep (100);
                 }鈥�                allDone.Set ();鈥�            } else {
                 try {
-                    System.Console.WriteLine ("鍙戦�佹暟鎹�:" + SendFlag);
+                    Utlis.WriteLine ("鍙戦�佹暟鎹�:" + SendFlag);
                     BusSocket.AsyncBeginSend (Packet);
+
+                    Packet.FlagDateTime = DateTime.Now;
                     Packet.HaveSendCount--;
 
                     //杩欓噷鏄噸鍙戜袱娆�
-                    while (Packet.HaveSendCount < 3) {
+                    while (Packet.HaveSendCount < 3 && BusSocket.IsRunning) {
                         if (Packet.FlagDateTime.AddMilliseconds (1000).Ticks <= System.DateTime.Now.Ticks) {
-                            System.Console.WriteLine ("閲嶅彂鏁版嵁:" + SendFlag);
+                            Utlis.WriteLine ("閲嶅彂鏁版嵁:" + SendFlag);
                             BusSocket.AsyncBeginSend (Packet);
                         }
                         System.Threading.Thread.Sleep (100);
                     }
 
                 } catch (Exception ex) {
-                    Console.WriteLine ("managerSendCount:" + ex.ToString ());
+                    Utlis.WriteLine ("managerSendCount:" + ex.ToString ());
                 } finally {
                     allDone.Set ();
                 }
@@ -493,6 +521,8 @@
             case Command.SetGateWayTopic:
             case Command.ReadGateWayAdminInfo:
             case Command.SetGateWayAdminInfo:
+            case Command.SetGateWayLocalEncryption:
+            case Command.ReadGateWayLocalEncryption:
             //************************************
             case Command.ReadGateWayModelInfo:
             case Command.ReadGatewayServerIP:
@@ -546,6 +576,7 @@
             case Command.READ_JOG_OPEN_TIME_CMD:
             case Command.SET_JOG_CLOSE_TIME_CMD:
             case Command.READ_JOG_CLOSE_TIME_CMD:
+            case Command.ReadRemark:
                 this.SendFlag += "";
                 break;
             case Command.ControlMusicModel2:

--
Gitblit v1.8.0