From a251442d9fc088b3d8cf74d20b959f0f6103b095 Mon Sep 17 00:00:00 2001 From: wxr <464027401@qq.com> Date: 星期一, 14 九月 2020 17:42:10 +0800 Subject: [PATCH] 20200914 --- HDL_ON/DriverLayer/CommonPage.cs | 235 +++++++++------------------------------------------------- 1 files changed, 38 insertions(+), 197 deletions(-) diff --git a/HDL_ON/DriverLayer/CommonPage.cs b/HDL_ON/DriverLayer/CommonPage.cs index 285baea..f366770 100644 --- a/HDL_ON/DriverLayer/CommonPage.cs +++ b/HDL_ON/DriverLayer/CommonPage.cs @@ -1,10 +1,8 @@ 锘縰sing System; +using System.Collections.Generic; using System.Text; -using HDL_ON.DAL.Net; using HDL_ON.Entity; using HDL_ON.UI; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using Shared; using Shared.Net; @@ -12,11 +10,7 @@ { public static class CommonPage { - - public static bool IsRemote; public static Action RefreshAir; - public static string FindGatewayChilrenIPAddress = new NetWiFi().BroadcastIpAddress.ToString(); - private static string ip = "0.0.0.0"; public static System.Net.IPEndPoint EndPoint { get @@ -30,16 +24,6 @@ //闃叉寮傚父瀵艰嚧绋嬪簭閫�鍑� return new System.Net.IPEndPoint(System.Net.IPAddress.Parse("127.0.0.1"), 6000); } - } - } - - - public static System.Net.IPEndPoint GetGatewayIP_EndPoint - { - get - { - //闃叉寮傚父瀵艰嚧绋嬪簭閫�鍑� - return new System.Net.IPEndPoint(System.Net.IPAddress.Parse("224.0.168.188"), 6688); } } @@ -67,30 +51,6 @@ } } } - //public static bool isHttpListenerStart; - //public static DateTime dt; - //public static byte currentSubnetID = 0; - //public static void InitHttpListener() - //{ - // if (isHttpListenerStart) - // { - // return; - // } - // Console.WriteLine("Init Http Listener !"); - // HttpListener.Start(new NetWiFi().IpAddress, 6002); - // HttpListener.EventHandler -= httpListener_EventHandler; - // HttpListener.EventHandler += httpListener_EventHandler; - // isHttpListenerStart = true; - //} - //public static void CloseHttpListener() - //{ - // //isHttpListenerStart = false; - // //return; - // if (!isHttpListenerStart) - // return; - // HttpListener.Close(); - // isHttpListenerStart = false; - //} /// <summary> /// 鍒濆鍖栧鐞唖ocket鎺ユ敹鐨勬暟鎹� /// </summary> @@ -105,90 +65,68 @@ return BitConverter.ToSingle(byteTemp, 0); } - static void Packet_ReceiveEvent(byte subnetID, byte deviceID, Command command, byte[] receiveBytes, string revGatewayIP) { try { - if(revGatewayIP == "172.16.2.237") - { - - } Control.controlLostCount = 0; switch (command) { case Command.SetSingleLightACK: - foreach (var light in DB_ResidenceData.functionList.lights) + var queryList = new List<Function>(); + queryList.AddRange(DB_ResidenceData.functionList.electricals); + queryList.AddRange(DB_ResidenceData.functionList.lights); + foreach (var updataObj in queryList) { - if (light.GetBusId() == subnetID + "_" + deviceID + "_" + receiveBytes[0]) + if (updataObj.GetBusId() == subnetID + "_" + deviceID + "_" + receiveBytes[0]) { - if (light.functionType != FunctionType.RGB) + if (updataObj.functionType != FunctionType.RGB) { - light.trait_on_off.value = receiveBytes[2] == 0 ? "off" : "on"; - if (light.trait_on_off.value.ToString() == "on") + if (updataObj.trait_on_off.value.ToString() == "on") { - light.brightness = receiveBytes[2]; - light.lastState = Language.StringByID(StringId.Brightness) + " : " + receiveBytes[2] + "%"; + if (updataObj.functionType == FunctionType.Fan) + { + (updataObj as Fan).openLevel = receiveBytes[2]; + updataObj.lastState = Language.StringByID(StringId.Level) + " : " + receiveBytes[2]; + } + else + { + (updataObj as Light).brightness = receiveBytes[2]; + updataObj.lastState = Language.StringByID(StringId.Brightness) + " : " + receiveBytes[2] + "%"; + } } - HomePage.UpdataFunctionStates(light); - RoomPage.UpdataStates(light); - FunctionPage.UpdataStates(light); - ClassificationPage.UpdataInfo(light); - switch (light.functionType) + HomePage.UpdataFunctionStates(updataObj); + RoomPage.UpdataStates(updataObj); + FunctionPage.UpdataStates(updataObj); + ClassificationPage.UpdataInfo(updataObj); + switch (updataObj.functionType) { case FunctionType.Relay: - RelayPage.UpdataState(light); + RelayPage.UpdataState(updataObj as Light); break; case FunctionType.Dimmer: - DimmerPage.UpdataStates(light); + DimmerPage.UpdataStates(updataObj as Light); break; - } - } - } - } - - foreach (var e in DB_ResidenceData.functionList.electricals) - { - if (e.GetBusId() == subnetID + "_" + deviceID + "_" + receiveBytes[0]) - { - if (e.functionType == FunctionType.Fan) - { - var fan = e as Fan; - fan.trait_on_off.value = receiveBytes[2] == 0 ? "off" : "on"; - if (fan.trait_on_off.value == "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.functionType) - { case FunctionType.Fan: - FanPage.UpdataState(fan); - break; - case FunctionType.Socket: - + FanPage.UpdataState(updataObj as Fan); break; } + break; } } } - break; case Command.ReadLightAllLoopBrightnessACK: for (int i = 0; i < receiveBytes[0]; i++) { - var light = DB_ResidenceData.functionList.lights.Find((obj) => obj.bus_Data.SubnetID == subnetID && obj.bus_Data.DeviceID == deviceID && obj.bus_Data.LoopID == i); + var light = DB_ResidenceData.functionList.lights.Find((obj) => obj.bus_Data.SubnetID == subnetID && obj.bus_Data.DeviceID == deviceID && obj.bus_Data.LoopID == (i+1)); if (light != null) { if (light.functionType != FunctionType.RGB) { - light.trait_on_off.value = receiveBytes[2] == 0 ? "off" : "on"; - if (light.trait_on_off.value == "on") + light.trait_on_off.value = receiveBytes[light.bus_Data.LoopID] == 0 ? "off" : "on"; + if (light.trait_on_off.value.ToString() == "on") { light.brightness = receiveBytes[2]; light.lastState = Language.StringByID(StringId.Brightness) + " : " + receiveBytes[2] + "%"; @@ -280,8 +218,8 @@ { curtain.trait_on_off.value = "off"; } - curtain.openLevel = receiveBytes[1]; - curtain.lastState = Language.StringByID(StringId.Open) + curtain.openLevel + "%"; + curtain.percent = receiveBytes[1]; + curtain.lastState = Language.StringByID(StringId.Open) + curtain.percent + "%"; } else { @@ -306,11 +244,16 @@ FunctionPage.UpdataStates(curtain); HomePage.UpdataFunctionStates(curtain); ClassificationPage.UpdataInfo(curtain); - RollingShutterPage.UpdataState(curtain); switch (curtain.functionType) { case FunctionType.Curtain: CurtainModulePage.UpdataState(curtain); + break; + case FunctionType.MotorCurtain: + MotorCurtainPage.UpdataState(curtain); + break; + case FunctionType.RollingShutter: + RollingShutterPage.UpdataState(curtain); break; } } @@ -457,7 +400,6 @@ case Command.ReadDeviceLoopInfoACK: FunctionType dt = (FunctionType)(11 * 256 + receiveBytes[1]); string tag = receiveBytes[1] + "_" + subnetID + "_" + deviceID + "_" + receiveBytes[2]; - foreach (var sensor in DB_ResidenceData.functionList.sensorsEnvironmentalScience) { if (sensor.bus_Data != null) @@ -569,39 +511,6 @@ HomePage.UpdataFunctionStates(ac); ClassificationPage.UpdataInfo(ac); ACPage.UpdataStates(ac); - //else if (common.Type == DeviceType.FoolHeatPanel) - { - //switch (receiveBytes[0]) - //{ - // case 20:// - // fh.Status = receiveBytes[1]; - // break; - // case 21: - // fh.TemperatureType = receiveBytes[1]; - // if (receiveBytes[1] == 5) - // { - // if (fh.Timer == 0)//鏃堕棿妯″紡鐨勬椂闂存鏍囧織 (0锛氱櫧澶╋紝1锛氬鏅�) (1byte) //20110112鍔犳椂闂存鏍囧織 - // Control.ControlBytesSend(Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte[] { 26, 2, fh.LoopID }, SendCount.Zero); - // else - // Control.ControlBytesSend(Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte[] { 27, 3, fh.LoopID }, SendCount.Zero); - // } - // else - // Control.ControlBytesSend(Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte[] { (byte)(receiveBytes[1] + 24), fh.LoopID }, SendCount.Zero); - // break; - // case 25: - // fh.NormalTemperature = receiveBytes[1]; - // break; - // case 26: - // fh.DayTemperature = receiveBytes[1]; - // break; - // case 27: - // fh.NightTemperature = receiveBytes[1]; - // break; - // case 28: - // fh.AwayTemperature = receiveBytes[1]; - // break; - //} - } } } break; @@ -614,12 +523,6 @@ ac.indoorTemp = receiveBytes[1]; FunctionPage.UpdataStates(ac); } - //else if (common.Type == DeviceType.FoolHeatPanel) - // { - // var tempFH22 = common as FoolHeatPanel; - // tempFH22.IndoorTemperature = receiveBytes[1]; - // UserFHPage.UpdateIndoorTemp(tempFH22.CommonLoopID, receiveBytes[1]); - // } } break; } @@ -643,67 +546,5 @@ } return s;// } - /* 2020-09-01寮冪敤锛屼娇鐢╰cp鎺ユ敹鏁版嵁 - static void httpListener_EventHandler(System.Collections.Specialized.NameValueCollection nameValueCollection, System.IO.Stream outputStream, System.IO.Stream inputStream) - { - try - { - if (nameValueCollection["Command"] != null && nameValueCollection["Command"].StartsWith("Get")) - { - string tempFileName = nameValueCollection["Command"].Replace("Get", ""); - if ("AllFiles" == tempFileName) - { - byte[] bytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(FileUtils.ReadFiles())); - outputStream.Write(bytes, 0, bytes.Length); - outputStream.Flush(); - } - else - { - byte[] bytes; - if (!FileUtils.Exists(tempFileName)) - { - bytes = Encoding.UTF8.GetBytes("鏂囦欢鍚嶄笉瀛樺湪锛�"); - outputStream.Write(bytes, 0, bytes.Length); - outputStream.Flush(); - return; - } - System.IO.FileStream fs = new System.IO.FileStream(Application.RootPath + tempFileName, System.IO.FileMode.Open); - bytes = new byte[fs.Length]; - fs.Read(bytes, 0, bytes.Length); - fs.Close(); - outputStream.Write(bytes, 0, bytes.Length); - outputStream.Flush(); - } - } - else if (nameValueCollection["Command"].StartsWith("Upload")) - { - string path = Application.RootPath + nameValueCollection["Command"].Replace("Upload", ""); - string dePath = nameValueCollection["Command"].Replace("Upload", ""); - FileUtils.WriteFileByInputStream(path, inputStream); - var reString = CommonPage.MyEncodingUTF8.GetString(FileUtils.ReadFile(path)); - var common = JsonConvert.DeserializeObject<AProtocolEntity>(reString); - //Console.WriteLine(common.ToString()); - if(dePath == "FunctionList") - { - foreach(var obj in common.objects) - { - DB_ResidenceData.functionList.AddFunction(obj); - } - DB_ResidenceData.functionList.GetAllFunction(); - } - } - else - { - byte[] bytes = System.Text.Encoding.UTF8.GetBytes("璇锋眰鍛戒护鏃犳晥锛�"); - outputStream.Write(bytes, 0, bytes.Length); - outputStream.Flush(); - } - } - catch (Exception ex) - { - MainPage.Log("httpListener_EventHandler" + ex.ToString()); - } - } - */ } } \ No newline at end of file -- Gitblit v1.8.0