From ea0b1e8e5f43c5fd0a7d479e25ede3b8cbea464a Mon Sep 17 00:00:00 2001 From: wxr <wxr@hdlchina.com.cn> Date: 星期一, 02 十二月 2024 17:17:19 +0800 Subject: [PATCH] tcp;可视对讲; --- HDL_ON/DAL/DriverLayer/Control_Tcp.cs | 274 +++++++++++++++++++++++++++--------------------------- 1 files changed, 138 insertions(+), 136 deletions(-) diff --git a/HDL_ON/DAL/DriverLayer/Control_Tcp.cs b/HDL_ON/DAL/DriverLayer/Control_Tcp.cs index 481c997..0d29fb4 100644 --- a/HDL_ON/DAL/DriverLayer/Control_Tcp.cs +++ b/HDL_ON/DAL/DriverLayer/Control_Tcp.cs @@ -52,154 +52,154 @@ #region 鈻� 鎼滅储Link缃戝叧_______________________ -// /// <summary> -// /// 鎼滅储Link缃戝叧 -// /// </summary> -// /// <param name="resultEvent">鎼滅储鍒扮綉鍏崇殑鍥炶皟鍑芥暟,-1:寮傚父浜� 1:鏀跺埌涓�涓狝缃戝叧</param> -// /// <param name="searchTime">鎼滅储鏃堕棿(绉�)</param> -// /// <param name="connectLocalOnly">褰撴悳绱㈠埌缃戝叧鏃�,鏄惁鍙繛鎺ユ湰鍦扮殑(涓嶈兘鐬庤繛鍏朵粬鐨勭綉鍏�,浣嗘槸缃戝叧鎼滅储鐣岄潰鐗规畩)</param> -// public void SearchLinkGateway(Action<int, AGatewayInfo> resultEvent, int searchTime, bool connectLocalOnly) -// { -// this.isSearchGateway = true; -// //绠椾簡,鍦ㄨ繖閲屽惎鍔ㄨ繙绋嬭繛鎺ュ惂,鍙嶆涔熷氨鎵ц涓�娆� -// HdlLinkCloudConnectLogic.Current.StartCloudMqttConnection(); + // /// <summary> + // /// 鎼滅储Link缃戝叧 + // /// </summary> + // /// <param name="resultEvent">鎼滅储鍒扮綉鍏崇殑鍥炶皟鍑芥暟,-1:寮傚父浜� 1:鏀跺埌涓�涓狝缃戝叧</param> + // /// <param name="searchTime">鎼滅储鏃堕棿(绉�)</param> + // /// <param name="connectLocalOnly">褰撴悳绱㈠埌缃戝叧鏃�,鏄惁鍙繛鎺ユ湰鍦扮殑(涓嶈兘鐬庤繛鍏朵粬鐨勭綉鍏�,浣嗘槸缃戝叧鎼滅储鐣岄潰鐗规畩)</param> + // public void SearchLinkGateway(Action<int, AGatewayInfo> resultEvent, int searchTime, bool connectLocalOnly) + // { + // this.isSearchGateway = true; + // //绠椾簡,鍦ㄨ繖閲屽惎鍔ㄨ繙绋嬭繛鎺ュ惂,鍙嶆涔熷氨鎵ц涓�娆� + // HdlLinkCloudConnectLogic.Current.StartCloudMqttConnection(); -// var listGateway = HdlLinkGatewayLogic.Current.GetAllLocalGateway(); -// var dicGateway = new Dictionary<string, ZigBee.Device.LinkGateway>(); -// foreach (var gw in listGateway) -// { -// //鑾峰彇鏈湴鍏ㄩ儴鐨凙缃戝叧鐨刴ac -// dicGateway[gw.GwMac] = gw; -// } -// //閲嶅妫�娴� -// var listCheck = new HashSet<string>(); + // var listGateway = HdlLinkGatewayLogic.Current.GetAllLocalGateway(); + // var dicGateway = new Dictionary<string, ZigBee.Device.LinkGateway>(); + // foreach (var gw in listGateway) + // { + // //鑾峰彇鏈湴鍏ㄩ儴鐨凙缃戝叧鐨刴ac + // dicGateway[gw.GwMac] = gw; + // } + // //閲嶅妫�娴� + // var listCheck = new HashSet<string>(); -// var sendData = "Topic:/user/all/custom/gateway/search\r\n"; + // var sendData = "Topic:/user/all/custom/gateway/search\r\n"; -// var dic = new Dictionary<string, string>(); -// dic["id"] = HdlGatewayResourse.AGatewayLinkFlage; -// dic["time_stamp"] = HdlHttpLogic.Current.GetTimestamp().PadRight(13, '0'); -// var bodyData = Newtonsoft.Json.JsonConvert.SerializeObject(dic); -// sendData += "Length:" + bodyData.Length + "\r\n\r\n"; -// sendData += bodyData; + // var dic = new Dictionary<string, string>(); + // dic["id"] = HdlGatewayResourse.AGatewayLinkFlage; + // dic["time_stamp"] = HdlHttpLogic.Current.GetTimestamp().PadRight(13, '0'); + // var bodyData = Newtonsoft.Json.JsonConvert.SerializeObject(dic); + // sendData += "Length:" + bodyData.Length + "\r\n\r\n"; + // sendData += bodyData; -// //鍒濆鍖杣dp -// var udpLogic = new HdlUdpLogic(); -// if (udpLogic.InitUdp("239.0.168.188", 8585) == false) -// { -// //鍏抽棴udp -// udpLogic.CloseUdp(); + // //鍒濆鍖杣dp + // var udpLogic = new HdlUdpLogic(); + // if (udpLogic.InitUdp("239.0.168.188", 8585) == false) + // { + // //鍏抽棴udp + // udpLogic.CloseUdp(); -// resultEvent?.Invoke(-1, null); -// return; -// } + // resultEvent?.Invoke(-1, null); + // return; + // } -// HDL_ON.DriverLayer.Control.Ins.OpenUdp(8585); + // HDL_ON.DriverLayer.Control.Ins.OpenUdp(8585); -// //鎺ユ敹浜嬩欢 -// Action<System.Net.IPEndPoint, string> actionEvent = (ipPoint, result) => -// { -// //澶勭悊鎼滅储A缃戝叧鏃�,缃戝叧鍥炲鐨勬暟鎹� -// try -// { -// ///// -// System.Net.IPAddress s = ipPoint.Address; -// MainPage.Log("TcpClient->SearchLinkGateway", $"{s}==缃戝叧鎼滅储鏈湴鍥炲,鏁版嵁鍐呭{result}"); + // //鎺ユ敹浜嬩欢 + // Action<System.Net.IPEndPoint, string> actionEvent = (ipPoint, result) => + // { + // //澶勭悊鎼滅储A缃戝叧鏃�,缃戝叧鍥炲鐨勬暟鎹� + // try + // { + // ///// + // System.Net.IPAddress s = ipPoint.Address; + // MainPage.Log("TcpClient->SearchLinkGateway", $"{s}==缃戝叧鎼滅储鏈湴鍥炲,鏁版嵁鍐呭{result}"); -// //妫�楠孉鍗忚缃戝叧涓婚(濡傛灉妫�楠屾槸鎸囧畾涓婚,鍒欒繑鍥炶礋杞芥暟鎹�,鍚﹀垯杩斿洖null) -// var resultData = HdlLinkGatewaySendLogic.Current.CheckLinkGatewayTopic("/user/all/custom/gateway/search_reply", result); -// if (resultData == null) { return; } -// //璋冪敤鍥炶皟鍑芥暟 -// var info = Newtonsoft.Json.JsonConvert.DeserializeObject<AGatewayInfo>(resultData); -// if (info == null) -// { -// //鏁版嵁寮傚父锛岄��鍑� -// return; -// } -// if (!(string.IsNullOrEmpty(info.HomeId) == true || info.HomeId == Common.Config.Instance.HomeId)) -// { -// //缃戝叧宸茬粡缁戝畾鍏朵粬浣忓畢锛岄��鍑� -// return; -// } -// ///tcp杩炴帴鐩爣璁惧鐨刬p -// info.Ip_address = ipPoint.Address.ToString(); -// //鎼滅储鍒扮殑杩欎釜缃戝叧,鏄惁鏄瓨鍦ㄥ湪鏈湴浜嗙殑 -// if (dicGateway.ContainsKey(info.Device_mac) == true) -// { -// var gateWay = dicGateway[info.Device_mac]; -// //濡傛灉鎼滅储寰楀埌鏈湴瀛樺湪鐨勭綉鍏�,鍒欎娇鐢ㄦ湰鍦伴�氫俊 -// gateWay.OnlineStatu = 1; -// gateWay.isLocalEncrypt = info.isLocalEncrypt; -// gateWay.Master = info.Master; -// //gateWay.Slaver_list1 = info.Slaver_list1; -// gateWay.Oid = info.Oid; -// gateWay.InGatewayHomeId = info.HomeId; -// info.IsBindGateway = true; + // //妫�楠孉鍗忚缃戝叧涓婚(濡傛灉妫�楠屾槸鎸囧畾涓婚,鍒欒繑鍥炶礋杞芥暟鎹�,鍚﹀垯杩斿洖null) + // var resultData = HdlLinkGatewaySendLogic.Current.CheckLinkGatewayTopic("/user/all/custom/gateway/search_reply", result); + // if (resultData == null) { return; } + // //璋冪敤鍥炶皟鍑芥暟 + // var info = Newtonsoft.Json.JsonConvert.DeserializeObject<AGatewayInfo>(resultData); + // if (info == null) + // { + // //鏁版嵁寮傚父锛岄��鍑� + // return; + // } + // if (!(string.IsNullOrEmpty(info.HomeId) == true || info.HomeId == Common.Config.Instance.HomeId)) + // { + // //缃戝叧宸茬粡缁戝畾鍏朵粬浣忓畢锛岄��鍑� + // return; + // } + // ///tcp杩炴帴鐩爣璁惧鐨刬p + // info.Ip_address = ipPoint.Address.ToString(); + // //鎼滅储鍒扮殑杩欎釜缃戝叧,鏄惁鏄瓨鍦ㄥ湪鏈湴浜嗙殑 + // if (dicGateway.ContainsKey(info.Device_mac) == true) + // { + // var gateWay = dicGateway[info.Device_mac]; + // //濡傛灉鎼滅储寰楀埌鏈湴瀛樺湪鐨勭綉鍏�,鍒欎娇鐢ㄦ湰鍦伴�氫俊 + // gateWay.OnlineStatu = 1; + // gateWay.isLocalEncrypt = info.isLocalEncrypt; + // gateWay.Master = info.Master; + // //gateWay.Slaver_list1 = info.Slaver_list1; + // gateWay.Oid = info.Oid; + // gateWay.InGatewayHomeId = info.HomeId; + // info.IsBindGateway = true; -// Common.Config.Instance.Home.NowHomeOnlineStatu = "1"; -// } -// //鎼滅储鍒扮殑缃戝叧,寤虹珛閾炬帴 -// if (connectLocalOnly == false || info.IsBindGateway == true) -// { -// this.ConnectLocalLinkGateway(info.Device_mac, info.Ip_address, info.GatewayId, info.isLocalEncrypt); -// } -// else -// { -// //鑾峰彇杩炴帴瀵硅薄 -// var connectObj = this.GetConnectObject(info.Device_mac, false); -// if (connectObj != null) -// { -// //濡傛灉鏈夎繖涓璞�, 鍒欐浛鎹竴涓嬪畠鐨勭綉鍏砳d -// connectObj.GatewayId = info.GatewayId; -// connectObj.localEncrypt = info.isLocalEncrypt; -// return; -// } -// } -// if (listCheck.Contains(info.Device_mac) == true) -// { -// //宸茬粡澶勭悊杩囦簡 -// return; -// } -// listCheck.Add(info.Device_mac); + // Common.Config.Instance.Home.NowHomeOnlineStatu = "1"; + // } + // //鎼滅储鍒扮殑缃戝叧,寤虹珛閾炬帴 + // if (connectLocalOnly == false || info.IsBindGateway == true) + // { + // this.ConnectLocalLinkGateway(info.Device_mac, info.Ip_address, info.GatewayId, info.isLocalEncrypt); + // } + // else + // { + // //鑾峰彇杩炴帴瀵硅薄 + // var connectObj = this.GetConnectObject(info.Device_mac, false); + // if (connectObj != null) + // { + // //濡傛灉鏈夎繖涓璞�, 鍒欐浛鎹竴涓嬪畠鐨勭綉鍏砳d + // connectObj.GatewayId = info.GatewayId; + // connectObj.localEncrypt = info.isLocalEncrypt; + // return; + // } + // } + // if (listCheck.Contains(info.Device_mac) == true) + // { + // //宸茬粡澶勭悊杩囦簡 + // return; + // } + // listCheck.Add(info.Device_mac); -//#if DEBUG -// Console.WriteLine($"鎼滅储缃戝叧鎹曟姄鍒扮綉鍏�:{info.Device_mac}"); -//#endif -// //info + //#if DEBUG + // Console.WriteLine($"鎼滅储缃戝叧鎹曟姄鍒扮綉鍏�:{info.Device_mac}"); + //#endif + // //info -// //鍥炶皟鍑芥暟 -// resultEvent?.Invoke(1, info); -// } -// catch (Exception e) -// { -// string str = e.Message; -// } -// }; -// udpLogic.ReceviceEvent += actionEvent; -// var dateTime = System.DateTime.Now.AddSeconds(searchTime); -// while (this.isSearchGateway && System.DateTime.Now < dateTime) -// { -// udpLogic.SendData(sendData, "239.0.168.188", 8585); -// udpLogic.SendData(sendData, "255.255.255.255", 8585); -// System.Threading.Thread.Sleep(1000); -// } -// udpLogic.ReceviceEvent -= actionEvent; -// //鍒叧閭d箞蹇� -// System.Threading.Thread.Sleep(300); -// this.isSearchGateway = false; -// //鍏抽棴udp -// udpLogic.CloseUdp(); + // //鍥炶皟鍑芥暟 + // resultEvent?.Invoke(1, info); + // } + // catch (Exception e) + // { + // string str = e.Message; + // } + // }; + // udpLogic.ReceviceEvent += actionEvent; + // var dateTime = System.DateTime.Now.AddSeconds(searchTime); + // while (this.isSearchGateway && System.DateTime.Now < dateTime) + // { + // udpLogic.SendData(sendData, "239.0.168.188", 8585); + // udpLogic.SendData(sendData, "255.255.255.255", 8585); + // System.Threading.Thread.Sleep(1000); + // } + // udpLogic.ReceviceEvent -= actionEvent; + // //鍒叧閭d箞蹇� + // System.Threading.Thread.Sleep(300); + // this.isSearchGateway = false; + // //鍏抽棴udp + // udpLogic.CloseUdp(); -// } + // } -// /// <summary> -// /// 鍋滄鎼滅储Link缃戝叧 -// /// </summary> -// public void StopSearchLinkGateway() -// { -// this.isSearchGateway = false; -// } + // /// <summary> + // /// 鍋滄鎼滅储Link缃戝叧 + // /// </summary> + // public void StopSearchLinkGateway() + // { + // this.isSearchGateway = false; + // } #endregion @@ -359,6 +359,8 @@ connectData.tcpClient?.CommSend(byteData, byteData.Length); } + + #endregion #region 鈻� 澶勭悊Link缃戝叧鐨勬暟鎹甠________________ @@ -377,7 +379,7 @@ //闈炴瑙勪富棰� return; } - + var connectData = this.GetConnectObjectBySocket(socket); if (connectData == null) @@ -401,7 +403,7 @@ var bodyData = System.Text.Encoding.UTF8.GetString(bytes); MainPage.Log(DateTime.Now + ":Control_Tcp->鏈湴鎺ユ敹鏁版嵁", $"Topic:{topic}\r\nData:{bodyData}"); - + if (topic.Contains("thing/property/up") == true) { //杩欎釜鏄疞ink璁惧鐨勭姸鎬佷笂鎶�,鍒暣,鍙zigbee鐨� -- Gitblit v1.8.0