From a5ba89efa83d0a4afd0d25dbeba5989e4944b5b8 Mon Sep 17 00:00:00 2001 From: wxr <464027401@qq.com> Date: 星期二, 24 十一月 2020 18:57:56 +0800 Subject: [PATCH] 20201124;mqtt代码整理备份 --- HDL_ON/DAL/DriverLayer/Control.cs | 137 ++++++++++++++++++++++++--------------------- 1 files changed, 72 insertions(+), 65 deletions(-) diff --git a/HDL_ON/DriverLayer/Control.cs b/HDL_ON/DAL/DriverLayer/Control.cs similarity index 66% rename from HDL_ON/DriverLayer/Control.cs rename to HDL_ON/DAL/DriverLayer/Control.cs index ea4b55e..ed155f1 100644 --- a/HDL_ON/DriverLayer/Control.cs +++ b/HDL_ON/DAL/DriverLayer/Control.cs @@ -4,32 +4,26 @@ namespace HDL_ON.DriverLayer { - /// <summary> /// 閫氳鏂瑰紡 /// </summary> public enum CommunicationMode { + none, /// <summary> /// 鏈湴udp /// </summary> local_BusUdp, - /// <summary> - /// 鏈湴tcp鏈嶅姟绔� - /// </summary> - tcp_local_server, /// <summary> /// 鏈湴tcp瀹㈡埛绔� /// </summary> tcp_local_client, } - - public class Control { static Control _control; - public static Control ins + public static Control Ins { get { @@ -40,6 +34,26 @@ return _control; } } + bool _gatewayOnline = false; + /// <summary> + /// 缃戝叧鏄惁鍦ㄧ嚎 + /// </summary> + public bool GatewayOnline { + get + { + return _gatewayOnline; + } + set + { + _gatewayOnline = value; + //淇敼涓婚〉杩炴帴鐘舵�� + UI.HomePage.LoadEvent_CheckLinkStatus(); + } + } + /// <summary> + /// 鏄惁涓鸿繙绋嬭繛鎺� + /// </summary> + public bool IsRemote = false; /// <summary> /// 閫氳鍦板潃IP /// </summary> @@ -55,7 +69,7 @@ /// <summary> /// 鏈湴udp /// </summary> - public Control_Udp_Bus myUdp = null; + public Control_Udp myUdp = null; /// <summary> /// 閫氳鏂瑰紡 @@ -63,66 +77,59 @@ public CommunicationMode communicationMode; /// <summary> - /// 鏀瑰彉閫氳鏂瑰紡 + /// 鎵撳紑tcp鏈嶅姟绔� /// </summary> - public void ChangeCommunicationMode(CommunicationMode communicationMode) + public void OpenTcpServer() { - this.communicationMode = communicationMode; + myTcpServer = new Control_TcpServer(); + myTcpServer.OpenServer(); + } - - switch (this.communicationMode) + /// <summary> + /// 鎵撳紑Udp + /// </summary> + public void OpenUdp() + { + if (myUdp == null) { - case CommunicationMode.local_BusUdp: - if (myUdp == null) - { - 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: - if (myTcpClient == null) - { - myTcpClient = new Control_TcpClient(reportIp); - myTcpClient.Connect(); - } - if (myTcpServer != null) - { - myTcpClient.Close(); - myTcpClient = null; - } - if (myUdp != null) - { - UdpSocket._BusSocket.Stop(); - myUdp = null; - } - break; + myUdp = new Control_Udp(); + } + + UdpSocket._BusSocket.Start(); + } + /// <summary> + /// 鎵撳紑tcp瀹㈡湇绔� + /// </summary> + public void OpenTcpClent() + { + if (myTcpClient == null) + { + myTcpClient = new Control_TcpClient(reportIp); + myTcpClient.Connect(); + } + } + + ///// <summary> + ///// 鏀瑰彉閫氳鏂瑰紡 + ///// </summary> + //public void ChangeCommunicationMode(CommunicationMode communicationMode) + //{ + // this.communicationMode = communicationMode; + //} + + /// <summary> + /// 鎼滅储鏈湴缃戝叧鍒楄〃 + /// </summary> + public void SearchLoaclGateway() + { + OpenUdp(); + 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) + { + myUdp.SearchLocalGateway(); } } -- Gitblit v1.8.0