| | |
| | | { |
| | | 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 scene.sceneFunctionList) |
| | | { |
| | | foreach(var function in DB_ResidenceData.functionList.GetAllDeviceFunctionList()) |
| | | switch (function.functionType) |
| | | { |
| | | if(busSceneData.Key == function.sid) |
| | | { |
| | | switch (function.functionType) |
| | | case FunctionType.Curtain: |
| | | byte curtainState = 0; |
| | | if (function.trait_on_off.value.ToString() == "on") |
| | | { |
| | | case FunctionType.Curtain: |
| | | ControlBytesSend(Command.SetCurtainModelStutas, function.bus_Data.SubnetID, function.bus_Data.DeviceID, busSceneData.Value); |
| | | 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: |
| | | 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 FunctionType.AC: |
| | | ControlBytesSend(Command.SetACMode, function.bus_Data.SubnetID, function.bus_Data.DeviceID, busSceneData.Value); |
| | | case 0: |
| | | modeKey = 4; |
| | | break; |
| | | case FunctionType.Relay: |
| | | case FunctionType.Dimmer: |
| | | ControlBytesSend(Command.SetSingleLight, function.bus_Data.SubnetID, function.bus_Data.DeviceID, busSceneData.Value); |
| | | case 1: |
| | | modeKey = 7; |
| | | break; |
| | | case FunctionType.RGB: |
| | | ControlBytesSend(Command.SetLogicLoopColor, function.bus_Data.SubnetID, function.bus_Data.DeviceID, busSceneData.Value); |
| | | case 4: |
| | | modeKey = 19; |
| | | break; |
| | | case FunctionType.FloorHeating: |
| | | var fh = function as FloorHeating; |
| | | if (fh.modeTemp.Count == 4) |
| | | { |
| | | byte b1 = fh.trait_on_off.value.ToString() == "on" ? (byte)1 : (byte)0; |
| | | if (fh.workMode > 0) |
| | | { |
| | | b1 += (byte)(16 + fh.workMode); |
| | | } |
| | | ControlBytesSend(Command.SetFloorHeat, function.bus_Data.SubnetID, function.bus_Data.DeviceID, new byte[] { fh.bus_Data.LoopID, b1, (byte)fh.curTempType, fh.curModeIndex, fh.modeTemp["normal"], fh.modeTemp["day"], fh.modeTemp["night"], fh.modeTemp["away"], 0, 0 }); |
| | | } |
| | | break; |
| | | case FunctionType.Socket: |
| | | var s = function as SwitchSocket; |
| | | ControlBytesSend(Command.SetSingleLight, function.bus_Data.SubnetID, function.bus_Data.DeviceID, new byte[] { s.bus_Data.LoopID, s.trait_on_off.value.ToString() == "on" ? (byte)100 : (byte)0 }); |
| | | 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: |
| | | 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, |
| | | // new byte[] { |
| | | // }); |
| | | break; |
| | | case FunctionType.FloorHeating: |
| | | var fh = function as FloorHeating; |
| | | if (fh.modeTemp.Count == 4) |
| | | { |
| | | byte b1 = fh.trait_on_off.value.ToString() == "on" ? (byte)1 : (byte)0; |
| | | if (fh.workMode > 0) |
| | | { |
| | | b1 += (byte)(16 + fh.workMode); |
| | | } |
| | | ControlBytesSend(Command.SetFloorHeat, function.bus_Data.SubnetID, function.bus_Data.DeviceID, new byte[] { fh.bus_Data.LoopID, b1, (byte)fh.curTempType, fh.curModeIndex, fh.modeTemp["normal"], fh.modeTemp["day"], fh.modeTemp["night"], fh.modeTemp["away"], 0, 0 }); |
| | | } |
| | | break; |
| | | case FunctionType.Socket: |
| | | var s = function as SwitchSocket; |
| | | ControlBytesSend(Command.SetSingleLight, function.bus_Data.SubnetID, function.bus_Data.DeviceID, new byte[] { s.bus_Data.LoopID, s.trait_on_off.value.ToString() == "on" ? (byte)100 : (byte)0 }); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | /// <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}"); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | //switch (function.functionCategory) |
| | | //{ |
| | | // case FunctionCategory.Light: |
| | | // var light = function as Light; |
| | | // switch (light.functionType) |
| | | // { |
| | | // case FunctionType.RGB: |
| | | // MainPage.Log($"rgb level : {light.brightness}"); |
| | | // byte b = 100;//开关操作依据on_off字段,实际开关值依据brightness,当on_off为打开,brightness不能为0 |
| | | // if (light.on_off == "off") |
| | | // { |
| | | // b = 0; |
| | | // } |
| | | // else |
| | | // { |
| | | // b = (byte)light.brightness == 0 ? (byte)100 : (byte)light.brightness; |
| | | // } |
| | | // var bytes = new byte[] { function.bus_Data.LoopID, |
| | | // b, |
| | | // 254, 0,0,3, |
| | | // (byte)light.redColor,(byte)light.greenColor, |
| | | // (byte)light.blueColor, |
| | | // 0,0}; |
| | | // MainPage.Log($"rgb level1 : {light.brightness}"); |
| | | // ControlBytesSend(Command.SetLogicLoopColor, subnetId, deviceId, bytes, 1); |
| | | // MainPage.Log($"rgb level2 : {light.brightness}"); |
| | | // break; |
| | | // case FunctionType.Dimmer: |
| | | // byte b1 = 100; |
| | | // if (light.on_off == "off") |
| | | // { |
| | | // b1 = 0; |
| | | // } |
| | | // else |
| | | // { |
| | | // b1 = (byte)light.brightness == 0 ? (byte)100 : (byte)light.brightness; |
| | | // } |
| | | // ControlBytesSend(Command.SetSingleLight, subnetId, deviceId, new byte[] { |
| | | // function.bus_Data.LoopID, |
| | | // b1, |
| | | // 0, 0 }); |
| | | // break; |
| | | // case FunctionType.Relay: |
| | | // ControlBytesSend(Command.SetSingleLight, subnetId, deviceId, new byte[] { function.bus_Data.LoopID, light.on_off == "on" ? (byte)100 : (byte)0, 0, 0 }); |
| | | // break; |
| | | // } |
| | | // break; |
| | | // case FunctionCategory.Curtain: |
| | | // var curtain = function as Curtain; |
| | | // switch (curtain.functionType) |
| | | // { |
| | | // case FunctionType.Curtain: |
| | | // byte b1 = 0; |
| | | // if (curtain.on_off == "stop") |
| | | // { |
| | | // b1 = 0; |
| | | // } |
| | | // else if (curtain.on_off == "on") |
| | | // { |
| | | // b1 = 1; |
| | | // } |
| | | // else |
| | | // { |
| | | // b1 = 2; |
| | | // } |
| | | // ControlBytesSend(Command.SetCurtainModelStutas, subnetId, deviceId, new byte[] { curtain.bus_Data.LoopID, b1 }); |
| | | // break; |
| | | // case FunctionType.MotorCurtain: |
| | | // case FunctionType.RollingShutter: |
| | | // if (curtain.on_off == "stop") |
| | | // { |
| | | // ControlBytesSend(Command.SetCurtainModelStutas, subnetId, deviceId, new byte[] { curtain.bus_Data.LoopID, 0 }); |
| | | // } |
| | | // else if (curtain.on_off == "on") |
| | | // { |
| | | // ControlBytesSend(Command.SetCurtainModelStutas, subnetId, deviceId, new byte[] { 17, 100 }); |
| | | // } |
| | | // else if (curtain.on_off == "off") |
| | | // { |
| | | // ControlBytesSend(Command.SetCurtainModelStutas, subnetId, deviceId, new byte[] { 17, 0 }); |
| | | // } |
| | | // break; |
| | | // } |
| | | // break; |
| | | // case FunctionCategory.Thermostat: |
| | | // switch (function.functionType) |
| | | // { |
| | | // case FunctionType.AC: |
| | | // var aC = function as AC; |
| | | // ControlBytesSend(Command.SetACMode, subnetId, deviceId, new byte[] { aC.bus_Data.LoopID, (byte)aC.curTempType, 32, 32, 32, 32, 32, 0, aC.on_off == "on" ? (byte)1 : (byte)0, aC.curModeIndex, aC.curFanIndex, (byte)aC.curTemp, 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 }); |
| | | // break; |
| | | // case FunctionType.FloorHeating: |
| | | // var fh = function as FloorHeating; |
| | | // if (fh.modeTemp.Count == 4) |
| | | // { |
| | | // byte b1 = fh.on_off == "on" ? (byte)1 : (byte)0; |
| | | // if (fh.workMode > 0) |
| | | // { |
| | | // b1 += (byte)(16 + fh.workMode); |
| | | // } |
| | | // ControlBytesSend(Command.SetFloorHeat, subnetId, deviceId, new byte[] { fh.bus_Data.LoopID, b1, (byte)fh.curTempType, fh.curModeIndex, fh.modeTemp["ordinary"], fh.modeTemp["day"], fh.modeTemp["night"], fh.modeTemp["away"], 0, 0 }); |
| | | // } |
| | | // //else |
| | | // //{ |
| | | // // ControlBytesSend(Command.ReadFloorHeat, subnetId,deviceId,new byte[] { fh.bus_Data.LoopID}); |
| | | // //} |
| | | // break; |
| | | // } |
| | | // break; |
| | | // case FunctionCategory.Electrical: |
| | | // switch (function.functionType) |
| | | // { |
| | | // case FunctionType.Fan: |
| | | // var fan = function as Fan; |
| | | // if (fan.on_off == "on") |
| | | // { |
| | | // ControlBytesSend(Command.SetSingleLight, subnetId, deviceId, new byte[] { fan.bus_Data.LoopID, (byte)fan.openLevel }); |
| | | // } |
| | | // { |
| | | // ControlBytesSend(Command.SetSingleLight, subnetId, deviceId, new byte[] { fan.bus_Data.LoopID, 0 }); |
| | | // } |
| | | // break; |
| | | // } |
| | | // break; |
| | | // case FunctionCategory.SwitchDevice: |
| | | // switch (function.functionType) |
| | | // { |
| | | // case FunctionType.Socket: |
| | | // var s = function as SwitchSocket; |
| | | // ControlBytesSend(Command.SetSingleLight, subnetId, deviceId, new byte[] { s.bus_Data.LoopID, s.on_off == "on" ? (byte)100 : (byte)0 }); |
| | | // break; |
| | | // } |
| | | // break; |
| | | //} |
| | | |
| | | |
| | | } |