From a40848272e33822f72a7fe0310f079717bf73f23 Mon Sep 17 00:00:00 2001
From: wxr <wxr@hdlchina.com.cn>
Date: 星期五, 18 十月 2024 16:21:39 +0800
Subject: [PATCH] 修复金茂科技系统,金茂光伏问题

---
 HDL_ON/DAL/DriverLayer/Control_Udp.cs |  203 +++++++++++++++++++++++++++++---------------------
 1 files changed, 118 insertions(+), 85 deletions(-)

diff --git a/HDL_ON/DAL/DriverLayer/Control_Udp.cs b/HDL_ON/DAL/DriverLayer/Control_Udp.cs
index 2791215..3dceeb3 100644
--- a/HDL_ON/DAL/DriverLayer/Control_Udp.cs
+++ b/HDL_ON/DAL/DriverLayer/Control_Udp.cs
@@ -104,7 +104,7 @@
             try
             {
                 //璐﹀彿娌$櫥褰曚笉鍥炲
-                if ( UserInfo.Current == null || ! UserInfo.Current.IsLogin)
+                if ( UserInfo.Current == null )///|| ! UserInfo.Current.IsLogin)
                 {
                     return;
                 }
@@ -197,7 +197,7 @@
                             }
                             break;
                         case SPK.AcStandard:
-                        case SPK.HvacAC:
+                        case SPK.HvacAC:case SPK.HvacAcPanel:
                             AC acTemp = new AC();
                             byte onoff = 0;
                             byte mode = 0;
@@ -302,7 +302,8 @@
                             break;
                         case SPK.LightRGB:
                             break;
-                        case SPK.HvacFloorHeat:case SPK.FloorHeatStandard:
+                        case SPK.HvacFloorHeat:case SPK.HvacFloorHeatPanel:
+                        case SPK.FloorHeatStandard:
                             if (f.status.Find((obj)=>obj.key ==FunctionAttributeKey.Mode) == null)
                             {
                                 foreach (var dic in f.status)
@@ -392,6 +393,27 @@
                                 }
                             }
                             break;
+                        case SPK.OtherCommon://2024-02-01 15:19:28
+                            foreach (var attr in f.status)
+                            {
+                                if (attr.key == FunctionAttributeKey.OnOff)
+                                {
+                                    byte onOffValue = 0;
+                                    switch (attr.value)
+                                    {
+                                        case "on":
+                                            onOffValue = 0;
+                                            break;
+                                        case "off":
+                                            onOffValue = 255;
+                                            break;
+                                    }
+                                    ControlBytesSend(Command.SetCommonSwitch, f.localFunction.bus.SubnetID, f.localFunction.bus.DeviceID,
+                                        new byte[] { f.localFunction.bus.LoopId, onOffValue });
+                                    break;
+                                }
+                            }
+                            break;
                     }
                 }
             }
@@ -442,21 +464,24 @@
                 {
                     case SPK.LightCCT:
                         #region cct light
-                        byte b0 = 100;
-                        if (commandDictionary.ContainsKey(FunctionAttributeKey.OnOff))
+                        byte b0 = Convert.ToByte(function.lastBrightness);
+                        if (commandDictionary.ContainsKey(FunctionAttributeKey.Brightness))
                         {
-                            if (function.trait_on_off.curValue.ToString() == "off")
-                            {
-                                b0 = 0;
-                            }
-                            else
-                            {
-                                b0 = function.lastBrightness == 0 ? (byte)100 : Convert.ToByte(function.lastBrightness);
-                            }
+                            b0 = Convert.ToByte(function.GetAttrState(FunctionAttributeKey.Brightness));
                         }
                         else
                         {
-                            b0 = Convert.ToByte(function.GetAttrState(FunctionAttributeKey.Brightness));
+                            if (commandDictionary.ContainsKey(FunctionAttributeKey.OnOff))
+                            {
+                                if (function.trait_on_off.curValue.ToString() == "off")
+                                {
+                                    b0 = 0;
+                                }
+                                else
+                                {
+                                    b0 = function.lastBrightness == 0 ? (byte)100 : Convert.ToByte(function.lastBrightness);
+                                }
+                            }
                         }
                         var bytes0 = new byte[] { function.bus.LoopId,
                                             b0,
@@ -470,21 +495,24 @@
                         break;
                     case SPK.LightRGB:
                         #region rgb light
-                        byte b = 100;
-                        if (commandDictionary.ContainsKey(FunctionAttributeKey.OnOff))
+                        byte b = Convert.ToByte(function.lastBrightness);
+                        if (commandDictionary.ContainsKey(FunctionAttributeKey.Brightness))
                         {
-                            if (function.trait_on_off.curValue.ToString() == "off")
-                            {
-                                b = 0;
-                            }
-                            else
-                            {
-                                b = function.lastBrightness == 0 ? (byte)100 : Convert.ToByte(function.lastBrightness);
-                            }
+                            b = Convert.ToByte(function.GetAttrState(FunctionAttributeKey.Brightness));
                         }
                         else
                         {
-                            b = Convert.ToByte(function.GetAttrState(FunctionAttributeKey.Brightness));
+                            if (commandDictionary.ContainsKey(FunctionAttributeKey.OnOff))
+                            {
+                                if (function.trait_on_off.curValue.ToString() == "off")
+                                {
+                                    b = 0;
+                                }
+                                else
+                                {
+                                    b = function.lastBrightness == 0 ? (byte)100 : Convert.ToByte(function.lastBrightness);
+                                }
+                            }
                         }
                         var tempLight = new Light();
                         var bytes = new byte[] { function.bus.LoopId,
@@ -499,21 +527,24 @@
                         break;
                     case SPK.LightDimming:
                         #region dimming light
-                        byte b1 = 100;
-                        if (commandDictionary.ContainsKey(FunctionAttributeKey.OnOff))
+                        byte b1 = Convert.ToByte(function.lastBrightness);
+                        if (commandDictionary.ContainsKey(FunctionAttributeKey.Brightness))
                         {
-                            if (function.trait_on_off.curValue.ToString() == "off")
-                            {
-                                b1 = 0;
-                            }
-                            else
-                            {
-                                b1 = function.lastBrightness == 0 ? (byte)100 : Convert.ToByte(function.lastBrightness);
-                            }
+                            b1 = Convert.ToByte(function.GetAttrState(FunctionAttributeKey.Brightness));
                         }
                         else
                         {
-                            b1 = Convert.ToByte(function.GetAttrState(FunctionAttributeKey.Brightness));
+                            if (commandDictionary.ContainsKey(FunctionAttributeKey.OnOff))
+                            {
+                                if (function.trait_on_off.curValue.ToString() == "off")
+                                {
+                                    b1 = 0;
+                                }
+                                else
+                                {
+                                    b1 = function.lastBrightness == 0 ? (byte)100 : Convert.ToByte(function.lastBrightness);
+                                }
+                            }
                         }
                         ControlBytesSend(Command.SetSingleLight, subnetId, deviceId, new byte[] {
                                             function.bus.LoopId,
@@ -552,14 +583,34 @@
                         }
                         else
                         {
-                            ControlBytesSend(Command.SetCurtainModelStutas, subnetId, deviceId, new byte[] { (byte)(((int)function.bus.LoopId) + 16), Convert.ToByte(function.GetAttrState(FunctionAttributeKey.Percent)) });
+                            if (commandDictionary.ContainsKey(FunctionAttributeKey.Percent))
+                            {
+                                ControlBytesSend(Command.SetCurtainModelStutas, subnetId, deviceId, new byte[] { (byte)(((int)function.bus.LoopId) + 16), Convert.ToByte(function.GetAttrState(FunctionAttributeKey.Percent)) });
+                            }
+                            else
+                            {
+
+                                byte tempCurtainState = 0;
+                                if (function.trait_on_off.curValue.ToString() == "stop")
+                                {
+                                    tempCurtainState = 0;
+                                }
+                                else if (function.trait_on_off.curValue.ToString() == "on")
+                                {
+                                    tempCurtainState = 1;
+                                }
+                                else
+                                {
+                                    tempCurtainState = 2;
+                                }
+                                ControlBytesSend(Command.SetCurtainModelStutas, subnetId, deviceId, new byte[] { function.bus.LoopId, tempCurtainState });
+                            }
 
                         }
                         break;
                     case SPK.AcStandard:
-                    case SPK.HvacAC:
+                    case SPK.HvacAC:case SPK.HvacAcPanel:
                         var ac = new AC();
-
                         byte onoff = 0;
                         onoff = function.trait_on_off.curValue.ToString() == "on" ? (byte)1 : (byte)0;
                         byte mode = 0;
@@ -569,28 +620,34 @@
                         byte sanfan = 0;
                         byte temp = 16;
                         temp = Convert.ToByte(function.GetAttrState(FunctionAttributeKey.SetTemp));
+                        byte coolTemp = Convert.ToByte(function.GetAttrState(FunctionAttributeKey.CoolTemperatrue));
+                        byte heatTemp = Convert.ToByte(function.GetAttrState(FunctionAttributeKey.HeatTemperatrue));
+                        byte autoTemp = Convert.ToByte(function.GetAttrState(FunctionAttributeKey.AutoTemperatrue));
+                        byte dehumiTemp = Convert.ToByte(function.GetAttrState(FunctionAttributeKey.DehumiTemperatrue));
                         foreach (var dic in commandDictionary)
                         {
                             switch (dic.Key)
                             {
                                 case FunctionAttributeKey.OnOff:
                                     onoff = dic.Value == "on" ? (byte)1 : (byte)0;
-                                    //ControlBytesSend(Command.InstructionPanelKey, function.bus.SubnetID, function.bus.DeviceID,
-                                    //    new byte[] { 3, onoff, function.bus.LoopId });
                                     break;
                                 case "mode":
                                     switch (dic.Value)
                                     {
                                         case "auto":
                                             mode = 3;
+                                            temp = autoTemp;
                                             break;
                                         case "cool":
                                             mode = 0;
+                                            temp = coolTemp;
                                             break;
                                         case "heat":
                                             mode = 1;
+                                            temp = heatTemp;
                                             break;
                                         case "dry":
+                                            temp = dehumiTemp;
                                             mode = 4;
                                             break;
                                         case "fan":
@@ -600,8 +657,6 @@
                                             mode = 0;
                                             break;
                                     }
-                                    //ControlBytesSend(Command.InstructionPanelKey, function.bus.SubnetID, function.bus.DeviceID,
-                                    //    new byte[] { 6, mode, function.bus.LoopId });
                                     break;
                                 case "fan":
                                     switch (dic.Value)
@@ -622,8 +677,6 @@
                                             fan = 0;
                                             break;
                                     }
-                                    //ControlBytesSend(Command.InstructionPanelKey, function.bus.SubnetID, function.bus.DeviceID,
-                                    //    new byte[] { 5, fan, function.bus.LoopId });
                                     break;
                                 case FunctionAttributeKey.SetTemp:
                                     try
@@ -634,28 +687,6 @@
                                     {
                                         temp = 16;
                                     }
-                                    //byte modeKey = 4;
-                                    //switch (ac.GetModeIndex(function))
-                                    //{
-                                    //    case 3:
-                                    //        modeKey = 8;
-                                    //        break;
-                                    //    case 0:
-                                    //        modeKey = 4;
-                                    //        break;
-                                    //    case 1:
-                                    //        modeKey = 7;
-                                    //        break;
-                                    //    case 4:
-                                    //        modeKey = 19;
-                                    //        break;
-                                    //    case 2:
-                                    //        modeKey = 2;
-                                    //        break;
-                                    //}
-                                    
-                                    //ControlBytesSend(Command.InstructionPanelKey, function.bus.SubnetID, function.bus.DeviceID, new byte[] {
-                                    //            modeKey, temp, function.bus.LoopId });
                                     break;
                                 case FunctionAttributeKey.Swing:
                                     //sanfan
@@ -665,25 +696,26 @@
                                     break;
                             }
                         }
-                        /// 璁剧疆绌鸿皟妯″潡鍛戒护
-                        /// 1绌鸿皟鍙�(1-128) 
-                        ///2娓╁害妯″紡(鎽勬皬Celsius:0锛屽崕姘廎ahrenheit:1)                                     
-                        ///3鐜娓╁害 (鎽勬皬0-40锛屽崕姘�32-99)    
-                        ///4鍒跺喎鎺у埗娓╁害(鎽勬皬0-30锛屽崕姘�32-86)    
-                        ///5鍒剁儹鎺у埗娓╁害(鎽勬皬0-30锛屽崕姘�32-86)
-                        ///6鑷姩鎺у埗娓╁害(鎽勬皬0-30锛屽崕姘�32-86)                                                                                           
-                        ///7闄ゆ箍鎺у埗娓╁害(鎽勬皬0-30锛屽崕姘�32-86)
-                        ///8妞掔饥鍋堝浣裤伔楂?  楂�4bit妯″紡(0 鍒跺喎锛�1鍒剁儹锛�2閫氶)  浣�4bit椋庨��(0 鑷姩锛�1楂橀?椋庯紝3浣庨)
-                        ///9绌鸿皟寮�鍏�                 (1寮�0鍏�)           
-                        ///10璁剧疆妯″紡               0 鍒跺喎1鍒剁儹锛�2閫氶锛�3鑷姩锛�4闄ゆ箍
-                        ///11璁剧疆椋庨��                0 鑷姩锛�1楂橀2涓锛�3浣庨          
-                        ///12宸ヤ綔妯℃帶鍒舵俯鑲氭幃鎽勬皬0-30锛屽崕姘�32-86)         
-                        ///13鎵妯″紡锛氶珮4bit(瀹為檯鎵鐘舵�侊細0涓嶆壂椋庯紝1鎵)锛屼綆4bit(璁剧疆鎵妯″紡锛�0涓嶆壂椋庯紝1鎵)
+                        switch (mode)
+                        {
+                            case 0:
+                                coolTemp = temp;
+                                break;
+                            case 1:
+                                heatTemp = temp;
+                                break;
+                            case 3:
+                                autoTemp = temp;
+                                break;
+                            case 4:
+                                dehumiTemp = temp;
+                                break;
+                        }
                         ControlBytesSend(Command.SetACMode, function.bus.SubnetID, function.bus.DeviceID, new byte[] { function.bus.LoopId,
-                        0,0,0,0,0,0,0,onoff,mode,fan,temp,sanfan});
+                        0,0,coolTemp,heatTemp,autoTemp,dehumiTemp,0,onoff,mode,fan,temp,sanfan});
 
                         break;
-                    case SPK.HvacFloorHeat:case SPK.FloorHeatStandard:
+                    case SPK.HvacFloorHeat:case SPK.FloorHeatStandard:case SPK.HvacFloorHeatPanel:
                         var fhTemp = new FloorHeating();
                         if (function.Fh_Mode_Temp.Count == 4)
                         {
@@ -905,10 +937,10 @@
                         ControlBytesSend(Command.ReadCurtainStatus, subnetId, deviceId, new byte[] { function.bus.LoopId });
                         break;
                     case SPK.AcStandard:
-                    case SPK.HvacAC:
+                    case SPK.HvacAC:case SPK.HvacAcPanel:
                         ControlBytesSend(Command.ReadACMode, subnetId, deviceId, new byte[] { function.bus.LoopId });
                         break;
-                    case SPK.HvacFloorHeat:case SPK.FloorHeatStandard:
+                    case SPK.HvacFloorHeat:case SPK.FloorHeatStandard:case SPK.HvacFloorHeatPanel:
                         ControlBytesSend(Command.ReadFloorHeat, subnetId, deviceId, new byte[] { function.bus.LoopId });
                         break;
                     case SPK.HvacFan:
@@ -1166,6 +1198,7 @@
         /// </summary>
         public void SearchLocalGateway(bool broadcast = false)
         {
+            //MainPage.Log("SearchLocalGateway");
             try
             {
                 var sendJob = new JObject { { "id", Control.Ins.msg_id.ToString() }, { "time_stamp", Utlis.GetTimestamp ()} };

--
Gitblit v1.8.0