From 1293fea19c6a2b558986856e301d5218c1979692 Mon Sep 17 00:00:00 2001 From: wei <kaede@kaededeMacBook-Air.local> Date: 星期五, 27 十一月 2020 14:08:43 +0800 Subject: [PATCH] Revert "20201127 接受bus数据修改完成,搜索网关、一端口修改完成" --- HDL_ON/DAL/DriverLayer/UdpSocket.cs | 43 ++++++------------------------------------- 1 files changed, 6 insertions(+), 37 deletions(-) diff --git a/HDL_ON/DriverLayer/UdpSocket.cs b/HDL_ON/DAL/DriverLayer/UdpSocket.cs similarity index 77% rename from HDL_ON/DriverLayer/UdpSocket.cs rename to HDL_ON/DAL/DriverLayer/UdpSocket.cs index ac83f9b..39b3dfd 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,37 +19,22 @@ } } - /// <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; /// <summary> /// 鍚姩Socket鎺ユ敹鍜屽彂閫佸姛鑳� /// </summary> - public void Start () + public void Start (int port) { - if (IsRunning || port == 0) { + if (IsRunning ) { return; } busSocket = new Socket (AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); busSocket.EnableBroadcast = true; try { - busSocket.Bind (new IPEndPoint (IPAddress.Any, port)); + busSocket.Bind (new IPEndPoint (IPAddress.Any, 6000)); busSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(IPAddress.Parse("239.0.168.188"))); } @@ -113,10 +97,6 @@ Console.WriteLine($"asyncBeginReceive {e.Message}"); } } - /// <summary> - /// 鎼滅储缃戠粶璁惧瑙﹀彂鐨勫洖璋冧簨浠� - /// </summary> - public Action<string> SearchNetDeviceAction; /// <summary> /// 寮傛鎺ユ敹鏁版嵁缁撴潫 @@ -139,22 +119,11 @@ packet.Bytes = new byte[len]; Array.Copy(bytes, 0, packet.Bytes, 0, packet.Bytes.Length); + MainPage.Log($"鎺ユ敹IP{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