From 493d35bf9672271ab9417cfb5a0bde9b4d3b9e66 Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期三, 25 十二月 2019 17:57:23 +0800
Subject: [PATCH] 2019-12-25 1.增加MQTT。

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

diff --git a/Crabtree/SmartHome/HDL/Operation/Control.cs b/Crabtree/SmartHome/HDL/Operation/Control.cs
index c30e693..c8a7a12 100644
--- a/Crabtree/SmartHome/HDL/Operation/Control.cs
+++ b/Crabtree/SmartHome/HDL/Operation/Control.cs
@@ -371,30 +371,42 @@
         void managerSendCount (object o)
         {
             add ();
-            try {
-                System.Console.WriteLine ("鍙戦�佹暟鎹�:" + SendFlag);
-                BusSocket.AsyncBeginSend (Packet);
+            if (Shared.SimpleControl.CommonPage.IsRemote && !isLocal) {
+                System.Console.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) {
-                        //System.Console.WriteLine ("閲嶅彂鏁版嵁:" + SendFlag);
-                        BusSocket.AsyncBeginSend (Packet);
+                        SmartHome.MqttCommon.MqttRemoteSend (Packet.Bytes);
+                        System.Console.WriteLine ("閲嶅彂杩滅▼鍙戦�佹暟鎹�:" + SendFlag);
+                        Packet.FlagDateTime = DateTime.Now;
+                        Packet.HaveSendCount++;
                     }
                     System.Threading.Thread.Sleep (100);
-                }
+                }鈥�                allDone.Set ();鈥�            } else {
+                try {
+                    System.Console.WriteLine ("鍙戦�佹暟鎹�:" + SendFlag);
+                    BusSocket.AsyncBeginSend (Packet);
+                    Packet.HaveSendCount--;
 
-            } catch (Exception ex) {
-                Console.WriteLine ("managerSendCount:" + ex.ToString ());
-            } finally {
-                allDone.Set ();
-                if (Packet.HaveSendCount == 3 && IsCanShowTip) {
-                    //MainPage.AddTip (Language.StringByID (SimpleControl.R.MyInternationalizationString.OperationFailed));
+                    //杩欓噷鏄噸鍙戜袱娆�
+                    while (Packet.HaveSendCount < 3) {
+                        if (Packet.FlagDateTime.AddMilliseconds (1000).Ticks <= System.DateTime.Now.Ticks) {
+                            System.Console.WriteLine ("閲嶅彂鏁版嵁:" + SendFlag);
+                            BusSocket.AsyncBeginSend (Packet);
+                        }
+                        System.Threading.Thread.Sleep (100);
+                    }
+
+                } catch (Exception ex) {
+                    Console.WriteLine ("managerSendCount:" + ex.ToString ());
+                } finally {
+                    allDone.Set ();
                 }
             }
         }
-
         /// <summary>
         /// 褰撳墠鏁版嵁鍖�
         /// </summary>
@@ -586,8 +598,9 @@
         /// </summary>
         /// <param name="target">鍙戦�佸璞�</param>
         /// <param name="sendCount">閲嶅彂娆℃暟</param>
-        public void Send (Target target, SendCount sendCount, bool isWait)
+        public void Send (Target target, SendCount sendCount, bool isWait, bool needLocal = false)
         {
+            isLocal = needLocal;
             Packet = new Packet (target.SendBytes, target.IPEndPoint);
             Packet.HaveSendCount = 3 - (int)sendCount;
 
@@ -597,5 +610,6 @@
                 this.wait ();
             }
         }
+        bool isLocal = false;
     }
 }
\ No newline at end of file

--
Gitblit v1.8.0