From 2bec9c838d2d688025698de8ec1de401ffd7dd1f Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期二, 11 八月 2020 14:13:55 +0800
Subject: [PATCH] 20200811

---
 HDL_ON/DriverLayer/CommonPage.cs |  267 +++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 237 insertions(+), 30 deletions(-)

diff --git a/HDL_ON/DriverLayer/CommonPage.cs b/HDL_ON/DriverLayer/CommonPage.cs
index f684d0b..d12e95e 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,12 @@
         {
             try
             {
+                if(revGatewayIP == "172.16.2.237")
+                {
+
+                }
+                Control.controlLostCount = 0;
+
                 switch (command)
                 {
                     case Command.ReadLightSingleLoopBrightnessACK:
@@ -106,7 +125,7 @@
                         {
                             if (light.GetBusId() == subnetID + "_" + deviceID + "_" + receiveBytes[0])
                             {
-                                if ( light.functionType != FunctionType.RGB)
+                                if (light.functionType != FunctionType.RGB)
                                 {
                                     light.on_off = receiveBytes[2] == 0 ? "off" : "on";
                                     if (light.on_off == "on")
@@ -171,7 +190,7 @@
                                 if (rgb.functionType == FunctionType.RGB)
                                 {
                                     rgb.on_off = receiveBytes[1] > 0 ? "on" : "off";
-                                    if (receiveBytes[1] >0)
+                                    if (receiveBytes[1] > 0)
                                     {
                                         rgb.brightness = receiveBytes[1];
                                         rgb.lastState = Language.StringByID(StringId.Brightness) + " : " + receiveBytes[1] + "%";
@@ -193,38 +212,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:
@@ -296,11 +322,11 @@
                             if (fh.GetBusId() == subnetID + "_" + deviceID + "_" + receiveBytes[0])
                             {
                                 fh.curTempType = receiveBytes[2];
-                                fh.on_off = receiveBytes[1] % 2 ==0?"off":"on";
+                                fh.on_off = receiveBytes[1] % 2 == 0 ? "off" : "on";
                                 fh.curModeIndex = receiveBytes[3];
                                 if (fh.modeTemp.ContainsKey("ordinary"))
                                 {
-                                    fh.modeTemp["ordinary"]= receiveBytes[4];
+                                    fh.modeTemp["ordinary"] = receiveBytes[4];
                                 }
                                 else
                                 {
@@ -345,9 +371,10 @@
                                         break;
                                     case "timer":
                                         fh.lastState = Language.StringByID(StringId.Auto);
-                                        if(receiveBytes[8]==0)
+                                        if (receiveBytes[8] == 0)
                                         {
-                                        }else
+                                        }
+                                        else
                                         {
                                         }
                                         break;
@@ -363,6 +390,174 @@
                                 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 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;
+                    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 DB_ResidenceData.residenceData.functionList.aCs)
+                        {
+                            if (ac.GetBusId() == subnetID + "_" + deviceID + "_" + reACPanel)
+                            {
+                                switch (receiveBytes[0])
+                                {
+                                    case 3://
+                                        ac.on_off = receiveBytes[1] == 1 ? "on" : "off";
+                                        break;
+                                    case 4:
+                                    case 7:
+                                    case 8:
+                                    case 19:
+                                        ac.curTemp = receiveBytes[1];
+                                        break;
+                                    case 5:
+                                        ac.curFanIndex = receiveBytes[1];
+                                        break;
+                                    case 6:
+                                        ac.curModeIndex = receiveBytes[1];
+                                        break;
+
+                                }
+                                ac.lastState = "";
+                                ac.lastState += " " + ac.curTemp + ac.curTempTypeString;
+                                RoomPage.UpdataStates(ac);
+                                FunctionPage.UpdataStates(ac);
+                                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;
+                    case Command.ReadPanleTempACK://1944
+                    case Command.PanleBroadcastTemp:
+                        foreach (var ac in DB_ResidenceData.residenceData.functionList.aCs)
+                        {
+                            if (ac.GetBusId() == subnetID + "_" + deviceID + "_" + receiveBytes[0])
+                            {
+                                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;
                 }
@@ -396,7 +591,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 +600,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 +617,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