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;
@@ -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.HvacFloorHeatPanel:
                        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,56 +583,139 @@
                        }
                        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:
                    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;
                        mode = ac.GetModeIndex(function);
                        byte fan = 0;
                        fan = ac.GetFanIndex(function);
                        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:
                                    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;
                                    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;
                                            temp = autoTemp;
                                            break;
                                        case 0:
                                            modeKey = 4;
                                        case "cool":
                                            mode = 0;
                                            temp = coolTemp;
                                            break;
                                        case 1:
                                            modeKey = 7;
                                        case "heat":
                                            mode = 1;
                                            temp = heatTemp;
                                            break;
                                        case 4:
                                            modeKey = 19;
                                        case "dry":
                                            temp = dehumiTemp;
                                            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 });
                                    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;
                                    }
                                    break;
                                case FunctionAttributeKey.SetTemp:
                                    try
                                    {
                                        temp = Convert.ToByte(dic.Value);
                                    }
                                    catch
                                    {
                                        temp = 16;
                                    }
                                    break;
                                case FunctionAttributeKey.Swing:
                                    //sanfan
                                    break;
                                default:
                                    MainPage.Log($"功能未支持 : {dic.Key}");
                                    break;
                            }
                        }
                        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,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)
                        {
@@ -656,8 +775,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;
@@ -818,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:
@@ -1079,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 ()} };