From 3f6685c77beeb12baf840733fb890860f4c26e7c Mon Sep 17 00:00:00 2001 From: mac <user@users-MacBook-Pro.local> Date: 星期四, 25 七月 2024 17:25:59 +0800 Subject: [PATCH] 2024年07月25日17:24:45 --- HDL_ON/DAL/DriverLayer/Control_Udp.cs | 257 +++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 198 insertions(+), 59 deletions(-) diff --git a/HDL_ON/DAL/DriverLayer/Control_Udp.cs b/HDL_ON/DAL/DriverLayer/Control_Udp.cs index e6eba3b..5f3e595 100644 --- a/HDL_ON/DAL/DriverLayer/Control_Udp.cs +++ b/HDL_ON/DAL/DriverLayer/Control_Udp.cs @@ -262,12 +262,17 @@ break; } break; + case FunctionAttributeKey.SetTemp: + ControlBytesSend(Command.InstructionPanelKey, f.localFunction.bus.SubnetID, f.localFunction.bus.DeviceID, new byte[] { + modeKey, Convert.ToByte(attr.value), f.localFunction.bus.LoopId }); + break; } ControlBytesSend(Command.InstructionPanelKey, f.localFunction.bus.SubnetID, f.localFunction.bus.DeviceID, new byte[] { 3, onoff, f.localFunction.bus.LoopId }); ControlBytesSend(Command.InstructionPanelKey, f.localFunction.bus.SubnetID, f.localFunction.bus.DeviceID, new byte[] { 6, mode, f.localFunction.bus.LoopId }); ControlBytesSend(Command.InstructionPanelKey, f.localFunction.bus.SubnetID, f.localFunction.bus.DeviceID, new byte[] { 5, fan, f.localFunction.bus.LoopId }); ControlBytesSend(Command.InstructionPanelKey, f.localFunction.bus.SubnetID, f.localFunction.bus.DeviceID, new byte[] { modeKey, modeKey, f.localFunction.bus.LoopId }); - } + + } break; case SPK.LightSwitch: case SPK.LightDimming: @@ -297,7 +302,8 @@ break; case SPK.LightRGB: break; - case SPK.HvacFloorHeat:case SPK.FloorHeatStandard: + case SPK.HvacFloorHeat: + case SPK.FloorHeatStandard: if (f.status.Find((obj)=>obj.key ==FunctionAttributeKey.Mode) == null) { foreach (var dic in f.status) @@ -387,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; } } } @@ -437,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, @@ -465,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, @@ -494,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, @@ -547,54 +583,157 @@ } else { - ControlBytesSend(Command.SetCurtainModelStutas, subnetId, deviceId, new byte[] { 17, 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: var ac = new AC(); + + byte onoff = 0; + onoff = function.trait_on_off.curValue.ToString() == "on" ? (byte)1 : (byte)0; + byte mode = 0; + mode = ac.GetModeIndex(function); + byte fan = 0; + fan = ac.GetFanIndex(function); + byte sanfan = 0; + byte temp = 16; + temp = Convert.ToByte(function.GetAttrState(FunctionAttributeKey.SetTemp)); foreach (var dic in commandDictionary) { switch (dic.Key) { case FunctionAttributeKey.OnOff: - ControlBytesSend(Command.InstructionPanelKey, function.bus.SubnetID, function.bus.DeviceID, new byte[] { 3, function.trait_on_off.curValue.ToString() == "on" ? (byte)1 : (byte)0, function.bus.LoopId }); + 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": - ControlBytesSend(Command.InstructionPanelKey, function.bus.SubnetID, function.bus.DeviceID, new byte[] { 6, ac.GetModeIndex(function), function.bus.LoopId }); - break; - case "fan": - ControlBytesSend(Command.InstructionPanelKey, function.bus.SubnetID, function.bus.DeviceID, new byte[] { 5, ac.GetFanIndex(function), function.bus.LoopId }); - break; - case FunctionAttributeKey.SetTemp: - byte modeKey = 4; - switch (ac.GetModeIndex(function)) + switch (dic.Value) { - case 3: - modeKey = 8; + case "auto": + mode = 3; break; - case 0: - modeKey = 4; + case "cool": + mode = 0; break; - case 1: - modeKey = 7; + case "heat": + mode = 1; break; - case 4: - modeKey = 19; + case "dry": + mode = 4; break; - case 2: - modeKey = 2; + case "fan": + mode = 2; + break; + default: + mode = 0; break; } - ControlBytesSend(Command.InstructionPanelKey, function.bus.SubnetID, function.bus.DeviceID, new byte[] { - modeKey, Convert.ToByte(function.GetAttrState(FunctionAttributeKey.SetTemp)), function.bus.LoopId }); + //ControlBytesSend(Command.InstructionPanelKey, function.bus.SubnetID, function.bus.DeviceID, + // new byte[] { 6, mode, function.bus.LoopId }); + break; + case "fan": + switch (dic.Value) + { + case "high": + fan = 1; + break; + case "medium": + fan = 2; + break; + case "low": + fan = 3; + break; + case "auto": + fan = 0; + break; + default: + fan = 0; + break; + } + //ControlBytesSend(Command.InstructionPanelKey, function.bus.SubnetID, function.bus.DeviceID, + // new byte[] { 5, fan, function.bus.LoopId }); + break; + case FunctionAttributeKey.SetTemp: + try + { + temp = Convert.ToByte(dic.Value); + } + catch + { + 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 break; default: MainPage.Log($"鍔熻兘鏈敮鎸� : {dic.Key}"); 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鎵) + 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}); + break; case SPK.HvacFloorHeat:case SPK.FloorHeatStandard: var fhTemp = new FloorHeating(); @@ -656,8 +795,8 @@ var dicTempString = ""; commandDictionary.TryGetValue("set_temp", out dicTempString); var dicTemp = Convert.ToByte(dicTempString); - var mode = function.GetAttrState(FunctionAttributeKey.Mode); - switch (mode) + var mode22 = function.GetAttrState(FunctionAttributeKey.Mode); + switch (mode22) { case "day": function.Fh_Mode_Temp["day"] = dicTemp; -- Gitblit v1.8.0