From ed3bfb7462d44747230437717e8673a5192f833f Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期一, 30 十一月 2020 20:34:51 +0800
Subject: [PATCH] 2020-11-30-2

---
 HDL_ON/DriverLayer/Packet.cs |  115 ++++++++++++++++++++++++---------------------------------
 1 files changed, 48 insertions(+), 67 deletions(-)

diff --git a/HDL_ON/DAL/DriverLayer/Packet.cs b/HDL_ON/DriverLayer/Packet.cs
similarity index 87%
rename from HDL_ON/DAL/DriverLayer/Packet.cs
rename to HDL_ON/DriverLayer/Packet.cs
index 6fce368..d957a86 100644
--- a/HDL_ON/DAL/DriverLayer/Packet.cs
+++ b/HDL_ON/DriverLayer/Packet.cs
@@ -5,10 +5,10 @@
 using HDL_ON.UI;
 using Shared;
 
-namespace HDL_ON.DriverLayer
+namespace HDL_ON
 {
     /// <summary>
-    /// bus鏁版嵁鍖�
+    /// bus鎺у埗鏁版嵁鍖�
     /// </summary>
     public class Packet
     {
@@ -54,7 +54,12 @@
         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)))
                 {
@@ -73,7 +78,7 @@
                 byte targetDeviceID = this.Bytes[24];
 
                 //涓嶆槸瑕佹帴鏀剁殑鎸囦护灏辫繑鍥�
-                if (!((targetSubnetID == 0 && targetDeviceID == 252) || (targetSubnetID == 0xff && targetDeviceID == 0xff)))
+                if (!((targetSubnetID == 252 && targetDeviceID == 252) || (targetSubnetID == 0xff && targetDeviceID == 0xff)))
                 {
                     return;
                 }
@@ -124,19 +129,17 @@
                             {
                                 if (updataObj.functionType != FunctionType.RGB)
                                 {
-                                    updataObj.trait_on_off.curValue = receiveBytes[2] > 0 ? "on" : "off";
-                                    if (updataObj.trait_on_off.curValue.ToString() == "on")
+                                    if (updataObj.trait_on_off.value.ToString() == "on")
                                     {
-                                        switch (updataObj.functionType)
+                                        if (updataObj.functionType == FunctionType.Fan)
                                         {
-                                            case FunctionType.Fan:
-                                                (updataObj as Fan).openLevel = receiveBytes[2];
-                                                updataObj.lastState = Language.StringByID(StringId.Level) + " : " + receiveBytes[2];
-                                                break;
-                                            case FunctionType.Dimmer:
-                                                (updataObj as Light).brightness = receiveBytes[2];
-                                                updataObj.lastState = Language.StringByID(StringId.Brightness) + " : " + receiveBytes[2] + "%";
-                                                break;
+                                            (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] + "%";
                                         }
                                     }
                                     HomePage.UpdataFunctionStates(updataObj);
@@ -168,8 +171,8 @@
                             {
                                 if (light.functionType != FunctionType.RGB)
                                 {
-                                    light.trait_on_off.curValue = receiveBytes[light.bus_Data.LoopID] == 0 ? "off" : "on";
-                                    if (light.trait_on_off.curValue.ToString() == "on")
+                                    light.trait_on_off.value = receiveBytes[light.bus_Data.LoopID] == 0 ? "off" : "on";
+                                    if (light.trait_on_off.value.ToString() == "on")
                                     {
                                         light.brightness = receiveBytes[2];
                                         light.lastState = Language.StringByID(StringId.Brightness) + " : " + receiveBytes[2] + "%";
@@ -195,8 +198,8 @@
                                 if (e != null)
                                 {
                                     var fan = e as Fan;
-                                    fan.trait_on_off.curValue = receiveBytes[2] == 0 ? "off" : "on";
-                                    if (fan.trait_on_off.curValue.ToString() == "on")
+                                    fan.trait_on_off.value = receiveBytes[2] == 0 ? "off" : "on";
+                                    if (fan.trait_on_off.value.ToString() == "on")
                                     {
                                         fan.openLevel = receiveBytes[2];
                                         fan.lastState = Language.StringByID(StringId.Level) + " : " + receiveBytes[2];
@@ -226,7 +229,7 @@
                             {
                                 if (rgb.functionType == FunctionType.RGB)
                                 {
-                                    rgb.trait_on_off.curValue = receiveBytes[1] > 0 ? "on" : "off";
+                                    rgb.trait_on_off.value = receiveBytes[1] > 0 ? "on" : "off";
                                     if (receiveBytes[1] > 0)
                                     {
                                         rgb.brightness = receiveBytes[1];
@@ -255,11 +258,11 @@
                                 {
                                     if (receiveBytes[1] > 1)
                                     {
-                                        curtain.trait_on_off.curValue = "on";
+                                        curtain.trait_on_off.value = "on";
                                     }
                                     else
                                     {
-                                        curtain.trait_on_off.curValue = "off";
+                                        curtain.trait_on_off.value = "off";
                                     }
                                     curtain.percent = receiveBytes[1];
                                     curtain.lastState = Language.StringByID(StringId.Open) + curtain.percent + "%";
@@ -271,14 +274,14 @@
                                     switch (receiveBytes[1])
                                     {
                                         case 0:
-                                            curtain.trait_on_off.curValue = "stop";
+                                            curtain.trait_on_off.value = "stop";
                                             break;
                                         case 1:
-                                            curtain.trait_on_off.curValue = "on";
+                                            curtain.trait_on_off.value = "on";
                                             curtain.lastState = Language.StringByID(StringId.Open);
                                             break;
                                         case 2:
-                                            curtain.trait_on_off.curValue = "off";
+                                            curtain.trait_on_off.value = "off";
                                             curtain.lastState = Language.StringByID(StringId.Close);
                                             break;
                                     }
@@ -310,12 +313,12 @@
                             {
                                 ac.curTempType = receiveBytes[1];
                                 ac.indoorTemp = receiveBytes[2];
-                                ac.trait_on_off.curValue = receiveBytes[8] == 1 ? "on" : "off";
+                                ac.trait_on_off.value = receiveBytes[8] == 1 ? "on" : "off";
                                 ac.curModeIndex = receiveBytes[9];
                                 ac.curFanIndex = receiveBytes[10];
-                                ac.trait_temp.curValue = receiveBytes[11];
+                                ac.trait_temp.value = receiveBytes[11];
                                 ac.lastState = "";
-                                switch (ac.trait_mode.curValue.ToString())
+                                switch (ac.trait_mode.value.ToString())
                                 {
                                     case "cool":
                                         ac.lastState = Language.StringByID(StringId.Cool);
@@ -333,7 +336,7 @@
                                         ac.lastState = Language.StringByID(StringId.AirSupply);
                                         break;
                                 }
-                                switch (ac.trait_fan.curValue.ToString())
+                                switch (ac.trait_fan.value.ToString())
                                 {
                                     case "high":
                                         ac.lastState += " " + Language.StringByID(StringId.HighWindSpeed);
@@ -348,7 +351,7 @@
                                         ac.lastState += " " + Language.StringByID(StringId.Auto);
                                         break;
                                 }
-                                ac.lastState += " " + ac.trait_temp.curValue + ac.tempUnitString;
+                                ac.lastState += " " + ac.trait_temp.value + ac.tempUnitString;
                                 RoomPage.UpdataStates(ac);
                                 FunctionPage.UpdataStates(ac);
                                 HomePage.UpdataFunctionStates(ac);
@@ -364,7 +367,7 @@
                             if (fh.GetBusId() == subnetID + "_" + deviceID + "_" + receiveBytes[0])
                             {
                                 fh.curTempType = receiveBytes[2];
-                                fh.trait_on_off.curValue = receiveBytes[1] % 2 == 0 ? "off" : "on";
+                                fh.trait_on_off.value = receiveBytes[1] % 2 == 0 ? "off" : "on";
                                 fh.curModeIndex = receiveBytes[3];
                                 if (fh.modeTemp.ContainsKey("normal"))
                                 {
@@ -399,39 +402,39 @@
                                     fh.modeTemp.Add("away", receiveBytes[7]);
                                 }
 
-                                switch (fh.trait_mode.curValue)
+                                switch (fh.trait_mode.value)
                                 {
                                     case "normal":
                                         fh.lastState = Language.StringByID(StringId.Normal);
-                                        fh.trait_temp.curValue = receiveBytes[4];
+                                        fh.trait_temp.value = receiveBytes[4];
                                         break;
                                     case "day":
                                         fh.lastState = Language.StringByID(StringId.Day);
-                                        fh.trait_temp.curValue = receiveBytes[5];
+                                        fh.trait_temp.value = receiveBytes[5];
                                         break;
                                     case "night":
                                         fh.lastState = Language.StringByID(StringId.Night);
-                                        fh.trait_temp.curValue = receiveBytes[6];
+                                        fh.trait_temp.value = receiveBytes[6];
                                         break;
                                     case "timer":
                                         fh.lastState = Language.StringByID(StringId.Auto);
                                         if (receiveBytes[8] == 0)
                                         {
                                             fh.timeFlag = 0;
-                                            fh.trait_temp.curValue = receiveBytes[5];
+                                            fh.trait_temp.value = receiveBytes[5];
                                         }
                                         else
                                         {
                                             fh.timeFlag = 1;
-                                            fh.trait_temp.curValue = receiveBytes[6];
+                                            fh.trait_temp.value = receiveBytes[6];
                                         }
                                         break;
                                     case "away":
-                                        fh.trait_temp.curValue = receiveBytes[7];
+                                        fh.trait_temp.value = receiveBytes[7];
                                         fh.lastState = Language.StringByID(StringId.Away);
                                         break;
                                 }
-                                fh.lastState += " " + fh.trait_temp.curValue + fh.tempUnitString;
+                                fh.lastState += " " + fh.trait_temp.value + fh.tempUnitString;
                                 RoomPage.UpdataStates(fh);
                                 FunctionPage.UpdataStates(fh);
                                 HomePage.UpdataFunctionStates(fh);
@@ -531,13 +534,13 @@
                                 switch (receiveBytes[0])
                                 {
                                     case 3://
-                                        ac.trait_on_off.curValue = receiveBytes[1] == 1 ? "on" : "off";
+                                        ac.trait_on_off.value = receiveBytes[1] == 1 ? "on" : "off";
                                         break;
                                     case 4:
                                     case 7:
                                     case 8:
                                     case 19:
-                                        ac.trait_temp.curValue = receiveBytes[1];
+                                        ac.trait_temp.value = receiveBytes[1];
                                         break;
                                     case 5:
                                         ac.curFanIndex = receiveBytes[1];
@@ -548,7 +551,7 @@
 
                                 }
                                 ac.lastState = "";
-                                ac.lastState += " " + ac.trait_temp.curValue + ac.tempUnitString;
+                                ac.lastState += " " + ac.trait_temp.value + ac.tempUnitString;
                                 RoomPage.UpdataStates(ac);
                                 FunctionPage.UpdataStates(ac);
                                 HomePage.UpdataFunctionStates(ac);
@@ -568,15 +571,6 @@
                             }
                         }
                         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 (DB_ResidenceData.residenceData.residenceGatewayMAC == mac)
-                        {
-                            DriverLayer.Control.Ins.GatewayOnline = true;
-                        }
-                        break;
                 }
             }
             catch (Exception ex)
@@ -584,20 +578,7 @@
                 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>
         /// 澶勭悊鎺ユ敹鍥炴潵鐨勬暟鎹�
@@ -642,12 +623,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