From 4cc04639fbadde3a7f3b9875353df0d90fc09043 Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期六, 18 一月 2020 14:33:40 +0800
Subject: [PATCH] 节前备份

---
 HDL_ON/DAL/Net/CommonPage.cs |  130 +++++++++++++++++++++++++------------------
 1 files changed, 75 insertions(+), 55 deletions(-)

diff --git a/HDL_ON/DAL/Net/CommonPage.cs b/HDL_ON/DAL/Net/CommonPage.cs
index d248b8a..efd3d4a 100644
--- a/HDL_ON/DAL/Net/CommonPage.cs
+++ b/HDL_ON/DAL/Net/CommonPage.cs
@@ -1,7 +1,8 @@
 锘縰sing System;
 using System.Text;
 using HDL_ON.DAL.Net;
-using HDL_ON.Entity.Enumerative;
+using HDL_ON.Entity;
+using HDL_ON.UI;
 using Shared;
 using Shared.Net;
 
@@ -11,30 +12,20 @@
     {
 
         public static bool IsRemote;
-        //public static AirQuality AirQuality;
         public static Action RefreshAir;
-        public static bool FindGateway = false;
-        public static bool FindGatewayChilren = false;
         public static string FindGatewayChilrenIPAddress = new NetWiFi ().BroadcastIpAddress.ToString ();
-        public static bool LocalPhoneFindDevice = false;
         private static string ip = "0.0.0.0";
         public static System.Net.IPEndPoint EndPoint {
-            get {
-                try {
-                    if (FindGateway) {
-                        return new System.Net.IPEndPoint (System.Net.IPAddress.Parse (new NetWiFi ().BroadcastIpAddress.ToString ()), 6000);
-                    } else if (FindGatewayChilren) {
-                        try {
-                            return new System.Net.IPEndPoint (System.Net.IPAddress.Parse (FindGatewayChilrenIPAddress), 6000);
-                        } catch {
-                            return new System.Net.IPEndPoint (System.Net.IPAddress.Parse ("224.0.168.188"), 6000);
-                        }
-                    } else {
-                        return new System.Net.IPEndPoint (System.Net.IPAddress.Parse (new NetWiFi ().BroadcastIpAddress.ToString ()), 6000);
-                    }
-                } catch {
+            get
+            {
+                try
+                {
+                    return new System.Net.IPEndPoint(System.Net.IPAddress.Parse(new NetWiFi().BroadcastIpAddress.ToString()), 6000);
+                }
+                catch
+                {
                     //闃叉寮傚父瀵艰嚧绋嬪簭閫�鍑�
-                    return new System.Net.IPEndPoint (System.Net.IPAddress.Parse ("127.0.0.1"), 6000);
+                    return new System.Net.IPEndPoint(System.Net.IPAddress.Parse("127.0.0.1"), 6000);
                 }
             }
         }
@@ -42,16 +33,23 @@
         ///淇濆瓨璁惧澶囨敞鎵嶇敤gb2312锛屽叾浠栨儏鍐电敤utf8
         public static Encoding MyEncodingUTF8 = Encoding.UTF8;//Get
         public static Encoding MyEncodingGB2312 {
-            get {
-                try {
-                    if (System.Globalization.CultureInfo.InstalledUICulture.EnglishName.ToUpper().StartsWith("CZECH")) {
-                        return System.Text.Encoding.GetEncoding (1250);
-                    } else {
-                        return Encoding.GetEncoding ("gb2312");
+            get
+            {
+                try
+                {
+                    if (System.Globalization.CultureInfo.InstalledUICulture.EnglishName.ToUpper().StartsWith("CZECH"))
+                    {
+                        return Encoding.GetEncoding(1250);
                     }
-                }catch (Exception ex) {
-                    MainPage.Log ("MyEncodingGB2312 Erorr : "+ex.Message);
-                    return Encoding.GetEncoding ("gb2312");
+                    else
+                    {
+                        return Encoding.GetEncoding("gb2312");
+                    }
+                }
+                catch (Exception ex)
+                {
+                    MainPage.Log("MyEncodingGB2312 Erorr : " + ex.Message);
+                    return Encoding.GetEncoding("gb2312");
                 }
             }
         }
@@ -88,15 +86,57 @@
 
         public static float floatChange (byte b1, byte b2, byte b3, byte b4)
         {
-            byte [] byteTemp = new byte [4] { b4, b3, b2, b1 };
+            byte[] byteTemp = { b4, b3, b2, b1 };
             return BitConverter.ToSingle (byteTemp, 0);
         }
 
 
-        static void Packet_ReceiveEvent (byte subnetID, byte deviceID, Command command, byte [] usefullBytes, string revGatewayIP)
+        static void Packet_ReceiveEvent(byte subnetID, byte deviceID, Command command, byte[] receiveBytes, string revGatewayIP)
         {
-
-
+            try
+            {
+                switch (command)
+                {
+                    case Command.SetSingleLightACK:
+                        foreach (var function in DB_ResidenceData.residenceData.functions)
+                        {
+                            if (function.GetBusId() == subnetID + "_" + deviceID + "_" + receiveBytes[0])
+                            {
+                                if (function.funcType == FunctionType.Light)
+                                {
+                                    var light = function as Light;
+                                    if (receiveBytes[2] == 0 && light.state == 0)
+                                    {
+                                        break;
+                                    }
+                                    if (receiveBytes[2] == 100 && light.state == 1)
+                                    {
+                                        break;
+                                    }
+                                    if (function.bus_DeviceType == "Relay")
+                                    {
+                                        var relay = function as Light;
+                                        relay.state = receiveBytes[2] == 0 ? 0 : 1;
+                                        HomePage.UpdataLightView(relay);
+                                    }
+                                    else if (function.bus_DeviceType == "Dimmer")
+                                    {
+                                        var dimmer = function as Dimmer;
+                                        dimmer.state = receiveBytes[2] == 0 ? 0 : 1;
+                                        dimmer.brightness = receiveBytes[1];
+                                        if (receiveBytes[2] > 0)
+                                            dimmer.lastState = Language.StringByID(StringId.Brightness) + " : " + receiveBytes[2] + "%";
+                                        HomePage.UpdataLightView(dimmer);
+                                    }
+                                }
+                            }
+                        }
+                        break;
+                }
+            }
+            catch (Exception ex) {
+                MainPage.Log($"Bus Rev Erorr : {ex.Message}");
+            }
         }
         /// <summary>
         /// byte 鍙樺瓧绗︿覆
@@ -118,12 +158,12 @@
                 if (nameValueCollection ["Command"] != null && nameValueCollection ["Command"].StartsWith ("Get")) {
                     string tempFileName = nameValueCollection ["Command"].Replace ("Get", "");
                     if ("AllFiles" == tempFileName) {
-                        byte [] bytes = System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (MyIO.FileUtils.ReadFiles ()));
+                        byte [] bytes = System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (FileUtils.ReadFiles ()));
                         outputStream.Write (bytes, 0, bytes.Length);
                         outputStream.Flush ();
                     } else {
                         byte [] bytes;
-                        if (!MyIO.FileUtils.Exists (tempFileName)) {
+                        if (!FileUtils.Exists (tempFileName)) {
                             bytes = System.Text.Encoding.UTF8.GetBytes ("鏂囦欢鍚嶄笉瀛樺湪锛�");
                             outputStream.Write (bytes, 0, bytes.Length);
                             outputStream.Flush ();
@@ -147,26 +187,6 @@
             } catch (Exception ex) {
                 MainPage.Log ("httpListener_EventHandler" + ex.ToString ());
             }
-        }
-
-        /// <summary>
-        /// 闅忔満鏁伴珮浣�
-        /// </summary>
-        public static byte RandomHigh;
-        /// <summary>
-        /// 闅忔満鏁颁綆浣�
-        /// </summary>
-        public static byte RandomLow;
-
-        /// <summary>
-        /// Updates Device's remake.
-        /// </summary>
-        public static void UpdateRemark (byte subnetID, byte deviceID, string remark)
-        {
-            byte [] updateBytes = new byte [20];
-            byte [] remakeBytes = MyEncodingGB2312.GetBytes (remark);
-            Array.Copy (remakeBytes, 0, updateBytes, 0, remakeBytes.Length < 20 ? remakeBytes.Length : 20);
-            Control.ControlBytesSend (Command.UpdataRemake, subnetID, deviceID, updateBytes);
         }
 
         /// <summary>

--
Gitblit v1.8.0