From a40db3104e6d5d8a5d146ad808e5bb1ad6c8cb07 Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期五, 20 十一月 2020 17:53:22 +0800
Subject: [PATCH] 20201120

---
 HDL_ON/DAL/DriverLayer/Control.cs |   68 ++++++++++++++++++----------------
 1 files changed, 36 insertions(+), 32 deletions(-)

diff --git a/HDL_ON/DriverLayer/Control.cs b/HDL_ON/DAL/DriverLayer/Control.cs
similarity index 82%
rename from HDL_ON/DriverLayer/Control.cs
rename to HDL_ON/DAL/DriverLayer/Control.cs
index ea4b55e..82d3a9a 100644
--- a/HDL_ON/DriverLayer/Control.cs
+++ b/HDL_ON/DAL/DriverLayer/Control.cs
@@ -15,10 +15,6 @@
         /// </summary>
         local_BusUdp,
         /// <summary>
-        /// 鏈湴tcp鏈嶅姟绔�
-        /// </summary>
-        tcp_local_server,
-        /// <summary>
         /// 鏈湴tcp瀹㈡埛绔�
         /// </summary>
         tcp_local_client,
@@ -45,6 +41,10 @@
         /// </summary>
         public string reportIp = "255.255.255.255";
         /// <summary>
+        /// 缃戝叧鏄惁鍦ㄧ嚎
+        /// </summary>
+        public bool gatewayOnline = false;
+        /// <summary>
         /// tcp鏈嶅姟绔�
         /// </summary>
         public Control_TcpServer myTcpServer = null;
@@ -63,12 +63,24 @@
         public CommunicationMode communicationMode;
 
         /// <summary>
+        /// 鎵撳紑tcp鏈嶅姟绔�
+        /// </summary>
+        public void OpenTcpServer()
+        {
+            myTcpServer = new Control_TcpServer();
+            myTcpServer.OpenServer();
+        }
+
+        /// <summary>
         /// 鏀瑰彉閫氳鏂瑰紡
         /// </summary>
         public void ChangeCommunicationMode(CommunicationMode communicationMode)
         {
+            if(this.communicationMode == communicationMode)
+            {
+                return;
+            }
             this.communicationMode = communicationMode;
-
 
             switch (this.communicationMode)
             {
@@ -78,32 +90,10 @@
                         myUdp = new Control_Udp_Bus();
                     }
                     UdpSocket._BusSocket.Start();
-                    if (myTcpServer != null)
-                    {
-                        myTcpClient.Close();
-                        myTcpClient = null;
-                    }
                     if (myTcpClient != null)
                     {
                         myTcpClient.Close();
                         myTcpClient = null;
-                    }
-                    break;
-                case CommunicationMode.tcp_local_server:
-                    if (myTcpServer == null)
-                    {
-                        myTcpServer = new Control_TcpServer();
-                        myTcpServer.OpenServer();
-                    }
-                    if (myTcpClient != null)
-                    {
-                        myTcpClient.Close();
-                        myTcpClient = null;
-                    }
-                    if(myUdp != null)
-                    {
-                        UdpSocket._BusSocket.Stop();
-                        myUdp = null;
                     }
                     break;
                 case CommunicationMode.tcp_local_client:
@@ -112,11 +102,6 @@
                         myTcpClient = new Control_TcpClient(reportIp);
                         myTcpClient.Connect();
                     }
-                    if (myTcpServer != null)
-                    {
-                        myTcpClient.Close();
-                        myTcpClient = null;
-                    }
                     if (myUdp != null)
                     {
                         UdpSocket._BusSocket.Stop();
@@ -125,6 +110,25 @@
                     break;
             }
         }
+        /// <summary>
+        /// 鎼滅储鏈湴缃戝叧鍒楄〃
+        /// </summary>
+        public void SearchLoaclGateway()
+        {
+            ChangeCommunicationMode(CommunicationMode.local_BusUdp);
+            if (DB_ResidenceData.residenceData.GatewayType == 0)
+            {
+                myUdp.ControlBytesSend(Command.ReadGateway, 255, 255, new byte[] { (byte)new Random().Next(255), (byte)new Random().Next(255) });
+            }
+            else if (DB_ResidenceData.residenceData.GatewayType == 1)
+            {
+                UdpSocket._BusSocket.SearchNetDeviceAction = (revIp) =>
+                {
+                    MainPage.Log($"鎼滅储鍒扮綉缁滆澶囷細{revIp}");
+                };
+                myUdp.SearchLocalGateway();
+            }
+        }
 
         /// <summary>
         /// 鍦烘櫙鎺у埗鍏ュ彛

--
Gitblit v1.8.0