From df8d4ab0ef17a7fab5dea9c47bbd9f4d4a2a40b0 Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期一, 15 三月 2021 14:55:49 +0800
Subject: [PATCH] 合并前上传一个版本

---
 HDL_ON/DAL/DriverLayer/Control_Udp.cs |  104 +++++++++++++++++++++++++++++++---------------------
 1 files changed, 62 insertions(+), 42 deletions(-)

diff --git a/HDL_ON/DAL/DriverLayer/Control_Udp.cs b/HDL_ON/DAL/DriverLayer/Control_Udp.cs
index 5d91266..456591d 100644
--- a/HDL_ON/DAL/DriverLayer/Control_Udp.cs
+++ b/HDL_ON/DAL/DriverLayer/Control_Udp.cs
@@ -156,35 +156,7 @@
         /// </summary>
         public void ControlBusScenes(Scene scene)
         {
-            if (Control.Ins.IsRemote)
-            {
-                foreach (var f in scene.functions)
-                {
-                    var count = 0;
-                    List<ApiAlinkControlActionObj> actionObjs = new List<ApiAlinkControlActionObj>();
-                    Dictionary<string, string> d = new Dictionary<string, string>();
-                    var pm = new DAL.Server.HttpServerRequest();
-                    foreach (var temp in f.status)
-                    {
-                        if (f.localFunction == null)
-                        {
-                            continue;
-                        }
-                        d.Add(temp.key, temp.value);
-                        var apiControlData = f.localFunction.GetApiControlData(d);
-                        actionObjs.Add(apiControlData);
-                        count++;
-                        if (count > 9)
-                        {
-                            var result = pm.ControlDevice(actionObjs);
-                            actionObjs = new List<ApiAlinkControlActionObj>();
-                            count = 0;
-                        }
-                    }
-                    var pack = pm.ControlDevice(actionObjs);
-                }
-            }
-            else
+            if(Control.Ins.GatewayOnline_Local)
             {
                 foreach (var f in scene.functions)
                 {
@@ -226,14 +198,14 @@
                                         tempAc.trait_on_off.curValue = attr.value;
                                         break;
                                     case FunctionAttributeKey.Mode:
-                                        tempAc.trait_mode.curValue = attr.value;
+                                        tempAc.SetAttrState(FunctionAttributeKey.Mode, attr.value);
                                         break;
                                     case FunctionAttributeKey.FanSpeed:
-                                        tempAc.trait_fan.curValue = attr.value;
+                                        tempAc.SetAttrState(FunctionAttributeKey.FanSpeed, attr.value);
                                         break;
                                     case FunctionAttributeKey.SetTemp:
-                                        tempAc.trait_temp.curValue = attr.value;
-                                        switch (tempAc.curModeIndex)
+                                        tempAc.SetAttrState(FunctionAttributeKey.SetTemp, attr.value);
+                                        switch (tempAc.curModeIndex())
                                         {
                                             case 3:
                                                 modeKey = 8;
@@ -254,9 +226,9 @@
                                         break;
                                 }
                                 ControlBytesSend(Command.InstructionPanelKey, f.localFunction.bus.SubnetID, f.localFunction.bus.DeviceID, new byte[] { 3, tempAc.trait_on_off.curValue.ToString() == "on" ? (byte)1 : (byte)0, f.localFunction.bus.LoopId });
-                                ControlBytesSend(Command.InstructionPanelKey, f.localFunction.bus.SubnetID, f.localFunction.bus.DeviceID, new byte[] { 6, tempAc.curModeIndex, f.localFunction.bus.LoopId });
-                                ControlBytesSend(Command.InstructionPanelKey, f.localFunction.bus.SubnetID, f.localFunction.bus.DeviceID, new byte[] { 5, tempAc.curFanIndex, f.localFunction.bus.LoopId });
-                                ControlBytesSend(Command.InstructionPanelKey, f.localFunction.bus.SubnetID, f.localFunction.bus.DeviceID, new byte[] { modeKey, Convert.ToByte(tempAc.trait_temp.curValue), f.localFunction.bus.LoopId });
+                                ControlBytesSend(Command.InstructionPanelKey, f.localFunction.bus.SubnetID, f.localFunction.bus.DeviceID, new byte[] { 6, tempAc.curModeIndex(), f.localFunction.bus.LoopId });
+                                ControlBytesSend(Command.InstructionPanelKey, f.localFunction.bus.SubnetID, f.localFunction.bus.DeviceID, new byte[] { 5, tempAc.curFanIndex(), f.localFunction.bus.LoopId });
+                                ControlBytesSend(Command.InstructionPanelKey, f.localFunction.bus.SubnetID, f.localFunction.bus.DeviceID, new byte[] { modeKey, Convert.ToByte(tempAc.GetAttrState(FunctionAttributeKey.SetTemp)), f.localFunction.bus.LoopId });
                             }
                             break;
                         case SPK.LightSwitch:
@@ -332,6 +304,34 @@
                     }
                 }
             }
+            else
+            {
+                foreach (var f in scene.functions)
+                {
+                    var count = 0;
+                    List<ApiAlinkControlActionObj> actionObjs = new List<ApiAlinkControlActionObj>();
+                    Dictionary<string, string> d = new Dictionary<string, string>();
+                    var pm = new DAL.Server.HttpServerRequest();
+                    foreach (var temp in f.status)
+                    {
+                        if (f.localFunction == null)
+                        {
+                            continue;
+                        }
+                        d.Add(temp.key, temp.value);
+                        var apiControlData = f.localFunction.GetApiControlData(d);
+                        actionObjs.Add(apiControlData);
+                        count++;
+                        if (count > 9)
+                        {
+                            var result = pm.ControlDevice(actionObjs);
+                            actionObjs = new List<ApiAlinkControlActionObj>();
+                            count = 0;
+                        }
+                    }
+                    var pack = pm.ControlDevice(actionObjs);
+                }
+            }
         }
 
         /// <summary>
@@ -353,8 +353,25 @@
                         var light = function as Light;
                         switch (light.spk)
                         {
+                            case SPK.LightCCT:
+                                byte b0 = 100;//寮�鍏虫搷浣滀緷鎹畂n_off瀛楁锛屽疄闄呭紑鍏冲�间緷鎹産rightness锛屽綋on_off涓烘墦寮�锛宐rightness涓嶈兘涓�0
+                                if (light.trait_on_off.curValue.ToString() == "off")
+                                {
+                                    b0 = 0;
+                                }
+                                else
+                                {
+                                    b0 = (byte)light.brightness == 0 ? (byte)100 : (byte)light.brightness;
+                                }
+                                var bytes0 = new byte[] { function.bus.LoopId,
+                                            b0,
+                                            254, 0,Convert.ToByte(light.fadeTime) ,2,
+                                            (byte)((int)light.Attr_CCT.curValue/256),(byte)((int)light.Attr_CCT.curValue%256),
+                                            (byte)light.BlueColor,
+                                            0,0};
+                                ControlBytesSend(Command.SetLogicLoopColor, subnetId, deviceId, bytes0, 1);
+                                break;
                             case SPK.LightRGB:
-                                MainPage.Log($"rgb level : {light.brightness}");
                                 byte b = 100;//寮�鍏虫搷浣滀緷鎹畂n_off瀛楁锛屽疄闄呭紑鍏冲�间緷鎹産rightness锛屽綋on_off涓烘墦寮�锛宐rightness涓嶈兘涓�0
                                 if (light.trait_on_off.curValue.ToString() == "off")
                                 {
@@ -451,7 +468,7 @@
                         {
                             case SPK.AcStandard:
                                 var aC = function as AC;
-                                ControlBytesSend(Command.SetACMode, subnetId, deviceId, new byte[] { aC.bus.LoopId, (byte)aC.curTempType, 32, 32, 32, 32, 32, 0, aC.trait_on_off.curValue.ToString() == "on" ? (byte)1 : (byte)0, aC.curModeIndex, aC.curFanIndex, Convert.ToByte(aC.trait_temp.curValue), 0 });
+                                ControlBytesSend(Command.SetACMode, subnetId, deviceId, new byte[] { aC.bus.LoopId, (byte)aC.curTempType, 32, 32, 32, 32, 32, 0, aC.trait_on_off.curValue.ToString() == "on" ? (byte)1 : (byte)0, aC.curModeIndex(), aC.curFanIndex(), Convert.ToByte(aC.GetAttrState(FunctionAttributeKey.SetTemp)), 0 });
                                 //ControlBytesSend(Command.InstructionPanelKey, aC.bus_Data.SubnetID, aC.bus_Data.DeviceID, new byte[] { 3, aC.on_off == "on" ? (byte)1 : (byte)0, aC.bus_Data.loopId });
                                 foreach (var dic in commandDictionary)
                                 {
@@ -461,14 +478,14 @@
                                             ControlBytesSend(Command.InstructionPanelKey, aC.bus.SubnetID, aC.bus.DeviceID, new byte[] { 3, aC.trait_on_off.curValue.ToString() == "on" ? (byte)1 : (byte)0, aC.bus.LoopId });
                                             break;
                                         case "mode":
-                                            ControlBytesSend(Command.InstructionPanelKey, aC.bus.SubnetID, aC.bus.DeviceID, new byte[] { 6, aC.curModeIndex, aC.bus.LoopId });
+                                            ControlBytesSend(Command.InstructionPanelKey, aC.bus.SubnetID, aC.bus.DeviceID, new byte[] { 6, aC.curModeIndex(), aC.bus.LoopId });
                                             break;
                                         case "fan":
-                                            ControlBytesSend(Command.InstructionPanelKey, aC.bus.SubnetID, aC.bus.DeviceID, new byte[] { 5, aC.curFanIndex, aC.bus.LoopId });
+                                            ControlBytesSend(Command.InstructionPanelKey, aC.bus.SubnetID, aC.bus.DeviceID, new byte[] { 5, aC.curFanIndex(), aC.bus.LoopId });
                                             break;
                                         case "temp":
                                             byte modeKey = 4;
-                                            switch (aC.curModeIndex)
+                                            switch (aC.curModeIndex())
                                             {
                                                 case 3:
                                                     modeKey = 8;
@@ -486,7 +503,7 @@
                                                     modeKey = 2;
                                                     break;
                                             }
-                                            ControlBytesSend(Command.InstructionPanelKey, aC.bus.SubnetID, aC.bus.DeviceID, new byte[] { modeKey, Convert.ToByte(aC.trait_temp.curValue), aC.bus.LoopId });
+                                            ControlBytesSend(Command.InstructionPanelKey, aC.bus.SubnetID, aC.bus.DeviceID, new byte[] { modeKey, Convert.ToByte(aC.GetAttrState(FunctionAttributeKey.SetTemp)), aC.bus.LoopId });
                                             break;
                                         default:
                                             MainPage.Log($"鍔熻兘鏈敮鎸� : {dic.Key}");
@@ -588,6 +605,9 @@
                                 ControlBytesSend(Command.ReadLightAllLoopBrightness, subnetId, deviceId, new byte[] { });
                                 break;
                             case SPK.LightRGB:
+                                ControlBytesSend(Command.ReadLogicLoopColor, subnetId, deviceId, new byte[] { function.bus.LoopId});
+                                break;
+                            case SPK.LightCCT:
                                 ControlBytesSend(Command.ReadLogicLoopColor, subnetId, deviceId, new byte[] { function.bus.LoopId });
                                 break;
                         }

--
Gitblit v1.8.0