From 300a5d5370d10d97eb5dfdfa43bb0156c15d23e3 Mon Sep 17 00:00:00 2001 From: wxr <464027401@qq.com> Date: 星期三, 03 一月 2024 17:36:15 +0800 Subject: [PATCH] packet类复原 --- HDL_ON/DAL/DriverLayer/Packet.cs | 82 ++++++++++++++++++++--------------------- 1 files changed, 40 insertions(+), 42 deletions(-) diff --git a/HDL_ON/DAL/DriverLayer/Packet.cs b/HDL_ON/DAL/DriverLayer/Packet.cs index 99f46b8..dc75315 100644 --- a/HDL_ON/DAL/DriverLayer/Packet.cs +++ b/HDL_ON/DAL/DriverLayer/Packet.cs @@ -12,11 +12,11 @@ /// </summary> public class Packet { - ///// <summary> - ///// 缂撳啿鍖哄ぇ灏� - ///// Link鍗忚鐜板湪涓�涓寘鐨勬暟鎹瘮杈冨ぇ锛岀紦鍐插尯澶皬瀛樹笉瀹屽叏閮ㄦ暟鎹� 2023-07-14 16:03:56 wxr - ///// </summary> - //public const int Size = 2000; + /// <summary> + /// 缂撳啿鍖哄ぇ灏� + /// Link鍗忚鐜板湪涓�涓寘鐨勬暟鎹瘮杈冨ぇ锛岀紦鍐插尯澶皬瀛樹笉瀹屽叏閮ㄦ暟鎹� 2023-07-14 16:03:56 wxr + /// </summary> + public const int Size = 1024 * 10; /// <summary> /// 鎺ユ敹鍒扮殑鏁版嵁 @@ -28,15 +28,11 @@ /// </summary> public System.Net.EndPoint RemoteEndPoint; - public Packet(int lenght) + public Packet() { - this.Bytes = new byte[lenght]; - + this.Bytes = new byte[Size]; RemoteEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Any, 0); } - - - public Packet(byte[] data, System.Net.EndPoint remoteEndPoint) { this.Bytes = data; @@ -113,7 +109,7 @@ #if DEBUG #else - } + } catch (Exception ex) { MainPage.Log($"packet {ex.Message} "); @@ -196,7 +192,7 @@ light.SetAttrState(FunctionAttributeKey.OnOff, receiveBytes[light.bus.LoopId] == 0 ? "off" : "on"); if (light.trait_on_off.curValue.ToString() == "on") { - light.SetAttrState(FunctionAttributeKey.Brightness, receiveBytes[i+1].ToString()); + light.SetAttrState(FunctionAttributeKey.Brightness, receiveBytes[i + 1].ToString()); light.lastState = Language.StringByID(StringId.Brightness) + " : " + receiveBytes[2] + "%"; } HomePage.UpdataFunctionStates(light); @@ -265,7 +261,8 @@ FunctionPage.UpdataStates(lightTeme); ClassificationPage.UpdataInfo(lightTeme); RGBPage.UpdataStates(lightTeme); - }else if(lightTeme.spk == SPK.LightCCT) + } + else if (lightTeme.spk == SPK.LightCCT) { lightTeme.SetAttrState(FunctionAttributeKey.OnOff, receiveBytes[1] > 0 ? "on" : "off"); if (receiveBytes[1] > 0) @@ -349,21 +346,21 @@ case Command.ReadACModeACK: foreach (var function in FunctionList.List.Functions) { - if (function.bus == null || function.spk != SPK.AcStandard) - { - continue; - } + if (function.bus == null || function.spk != SPK.AcStandard) + { + continue; + } var acFunction = new AC(); if (function.bus.SubnetID == subnetID && - function.bus.DeviceID == deviceID && + function.bus.DeviceID == deviceID && function.bus.LoopId == receiveBytes[0]) { - Console.WriteLine(function.GetBusId()); + Console.WriteLine(function.GetBusId()); function.SetAttrState(FunctionAttributeKey.TempType, receiveBytes[1].ToString()); function.SetAttrState(FunctionAttributeKey.RoomTemp, receiveBytes[2].ToString()); - function.SetAttrState(FunctionAttributeKey.OnOff, receiveBytes[8] == 1 ? "on" : "off"); - acFunction.SetMode(receiveBytes[9],function); - acFunction.SetFan(receiveBytes[10],function); + function.SetAttrState(FunctionAttributeKey.OnOff, receiveBytes[8] == 1 ? "on" : "off"); + acFunction.SetMode(receiveBytes[9], function); + acFunction.SetFan(receiveBytes[10], function); function.SetAttrState(FunctionAttributeKey.SetTemp, receiveBytes[11].ToString()); function.lastState = ""; switch (function.GetAttrState(FunctionAttributeKey.Mode)) @@ -417,7 +414,7 @@ { function.SetAttrState(FunctionAttributeKey.TempType, receiveBytes[2]); function.SetAttrState(FunctionAttributeKey.OnOff, receiveBytes[1] % 2 == 0 ? "off" : "on"); - new FloorHeating().SetModeIndex(receiveBytes[3],function); + new FloorHeating().SetModeIndex(receiveBytes[3], function); if (function.Fh_Mode_Temp.ContainsKey("normal")) { @@ -494,7 +491,8 @@ if (receiveBytes[9] > 128) { indoorTemp = 1 - (receiveBytes[9] - 128); - }else + } + else { indoorTemp = receiveBytes[9]; } @@ -548,8 +546,8 @@ { case SPK.SensorTemperature: byte[] tempBytes = new byte[] { receiveBytes[24], receiveBytes[25], receiveBytes[26], receiveBytes[27] }; - sensor.SetAttrState(FunctionAttributeKey.Value,Math.Round(BitConverter.ToSingle(tempBytes, 0), 1).ToString()); - sensor.SetAttrState(sensor.spk,Math.Round(BitConverter.ToSingle(tempBytes, 0), 1).ToString()); + sensor.SetAttrState(FunctionAttributeKey.Value, Math.Round(BitConverter.ToSingle(tempBytes, 0), 1).ToString()); + sensor.SetAttrState(sensor.spk, Math.Round(BitConverter.ToSingle(tempBytes, 0), 1).ToString()); break; case SPK.SensorHumidity: sensor.SetAttrState(FunctionAttributeKey.Value, (Convert.ToDouble(receiveBytes[24] * 256 + receiveBytes[25]) / 10).ToString()); @@ -560,8 +558,8 @@ sensor.SetAttrState(sensor.spk, (Convert.ToDouble(receiveBytes[24] * 256 + receiveBytes[25]) / 100).ToString()); break; case SPK.SensorPm25: - sensor.SetAttrState(FunctionAttributeKey.Value,Convert.ToInt32(receiveBytes[24] * 256 + receiveBytes[25]).ToString()); - sensor.SetAttrState(sensor.spk,Convert.ToInt32(receiveBytes[24] * 256 + receiveBytes[25]).ToString()); + sensor.SetAttrState(FunctionAttributeKey.Value, Convert.ToInt32(receiveBytes[24] * 256 + receiveBytes[25]).ToString()); + sensor.SetAttrState(sensor.spk, Convert.ToInt32(receiveBytes[24] * 256 + receiveBytes[25]).ToString()); break; case SPK.SensorCO2: sensor.SetAttrState(FunctionAttributeKey.Value, Convert.ToInt32(receiveBytes[24] * 256 + receiveBytes[25]).ToString()); @@ -569,7 +567,7 @@ break; } EnvironmentalPage.LoadEvent_UpdataStatus(sensor); - //A_EnvironmentalDataCenter.LoadEvent_UpdataStatus(sensor); + //A_EnvironmentalDataCenter.LoadEvent_UpdataStatus(sensor); } } } @@ -606,17 +604,17 @@ switch (receiveBytes[3]) { case 1: - sensor.SetAttrState(FunctionAttributeKey.Value,( (receiveBytes[5] * 256 * 256 * 256) + (receiveBytes[6] * 256 * 256) + (receiveBytes[7] * 256) + receiveBytes[8]).ToString()); - sensor.SetAttrState(sensor.spk,( (receiveBytes[5] * 256 * 256 * 256) + (receiveBytes[6] * 256 * 256) + (receiveBytes[7] * 256) + receiveBytes[8]).ToString()); + sensor.SetAttrState(FunctionAttributeKey.Value, ((receiveBytes[5] * 256 * 256 * 256) + (receiveBytes[6] * 256 * 256) + (receiveBytes[7] * 256) + receiveBytes[8]).ToString()); + sensor.SetAttrState(sensor.spk, ((receiveBytes[5] * 256 * 256 * 256) + (receiveBytes[6] * 256 * 256) + (receiveBytes[7] * 256) + receiveBytes[8]).ToString()); break; case 2: - sensor.SetAttrState(FunctionAttributeKey.Value,( -1 * ((receiveBytes[5] * 256 * 256 * 256) + (receiveBytes[6] * 256 * 256) + (receiveBytes[7] * 256) + receiveBytes[8])).ToString()); - sensor.SetAttrState(sensor.spk,( -1 * ((receiveBytes[5] * 256 * 256 * 256) + (receiveBytes[6] * 256 * 256) + (receiveBytes[7] * 256) + receiveBytes[8])).ToString()); + sensor.SetAttrState(FunctionAttributeKey.Value, (-1 * ((receiveBytes[5] * 256 * 256 * 256) + (receiveBytes[6] * 256 * 256) + (receiveBytes[7] * 256) + receiveBytes[8])).ToString()); + sensor.SetAttrState(sensor.spk, (-1 * ((receiveBytes[5] * 256 * 256 * 256) + (receiveBytes[6] * 256 * 256) + (receiveBytes[7] * 256) + receiveBytes[8])).ToString()); break; case 3: byte[] tempBytes = new byte[] { receiveBytes[5], receiveBytes[6], receiveBytes[7], receiveBytes[8] }; - sensor.SetAttrState(FunctionAttributeKey.Value,( Math.Round(BitConverter.ToSingle(tempBytes, 0), 1)).ToString()); - sensor.SetAttrState(sensor.spk,( Math.Round(BitConverter.ToSingle(tempBytes, 0), 1)).ToString()); + sensor.SetAttrState(FunctionAttributeKey.Value, (Math.Round(BitConverter.ToSingle(tempBytes, 0), 1)).ToString()); + sensor.SetAttrState(sensor.spk, (Math.Round(BitConverter.ToSingle(tempBytes, 0), 1)).ToString()); break; } switch (receiveBytes[4]) @@ -630,8 +628,8 @@ } break; } - - //A_EnvironmentalDataCenter.LoadEvent_UpdataStatus(sensor); + + //A_EnvironmentalDataCenter.LoadEvent_UpdataStatus(sensor); EnvironmentalPage.LoadEvent_UpdataStatus(sensor); } } @@ -669,10 +667,10 @@ function.SetAttrState(FunctionAttributeKey.SetTemp, receiveBytes[1].ToString()); break; case 5: - acFunction.SetFan ( receiveBytes[1],function); + acFunction.SetFan(receiveBytes[1], function); break; case 6: - acFunction.SetMode ( receiveBytes[1],function); + acFunction.SetMode(receiveBytes[1], function); break; } @@ -756,7 +754,7 @@ #if DEBUG #else - } + } catch (Exception ex) { MainPage.Log($"Bus Rev Erorr : {ex.Message}"); @@ -831,7 +829,7 @@ default: break; } - Control_Udp.ReceiveRepeatManager(receiveFlag,usefulBytes); + Control_Udp.ReceiveRepeatManager(receiveFlag, usefulBytes); } catch (Exception ex) { -- Gitblit v1.8.0