From 3272ca5b51e19f7f8a827b0f68400570a547fe60 Mon Sep 17 00:00:00 2001 From: 陈嘉乐 <cjl@hdlchina.com.cn> Date: 星期二, 28 四月 2020 15:02:44 +0800 Subject: [PATCH] 2020-04-28-1 --- ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs | 150 ++++++++++++++++++-------------------------------- 1 files changed, 54 insertions(+), 96 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs b/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs index 36c1d58..a105443 100755 --- a/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs +++ b/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs @@ -143,12 +143,6 @@ public List<CommonDevice> DeviceList = new List<CommonDevice>(); /// <summary> - /// 鎵�鏈夌綉鍏充腑鐨勮澶囧垪琛� - /// </summary> - [Newtonsoft.Json.JsonIgnore] - public List<CommonDevice> AllGatewayDeviceList = new List<CommonDevice>(); - - /// <summary> /// 缃戝叧涓満鏅垪琛� /// 涓�涓満鏅腑鍖呭惈鎵�鏈変俊鎭紝鍖呮嫭鍦烘櫙璁惧淇℃伅 /// </summary> @@ -160,34 +154,6 @@ /// </summary> [Newtonsoft.Json.JsonIgnore] public List<Scene.GetSceneDeviceListInfo> SceneDeviceList = new List<Scene.GetSceneDeviceListInfo>(); - - /// <summary> - /// 缃戝叧涓�昏緫鍒楄〃 - /// </summary> - [Newtonsoft.Json.JsonIgnore] - public static List<Logic.GetLogicInfoResponseData> LogicList = new List<Logic.GetLogicInfoResponseData>(); - - /// <summary> - /// 缃戝叧涓環dl绉佹湁鎸夐敭缁戝畾鍒楄〃 - /// </summary> - [Newtonsoft.Json.JsonIgnore] - public List<HDLbutton> HdlButtonList = new List<HDLbutton>(); - - //缃戝叧涓柊鐨勮澶囧垪琛� - [Newtonsoft.Json.JsonIgnore] - public List<CommonDevice> ListNewDeviceInfoData = new List<CommonDevice>(); - - /// <summary> - /// 绉佹湁鎸夐敭淇℃伅鍒楄〃 - /// </summary> - [Newtonsoft.Json.JsonIgnore] - public System.Collections.Generic.Dictionary<string, HDLbutton> hdlButtonInfoList = new Dictionary<string, HDLbutton>(); - - /// <summary> - /// 浼犳劅鍣ㄤ俊鎭垪琛� - /// </summary> - [Newtonsoft.Json.JsonIgnore] - public System.Collections.Generic.Dictionary<string, Scene.TaskListInfo> sceneTaskInfoList = new Dictionary<string, Scene.TaskListInfo>(); #region action variable /// <summary> @@ -3054,22 +3020,6 @@ public static readonly System.Collections.Generic.List<IStatus> StatusList = new System.Collections.Generic.List<IStatus>(); /// <summary> - /// 璁惧鐘舵�佹洿鏂� - /// </summary> - /// <param name="commonDevice">Common device.</param> - public static void UpdateDeviceStatus(CommonDevice commonDevice) - { - if (commonDevice == null) - { - return; - } - for (int i = 0; i < StatusList.Count; i++) - { - StatusList[i].Changed(commonDevice); - } - } - - /// <summary> /// 璁惧淇℃伅鍙樺寲 /// <para>type锛氬鏋滀负 DeviceInComingRespon:璁惧鏂颁笂鎶�</para> /// <para>type锛氬鏋滀负 IASInfoReport:RemoveDeviceRespon</para> @@ -3180,14 +3130,14 @@ { if (localMqttClient.Options == null) { - var options = new MQTTnet.Client.Options.MqttClientOptionsBuilder().WithClientId(currentGuid.ToString()) - .WithTcpServer(brokerName, 1883) - .WithKeepAlivePeriod(TimeSpan.FromSeconds(20)) - .WithCleanSession() - //.WithCommunicationTimeout(TimeSpan.FromSeconds(10)) - .WithCredentials("", "") - .Build(); - await localMqttClient.ConnectAsync(options, CancellationToken.None); + var options = new MQTTnet.Client.Options.MqttClientOptionsBuilder()//MQTT杩炴帴鍙傛暟濉厖 + .WithClientId(currentGuid.ToString())//瀹㈡埛绔疘D + .WithTcpServer(brokerName, 1883)//TCP鏈嶅姟绔� 1883 锛屽嵆MQTT鏈嶅姟绔� + .WithCredentials("", "")//"", "")//鍑瘉 甯愬彿 瀵嗙爜 + .WithCommunicationTimeout(new TimeSpan(0, 0, 60)) //閲嶈繛瓒呮椂鏃堕棿锛岄粯璁�5s + .WithKeepAlivePeriod(new TimeSpan(0, 0, 15)) //淇濇寔杩炴帴鏃堕棿锛岄粯璁�5s锛屽績璺冲寘 + .Build();// + await localMqttClient.ConnectAsync(options); } else { @@ -3359,10 +3309,20 @@ if (RemoteMqttClient.ApplicationMessageReceivedHandler == null) { RemoteMqttClient.UseApplicationMessageReceivedHandler((e) => - { - if (!RemoteMqttClient.IsConnected || !IsRemote) - { - return; + { + //杩欓噷鏄壒娈婄殑涓婚 + if (e.ApplicationMessage.Topic == "/ZigbeeGateWayToClient/" + Config.Instance.ConnEmqClientId + "/Push/NotifySqueeze"//韪汉涓嬬嚎 + || e.ApplicationMessage.Topic == "/ZigbeeGateWayToClient/" + Config.Instance.Guid + "/Push/Deleted"//鍒嗕韩鍒犻櫎 + || e.ApplicationMessage.Topic == "/ZigbeeGateWayToClient/" + Config.Instance.Guid + "/Push/DeletedShareData"//鍒嗕韩鍒犻櫎 + || e.ApplicationMessage.Topic == "/ZigbeeGateWayToClient/" + Config.Instance.Guid + "/Push/Update"//鎴愬憳鏉冮檺鍙樻洿 + || e.ApplicationMessage.Topic == "/ZigbeeGateWayToClient/" + Config.Instance.Home.Id + "_" + Config.Instance.Guid + "/PrimaryUserDelYou")//瀛愯处鍙疯鍒犻櫎 + { + mqttRemoteClient_MqttMsgPublishReceived(e); + return; + } + if (!RemoteMqttClient.IsConnected || !IsRemote) + { + return; } mqttRemoteClient_MqttMsgPublishReceived(e); }); @@ -3390,6 +3350,10 @@ await RemoteMqttClient.SubscribeAsync("/ZigbeeGateWayToClient/" + myGuid + "/Push/Deleted"); //璁㈤槄涓�涓垎浜暟鎹凡缁忓彉鏇寸殑涓婚 await RemoteMqttClient.SubscribeAsync("/ZigbeeGateWayToClient/" + myGuid + "/Push/DeletedShareData"); + //璁㈤槄涓�涓瓙璐﹀彿琚垹闄ょ殑涓婚 + await RemoteMqttClient.SubscribeAsync("/ZigbeeGateWayToClient/" + Config.Instance.Home.Id + "_" + myGuid + "/PrimaryUserDelYou"); + //璁㈤槄涓�涓垚鍛樻潈闄愬凡缁忓彉鏇寸殑涓婚 + await RemoteMqttClient.SubscribeAsync("/ZigbeeGateWayToClient/" + myGuid + "/Push/Update"); } //璁㈤槄涓�涓尋涓嬬嚎鐨勪富棰� await RemoteMqttClient.SubscribeAsync("/ZigbeeGateWayToClient/" + Config.Instance.ConnEmqClientId + "/Push/NotifySqueeze"); @@ -3481,6 +3445,9 @@ AllowRemoteCtrl = false; return; } + //铏界劧涓嶇煡閬撳鎸や笅绾块偅涓�鍧楁湁娌℃湁鐢�,涓嶈繃鍏堣繖涔堝紕 + await System.Threading.Tasks.Task.Delay(1500); + var responseData = jobject["ResponseData"]; if (responseData != null) { @@ -3999,8 +3966,7 @@ DebugPrintLog("DeviceInComingRespon宸茬粡閫氱煡"); gwa.ReportAction("DeviceInComingRespon", tempDevice.getNewDeviceInfo); } - UpdateDeviceInfo(tempDevice, "DeviceInComingRespon"); - UpdateDeviceStatus(gwa); + UpdateDeviceInfo(tempDevice, "DeviceInComingRespon"); } #endregion #region 璁惧鍦ㄧ嚎鐘舵�佹洿鏂板弽棣� @@ -4018,7 +3984,6 @@ if (infoTempDevice == null) { gwa.DeviceList.Add(tempDevice); - UpdateDeviceStatus(tempDevice); UpdateDeviceInfo(tempDevice, "OnlineStatusChange"); } else @@ -4028,7 +3993,6 @@ infoTempDevice.DeviceInfo.IsOnline = infoTempDevice.IsOnline; } UpdateDeviceInfo(infoTempDevice, "OnlineStatusChange"); - UpdateDeviceStatus(infoTempDevice); } } #endregion @@ -4054,7 +4018,6 @@ } else { - UpdateDeviceStatus(tempDevice); UpdateDeviceInfo(tempDevice, "RemoveDeviceRespon"); if (tempDevice.removeDeviceResponseData.Result == 0) { @@ -4082,7 +4045,6 @@ var tempDevice = new CommonDevice { DeviceID = deviceID, DeviceAddr = deviceAddr, DeviceEpoint = tempEpoint, DataID = dataId }; tempDevice.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.DeviceStatusReportData>(jobject["Data"].ToString()); - UpdateDeviceStatus(tempDevice); UpdateDeviceInfo(tempDevice, "DeviceStatusReport"); } #endregion @@ -4104,7 +4066,6 @@ DebugPrintLog("DoorLockProgrammingEventNotificationCommand宸茬粡閫氱煡"); gwa.ReportAction("DoorLockProgrammingEventNotificationCommand", doorLock); } - UpdateDeviceStatus(doorLock); UpdateDeviceInfo(doorLock, "DoorLockProgrammingEventNotificationCommand"); break; } @@ -4128,7 +4089,6 @@ DebugPrintLog("DoorLockProgrammingEventNotificationCommand宸茬粡閫氱煡"); gwa.ReportAction("DoorLockProgrammingEventNotificationCommand", doorLock); } - UpdateDeviceStatus(doorLock); UpdateDeviceInfo(doorLock, "DoorLockProgrammingEventNotificationCommand"); break; } @@ -4150,8 +4110,6 @@ //ias.Save(); gwa.ReportAction("IASInfoReport", ias.iASInfo); } - - UpdateDeviceStatus(ias); UpdateDeviceInfo(ias, "IASInfoReport"); break; } @@ -4266,37 +4224,37 @@ #region 閫昏緫琚皟鐢ㄥ弽棣� else if (topic == gatewayID + "/" + "Logic/Execute_Respon") { - var logic = new Logic() { DataID = jobject.Value<int>("Data_ID"), GateWayId = gwa.getGatewayBaseInfo.gwID }; - logic.logicExecuteRespo = Newtonsoft.Json.JsonConvert.DeserializeObject<Logic.ExecuteResponse>(jobject["Data"].ToString()); + //var logic = new Logic() { DataID = jobject.Value<int>("Data_ID"), GateWayId = gwa.getGatewayBaseInfo.gwID }; + //logic.logicExecuteRespo = Newtonsoft.Json.JsonConvert.DeserializeObject<Logic.ExecuteResponse>(jobject["Data"].ToString()); - if (logic.logicExecuteRespo == null) - { - return; - } - //涓婃姤绫诲瀷閫氱煡 - if (gwa.ReportAction != null) - { - DebugPrintLog("LogicExecuteReport宸茬粡閫氱煡"); - gwa.ReportAction("LogicExecuteReport", logic.logicExecuteRespo); - } + //if (logic.logicExecuteRespo == null) + //{ + // return; + //} + ////涓婃姤绫诲瀷閫氱煡 + //if (gwa.ReportAction != null) + //{ + // DebugPrintLog("LogicExecuteReport宸茬粡閫氱煡"); + // gwa.ReportAction("LogicExecuteReport", logic.logicExecuteRespo); + //} } #endregion #region 鏃堕棿鐐规潯浠舵帹杩熸墽琛� else if (topic == gatewayID + "/" + "Logic/TimingWillArrive") { - var logic = new Logic() { DataID = jobject.Value<int>("Data_ID"), GateWayId = gwa.getGatewayBaseInfo.gwID }; - logic.timingWillArriveData = Newtonsoft.Json.JsonConvert.DeserializeObject<Logic.TimingWillArriveData>(jobject["Data"].ToString()); + //var logic = new Logic() { DataID = jobject.Value<int>("Data_ID"), GateWayId = gwa.getGatewayBaseInfo.gwID }; + //logic.timingWillArriveData = Newtonsoft.Json.JsonConvert.DeserializeObject<Logic.TimingWillArriveData>(jobject["Data"].ToString()); - if (logic.timingWillArriveData == null) - { - return; - } - //涓婃姤绫诲瀷閫氱煡 - if (gwa.ReportAction != null) - { - DebugPrintLog("TimingWillArrive宸茬粡閫氱煡"); - gwa.ReportAction("TimingWillArrive", logic.timingWillArriveData); - } + //if (logic.timingWillArriveData == null) + //{ + // return; + //} + ////涓婃姤绫诲瀷閫氱煡 + //if (gwa.ReportAction != null) + //{ + // DebugPrintLog("TimingWillArrive宸茬粡閫氱煡"); + // gwa.ReportAction("TimingWillArrive", logic.timingWillArriveData); + //} } #endregion #region 妯″紡瀹夐槻鍔ㄤ綔琚渶缁堟縺娲绘椂鍙戦�佹姤璀︿俊鎭� -- Gitblit v1.8.0