From a5ba89efa83d0a4afd0d25dbeba5989e4944b5b8 Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期二, 24 十一月 2020 18:57:56 +0800
Subject: [PATCH] 20201124;mqtt代码整理备份

---
 HDL_ON/DAL/DriverLayer/Packet.cs |   61 +++++++++++++++++++++---------
 1 files changed, 42 insertions(+), 19 deletions(-)

diff --git a/HDL_ON/DriverLayer/Packet.cs b/HDL_ON/DAL/DriverLayer/Packet.cs
similarity index 92%
rename from HDL_ON/DriverLayer/Packet.cs
rename to HDL_ON/DAL/DriverLayer/Packet.cs
index d957a86..b649c62 100644
--- a/HDL_ON/DriverLayer/Packet.cs
+++ b/HDL_ON/DAL/DriverLayer/Packet.cs
@@ -5,10 +5,10 @@
 using HDL_ON.UI;
 using Shared;
 
-namespace HDL_ON
+namespace HDL_ON.DriverLayer
 {
     /// <summary>
-    /// bus鎺у埗鏁版嵁鍖�
+    /// bus鏁版嵁鍖�
     /// </summary>
     public class Packet
     {
@@ -54,12 +54,7 @@
         public virtual void Manager()
         {
             try
-            {
-                //濡傛灉褰撳墠閫氳鏂瑰紡涓嶆槸鏈湴bus udp鍒欓��鍑�
-                if(DriverLayer.Control.ins.communicationMode == DriverLayer.CommunicationMode.local_BusUdp)
-                {
-                    return;
-                }
+            { 
                 //瀵逛簬鎿嶄綔鏁版嵁搴撶殑鏃堕棿姣旇緝闀跨殑锛屽彲浠ュ垱寤哄彟涓�涓嚎绋嬪鐞�
                 if (!"HDLMIRACLE".Equals(Encoding.ASCII.GetString(Bytes, 4, 10)))
                 {
@@ -131,15 +126,18 @@
                                 {
                                     if (updataObj.trait_on_off.value.ToString() == "on")
                                     {
-                                        if (updataObj.functionType == FunctionType.Fan)
+                                        switch (updataObj.functionType)
                                         {
-                                            (updataObj as Fan).openLevel = receiveBytes[2];
-                                            updataObj.lastState = Language.StringByID(StringId.Level) + " : " + receiveBytes[2];
-                                        }
-                                        else
-                                        {
-                                            (updataObj as Light).brightness = receiveBytes[2];
-                                            updataObj.lastState = Language.StringByID(StringId.Brightness) + " : " + receiveBytes[2] + "%";
+                                            case FunctionType.Fan:
+                                                (updataObj as Fan).openLevel = receiveBytes[2];
+                                                updataObj.lastState = Language.StringByID(StringId.Level) + " : " + receiveBytes[2];
+                                                break;
+                                            case FunctionType.Relay:
+                                                (updataObj as Light).brightness = receiveBytes[2];
+                                                updataObj.lastState = Language.StringByID(StringId.Brightness) + " : " + receiveBytes[2] + "%";
+                                                break;
+                                            //case FunctionType.Socket:
+                                            //    (updataObj as SwitchSocket).
                                         }
                                     }
                                     HomePage.UpdataFunctionStates(updataObj);
@@ -571,6 +569,18 @@
                             }
                         }
                         break;
+                    case Command.ReadGatewayACK:
+                        var mac = ByteToHex16(receiveBytes[5]) + ByteToHex16(receiveBytes[6]) + ByteToHex16(receiveBytes[7]) + ByteToHex16(receiveBytes[8]) + ByteToHex16(receiveBytes[9]) + ByteToHex16(receiveBytes[10]) + ByteToHex16(receiveBytes[11]) + ByteToHex16(receiveBytes[12]);
+                        var Name = Encoding.GetEncoding("gb2312").GetString(receiveBytes, 13, 20).Trim('\0'); ;
+                        MainPage.Log($"name : {Name} ; mac : {mac}");
+#if DEBUG
+                        DB_ResidenceData.residenceData.residenceGatewayMAC = "4E47323347591243";
+#endif
+                        if (DB_ResidenceData.residenceData.residenceGatewayMAC == mac)
+                        {
+                            DriverLayer.Control.Ins.GatewayOnline = true;
+                        }
+                        break;
                 }
             }
             catch (Exception ex)
@@ -578,7 +588,20 @@
                 MainPage.Log($"Bus Rev Erorr : {ex.Message}");
             }
         }
-
+        /// <summary>
+        /// byte杞�16杩涘埗瀛楃涓�
+        /// </summary>
+        /// <param name="b"></param>
+        /// <returns></returns>
+        string ByteToHex16(byte b)
+        {
+            string s = Convert.ToString(b, 16).ToUpper();
+            if (s.Length <= 1)
+            {
+                return "0" + s;
+            }
+            return s;
+        }
 
         /// <summary>
         /// 澶勭悊鎺ユ敹鍥炴潵鐨勬暟鎹�
@@ -623,12 +646,12 @@
                         receiveFlag += string.Format("{0},{1}", usefulBytes[0], usefulBytes[1]);
                         break;
                     case Command.ReadRemark:
-                        DriverLayer.Control.ins.myUdp.ReceiveReadRemark(usefulBytes);
+                        DriverLayer.Control.Ins.myUdp.ReceiveReadRemark(usefulBytes);
                         break;
                     default:
                         break;
                 }
-                DriverLayer.Control.ins.myUdp.ReceiveRepeatManager(receiveFlag);
+                DriverLayer.Control.Ins.myUdp.ReceiveRepeatManager(receiveFlag);
             }
             catch (Exception ex)
             {

--
Gitblit v1.8.0