From 3069c032027eeea7a14fa9f462440bb2d802d9a9 Mon Sep 17 00:00:00 2001
From: wei <kaede@kaededeMacBook-Air.local>
Date: 星期一, 11 一月 2021 14:25:09 +0800
Subject: [PATCH] 20210111-合并代码
---
HDL_ON/DAL/DriverLayer/Packet.cs | 708 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 708 insertions(+), 0 deletions(-)
diff --git a/HDL_ON/DAL/DriverLayer/Packet.cs b/HDL_ON/DAL/DriverLayer/Packet.cs
new file mode 100644
index 0000000..1723234
--- /dev/null
+++ b/HDL_ON/DAL/DriverLayer/Packet.cs
@@ -0,0 +1,708 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Text;
+using HDL_ON.Entity;
+using HDL_ON.UI;
+using Shared;
+
+namespace HDL_ON.DriverLayer
+{
+ /// <summary>
+ /// bus鏁版嵁鍖�
+ /// </summary>
+ public class Packet
+ {
+ /// <summary>
+ /// 缂撳啿鍖哄ぇ灏�
+ /// </summary>
+ public const int Size = 1024 + 200;
+
+ /// <summary>
+ /// 鎺ユ敹鍒扮殑鏁版嵁
+ /// </summary>
+ public byte[] Bytes;
+
+ /// <summary>
+ /// 鏁版嵁鍙戦�両P鍦板潃
+ /// </summary>
+ public System.Net.EndPoint RemoteEndPoint;
+
+ public Packet()
+ {
+ 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;
+ this.RemoteEndPoint = remoteEndPoint;
+ }
+
+ /// <summary>
+ /// 璁板綍宸茬粡鍙戦�佹暟鎹嚭鍘荤殑鏃堕棿
+ /// </summary>
+ public DateTime FlagDateTime;
+
+ /// <summary>
+ /// 宸茬粡鍙戦�佷簡澶氬皯鏁�
+ /// </summary>
+ public int HaveSendCount;
+
+ /// <summary>
+ /// 澶勭悊鎺ユ敹鍒扮殑鏁版嵁
+ /// </summary>
+ public virtual void Manager()
+ {
+ try
+ {
+ //瀵逛簬鎿嶄綔鏁版嵁搴撶殑鏃堕棿姣旇緝闀跨殑锛屽彲浠ュ垱寤哄彟涓�涓嚎绋嬪鐞�
+ if (!"HDLMIRACLE".Equals(Encoding.ASCII.GetString(Bytes, 4, 10)))
+ {
+ return;
+ }
+
+ byte subnetID = this.Bytes[17]; //婧愬瓙缃戝彿
+ byte deviceID = this.Bytes[18]; //婧愯澶囧彿
+
+ //婧愯澶囩被鍨�
+ int deviceType = this.Bytes[19] * 256 + this.Bytes[20];
+
+ Command command = (Command)(Bytes[21] * 256 + Bytes[22]); //鎿嶄綔鐮佹帶鍒跺懡浠�
+
+ byte targetSubnetID = this.Bytes[23];
+ byte targetDeviceID = this.Bytes[24];
+
+ //涓嶆槸瑕佹帴鏀剁殑鎸囦护灏辫繑鍥�
+ if (!((targetSubnetID == 0 && targetDeviceID == 252) || (targetSubnetID == 0xff && targetDeviceID == 0xff)))
+ {
+ return;
+ }
+ byte[] usefulBytes = null;
+ if (this.Bytes[16] == 0xFF)
+ {
+ usefulBytes = new byte[Bytes.Length - 16 - 11];
+ Array.Copy(Bytes, 27, usefulBytes, 0, usefulBytes.Length);
+ }
+ else
+ {
+ //鏈夌敤鐨勯檮鍔犳暟鎹�
+ usefulBytes = new byte[this.Bytes[16] - 11];
+ Array.Copy(Bytes, 25, usefulBytes, 0, usefulBytes.Length);
+ }
+ //澶勭悊鎺ユ敹鍒扮殑鏁版嵁
+ UdpPacket_DataProcessing(subnetID, deviceID, command, usefulBytes);
+#if DEBUG
+ string ddd = "";
+ foreach(var bb in usefulBytes)
+ {
+ ddd += bb + ",";
+ }
+ MainPage.Log(ddd);
+#endif
+ //澶勭悊鏄惁瑕侀噸鍙戞暟鎹�
+ ManagerReceive(subnetID, deviceID, command, usefulBytes);
+ }
+ catch (Exception ex)
+ {
+ MainPage.Log($"packet {ex.Message} ");
+ }
+ }
+
+ /// <summary>
+ /// 鏁版嵁鍖呭鐞�
+ /// ps:鐢眂ommonpage杞Щ杩囨潵锛岃繕闇�瑕佽浆绉诲悎閫傜殑浣嶇疆绠$悊
+ /// </summary>
+ /// <param name="subnetID"></param>
+ /// <param name="deviceID"></param>
+ /// <param name="command"></param>
+ /// <param name="receiveBytes"></param>
+ void UdpPacket_DataProcessing(byte subnetID, byte deviceID, Command command, byte[] receiveBytes)
+ {
+ try
+ {
+ switch (command)
+ {
+ case Command.SetSingleLightACK:
+ var queryList = new List<Function>();
+ queryList.AddRange(FunctionList.List.electricals);
+ queryList.AddRange(FunctionList.List.lights);
+ foreach (var updataObj in queryList)
+ {
+ if (updataObj.GetBusId() == subnetID + "_" + deviceID + "_" + receiveBytes[0])
+ {
+ if (updataObj.spk != SPK.LightRGB)
+ {
+ updataObj.trait_on_off.curValue = receiveBytes[2] > 0 ? "on" : "off";
+ if (updataObj.trait_on_off.curValue.ToString() == "on")
+ {
+ switch (updataObj.spk)
+ {
+ case SPK.ElectricFan:
+ (updataObj as Fan).openLevel = receiveBytes[2];
+ updataObj.lastState = Language.StringByID(StringId.Level) + " : " + receiveBytes[2];
+ break;
+ case SPK.LightDimming:
+ (updataObj as Light).brightness = receiveBytes[2];
+ updataObj.lastState = Language.StringByID(StringId.Brightness) + " : " + receiveBytes[2] + "%";
+ break;
+ }
+ }
+ HomePage.UpdataFunctionStates(updataObj);
+ RoomPage.UpdataStates(updataObj);
+ FunctionPage.UpdataStates(updataObj);
+ ClassificationPage.UpdataInfo(updataObj);
+ switch (updataObj.spk)
+ {
+ case SPK.LightSwitch:
+ RelayPage.UpdataState(updataObj as Light);
+ break;
+ case SPK.LightDimming:
+ DimmerPage.UpdataStates(updataObj as Light);
+ break;
+ case SPK.ElectricFan:
+ FanPage.UpdataState(updataObj as Fan);
+ break;
+ }
+ break;
+ }
+ }
+ }
+ break;
+ case Command.ReadLightAllLoopBrightnessACK:
+ for (int i = 0; i < receiveBytes[0]; i++)
+ {
+ var light = FunctionList.List.lights.Find((obj) => obj.bus.SubnetID == subnetID && obj.bus.DeviceID == deviceID && obj.bus.LoopId == (i + 1));
+ if (light != null)
+ {
+ if (light.spk != SPK.LightRGB)
+ {
+ light.trait_on_off.curValue = receiveBytes[light.bus.LoopId] == 0 ? "off" : "on";
+ if (light.trait_on_off.curValue.ToString() == "on")
+ {
+ light.brightness = receiveBytes[2];
+ light.lastState = Language.StringByID(StringId.Brightness) + " : " + receiveBytes[2] + "%";
+ }
+ HomePage.UpdataFunctionStates(light);
+ RoomPage.UpdataStates(light);
+ FunctionPage.UpdataStates(light);
+ ClassificationPage.UpdataInfo(light);
+ switch (light.spk)
+ {
+ case SPK.LightSwitch:
+ RelayPage.UpdataState(light);
+ break;
+ case SPK.LightDimming:
+ DimmerPage.UpdataStates(light);
+ break;
+ }
+ }
+ }
+ else
+ {
+ var e = FunctionList.List.electricals.Find((obj) => obj.bus.SubnetID == subnetID && obj.bus.DeviceID == deviceID && obj.bus.LoopId == i);
+ if (e != null)
+ {
+ var fan = e as Fan;
+ fan.trait_on_off.curValue = receiveBytes[2] == 0 ? "off" : "on";
+ if (fan.trait_on_off.curValue.ToString() == "on")
+ {
+ fan.openLevel = receiveBytes[2];
+ fan.lastState = Language.StringByID(StringId.Level) + " : " + receiveBytes[2];
+ }
+ HomePage.UpdataFunctionStates(fan);
+ RoomPage.UpdataStates(fan);
+ FunctionPage.UpdataStates(fan);
+ ClassificationPage.UpdataInfo(fan);
+ switch (fan.spk)
+ {
+ case SPK.ElectricFan:
+ FanPage.UpdataState(fan);
+ break;
+ case SPK.ElectricSocket:
+
+ break;
+ }
+ }
+ }
+ }
+ break;
+ case Command.SetLogicLoopColorACK:
+ case Command.ReadLogicLoopColorACK:
+ foreach (var rgb in FunctionList.List.lights)
+ {
+ if (rgb.GetBusId() == subnetID + "_" + deviceID + "_" + receiveBytes[0])
+ {
+ if (rgb.spk == SPK.LightRGB)
+ {
+ rgb.trait_on_off.curValue = receiveBytes[1] > 0 ? "on" : "off";
+ if (receiveBytes[1] > 0)
+ {
+ rgb.brightness = receiveBytes[1];
+ rgb.lastState = Language.StringByID(StringId.Brightness) + " : " + receiveBytes[1] + "%";
+ }
+ rgb.SetRGBcolor(new byte[] { receiveBytes[6], receiveBytes[7], receiveBytes[8] });
+
+ HomePage.UpdataFunctionStates(rgb);
+ RoomPage.UpdataStates(rgb);
+ FunctionPage.UpdataStates(rgb);
+ ClassificationPage.UpdataInfo(rgb);
+ RGBPage.UpdataStates(rgb);
+ }
+ }
+ }
+ break;
+ case Command.SetCurtainModelStutasACK:
+ case Command.ReadCurtainStutasACK:
+ foreach (var curtain in FunctionList.List.curtains)
+ {
+ if (curtain.bus.SubnetID == subnetID && curtain.bus.DeviceID == deviceID)
+ {
+ if (receiveBytes[0] == 17)
+ {
+ if (receiveBytes[1] > 1)
+ {
+ curtain.trait_on_off.curValue = "on";
+ }
+ else
+ {
+ curtain.trait_on_off.curValue = "off";
+ }
+ curtain.percent = receiveBytes[1];
+ curtain.lastState = Language.StringByID(StringId.Open) + curtain.percent + "%";
+ }
+ else
+ {
+ if (curtain.bus.LoopId != receiveBytes[0])
+ continue;
+ switch (receiveBytes[1])
+ {
+ case 0:
+ curtain.trait_on_off.curValue = "stop";
+ break;
+ case 1:
+ curtain.trait_on_off.curValue = "on";
+ curtain.lastState = Language.StringByID(StringId.Open);
+ break;
+ case 2:
+ curtain.trait_on_off.curValue = "off";
+ curtain.lastState = Language.StringByID(StringId.Close);
+ break;
+ }
+ }
+ RoomPage.UpdataStates(curtain);
+ FunctionPage.UpdataStates(curtain);
+ HomePage.UpdataFunctionStates(curtain);
+ ClassificationPage.UpdataInfo(curtain);
+ switch (curtain.spk)
+ {
+ case SPK.CurtainSwitch:
+ CurtainModulePage.UpdataState(curtain);
+ break;
+ case SPK.CurtainTrietex:
+ MotorCurtainPage.UpdataState(curtain);
+ break;
+ case SPK.CurtainRoller:
+ RollingShutterPage.UpdataState(curtain);
+ break;
+ }
+ }
+ }
+ break;
+ case Command.SetACModeACK:
+ case Command.ReadACModeACK:
+ foreach (var ac in FunctionList.List.aCs)
+ {
+ if (ac.GetBusId() == subnetID + "_" + deviceID + "_" + receiveBytes[0])
+ {
+ ac.curTempType = receiveBytes[1];
+ ac.trait_IndoorTemp.curValue = receiveBytes[2].ToString();
+ ac.trait_on_off.curValue = receiveBytes[8] == 1 ? "on" : "off";
+ ac.curModeIndex = receiveBytes[9];
+ ac.curFanIndex = receiveBytes[10];
+ ac.trait_temp.curValue = receiveBytes[11].ToString();
+ ac.lastState = "";
+ switch (ac.trait_mode.curValue.ToString())
+ {
+ case "cool":
+ ac.lastState = Language.StringByID(StringId.Cool);
+ break;
+ case "heat":
+ ac.lastState = Language.StringByID(StringId.Heat);
+ break;
+ case "dry":
+ ac.lastState = Language.StringByID(StringId.Dry);
+ break;
+ case "auto":
+ ac.lastState = Language.StringByID(StringId.Auto);
+ break;
+ case "fan":
+ ac.lastState = Language.StringByID(StringId.AirSupply);
+ break;
+ }
+ switch (ac.trait_fan.curValue.ToString())
+ {
+ case "high":
+ ac.lastState += " " + Language.StringByID(StringId.HighWindSpeed);
+ break;
+ case "medium":
+ ac.lastState += " " + Language.StringByID(StringId.MiddleWindSpeed);
+ break;
+ case "low":
+ ac.lastState += " " + Language.StringByID(StringId.LowWindSpeed);
+ break;
+ case "auto":
+ ac.lastState += " " + Language.StringByID(StringId.Auto);
+ break;
+ }
+ ac.lastState += " " + ac.trait_temp.curValue + ac.tempUnitString;
+ RoomPage.UpdataStates(ac);
+ FunctionPage.UpdataStates(ac);
+ HomePage.UpdataFunctionStates(ac);
+ ClassificationPage.UpdataInfo(ac);
+ ACPage.UpdataStates(ac);
+ }
+ }
+ break;
+ case Command.ReadFloorHeatACK:
+ case Command.SetFloorHeatACK:
+ foreach (var fh in FunctionList.List.floorHeatings)
+ {
+ if (fh.GetBusId() == subnetID + "_" + deviceID + "_" + receiveBytes[0])
+ {
+ fh.curTempType = receiveBytes[2];
+ fh.trait_on_off.curValue = receiveBytes[1] % 2 == 0 ? "off" : "on";
+ fh.curModeIndex = receiveBytes[3];
+ if (fh.modeTemp.ContainsKey("normal"))
+ {
+ fh.modeTemp["normal"] = receiveBytes[4];
+ }
+ else
+ {
+ fh.modeTemp.Add("normal", receiveBytes[4]);
+ }
+ if (fh.modeTemp.ContainsKey("day"))
+ {
+ fh.modeTemp["day"] = receiveBytes[5];
+ }
+ else
+ {
+ fh.modeTemp.Add("day", receiveBytes[5]);
+ }
+ if (fh.modeTemp.ContainsKey("night"))
+ {
+ fh.modeTemp["night"] = receiveBytes[6];
+ }
+ else
+ {
+ fh.modeTemp.Add("night", receiveBytes[6]);
+ }
+ if (fh.modeTemp.ContainsKey("away"))
+ {
+ fh.modeTemp["away"] = receiveBytes[7];
+ }
+ else
+ {
+ fh.modeTemp.Add("away", receiveBytes[7]);
+ }
+
+ switch (fh.trait_mode.curValue)
+ {
+ case "normal":
+ fh.lastState = Language.StringByID(StringId.Normal);
+ fh.trait_temp.curValue = receiveBytes[4].ToString();
+ break;
+ case "day":
+ fh.lastState = Language.StringByID(StringId.Day);
+ fh.trait_temp.curValue = receiveBytes[5].ToString();
+ break;
+ case "night":
+ fh.lastState = Language.StringByID(StringId.Night);
+ fh.trait_temp.curValue = receiveBytes[6].ToString();
+ break;
+ case "timer":
+ fh.lastState = Language.StringByID(StringId.Auto);
+ if (receiveBytes[8] == 0)
+ {
+ fh.timeFlag = 0;
+ fh.trait_temp.curValue = receiveBytes[5].ToString();
+ }
+ else
+ {
+ fh.timeFlag = 1;
+ fh.trait_temp.curValue = receiveBytes[6].ToString();
+ }
+ break;
+ case "away":
+ fh.trait_temp.curValue = receiveBytes[7].ToString();
+ fh.lastState = Language.StringByID(StringId.Away);
+ break;
+ }
+ fh.lastState += " " + fh.trait_temp.curValue + fh.tempUnitString;
+ RoomPage.UpdataStates(fh);
+ FunctionPage.UpdataStates(fh);
+ HomePage.UpdataFunctionStates(fh);
+ ClassificationPage.UpdataInfo(fh);
+ FloorHeatingPage.UpdataStates(fh);
+ }
+ }
+ break;
+ case Command.ReadDeviceLoopInfoACK:
+ //FunctionType dt = (FunctionType)(11 * 256 + receiveBytes[1]);
+ string tag = receiveBytes[1] + "_" + subnetID + "_" + deviceID + "_" + receiveBytes[2];
+ foreach (var sensor in FunctionList.List.sensorsEnvironmentalScience)
+ {
+ byte sensorType = 0;
+ switch (sensor.spk)
+ {
+ case SPK.SensorTemperature:
+ sensorType = 2;
+ break;
+ case SPK.SensorHumidity:
+ sensorType = 3;
+ break;
+ case SPK.SensorTVOC:
+ sensorType = 5;
+ break;
+ case SPK.SensorPm25:
+ sensorType = 6;
+ break;
+ case SPK.SensorCO2:
+ sensorType = 7;
+ break;
+ }
+ if (sensor.bus != null)
+ {
+ if (sensorType == receiveBytes[1] && sensor.bus.SubnetID == subnetID &&
+ sensor.bus.DeviceID == deviceID && sensor.bus.LoopId == receiveBytes[2])
+ {
+ switch (sensor.spk)
+ {
+ case SPK.SensorTemperature:
+ byte[] tempBytes = new byte[] { receiveBytes[24], receiveBytes[25], receiveBytes[26], receiveBytes[27] };
+ sensor.values = Math.Round(BitConverter.ToSingle(tempBytes, 0), 1);
+ break;
+ case SPK.SensorHumidity:
+ sensor.values = Convert.ToDouble(receiveBytes[24] * 256 + receiveBytes[25]) / 10;
+ break;
+ case SPK.SensorTVOC:
+ sensor.values = Convert.ToDouble(receiveBytes[24] * 256 + receiveBytes[25]) / 100;
+ break;
+ case SPK.SensorPm25:
+ sensor.values = Convert.ToInt32(receiveBytes[24] * 256 + receiveBytes[25]);
+ break;
+ case SPK.SensorCO2:
+ sensor.values = Convert.ToInt32(receiveBytes[24] * 256 + receiveBytes[25]);
+ break;
+ }
+ EnvironmentalSciencePage.LoadEvent_UpdataStatus(sensor);
+ }
+ }
+ }
+ break;
+ case Command.New_Analog_Quantity_BROADCAST:
+ string tag1 = receiveBytes[1] + "_" + subnetID + "_" + deviceID + "_" + receiveBytes[2];
+ foreach (var sensor in FunctionList.List.sensorsEnvironmentalScience)
+ {
+ byte sensorType = 0;
+ switch (sensor.spk)
+ {
+ case SPK.SensorTemperature:
+ sensorType = 2;
+ break;
+ case SPK.SensorHumidity:
+ sensorType = 3;
+ break;
+ case SPK.SensorTVOC:
+ sensorType = 5;
+ break;
+ case SPK.SensorPm25:
+ sensorType = 6;
+ break;
+ case SPK.SensorCO2:
+ sensorType = 7;
+ break;
+ }
+ if (sensor.bus != null)
+ {
+ if (sensorType == receiveBytes[1] && sensor.bus.SubnetID == subnetID &&
+ sensor.bus.DeviceID == deviceID && sensor.bus.LoopId == receiveBytes[2])
+ {
+ //0淇濈暀 1鏃犵鍙�4Byte鏁村舰 2鏈夌鍙�4Byte鏁村舰 3Float褰紙浠B憋級
+ switch (receiveBytes[3])
+ {
+ case 1:
+ sensor.values = (receiveBytes[5] * 256 * 256 * 256) + (receiveBytes[6] * 256 * 256) + (receiveBytes[7] * 256) + receiveBytes[8];
+ break;
+ case 2:
+ sensor.values = -1 * ((receiveBytes[5] * 256 * 256 * 256) + (receiveBytes[6] * 256 * 256) + (receiveBytes[7] * 256) + receiveBytes[8]);
+ break;
+ case 3:
+ byte[] tempBytes = new byte[] { receiveBytes[5], receiveBytes[6], receiveBytes[7], receiveBytes[8] };
+ sensor.values = Math.Round(BitConverter.ToSingle(tempBytes, 0), 1);
+ break;
+ }
+ switch (receiveBytes[4])
+ {
+ case 2:
+ if (receiveBytes[1] == 5)//TVOC闇�姹傞櫎浠�100000
+ sensor.values /= 100000;
+ break;
+ }
+ EnvironmentalSciencePage.LoadEvent_UpdataStatus(sensor);
+ }
+ }
+ }
+ break;
+ case Command.InstructionPanelKeyACK:
+ case Command.ReadInstructionPanelKeyACK:
+ byte reACPanel = 0;
+ if (receiveBytes.Length == 2)
+ {
+ reACPanel = 1;
+ }
+ else if (receiveBytes.Length == 3)
+ {
+ reACPanel = receiveBytes[2];
+ }
+ else
+ {
+ break;
+ }
+ foreach (var ac in FunctionList.List.aCs)
+ {
+ if (ac.GetBusId() == subnetID + "_" + deviceID + "_" + reACPanel)
+ {
+ switch (receiveBytes[0])
+ {
+ case 3://
+ ac.trait_on_off.curValue = receiveBytes[1] == 1 ? "on" : "off";
+ break;
+ case 4:
+ case 7:
+ case 8:
+ case 19:
+ ac.trait_temp.curValue = receiveBytes[1].ToString();
+ break;
+ case 5:
+ ac.curFanIndex = receiveBytes[1];
+ break;
+ case 6:
+ ac.curModeIndex = receiveBytes[1];
+ break;
+
+ }
+ ac.lastState = "";
+ ac.lastState += " " + ac.trait_temp.curValue + ac.tempUnitString;
+ RoomPage.UpdataStates(ac);
+ FunctionPage.UpdataStates(ac);
+ HomePage.UpdataFunctionStates(ac);
+ ClassificationPage.UpdataInfo(ac);
+ ACPage.UpdataStates(ac);
+ }
+ }
+ break;
+ case Command.ReadPanleTempACK://1944
+ case Command.PanleBroadcastTemp:
+ foreach (var ac in FunctionList.List.aCs)
+ {
+ if (ac.GetBusId() == subnetID + "_" + deviceID + "_" + receiveBytes[0])
+ {
+ ac.trait_IndoorTemp.curValue = receiveBytes[1].ToString();
+ FunctionPage.UpdataStates(ac);
+ }
+ }
+ break;
+ case Command.ReadGatewayACK:
+ var mac = ByteToHex16(receiveBytes[5]) + ByteToHex16(receiveBytes[6]) + ByteToHex16(receiveBytes[7]) + ByteToHex16(receiveBytes[8]) + ByteToHex16(receiveBytes[9]) + ByteToHex16(receiveBytes[10]) + ByteToHex16(receiveBytes[11]) + ByteToHex16(receiveBytes[12]);
+ var Name = Encoding.GetEncoding("gb2312").GetString(receiveBytes, 13, 20).Trim('\0'); ;
+ MainPage.Log($"name : {Name} ; mac : {mac}");
+ if (DB_ResidenceData.Instance.residenceGatewayMAC == mac)
+ {
+ //鏈湴鎼滅储缃戝叧鎴愬姛
+ Control.Ins.IsSearchLocalGatewaySuccessful = true;
+ Control.Ins.GatewayOnline = true;
+ Control.Ins.IsRemote = false;
+ DAL.Mqtt.MqttClient.DisConnectRemote();//鏂紑mqtt
+ }
+ break;
+ }
+ }
+ catch (Exception ex)
+ {
+ MainPage.Log($"Bus Rev Erorr : {ex.Message}");
+ }
+ }
+ /// <summary>
+ /// byte杞�16杩涘埗瀛楃涓�
+ /// </summary>
+ /// <param name="b"></param>
+ /// <returns></returns>
+ string ByteToHex16(byte b)
+ {
+ string s = Convert.ToString(b, 16).ToUpper();
+ if (s.Length <= 1)
+ {
+ return "0" + s;
+ }
+ return s;
+ }
+
+ /// <summary>
+ /// 澶勭悊鎺ユ敹鍥炴潵鐨勬暟鎹�
+ /// </summary>
+ void ManagerReceive(byte subnetID, byte deviceID, Command command, byte[] usefulBytes)
+ {
+ try
+ {
+ string receiveFlag = string.Format("{0},{1},{2},", subnetID, deviceID, (int)command);
+
+ switch (command)
+ {
+ case Command.SetSingleLightACK:
+ receiveFlag += string.Format("{0}", usefulBytes[0]);
+ break;
+ case Command.SetLogicLoopColorACK:
+ receiveFlag += string.Format("{0},{1},{2}", usefulBytes[0], usefulBytes[1], usefulBytes[2]);
+ break;
+ case Command.ReadLogicLoopColorACK:
+ case Command.ReadACModeACK:
+ case Command.SetACModeACK:
+ case Command.ReadFloorHeatACK:
+ case Command.SetFloorHeatACK:
+ receiveFlag += string.Format("{0}", usefulBytes[0]);
+ break;
+ case Command.ReadLightAllLoopBrightnessACK:
+ receiveFlag += "";
+ break;
+ case Command.ReadGatewayACK:
+ receiveFlag = string.Format("{0},{1}", usefulBytes[0], usefulBytes[1]);
+ break;
+ case Command.ReadDeviceLoopInfoACK:
+ if (usefulBytes[0] == 1)
+ {
+ receiveFlag += string.Format("{0},{1}", usefulBytes[0], usefulBytes[2]); ;
+ }
+ else
+ receiveFlag += string.Format("{0},{1},{2}", usefulBytes[0], usefulBytes[1], usefulBytes[2]);
+ break;
+ case Command.InstructionPanelKeyACK:
+ case Command.ReadInstructionPanelKeyACK:
+ receiveFlag += string.Format("{0},{1}", usefulBytes[0], usefulBytes[1]);
+ break;
+ case Command.ReadRemark:
+ new Control_Udp().ReceiveReadRemark(usefulBytes);
+ break;
+ default:
+ break;
+ }
+ Control_Udp.ReceiveRepeatManager(receiveFlag,usefulBytes);
+ }
+ catch (Exception ex)
+ {
+ MainPage.Log("ManagerReceive鎶涘嚭寮傚父锛�" + ex.ToString());
+ }
+ }
+
+
+ }
+}
\ No newline at end of file
--
Gitblit v1.8.0