| | |
| | | { |
| | | public partial class Control |
| | | { |
| | | /// <summary> |
| | | /// 发送命令 |
| | | /// </summary> |
| | | public static void Send(Function function) |
| | | { |
| | | ControlBusScenes(function as Scene); |
| | | switch(function.functionCategory) |
| | | { |
| | | case FunctionCategory.Scene: |
| | | ControlScene(function as Scene); |
| | | break; |
| | | |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 场景控制入口 |
| | | /// </summary> |
| | | /// <param name="scene"></param> |
| | | static void ControlScene(Scene scene) |
| | | { |
| | | if (DB_ResidenceData.residenceData.GatewayType == 0) |
| | | { |
| | | ControlBusScenes(scene); |
| | | } |
| | | else |
| | | { |
| | | ControlAProtocolScene(scene); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// </summary> |
| | | static void ControlBusScenes(Scene scene) |
| | | { |
| | | foreach(var busSceneData in scene.bus_SceneData) |
| | | { |
| | | foreach(var function in DB_ResidenceData.functionList.GetAllDeviceFunctionList()) |
| | | { |
| | | if(busSceneData.Key == function.sid) |
| | | foreach (var function in scene.sceneFunctionList) |
| | | { |
| | | switch (function.functionType) |
| | | { |
| | | case FunctionType.Curtain: |
| | | ControlBytesSend(Command.SetCurtainModelStutas, function.bus_Data.SubnetID, function.bus_Data.DeviceID, busSceneData.Value); |
| | | byte curtainState = 0; |
| | | if (function.trait_on_off.value.ToString() == "on") |
| | | { |
| | | curtainState = 1; |
| | | } |
| | | else if (function.trait_on_off.value.ToString() =="off") |
| | | { |
| | | curtainState = 2; |
| | | } |
| | | ControlBytesSend(Command.SetCurtainModelStutas, function.bus_Data.SubnetID, function.bus_Data.DeviceID, |
| | | new byte[] { |
| | | function.bus_Data.LoopID, |
| | | curtainState, |
| | | }); |
| | | break; |
| | | case FunctionType.AC: |
| | | ControlBytesSend(Command.SetACMode, function.bus_Data.SubnetID, function.bus_Data.DeviceID, busSceneData.Value); |
| | | var aC = function as AC; |
| | | ControlBytesSend(Command.InstructionPanelKey, aC.bus_Data.SubnetID, aC.bus_Data.DeviceID, new byte[] { 3, aC.trait_on_off.value.ToString() == "on" ? (byte)1 : (byte)0, aC.bus_Data.LoopID }); |
| | | ControlBytesSend(Command.InstructionPanelKey, aC.bus_Data.SubnetID, aC.bus_Data.DeviceID, new byte[] { 6, aC.curModeIndex, aC.bus_Data.LoopID }); |
| | | ControlBytesSend(Command.InstructionPanelKey, aC.bus_Data.SubnetID, aC.bus_Data.DeviceID, new byte[] { 5, aC.curFanIndex, aC.bus_Data.LoopID }); |
| | | byte modeKey = 4; |
| | | switch (aC.curModeIndex) |
| | | { |
| | | 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, aC.bus_Data.SubnetID, aC.bus_Data.DeviceID, new byte[] { modeKey, Convert.ToByte(aC.trait_temp.value), aC.bus_Data.LoopID }); |
| | | |
| | | break; |
| | | case FunctionType.Relay: |
| | | case FunctionType.Dimmer: |
| | | ControlBytesSend(Command.SetSingleLight, function.bus_Data.SubnetID, function.bus_Data.DeviceID, busSceneData.Value); |
| | | byte brightness = 0; |
| | | if(function.trait_on_off.value.ToString() == "on") |
| | | { |
| | | var brightnessTrait = function.function.Find((obj) => obj.name == "brightness"); |
| | | if (brightnessTrait != null) |
| | | { |
| | | brightness = Convert.ToByte(brightnessTrait.value); |
| | | } |
| | | } |
| | | ControlBytesSend(Command.SetSingleLight, function.bus_Data.SubnetID, function.bus_Data.DeviceID, |
| | | new byte[] { |
| | | function.bus_Data.LoopID,brightness |
| | | }); |
| | | break; |
| | | case FunctionType.RGB: |
| | | ControlBytesSend(Command.SetLogicLoopColor, function.bus_Data.SubnetID, function.bus_Data.DeviceID, busSceneData.Value); |
| | | //ControlBytesSend(Command.SetLogicLoopColor, function.bus_Data.SubnetID, function.bus_Data.DeviceID, |
| | | // new byte[] { |
| | | // }); |
| | | break; |
| | | case FunctionType.FloorHeating: |
| | | var fh = function as FloorHeating; |
| | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 控制a协议场景 |
| | | /// </summary> |
| | | /// <param name="scene"></param> |
| | | static void ControlAProtocolScene(Scene scene) |
| | | { |
| | | var sendSidObj = new AProtocolSendingObject(); |
| | | //sendSidObj.from_oid = ""; |
| | | //sendSidObj.to_oid = ""; |
| | | sendSidObj.time_stamp = ""; |
| | | sendSidObj.type = "device_sid"; |
| | | sendSidObj.command = "get_list_response"; |
| | | //转换成bus需要的数据格式 |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | switch (dic.Key) |
| | | { |
| | | case "on_off": |
| | | Control.ControlBytesSend(Command.InstructionPanelKey, aC.bus_Data.SubnetID, aC.bus_Data.DeviceID, new byte[] { 3, aC.trait_on_off.value.ToString() == "on" ? (byte)1 : (byte)0, aC.bus_Data.LoopID }); |
| | | ControlBytesSend(Command.InstructionPanelKey, aC.bus_Data.SubnetID, aC.bus_Data.DeviceID, new byte[] { 3, aC.trait_on_off.value.ToString() == "on" ? (byte)1 : (byte)0, aC.bus_Data.LoopID }); |
| | | break; |
| | | case "mode": |
| | | Control.ControlBytesSend(Command.InstructionPanelKey, aC.bus_Data.SubnetID, aC.bus_Data.DeviceID, new byte[] { 6, aC.curModeIndex, aC.bus_Data.LoopID }); |
| | | ControlBytesSend(Command.InstructionPanelKey, aC.bus_Data.SubnetID, aC.bus_Data.DeviceID, new byte[] { 6, aC.curModeIndex, aC.bus_Data.LoopID }); |
| | | break; |
| | | case "fan": |
| | | Control.ControlBytesSend(Command.InstructionPanelKey, aC.bus_Data.SubnetID, aC.bus_Data.DeviceID, new byte[] { 5, aC.curFanIndex, aC.bus_Data.LoopID }); |
| | | ControlBytesSend(Command.InstructionPanelKey, aC.bus_Data.SubnetID, aC.bus_Data.DeviceID, new byte[] { 5, aC.curFanIndex, aC.bus_Data.LoopID }); |
| | | break; |
| | | case "temp": |
| | | byte modeKey = 4; |
| | |
| | | modeKey = 2; |
| | | break; |
| | | } |
| | | Control.ControlBytesSend(Command.InstructionPanelKey, aC.bus_Data.SubnetID, aC.bus_Data.DeviceID, new byte[] { modeKey, Convert.ToByte(aC.trait_temp.value), aC.bus_Data.LoopID }); |
| | | ControlBytesSend(Command.InstructionPanelKey, aC.bus_Data.SubnetID, aC.bus_Data.DeviceID, new byte[] { modeKey, Convert.ToByte(aC.trait_temp.value), aC.bus_Data.LoopID }); |
| | | break; |
| | | default: |
| | | MainPage.Log($"功能未支持 : {dic.Key}"); |