From 611786df5108dca0bdcff03834cc285cba4b8e61 Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期二, 13 十月 2020 16:48:43 +0800
Subject: [PATCH] 2020-10-13-1

---
 HDL_ON/DriverLayer/CommonPage.cs |  155 +++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 131 insertions(+), 24 deletions(-)

diff --git a/HDL_ON/DriverLayer/CommonPage.cs b/HDL_ON/DriverLayer/CommonPage.cs
index f684d0b..07fa7ec 100644
--- a/HDL_ON/DriverLayer/CommonPage.cs
+++ b/HDL_ON/DriverLayer/CommonPage.cs
@@ -3,6 +3,8 @@
 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;
 
@@ -31,6 +33,16 @@
             }
         }
 
+
+        public static System.Net.IPEndPoint GetGatewayIP_EndPoint
+        {
+            get
+            {
+                //闃叉寮傚父瀵艰嚧绋嬪簭閫�鍑�
+                return new System.Net.IPEndPoint(System.Net.IPAddress.Parse("224.0.168.188"), 6688);
+            }
+        }
+
         ///淇濆瓨璁惧澶囨敞鎵嶇敤gb2312锛屽叾浠栨儏鍐电敤utf8
         public static Encoding MyEncodingUTF8 = Encoding.UTF8;//Get
         public static Encoding MyEncodingGB2312
@@ -55,7 +67,7 @@
                 }
             }
         }
-        static bool isHttpListenerStart;
+        public static bool isHttpListenerStart;
         public static DateTime dt;
 
         //public static byte currentSubnetID = 0;
@@ -65,6 +77,7 @@
             {
                 return;
             }
+            Console.WriteLine("Init Http Listener !");
             HttpListener.Start(new NetWiFi().IpAddress, 6002);
             HttpListener.EventHandler -= httpListener_EventHandler;
             HttpListener.EventHandler += httpListener_EventHandler;
@@ -98,6 +111,11 @@
         {
             try
             {
+                if(revGatewayIP == "172.16.2.237")
+                {
+
+                }
+
                 switch (command)
                 {
                     case Command.ReadLightSingleLoopBrightnessACK:
@@ -193,38 +211,45 @@
                     case Command.ReadCurtainStutasACK:
                         foreach (var curtain in DB_ResidenceData.residenceData.functionList.curtains)
                         {
-                            if (curtain.GetBusId() == subnetID + "_" + deviceID + "_" + receiveBytes[0])
+                            if (curtain.bus_Data.SubnetID == subnetID && curtain.bus_Data.DeviceID == deviceID)
                             {
-                                switch(receiveBytes[1])
+                                if (receiveBytes[0] == 17)
                                 {
-                                    case 0:
-                                        curtain.on_off = "stop";
-                                        break;
-                                    case 1:
+                                    if (receiveBytes[1] > 1)
+                                    {
                                         curtain.on_off = "on";
-                                        curtain.lastState = Language.StringByID(StringId.Open);
-                                        break;
-                                    case 2:
+                                    }
+                                    else
+                                    {
                                         curtain.on_off = "off";
-                                        curtain.lastState = Language.StringByID(StringId.Close);
-                                        break;
-                                    default:
-                                        if (receiveBytes[1] > 1)
-                                        {
+                                    }
+                                    curtain.openLevel = receiveBytes[1];
+                                    curtain.lastState = Language.StringByID(StringId.Open) + curtain.openLevel + "%";
+                                }
+                                else
+                                {
+                                    if (curtain.bus_Data.LoopID != receiveBytes[0])
+                                        continue;
+                                    switch (receiveBytes[1])
+                                    {
+                                        case 0:
+                                            curtain.on_off = "stop";
+                                            break;
+                                        case 1:
                                             curtain.on_off = "on";
-                                        }
-                                        else
-                                        {
+                                            curtain.lastState = Language.StringByID(StringId.Open);
+                                            break;
+                                        case 2:
                                             curtain.on_off = "off";
-                                        }
-                                        curtain.openLevel = receiveBytes[1];
-                                        curtain.lastState = Language.StringByID(StringId.Open) + curtain.openLevel + "%";
-                                        break;
+                                            curtain.lastState = Language.StringByID(StringId.Close);
+                                            break;
+                                    }
                                 }
                                 RoomPage.UpdataStates(curtain);
                                 FunctionPage.UpdataStates(curtain);
                                 HomePage.UpdataFunctionStates(curtain);
                                 ClassificationPage.UpdataInfo(curtain);
+                                RollingShutterPage.UpdataState(curtain);
                                 switch (curtain.functionType)
                                 {
                                     case FunctionType.Curtain:
@@ -365,6 +390,76 @@
                             }
                         }
                         break;
+                    case Command.ReadDeviceLoopInfoACK:
+                        FunctionType dt = (FunctionType)(11 * 256 + receiveBytes[1]);
+                        string tag = receiveBytes[1] + "_" + subnetID + "_" + deviceID + "_" + receiveBytes[2];
+
+                        foreach (var sensor in DB_ResidenceData.residenceData.functionList.sensorsEnvironmentalScience)
+                        {
+                            if (sensor.bus_Data != null)
+                            {
+                                if ((int)sensor.functionType % 256 == receiveBytes[1] && sensor.bus_Data.SubnetID == subnetID &&
+                                    sensor.bus_Data.DeviceID == deviceID && sensor.bus_Data.LoopID == receiveBytes[2])
+                                {
+                                    switch (dt)
+                                    {
+                                        case FunctionType.Temp:
+                                            byte[] tempBytes = new byte[] { receiveBytes[24], receiveBytes[25], receiveBytes[26], receiveBytes[27] };
+                                            sensor.values = Math.Round(BitConverter.ToSingle(tempBytes, 0), 1);
+                                            break;
+                                        case FunctionType.Humidity:
+                                            sensor.values = Convert.ToDouble(receiveBytes[24] * 256 + receiveBytes[25]) / 10;
+                                            break;
+                                        case FunctionType.TVOC:
+                                            sensor.values = Convert.ToDouble(receiveBytes[24] * 256 + receiveBytes[25]) / 100;
+                                            break;
+                                        case FunctionType.PM25:
+                                            sensor.values = Convert.ToInt32(receiveBytes[24] * 256 + receiveBytes[25]);
+                                            break;
+                                        case FunctionType.CO2:
+                                            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 DB_ResidenceData.residenceData.functionList.sensorsEnvironmentalScience)
+                        {
+                            if (sensor.bus_Data != null)
+                            {
+                                if ((int)sensor.functionType % 256 == receiveBytes[1] && sensor.bus_Data.SubnetID == subnetID &&
+                                    sensor.bus_Data.DeviceID == deviceID && sensor.bus_Data.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;
                 }
             }
             catch (Exception ex)
@@ -396,7 +491,7 @@
                     string tempFileName = nameValueCollection["Command"].Replace("Get", "");
                     if ("AllFiles" == tempFileName)
                     {
-                        byte[] bytes = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(FileUtils.ReadFiles()));
+                        byte[] bytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(FileUtils.ReadFiles()));
                         outputStream.Write(bytes, 0, bytes.Length);
                         outputStream.Flush();
                     }
@@ -405,7 +500,7 @@
                         byte[] bytes;
                         if (!FileUtils.Exists(tempFileName))
                         {
-                            bytes = System.Text.Encoding.UTF8.GetBytes("鏂囦欢鍚嶄笉瀛樺湪锛�");
+                            bytes = Encoding.UTF8.GetBytes("鏂囦欢鍚嶄笉瀛樺湪锛�");
                             outputStream.Write(bytes, 0, bytes.Length);
                             outputStream.Flush();
                             return;
@@ -422,6 +517,18 @@
                 {
                     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.residenceData.functionList.AddFunction(obj);
+                        }
+                        DB_ResidenceData.residenceData.functionList.GetAllFunction();
+                    }
                 }
                 else
                 {

--
Gitblit v1.8.0