From b69d7735274b8d0f741da8a6bb8b8e1347477a5a Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期四, 19 三月 2020 17:14:16 +0800
Subject: [PATCH] 20200319

---
 HDL_ON/DAL/Net/CommonPage.cs |  191 ++++++++++++++++++++++++++++++-----------------
 1 files changed, 122 insertions(+), 69 deletions(-)

diff --git a/HDL_ON/DAL/Net/CommonPage.cs b/HDL_ON/DAL/Net/CommonPage.cs
index 582cbf2..3ef5e1b 100644
--- a/HDL_ON/DAL/Net/CommonPage.cs
+++ b/HDL_ON/DAL/Net/CommonPage.cs
@@ -13,9 +13,10 @@
 
         public static bool IsRemote;
         public static Action RefreshAir;
-        public static string FindGatewayChilrenIPAddress = new NetWiFi ().BroadcastIpAddress.ToString ();
+        public static string FindGatewayChilrenIPAddress = new NetWiFi().BroadcastIpAddress.ToString();
         private static string ip = "0.0.0.0";
-        public static System.Net.IPEndPoint EndPoint {
+        public static System.Net.IPEndPoint EndPoint
+        {
             get
             {
                 try
@@ -32,7 +33,8 @@
 
         ///淇濆瓨璁惧澶囨敞鎵嶇敤gb2312锛屽叾浠栨儏鍐电敤utf8
         public static Encoding MyEncodingUTF8 = Encoding.UTF8;//Get
-        public static Encoding MyEncodingGB2312 {
+        public static Encoding MyEncodingGB2312
+        {
             get
             {
                 try
@@ -57,37 +59,38 @@
         public static DateTime dt;
 
         //public static byte currentSubnetID = 0;
-        public static void InitHttpListener ()
+        public static void InitHttpListener()
         {
-            if (isHttpListenerStart) {
+            if (isHttpListenerStart)
+            {
                 return;
             }
-            HttpListener.Start (new NetWiFi ().IpAddress, 6001);
+            HttpListener.Start(new NetWiFi().IpAddress, 6001);
             HttpListener.EventHandler -= httpListener_EventHandler;
             HttpListener.EventHandler += httpListener_EventHandler;
             isHttpListenerStart = true;
         }
-        public static void CloseHttpListener ()
+        public static void CloseHttpListener()
         {
             //isHttpListenerStart = false;
             //return;
             if (!isHttpListenerStart)
                 return;
-            HttpListener.Close ();
+            HttpListener.Close();
             isHttpListenerStart = false;
         }
         /// <summary>
         /// 鍒濆鍖栧鐞唖ocket鎺ユ敹鐨勬暟鎹� 
         /// </summary>
-        public static void InitReceiveEvent ()
+        public static void InitReceiveEvent()
         {
             Packet.ReceiveEvent += Packet_ReceiveEvent;
         }
 
-        public static float floatChange (byte b1, byte b2, byte b3, byte b4)
+        public static float floatChange(byte b1, byte b2, byte b3, byte b4)
         {
             byte[] byteTemp = { b4, b3, b2, b1 };
-            return BitConverter.ToSingle (byteTemp, 0);
+            return BitConverter.ToSingle(byteTemp, 0);
         }
 
 
@@ -99,45 +102,76 @@
                 {
                     case Command.ReadLightSingleLoopBrightnessACK:
                     case Command.SetSingleLightACK:
-                        foreach (var function in DB_ResidenceData.residenceData.functions.lights)
+                        foreach (var function in DB_ResidenceData.residenceData.functionList.lights)
                         {
                             if (function.GetBusId() == subnetID + "_" + deviceID + "_" + receiveBytes[0])
                             {
                                 if (function.functionCategory == FunctionType.Light)
                                 {
                                     var light = function as Light;
-                                    if (receiveBytes[2] == 0 && light.state == 0)
-                                    {
-                                        break;
-                                    }
-                                    if (receiveBytes[2] == 100 && light.state == 1)
+                                    if (receiveBytes[2] == 0 && light.on_off == 0)
                                     {
                                         break;
                                     }
                                     if (function.functionType == "Relay")
                                     {
                                         var relay = function as Light;
-                                        relay.state = receiveBytes[2] == 0 ? 0 : 1;
+                                        relay.on_off = receiveBytes[2] == 0 ? 0 : 1;
                                         HomePage.UpdataLightView(relay);
-                                        //RoomPage.
                                     }
-                                    else if (function.functionType == "brightness")
+                                    else if (function.functionType == "Dimmer")
                                     {
                                         var dimmer = function as Light;
-                                        dimmer.state = receiveBytes[2] == 0 ? 0 : 1;
-                                        dimmer.dicPropert["brightness"] = receiveBytes[1];
-                                        //dimmer.brightness = receiveBytes[1];
-                                        if (receiveBytes[2] > 0)
+                                        dimmer.on_off = receiveBytes[2] == 0 ? 0 : 1;
+                                        if (dimmer.on_off == 1)
+                                        {
+                                            dimmer.brightness = receiveBytes[2];
                                             dimmer.lastState = Language.StringByID(StringId.Brightness) + " : " + receiveBytes[2] + "%";
+                                        }
                                         HomePage.UpdataLightView(dimmer);
+                                        RoomPage.UpdataStates(dimmer);
+                                        FunctionPage.UpdataStates(dimmer);
+                                        DimmerPage.UpdataStates(dimmer);
                                     }
+                                }
+                            }
+                        }
+                        break;
+                    case Command.SetLogicLoopColorACK:
+                        foreach (var function in DB_ResidenceData.residenceData.functionList.lights)
+                        {
+                            if (function.GetBusId() == subnetID + "_" + deviceID + "_" + receiveBytes[0])
+                            {
+                                if (function.functionType == "RGB")
+                                {
+                                    var light = function as Light;
+                                    if (receiveBytes[2] == 0 && light.on_off == 0)
+                                    {
+                                        break;
+                                    }
+                                    var rgb = function as Light;
+                                    rgb.on_off = receiveBytes[1] == 0 ? 0 : 1;
+                                    if (rgb.on_off == 1)
+                                    {
+                                        rgb.brightness = receiveBytes[1];
+                                        rgb.lastState = Language.StringByID(StringId.Brightness) + " : " + receiveBytes[1] + "%";
+                                    }
+                                    rgb.redColor = receiveBytes[6];
+                                    rgb.greenColor = receiveBytes[7];
+                                    rgb.blueColor = receiveBytes[8];
+
+                                    HomePage.UpdataLightView(rgb);
+                                    RoomPage.UpdataStates(rgb);
+                                    FunctionPage.UpdataStates(rgb);
+                                    RGBPage.UpdataStates(rgb);
                                 }
                             }
                         }
                         break;
                 }
             }
-            catch (Exception ex) {
+            catch (Exception ex)
+            {
                 MainPage.Log($"Bus Rev Erorr : {ex.Message}");
             }
         }
@@ -146,49 +180,62 @@
         /// </summary>
         /// <returns>The to hex16.</returns>
         /// <param name="b">The blue component.</param>
-        public static string byteToHex16 (byte b)
+        public static string byteToHex16(byte b)
         {
-            string s = Convert.ToString (b, 16).ToUpper (); 
-            if (s.Length <= 1) {
+            string s = Convert.ToString(b, 16).ToUpper();
+            if (s.Length <= 1)
+            {
                 return "0" + s;
             }
             return s;//
         }
 
-        static void httpListener_EventHandler (System.Collections.Specialized.NameValueCollection nameValueCollection, System.IO.Stream outputStream, System.IO.Stream inputStream)
+        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 = System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (FileUtils.ReadFiles ()));
-                        outputStream.Write (bytes, 0, bytes.Length);
-                        outputStream.Flush ();
-                    } else {
-                        byte [] bytes;
-                        if (!FileUtils.Exists (tempFileName)) {
-                            bytes = System.Text.Encoding.UTF8.GetBytes ("鏂囦欢鍚嶄笉瀛樺湪锛�");
-                            outputStream.Write (bytes, 0, bytes.Length);
-                            outputStream.Flush ();
+            try
+            {
+                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(FileUtils.ReadFiles()));
+                        outputStream.Write(bytes, 0, bytes.Length);
+                        outputStream.Flush();
+                    }
+                    else
+                    {
+                        byte[] bytes;
+                        if (!FileUtils.Exists(tempFileName))
+                        {
+                            bytes = System.Text.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 ();
+                        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", "");
-                } 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 ());
+                else if (nameValueCollection["Command"].StartsWith("Upload"))
+                {
+                    string path = Application.RootPath + nameValueCollection["Command"].Replace("Upload", "");
+                    string dePath = nameValueCollection["Command"].Replace("Upload", "");
+                }
+                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());
             }
         }
 
@@ -196,22 +243,28 @@
         /// 鐩戝惉璇锋眰鐨凥ttp绔彛
         /// </summary>
         public static int Port = 5555;
-        static void httpListener_EventHandler (string rawUrl, System.IO.Stream outputStream, System.IO.Stream inputStream)
+        static void httpListener_EventHandler(string rawUrl, System.IO.Stream outputStream, System.IO.Stream inputStream)
         {
-            foreach (var musicInfo in MusicInfo.MusicInfoList) {
-                if ("audio-item-" + musicInfo.ID == rawUrl.TrimStart ('/')) {
-                    var file = new System.IO.FileStream (musicInfo.Data, System.IO.FileMode.Open, System.IO.FileAccess.Read);
-                    byte [] bytes = new byte [1024];
-                    try {
-                        while (file.CanRead) {
-                            int len = file.Read (bytes, 0, bytes.Length);
-                            if (len == 0) {
+            foreach (var musicInfo in MusicInfo.MusicInfoList)
+            {
+                if ("audio-item-" + musicInfo.ID == rawUrl.TrimStart('/'))
+                {
+                    var file = new System.IO.FileStream(musicInfo.Data, System.IO.FileMode.Open, System.IO.FileAccess.Read);
+                    byte[] bytes = new byte[1024];
+                    try
+                    {
+                        while (file.CanRead)
+                        {
+                            int len = file.Read(bytes, 0, bytes.Length);
+                            if (len == 0)
+                            {
                                 break;
                             }
-                            outputStream.Write (bytes, 0, len);
+                            outputStream.Write(bytes, 0, len);
                         }
-                    } catch { }
-                    file.Close ();
+                    }
+                    catch { }
+                    file.Close();
                     break;
                 }
             }

--
Gitblit v1.8.0