wxr
2024-10-18 a40848272e33822f72a7fe0310f079717bf73f23
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,7 @@
                            break;
                        case SPK.LightRGB:
                            break;
                        case SPK.HvacFloorHeat:
                        case SPK.HvacFloorHeat:case SPK.HvacFloorHeatPanel:
                        case SPK.FloorHeatStandard:
                            if (f.status.Find((obj)=>obj.key ==FunctionAttributeKey.Mode) == null)
                            {
@@ -393,8 +393,26 @@
                                }
                            }
                            break;
                        case SPK.OtherCommon:
                        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;
                    }
                }
@@ -446,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,
@@ -474,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,
@@ -503,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,
@@ -582,9 +609,8 @@
                        }
                        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;
@@ -594,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":
@@ -625,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)
@@ -647,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
@@ -659,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
@@ -690,25 +696,26 @@
                                    break;
                            }
                        }
                        /// 设置空调模块命令
                        /// 1空调号(1-128)
                        ///2温度模式(摄氏Celsius:0,华氏Fahrenheit: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)
                        {
@@ -930,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:
@@ -1191,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 ()} };