wxr
2024-12-02 ea0b1e8e5f43c5fd0a7d479e25ede3b8cbea464a
HDL_ON/DAL/DriverLayer/Control_Udp.cs
@@ -11,10 +11,6 @@
{
    public class Control_Udp
    {
        //public Control_Udp()
        //{
        //    MainPage.Log($"control bus udp 被创建,时间:{DateTime.Now}");
        //}
        /// <summary>
        /// 通讯端口
        /// </summary>
@@ -69,7 +65,6 @@
                SubnetID = subnetID,
                DeviceID = deviceID,
                AddData = gatewayBytes,
            //}, 3, true);
            }, sendCount, reSend);
        }
@@ -104,7 +99,7 @@
            try
            {
                //账号没登录不回复
                if ( UserInfo.Current == null || ! UserInfo.Current.IsLogin)
                if (UserInfo.Current == null)///|| ! UserInfo.Current.IsLogin)
                {
                    return;
                }
@@ -136,7 +131,8 @@
                    }
                }
            }
            catch (Exception ex) {
            catch (Exception ex)
            {
                Console.WriteLine($"回复bus搜索异常 : {ex.Message}");
            }
        }
@@ -198,6 +194,7 @@
                            break;
                        case SPK.AcStandard:
                        case SPK.HvacAC:
                        case SPK.HvacAcPanel:
                            AC acTemp = new AC();
                            byte onoff = 0;
                            byte mode = 0;
@@ -303,6 +300,7 @@
                        case SPK.LightRGB:
                            break;
                        case SPK.HvacFloorHeat:
                        case SPK.HvacFloorHeatPanel:
                        case SPK.FloorHeatStandard:
                            if (f.status.Find((obj)=>obj.key ==FunctionAttributeKey.Mode) == null)
                            {
@@ -393,26 +391,26 @@
                                }
                            }
                            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;
                            //    }
                            //}
                        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;
                    }
                }
@@ -464,7 +462,13 @@
                {
                    case SPK.LightCCT:
                        #region cct light
                        byte b0 = 100;
                        byte b0 = Convert.ToByte(function.lastBrightness);
                        if (commandDictionary.ContainsKey(FunctionAttributeKey.Brightness))
                        {
                            b0 = Convert.ToByte(function.GetAttrState(FunctionAttributeKey.Brightness));
                        }
                        else
                        {
                        if (commandDictionary.ContainsKey(FunctionAttributeKey.OnOff))
                        {
                            if (function.trait_on_off.curValue.ToString() == "off")
@@ -476,9 +480,6 @@
                                b0 = function.lastBrightness == 0 ? (byte)100 : Convert.ToByte(function.lastBrightness);
                            }
                        }
                        else
                        {
                            b0 = Convert.ToByte(function.GetAttrState(FunctionAttributeKey.Brightness));
                        }
                        var bytes0 = new byte[] { function.bus.LoopId,
                                            b0,
@@ -492,7 +493,13 @@
                        break;
                    case SPK.LightRGB:
                        #region rgb light
                        byte b = 100;
                        byte b = Convert.ToByte(function.lastBrightness);
                        if (commandDictionary.ContainsKey(FunctionAttributeKey.Brightness))
                        {
                            b = Convert.ToByte(function.GetAttrState(FunctionAttributeKey.Brightness));
                        }
                        else
                        {
                        if (commandDictionary.ContainsKey(FunctionAttributeKey.OnOff))
                        {
                            if (function.trait_on_off.curValue.ToString() == "off")
@@ -504,9 +511,6 @@
                                b = function.lastBrightness == 0 ? (byte)100 : Convert.ToByte(function.lastBrightness);
                            }
                        }
                        else
                        {
                            b = Convert.ToByte(function.GetAttrState(FunctionAttributeKey.Brightness));
                        }
                        var tempLight = new Light();
                        var bytes = new byte[] { function.bus.LoopId,
@@ -521,7 +525,13 @@
                        break;
                    case SPK.LightDimming:
                        #region dimming light
                        byte b1 = 100;
                        byte b1 = Convert.ToByte(function.lastBrightness);
                        if (commandDictionary.ContainsKey(FunctionAttributeKey.Brightness))
                        {
                            b1 = Convert.ToByte(function.GetAttrState(FunctionAttributeKey.Brightness));
                        }
                        else
                        {
                        if (commandDictionary.ContainsKey(FunctionAttributeKey.OnOff))
                        {
                            if (function.trait_on_off.curValue.ToString() == "off")
@@ -533,9 +543,6 @@
                                b1 = function.lastBrightness == 0 ? (byte)100 : Convert.ToByte(function.lastBrightness);
                            }
                        }
                        else
                        {
                            b1 = Convert.ToByte(function.GetAttrState(FunctionAttributeKey.Brightness));
                        }
                        ControlBytesSend(Command.SetSingleLight, subnetId, deviceId, new byte[] {
                                            function.bus.LoopId,
@@ -601,8 +608,8 @@
                        break;
                    case SPK.AcStandard:
                    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;
@@ -612,28 +619,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":
@@ -643,8 +656,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)
@@ -665,8 +676,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
@@ -677,28 +686,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
@@ -708,25 +695,28 @@
                                    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)
                        {
@@ -825,7 +815,8 @@
                    case SPK.PanelSocket:
                        ControlBytesSend(Command.SetSingleLight, subnetId, deviceId, new byte[] { function.bus.LoopId, function.trait_on_off.curValue.ToString() == "on" ? (byte)100 : (byte)0 });
                        break;
                    case SPK.AirFreshJinmao:case SPK.HvacAirFreshJinmao:
                    case SPK.AirFreshJinmao:
                    case SPK.HvacAirFreshJinmao:
                        #region AirFresh
                        //1   新风编号    1~200
                        //2   类型 第三方类型  0:金茂新风
@@ -949,9 +940,12 @@
                        break;
                    case SPK.AcStandard:
                    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:
@@ -994,9 +988,6 @@
        /// </summary>
        void add()
        {
            /// <summary>
            /// 达到50条数据后就清理一下
            /// </summary>
            if (50 < controlList.Count)
            {
                lock (controlList)
@@ -1094,11 +1085,10 @@
            try
            {
                MainPage.Log("发送数据:" + SendFlag);
                UdpSocket._BusSocket.AsyncBeginSend(packet);
                packet.HaveSendCount--;
                //这里是重发两次
                //UDP重发数据
                while (packet.HaveSendCount < 3)
                {
                    if (packet.FlagDateTime.AddMilliseconds(1000).Ticks <= DateTime.Now.Ticks)
@@ -1265,16 +1255,12 @@
        public void SendLocalHdlLinkData(byte[] sendBytes,string id, int resend = 3)
        {
            packet = new Packet(sendBytes, new System.Net.IPEndPoint(System.Net.IPAddress.Parse(Control.Ins.reportIp), 8585));
            packet.HaveSendCount = 3 - resend;//重发次数
            packet.HaveSendCount = 3 - resend;
            sendFlag = id;
            System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(managerSendCount));
            thread.IsBackground = true;
            thread.Start(packet);
            //if (isWait)
            //{
            //    wait();
            //}
            MainPage.Log($"发送Hdl-Link数据,IP:{Control.Ins.reportIp}:8585");
            //MainPage.Log($"发送数据,IP:{Control.Ins.reportIp}:8585");
        }
    }