| | |
| | | using HDL_ON.DAL; |
| | | using HDL_ON.DAL.Net; |
| | | using HDL_ON.Entity; |
| | | using Newtonsoft.Json.Linq; |
| | | using Shared; |
| | | |
| | | namespace HDL_ON |
| | | { |
| | |
| | | /// <param name="commandString"></param> |
| | | /// <param name="function"></param> |
| | | /// <returns></returns> |
| | | public static void Send(CommandType_A commandType, Function function) |
| | | public static void SendWriteCommand(Function function, Dictionary<string, string> commandDictionary) |
| | | { |
| | | function.usageCount++; |
| | | function.refreshTime = DateTime.Now; |
| | | if (function.bus_Data!=null) |
| | | if (function.bus_Data != null) |
| | | { |
| | | try |
| | | { |
| | | ControlBusData(function, commandType); |
| | | WriteBusData(function, commandDictionary); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MainPage.Log($"发送数据异常: {ex.Message}"); |
| | | MainPage.Log($"发送数据异常: {ex.Message}"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | var commandObj = function.GetSendJObject(commandType); |
| | | var commandObj = function.GetSendJObject(CommandType_A.write); |
| | | var commandString = Newtonsoft.Json.JsonConvert.SerializeObject(commandObj); |
| | | var commandBytes = CommonPage.MyEncodingUTF8.GetBytes(commandString); |
| | | MqttCommon.MqttRemoteSend(commandBytes); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 发送读取命令 |
| | | /// 自动判断是否为A协议设备 |
| | | /// </summary> |
| | | /// <param name="function"></param> |
| | | public static void SendReadCommand(Function function) |
| | | { |
| | | //function.usageCount++; |
| | | function.refreshTime = DateTime.Now; |
| | | if (function.bus_Data != null) |
| | | { |
| | | try |
| | | { |
| | | ReadBusData(function); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MainPage.Log($"发送数据异常: {ex.Message}"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | var commandObj = function.GetSendJObject(CommandType_A.read); |
| | | var commandString = Newtonsoft.Json.JsonConvert.SerializeObject(commandObj); |
| | | var commandBytes = CommonPage.MyEncodingUTF8.GetBytes(commandString); |
| | | MqttCommon.MqttRemoteSend(commandBytes); |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 将A协议控制数据转换程bus协议的控制数据 |
| | | /// 控制bus设备 |
| | | /// </summary> |
| | | /// <param name="commandString"></param> |
| | | /// <returns></returns> |
| | | static void ControlBusData(Function function, CommandType_A command) |
| | | static void WriteBusData(Function function, Dictionary<string, string> commandDictionary) |
| | | { |
| | | try |
| | | { |
| | |
| | | var deviceId = function.bus_Data.DeviceID; |
| | | var loopId = function.bus_Data.LoopID; |
| | | |
| | | switch (command) |
| | | |
| | | switch (function.functionCategory) |
| | | { |
| | | case CommandType_A.write: |
| | | switch (function.functionCategory) |
| | | case FunctionCategory.Light: |
| | | var light = function as Light; |
| | | switch (light.functionType) |
| | | { |
| | | 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") |
| | | { |
| | | 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 = 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[] { |
| | | ControlBytesSend(Command.SetLogicLoopColor, subnetId, deviceId, bytes, 1); |
| | | 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; |
| | | } |
| | | 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; |
| | | case FunctionCategory.Thermostat: |
| | | switch (function.functionType) |
| | | } |
| | | break; |
| | | case FunctionCategory.Curtain: |
| | | var curtain = function as Curtain; |
| | | switch (curtain.functionType) |
| | | { |
| | | case FunctionType.Curtain: |
| | | byte b1 = 0; |
| | | if (curtain.on_off == "stop") |
| | | { |
| | | 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 }); |
| | | 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; |
| | | b1 = 0; |
| | | } |
| | | break; |
| | | case FunctionCategory.Electrical: |
| | | switch (function.functionType) |
| | | else if (curtain.on_off == "on") |
| | | { |
| | | 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; |
| | | b1 = 1; |
| | | } |
| | | break; |
| | | case FunctionCategory.SwitchDevice: |
| | | switch(function.functionType) |
| | | else |
| | | { |
| | | 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; |
| | | 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 CommandType_A.read: |
| | | switch (function.functionCategory) |
| | | case FunctionCategory.Thermostat: |
| | | switch (function.functionType) |
| | | { |
| | | case FunctionCategory.Light: |
| | | 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 }); |
| | | foreach (var dic in commandDictionary) |
| | | { |
| | | case FunctionType.Relay: |
| | | case FunctionType.Dimmer: |
| | | ControlBytesSend(Command.ReadLightSingleLoopBrightness, subnetId, deviceId, new byte[] { function.bus_Data.LoopID }); |
| | | break; |
| | | case FunctionType.RGB: |
| | | ControlBytesSend(Command.ReadLogicLoopColor, subnetId, deviceId, new byte[] { function.bus_Data.LoopID }); |
| | | break; |
| | | switch (dic.Key) |
| | | { |
| | | case "on_off": |
| | | Control.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 "mode": |
| | | Control.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 }); |
| | | break; |
| | | case "temp": |
| | | 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; |
| | | } |
| | | Control.ControlBytesSend(Command.InstructionPanelKey, aC.bus_Data.SubnetID, aC.bus_Data.DeviceID, new byte[] { modeKey, Convert.ToByte(aC.curTemp), aC.bus_Data.LoopID }); |
| | | break; |
| | | default: |
| | | MainPage.Log($"功能未支持 : {dic.Key}"); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | break; |
| | | case FunctionCategory.Curtain: |
| | | switch (function.functionType) |
| | | case FunctionType.FloorHeating: |
| | | var fh = function as FloorHeating; |
| | | if (fh.modeTemp.Count == 4) |
| | | { |
| | | case FunctionType.Curtain: |
| | | case FunctionType.MotorCurtain: |
| | | case FunctionType.RollingShutter: |
| | | ControlBytesSend(Command.ReadCurtainStatus, subnetId, deviceId, new byte[] { function.bus_Data.LoopID }); |
| | | break; |
| | | 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 }); |
| | | } |
| | | break; |
| | | case FunctionCategory.Thermostat: |
| | | switch (function.functionType) |
| | | { |
| | | case FunctionType.AC: |
| | | ControlBytesSend(Command.ReadACMode, subnetId, deviceId, new byte[] { function.bus_Data.LoopID }); |
| | | break; |
| | | case FunctionType.FloorHeating: |
| | | ControlBytesSend(Command.ReadFloorHeat, subnetId, deviceId, new byte[] { function.bus_Data.LoopID }); |
| | | break; |
| | | } |
| | | break; |
| | | case FunctionCategory.Electrical: |
| | | switch (function.functionType) |
| | | { |
| | | case FunctionType.Fan: |
| | | var fan = function as Fan; |
| | | ControlBytesSend(Command.SetSingleLightACK, subnetId, deviceId, new byte[] { fan.bus_Data.LoopID }); |
| | | break; |
| | | } |
| | | break; |
| | | case FunctionCategory.SwitchDevice: |
| | | switch (function.functionType) |
| | | { |
| | | case FunctionType.Socket: |
| | | var s = function as SwitchSocket; |
| | | ControlBytesSend(Command.SetSingleLightACK, subnetId, deviceId, new byte[] { s.bus_Data.LoopID }); |
| | | break; |
| | | } |
| | | break; |
| | | case FunctionCategory.Sensor: |
| | | var sensor = function as Sensor; |
| | | ControlBytesSend(Command.ReadDeviceLoopInfo, subnetId, deviceId, new byte[] { (byte)5, |
| | | (byte)((int)sensor.functionType % 256), sensor.bus_Data.LoopID }); |
| | | //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; |
| | | } |
| | | |
| | | |
| | | foreach (var dic in commandDictionary) |
| | | { |
| | | switch (dic.Key) |
| | | { |
| | | case "on_off": |
| | | break; |
| | | case "brightness": |
| | | break; |
| | | case "color": |
| | | break; |
| | | default: |
| | | MainPage.Log($"功能未支持 : {dic.Key}"); |
| | | break; |
| | | //case "cct": |
| | | //case "delay": |
| | | //case "fade_time": |
| | | //case "open_level": |
| | | //case "lock": |
| | | //case "ico": |
| | | //case "mode": |
| | | //case "fan": |
| | | //case "temp": |
| | | //case "swing": |
| | | //case "set_ point": |
| | | //case "pm25": |
| | | //case "volume": |
| | | //case "vol_step": |
| | | //case "source": |
| | | //case "treble": |
| | | //case "bass": |
| | | //case "playlist": |
| | | //case "song_name": |
| | | //case "current_status": |
| | | //case "enable": |
| | | //case "lux": |
| | | //case "adjust_value": |
| | | //case "range": |
| | | //case "humidity": |
| | | //case "type": |
| | | //case "state": |
| | | //case "sensitivity": |
| | | //case "pm25value": |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | //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; |
| | | //} |
| | | |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MainPage.Log($"DataConversion_Bus Erorr : {ex.Message}"); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 读取bus设备数据 |
| | | /// </summary> |
| | | static void ReadBusData(Function function) |
| | | { |
| | | try |
| | | { |
| | | var subnetId = function.bus_Data.SubnetID; |
| | | var deviceId = function.bus_Data.DeviceID; |
| | | var loopId = function.bus_Data.LoopID; |
| | | |
| | | switch (function.functionCategory) |
| | | { |
| | | case FunctionCategory.Light: |
| | | switch (function.functionType) |
| | | { |
| | | case FunctionType.Relay: |
| | | case FunctionType.Dimmer: |
| | | ControlBytesSend(Command.ReadLightSingleLoopBrightness, subnetId, deviceId, new byte[] { function.bus_Data.LoopID }); |
| | | break; |
| | | case FunctionType.RGB: |
| | | ControlBytesSend(Command.ReadLogicLoopColor, subnetId, deviceId, new byte[] { function.bus_Data.LoopID }); |
| | | break; |
| | | } |
| | | break; |
| | | case FunctionCategory.Curtain: |
| | | switch (function.functionType) |
| | | { |
| | | case FunctionType.Curtain: |
| | | case FunctionType.MotorCurtain: |
| | | case FunctionType.RollingShutter: |
| | | ControlBytesSend(Command.ReadCurtainStatus, subnetId, deviceId, new byte[] { function.bus_Data.LoopID }); |
| | | break; |
| | | } |
| | | break; |
| | | case FunctionCategory.Thermostat: |
| | | switch (function.functionType) |
| | | { |
| | | case FunctionType.AC: |
| | | ControlBytesSend(Command.ReadACMode, subnetId, deviceId, new byte[] { function.bus_Data.LoopID }); |
| | | break; |
| | | case FunctionType.FloorHeating: |
| | | ControlBytesSend(Command.ReadFloorHeat, subnetId, deviceId, new byte[] { function.bus_Data.LoopID }); |
| | | break; |
| | | } |
| | | break; |
| | | case FunctionCategory.Electrical: |
| | | switch (function.functionType) |
| | | { |
| | | case FunctionType.Fan: |
| | | var fan = function as Fan; |
| | | ControlBytesSend(Command.SetSingleLightACK, subnetId, deviceId, new byte[] { fan.bus_Data.LoopID }); |
| | | break; |
| | | } |
| | | break; |
| | | case FunctionCategory.SwitchDevice: |
| | | switch (function.functionType) |
| | | { |
| | | case FunctionType.Socket: |
| | | var s = function as SwitchSocket; |
| | | ControlBytesSend(Command.SetSingleLightACK, subnetId, deviceId, new byte[] { s.bus_Data.LoopID }); |
| | | break; |
| | | } |
| | | break; |
| | | case FunctionCategory.Sensor: |
| | | var sensor = function as Sensor; |
| | | ControlBytesSend(Command.ReadDeviceLoopInfo, subnetId, deviceId, new byte[] { (byte)5, |
| | | (byte)((int)sensor.functionType % 256), sensor.bus_Data.LoopID }); |
| | | break; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MainPage.Log($"DataConversion_Bus Erorr : {ex.Message}"); |
| | | MainPage.Log($"Read DataConversion_Bus Erorr : {ex.Message}"); |
| | | } |
| | | } |
| | | } |