From e53a1951d6aa07ad22aad9816da4703496fcbccd Mon Sep 17 00:00:00 2001 From: wei <kaede@kaededeMacBook-Air.local> Date: 星期五, 27 十一月 2020 14:27:16 +0800 Subject: [PATCH] 1127最新合并代码,合并嘉乐更新 --- HDL_ON/DAL/DriverLayer/UdpSocket.cs | 56 +++++++++++++++++--------------------------------------- 1 files changed, 17 insertions(+), 39 deletions(-) diff --git a/HDL_ON/DriverLayer/UdpSocket.cs b/HDL_ON/DAL/DriverLayer/UdpSocket.cs similarity index 78% rename from HDL_ON/DriverLayer/UdpSocket.cs rename to HDL_ON/DAL/DriverLayer/UdpSocket.cs index ac83f9b..376e6bb 100644 --- a/HDL_ON/DriverLayer/UdpSocket.cs +++ b/HDL_ON/DAL/DriverLayer/UdpSocket.cs @@ -1,9 +1,8 @@ 锘縰sing System; using System.Net.Sockets; using System.Net; -using Newtonsoft.Json.Linq; -namespace HDL_ON +namespace HDL_ON.DriverLayer { public class UdpSocket { @@ -20,32 +19,26 @@ } } - /// <summary> - /// 鐩戝惉绔彛 - /// </summary> - public int port - { - get - { - if (MainPage.LoginUser != null && Entity.DB_ResidenceData.residenceData != null) - { - return Entity.DB_ResidenceData.residenceData.GatewayType == 0 ? 6000 : 8585; - } - return 6000; - } - } - //鏈湴Socket private Socket busSocket; - + int _port = 0; /// <summary> /// 鍚姩Socket鎺ユ敹鍜屽彂閫佸姛鑳� /// </summary> - public void Start () + public void Start (int port) { - if (IsRunning || port == 0) { - return; - } + if (IsRunning) + { + if (port == _port) + { + return; + } + else + { + busSocket.Close(); + } + } + _port = port; busSocket = new Socket (AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); busSocket.EnableBroadcast = true; @@ -113,10 +106,6 @@ Console.WriteLine($"asyncBeginReceive {e.Message}"); } } - /// <summary> - /// 鎼滅储缃戠粶璁惧瑙﹀彂鐨勫洖璋冧簨浠� - /// </summary> - public Action<string> SearchNetDeviceAction; /// <summary> /// 寮傛鎺ユ敹鏁版嵁缁撴潫 @@ -139,22 +128,11 @@ packet.Bytes = new byte[len]; Array.Copy(bytes, 0, packet.Bytes, 0, packet.Bytes.Length); + //MainPage.Log($"鎺ユ敹{packet.RemoteEndPoint}鏁版嵁"); //mqtt杩炴帴鏁版嵁璇诲彇 A鍗忚缃戠粶璁惧淇℃伅璇诲彇鍥炲 澶勭悊 if (((IPEndPoint)packet.RemoteEndPoint).Port == 8585) { - var reString = System.Text.Encoding.UTF8.GetString(bytes); - var jt = Newtonsoft.Json.JsonConvert.DeserializeObject<JObject>(reString); - JToken jtc = null; - jt.TryGetValue("command", out jtc); - if (jtc != null && jtc.ToString() == "search_response") - { - JToken jto = null; - jt.TryGetValue("objects", out jto); - if (jto != null) - { - SearchNetDeviceAction?.Invoke(jto.ToString()); - } - } + Control.Ins.ConvertReceiveData(bytes); } else if(((IPEndPoint)packet.RemoteEndPoint).Port == 6000)//澶勭悊bus 6000绔彛鐨勬暟鎹� { -- Gitblit v1.8.0