From af1cb3ecd0f4b0589e00b28f7f9edccf39e6e12b Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期四, 10 九月 2020 16:15:11 +0800
Subject: [PATCH] 202009101

---
 HDL_ON/DriverLayer/Packet.cs |  117 ++++++++++++++++++++++++++++++++++++----------------------
 1 files changed, 72 insertions(+), 45 deletions(-)

diff --git a/HDL_ON/DriverLayer/Packet.cs b/HDL_ON/DriverLayer/Packet.cs
index d66da6a..8be1e97 100644
--- a/HDL_ON/DriverLayer/Packet.cs
+++ b/HDL_ON/DriverLayer/Packet.cs
@@ -2,7 +2,7 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
-using HDL_ON.Entity.Enumerative;
+using HDL_ON.Entity;
 
 namespace HDL_ON
 {
@@ -16,19 +16,19 @@
         /// <summary>
         /// 鎺ユ敹鍒扮殑鏁版嵁
         /// </summary>
-        public byte [] Bytes;
+        public byte[] Bytes;
 
         /// <summary>
         /// 杩滅▼鐨勫鎺ュ瓧
         /// </summary>
         public System.Net.EndPoint RemoteEndPoint;
 
-        public Packet ()
+        public Packet()
         {
-            this.Bytes = new byte [Size];
-            RemoteEndPoint = (System.Net.EndPoint)new System.Net.IPEndPoint (System.Net.IPAddress.Any, 0);
+            this.Bytes = new byte[Size];
+            RemoteEndPoint = (System.Net.EndPoint)new System.Net.IPEndPoint(System.Net.IPAddress.Any, 0);
         }
-        public Packet (byte [] data, System.Net.EndPoint remoteEndPoint)
+        public Packet(byte[] data, System.Net.EndPoint remoteEndPoint)
         {
             this.Bytes = data;
             this.RemoteEndPoint = remoteEndPoint;
@@ -44,60 +44,87 @@
         /// </summary>
         public int HaveSendCount;
 
-        public delegate void DelegateReceive (byte subnetID, byte deviceID, Command command, byte [] usefullBytes, string revGatewayIP);
+        public delegate void DelegateReceive(byte subnetID, byte deviceID, Command command, byte[] usefullBytes, string revGatewayIP);
         public static event DelegateReceive ReceiveEvent;
         /// <summary>
         /// 鎺ユ敹鍒扮殑鎵�鏈夋暟鎹�
         /// </summary>
-        public static Action<byte, byte, int, Command, byte, byte, byte [], System.Net.IPEndPoint> ReceviceAllDadaAction;
+        public static Action<byte, byte, int, Command, byte, byte, byte[], System.Net.IPEndPoint> ReceviceAllDadaAction;
         /// <summary>
         /// 澶勭悊鎺ユ敹鍒扮殑鏁版嵁
         /// </summary>
-        public virtual void Manager ()
+        public virtual void Manager()
         {
-            //瀵逛簬鎿嶄綔鏁版嵁搴撶殑鏃堕棿姣旇緝闀跨殑锛屽彲浠ュ垱寤哄彟涓�涓嚎绋嬪鐞�
-            if (!"HDLMIRACLE".Equals (System.Text.Encoding.ASCII.GetString (Bytes, 4, 10))) {
-                return;
+            if (((System.Net.IPEndPoint)RemoteEndPoint).Port == 6688)
+            {
+                ReceviceAllDadaAction?.Invoke(0, 0, 0, 0, 0, 0, Bytes, (System.Net.IPEndPoint)RemoteEndPoint);
+                Control.ManagerReceive(0, 0, 0, 0, 0, Bytes, (System.Net.IPEndPoint)RemoteEndPoint);
             }
+            else
+            {
+                try
+                {
+                    //瀵逛簬鎿嶄綔鏁版嵁搴撶殑鏃堕棿姣旇緝闀跨殑锛屽彲浠ュ垱寤哄彟涓�涓嚎绋嬪鐞�
+                    if (!"HDLMIRACLE".Equals(System.Text.Encoding.ASCII.GetString(Bytes, 4, 10)))
+                    {
+                        return;
+                    }
+                    Control.controlLostCount = 0;
 
-            byte subnetID = this.Bytes [17]; //婧愬瓙缃戝彿
-            byte deviceID = this.Bytes [18]; //婧愯澶囧彿
+                    byte subnetID = this.Bytes[17]; //婧愬瓙缃戝彿
+                    byte deviceID = this.Bytes[18]; //婧愯澶囧彿
 
-            //婧愯澶囩被鍨�
-            int deviceType = this.Bytes [19] * 256 + this.Bytes [20];
+                    //婧愯澶囩被鍨�
+                    int deviceType = this.Bytes[19] * 256 + this.Bytes[20];
 
-            Command command = (Command)(Bytes [21] * 256 + Bytes [22]); //鎿嶄綔鐮佹帶鍒跺懡浠�
+                    Command command = (Command)(Bytes[21] * 256 + Bytes[22]); //鎿嶄綔鐮佹帶鍒跺懡浠�
 
-            byte targetSubnetID = this.Bytes [23];
-            byte targetDeviceID = this.Bytes [24];
+                    byte targetSubnetID = this.Bytes[23];
+                    byte targetDeviceID = this.Bytes[24];
 
-            //涓嶆槸瑕佹帴鏀剁殑鎸囦护灏辫繑鍥�
-            if (!((targetSubnetID == 252 && targetDeviceID == 252) || (targetSubnetID == 0xff && targetDeviceID == 0xff))) {
-                return;
+                    //涓嶆槸瑕佹帴鏀剁殑鎸囦护灏辫繑鍥�
+                    if (!((targetSubnetID == 252 && targetDeviceID == 252) || (targetSubnetID == 0xff && targetDeviceID == 0xff)))
+                    {
+                        return;
+                    }
+                    byte[] usefulBytes = null;
+                    if (this.Bytes[16] == 0xFF)
+                    {
+                        usefulBytes = new byte[Bytes.Length - 16 - 11];
+                        System.Array.Copy(Bytes, 27, usefulBytes, 0, usefulBytes.Length);
+                    }
+                    else
+                    {
+                        //鏈夌敤鐨勯檮鍔犳暟鎹�
+                        usefulBytes = new byte[this.Bytes[16] - 11];
+                        Array.Copy(Bytes, 25, usefulBytes, 0, usefulBytes.Length);
+                    }
+
+                    if (ReceiveEvent != null)
+                    {
+                        string revIp = $"{Bytes[0]}.{Bytes[1]}.{Bytes[2]}.{Bytes[3]}";
+                        if (revIp == "172.16.2.237")
+                        {
+
+                        }
+                        ReceiveEvent(subnetID, deviceID, command, usefulBytes, revIp);
+                    }
+
+                    //if (command == Command.SuperGatewayAgentACK) {
+                    //    SuperGateWay.SendAndReceiveDatas.Recevice (subnetID, deviceID, usefulBytes);
+                    //}
+                    if (ReceviceAllDadaAction != null)
+                    {
+                        ReceviceAllDadaAction(subnetID, deviceID, deviceType, command, targetSubnetID, targetDeviceID, usefulBytes, (System.Net.IPEndPoint)RemoteEndPoint);
+                    }
+                    //澶勭悊鏄惁瑕侀噸鍙戞暟鎹�
+                    Control.ManagerReceive(subnetID, deviceID, command, targetSubnetID, targetDeviceID, usefulBytes, RemoteEndPoint);
+                }
+                catch (Exception ex)
+                {
+                    MainPage.Log($"packet {ex.Message} ");
+                }
             }
-            byte [] usefulBytes = null;
-            if (this.Bytes [16] == 0xFF) {
-                usefulBytes = new byte [Bytes.Length - 16 - 11];
-                System.Array.Copy (Bytes, 27, usefulBytes, 0, usefulBytes.Length);
-            } else {
-                //鏈夌敤鐨勯檮鍔犳暟鎹�
-                usefulBytes = new byte [this.Bytes [16] - 11];
-                Array.Copy (Bytes, 25, usefulBytes, 0, usefulBytes.Length);
-            }
-
-            if (ReceiveEvent != null) {
-                ReceiveEvent (subnetID, deviceID, command, usefulBytes, $"{Bytes [0]}.{Bytes [1]}.{Bytes [2]}.{Bytes [3]}");
-            }
-
-            //if (command == Command.SuperGatewayAgentACK) {
-            //    SuperGateWay.SendAndReceiveDatas.Recevice (subnetID, deviceID, usefulBytes);
-            //}
-            if (ReceviceAllDadaAction != null) {
-                ReceviceAllDadaAction (subnetID, deviceID, deviceType, command, targetSubnetID, targetDeviceID, usefulBytes, (System.Net.IPEndPoint)RemoteEndPoint);
-            }
-            //澶勭悊鏄惁瑕侀噸鍙戞暟鎹�
-            Control.ManagerReceive (subnetID, deviceID, command, targetSubnetID, targetDeviceID, usefulBytes, RemoteEndPoint);
-
         }
     }
 }
\ No newline at end of file

--
Gitblit v1.8.0