From d5b9ff8bf8cc36f5b13c46b66682f5988d3a6f36 Mon Sep 17 00:00:00 2001 From: 陈嘉乐 <cjl@hdlchina.com.cn> Date: 星期五, 15 五月 2020 11:36:11 +0800 Subject: [PATCH] 2020-05-15-1 --- ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs | 613 +++++++------------------------------------------------ 1 files changed, 85 insertions(+), 528 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs b/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs index 0b5fc0d..3cc5d12 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> @@ -634,422 +600,6 @@ return d; }); - } - #endregion - - #region 鑾峰彇宸插叆缃戣澶囦俊鎭� - /// <summary> - /// 鑾峰彇缃戝叧璁惧淇℃伅(娉ㄦ剰锛岃繖涓帴鍙d細琚幓鎺夛級 - /// </summary> - public async System.Threading.Tasks.Task<List<CommonDevice>> GetGwDeviceList() - { - DeviceList.Clear(); - return await System.Threading.Tasks.Task.Run((Func<System.Threading.Tasks.Task<List<CommonDevice>>>)(async () => - { - var dateTime = DateTime.Now; - bool canBreak = false; - Action<string, string> action = (topic, message) => - { - var gatewayID = topic.Split('/')[0]; - var jobject = Newtonsoft.Json.Linq.JObject.Parse(message); - - if (topic == gatewayID + "/" + "DeviceInfoRespon") - { - dateTime = DateTime.Now; - var totalNum = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["TotalNum"].ToString()); - if (totalNum == 0) - { - canBreak = true; - return; - } - var deviceID = jobject.Value<int>("Device_ID"); - switch ((DeviceType)(deviceID)) - { - //case DeviceType.DimmableLight: - // var dimmableLight = new DimmableLight() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID }; - // dimmableLight.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<DimmableLight.DeviceInfoData>(jobject["Data"].ToString()); - // if (dimmableLight.DeviceInfo == null) - // { - // return; - // } - // var light = DeviceList.Find(obj => obj.DeviceID == dimmableLight.DeviceID && obj.DeviceAddr == dimmableLight.DeviceAddr && obj.DeviceEpoint == dimmableLight.DeviceEpoint); - // if (light == null) - // { - // DeviceList.Add(dimmableLight); - // dimmableLight.DeviceName = dimmableLight.DeviceInfo.MacName; - // dimmableLight.DeviceEpointName = dimmableLight.DeviceInfo.DeviceName; - // dimmableLight.ImgVersion = dimmableLight.DeviceInfo.ImgVersion; - // dimmableLight.HwVersion = dimmableLight.DeviceInfo.HwVersion; - // dimmableLight.IsOnline = dimmableLight.DeviceInfo.IsOnline; - // dimmableLight.DriveCode = dimmableLight.DeviceInfo.DriveCode; - // dimmableLight.ImgTypeId = dimmableLight.DeviceInfo.ImgTypeId; - // dimmableLight.IasDeviceType = dimmableLight.DeviceInfo.DeviceType; - // dimmableLight.Profile = dimmableLight.DeviceInfo.Profile; - // dimmableLight.InClusterList = dimmableLight.DeviceInfo.InClusterList; - // dimmableLight.OutClusterList = dimmableLight.DeviceInfo.OutClusterList; - // dimmableLight.AttributeStatus = dimmableLight.DeviceInfo.AttributeStatus; - // //dimmableLight.Save(); - // } - // else - // { - // light.DeviceInfo = dimmableLight.DeviceInfo; - // light.DeviceName = dimmableLight.DeviceInfo.MacName; - // light.DeviceEpointName = dimmableLight.DeviceInfo.DeviceName; - // light.ImgVersion = dimmableLight.DeviceInfo.ImgVersion; - // light.HwVersion = dimmableLight.DeviceInfo.HwVersion; - // light.IsOnline = dimmableLight.DeviceInfo.IsOnline; - // light.DriveCode = dimmableLight.DeviceInfo.DriveCode; - // light.ImgTypeId = dimmableLight.DeviceInfo.ImgTypeId; - // light.IasDeviceType = dimmableLight.DeviceInfo.DeviceType; - // light.Profile = dimmableLight.DeviceInfo.Profile; - // light.InClusterList = dimmableLight.DeviceInfo.InClusterList; - // light.OutClusterList = dimmableLight.DeviceInfo.OutClusterList; - // light.AttributeStatus = dimmableLight.DeviceInfo.AttributeStatus; - // //dimmableLight.ReSave(); - // } - // DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}"); - - // break; - //case DeviceType.OnOffSwitch: - // var panel = new Panel() { Time = jobject.Value<int>("Time"), DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID }; - // panel.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel.DeviceInfoData>(jobject["Data"].ToString()); - // if (panel.DeviceInfo == null) - // { - // return; - // } - // var panelInfo = DeviceList.Find(obj => obj.DeviceID == panel.DeviceID && obj.DeviceAddr == panel.DeviceAddr && obj.DeviceEpoint == panel.DeviceEpoint); - // if (panelInfo == null) - // { - // DeviceList.Add(panel); - // panel.DeviceName = panel.DeviceInfo.MacName; - // panel.DeviceEpointName = panel.DeviceInfo.DeviceName; - // panel.ImgTypeId = panel.DeviceInfo.ImgTypeId; - // panel.ImgVersion = panel.DeviceInfo.ImgVersion; - // panel.HwVersion = panel.DeviceInfo.HwVersion; - // panel.IasDeviceType = panel.DeviceInfo.DeviceType; - // panel.IsOnline = panel.DeviceInfo.IsOnline; - // panel.DriveCode = panel.DeviceInfo.DriveCode; - // panel.Profile = panel.DeviceInfo.Profile; - // panel.InClusterList = panel.DeviceInfo.InClusterList; - // panel.OutClusterList = panel.DeviceInfo.OutClusterList; - // panel.AttributeStatus = panel.DeviceInfo.AttributeStatus; - // //panel.Save(); - // } - // else - // { - // panelInfo.DeviceInfo = panel.DeviceInfo; - // panelInfo.DeviceName = panel.DeviceInfo.MacName; - // panelInfo.DeviceEpointName = panel.DeviceInfo.DeviceName; - // panelInfo.ImgVersion = panel.DeviceInfo.ImgVersion; - // panelInfo.HwVersion = panel.DeviceInfo.HwVersion; - // panelInfo.IsOnline = panel.DeviceInfo.IsOnline; - // panelInfo.DriveCode = panel.DeviceInfo.DriveCode; - // panelInfo.IasDeviceType = panel.DeviceInfo.DeviceType; - // panelInfo.Profile = panel.DeviceInfo.Profile; - // panelInfo.ImgTypeId = panel.DeviceInfo.ImgTypeId; - // panelInfo.InClusterList = panel.DeviceInfo.InClusterList; - // panelInfo.OutClusterList = panel.DeviceInfo.OutClusterList; - // panelInfo.AttributeStatus = panel.DeviceInfo.AttributeStatus; - // //panel.ReSave(); - // } - // DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}"); - - // break; - //case DeviceType.OnOffOutput: - // var toggleLight = new ToggleLight() { Time = jobject.Value<int>("Time"), DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID }; - // toggleLight.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<ToggleLight.DeviceInfoData>(jobject["Data"].ToString()); - // if (toggleLight.DeviceInfo == null) - // { - // return; - // } - // var toggleLightInfo = DeviceList.Find(obj => obj.DeviceID == toggleLight.DeviceID && obj.DeviceAddr == toggleLight.DeviceAddr && obj.DeviceEpoint == toggleLight.DeviceEpoint); - // if (toggleLightInfo == null) - // { - // DeviceList.Add(toggleLight); - // toggleLight.DeviceName = toggleLight.DeviceInfo.MacName; - // toggleLight.DeviceEpointName = toggleLight.DeviceInfo.DeviceName; - // toggleLight.ImgVersion = toggleLight.DeviceInfo.ImgVersion; - // toggleLight.HwVersion = toggleLight.DeviceInfo.HwVersion; - // toggleLight.IsOnline = toggleLight.DeviceInfo.IsOnline; - // toggleLight.DriveCode = toggleLight.DeviceInfo.DriveCode; - // toggleLight.IasDeviceType = toggleLight.DeviceInfo.DeviceType; - // toggleLight.Profile = toggleLight.DeviceInfo.Profile; - // toggleLight.ImgTypeId = toggleLight.DeviceInfo.ImgTypeId; - // toggleLight.InClusterList = toggleLight.DeviceInfo.InClusterList; - // toggleLight.OutClusterList = toggleLight.DeviceInfo.OutClusterList; - // toggleLight.AttributeStatus = toggleLight.DeviceInfo.AttributeStatus; - // //toggleLight.Save(); - // } - // else - // { - // toggleLightInfo.DeviceName = toggleLight.DeviceInfo.MacName; - // toggleLightInfo.DeviceEpointName = toggleLight.DeviceInfo.DeviceName; - // toggleLightInfo.ImgVersion = toggleLight.DeviceInfo.ImgVersion; - // toggleLightInfo.HwVersion = toggleLight.DeviceInfo.HwVersion; - // toggleLightInfo.IsOnline = toggleLight.DeviceInfo.IsOnline; - // toggleLightInfo.DriveCode = toggleLight.DeviceInfo.DriveCode; - // toggleLightInfo.IasDeviceType = toggleLight.DeviceInfo.DeviceType; - // toggleLightInfo.Profile = toggleLight.DeviceInfo.Profile; - // toggleLightInfo.ImgTypeId = toggleLight.DeviceInfo.ImgTypeId; - // toggleLightInfo.InClusterList = toggleLight.DeviceInfo.InClusterList; - // toggleLightInfo.OutClusterList = toggleLight.DeviceInfo.OutClusterList; - // toggleLightInfo.AttributeStatus = toggleLight.DeviceInfo.AttributeStatus; - // toggleLightInfo.DeviceInfo = toggleLight.DeviceInfo; - // //toggleLightInfo.ReSave(); - // } - // DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}"); - - // break; - //case DeviceType.AirSwitch: - // var airSwitch = new AirSwitch() { Time = jobject.Value<int>("Time"), DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID }; - // airSwitch.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<AirSwitch.DeviceInfoData>(jobject["Data"].ToString()); - // if (airSwitch.DeviceInfo == null) - // { - // return; - // } - // var airSwitchInfo = DeviceList.Find(obj => obj.DeviceID == airSwitch.DeviceID && obj.DeviceAddr == airSwitch.DeviceAddr && obj.DeviceEpoint == airSwitch.DeviceEpoint); - // if (airSwitchInfo == null) - // { - // DeviceList.Add(airSwitch); - // airSwitch.DeviceName = airSwitch.DeviceInfo.MacName; - // airSwitch.DeviceEpointName = airSwitch.DeviceInfo.DeviceName; - // airSwitch.ImgVersion = airSwitch.DeviceInfo.ImgVersion; - // airSwitch.HwVersion = airSwitch.DeviceInfo.HwVersion; - // airSwitch.IsOnline = airSwitch.DeviceInfo.IsOnline; - // airSwitch.DriveCode = airSwitch.DeviceInfo.DriveCode; - // airSwitch.IasDeviceType = airSwitch.DeviceInfo.DeviceType; - // airSwitch.Profile = airSwitch.DeviceInfo.Profile; - // airSwitch.ImgTypeId = airSwitch.DeviceInfo.ImgTypeId; - // airSwitch.InClusterList = airSwitch.DeviceInfo.InClusterList; - // airSwitch.OutClusterList = airSwitch.DeviceInfo.OutClusterList; - // airSwitch.AttributeStatus = airSwitch.DeviceInfo.AttributeStatus; - // //airSwitch.Save(); - // } - // else - // { - // airSwitchInfo.DeviceName = airSwitch.DeviceInfo.MacName; - // airSwitchInfo.DeviceEpointName = airSwitch.DeviceInfo.DeviceName; - // airSwitchInfo.ImgVersion = airSwitch.DeviceInfo.ImgVersion; - // airSwitchInfo.HwVersion = airSwitch.DeviceInfo.HwVersion; - // airSwitchInfo.IsOnline = airSwitch.DeviceInfo.IsOnline; - // airSwitchInfo.DriveCode = airSwitch.DeviceInfo.DriveCode; - // airSwitchInfo.IasDeviceType = airSwitch.DeviceInfo.DeviceType; - // airSwitchInfo.Profile = airSwitch.DeviceInfo.Profile; - // airSwitchInfo.ImgTypeId = airSwitch.DeviceInfo.ImgTypeId; - // airSwitchInfo.InClusterList = airSwitch.DeviceInfo.InClusterList; - // airSwitchInfo.OutClusterList = airSwitch.DeviceInfo.OutClusterList; - // airSwitchInfo.AttributeStatus = airSwitch.DeviceInfo.AttributeStatus; - // airSwitchInfo.DeviceInfo = airSwitch.DeviceInfo; - // // airSwitchInfo.ReSave(); - // } - // DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}"); - - // break; - //case DeviceType.WindowCoveringDevice: - // var windowCovering = new Rollershade() { DeviceID = jobject.Value<int>((object)"Device_ID"), DeviceAddr = jobject.Value<string>((object)"DeviceAddr"), DeviceEpoint = jobject.Value<int>((object)"Epoint"), DataID = jobject.Value<int>((object)"Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID }; - // windowCovering.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<Rollershade.DeviceInfoData>(jobject["Data"].ToString()); - // if (windowCovering.DeviceInfo == null) - // { - // return; - // } - // var wc = DeviceList.Find(obj => obj.DeviceID == windowCovering.DeviceID && obj.DeviceAddr == windowCovering.DeviceAddr && obj.DeviceEpoint == windowCovering.DeviceEpoint); - // if (wc == null) - // { - // DeviceList.Add(windowCovering); - // windowCovering.DeviceName = windowCovering.DeviceInfo.MacName; - // windowCovering.DeviceEpointName = windowCovering.DeviceInfo.DeviceName; - // windowCovering.ImgVersion = windowCovering.DeviceInfo.ImgVersion; - // windowCovering.HwVersion = windowCovering.DeviceInfo.HwVersion; - // windowCovering.IsOnline = windowCovering.DeviceInfo.IsOnline; - // windowCovering.DriveCode = windowCovering.DeviceInfo.DriveCode; - // windowCovering.IasDeviceType = windowCovering.DeviceInfo.DeviceType; - // windowCovering.Profile = windowCovering.DeviceInfo.Profile; - // windowCovering.ImgTypeId = windowCovering.DeviceInfo.ImgTypeId; - // windowCovering.InClusterList = windowCovering.DeviceInfo.InClusterList; - // windowCovering.OutClusterList = windowCovering.DeviceInfo.OutClusterList; - // windowCovering.AttributeStatus = windowCovering.DeviceInfo.AttributeStatus; - // //windowCovering.Save(); - // } - // else - // { - // wc.DeviceName = windowCovering.DeviceInfo.MacName; - // wc.DeviceEpointName = windowCovering.DeviceInfo.DeviceName; - // wc.DeviceInfo = windowCovering.DeviceInfo; - // wc.ImgVersion = windowCovering.DeviceInfo.ImgVersion; - // wc.HwVersion = windowCovering.DeviceInfo.HwVersion; - // wc.IsOnline = windowCovering.DeviceInfo.IsOnline; - // wc.DriveCode = windowCovering.DeviceInfo.DriveCode; - // wc.IasDeviceType = windowCovering.DeviceInfo.DeviceType; - // wc.Profile = windowCovering.DeviceInfo.Profile; - // wc.ImgTypeId = windowCovering.DeviceInfo.ImgTypeId; - // wc.InClusterList = windowCovering.DeviceInfo.InClusterList; - // wc.OutClusterList = windowCovering.DeviceInfo.OutClusterList; - // wc.AttributeStatus = windowCovering.DeviceInfo.AttributeStatus; - // // wc.ReSave(); - // } - // DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}"); - // break; - //case DeviceType.IASZone: - // var ias = new IASZone() { Time = jobject.Value<int>("Time"), DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID }; - // ias.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<IASZone.DeviceInfoData>(jobject["Data"].ToString()); - // if (ias.DeviceInfo == null) - // { - // return; - // } - // var infoIAS = DeviceList.Find(obj => obj.DeviceID == ias.DeviceID && obj.DeviceAddr == ias.DeviceAddr && obj.DeviceEpoint == ias.DeviceEpoint); - // if (infoIAS == null) - // { - // DeviceList.Add(ias); - // ias.DeviceName = ias.DeviceInfo.MacName; - // ias.DeviceEpointName = ias.DeviceInfo.DeviceName; - // ias.ImgVersion = ias.DeviceInfo.ImgVersion; - // ias.HwVersion = ias.DeviceInfo.HwVersion; - // ias.IsOnline = ias.DeviceInfo.IsOnline; - // ias.DriveCode = ias.DeviceInfo.DriveCode; - // ias.IasDeviceType = ias.DeviceInfo.DeviceType; - // ias.Profile = ias.DeviceInfo.Profile; - // ias.ImgTypeId = ias.DeviceInfo.ImgTypeId; - // ias.InClusterList = ias.DeviceInfo.InClusterList; - // ias.OutClusterList = ias.DeviceInfo.OutClusterList; - // ias.AttributeStatus = ias.DeviceInfo.AttributeStatus; - // //ias.Save(); - // } - // else - // { - // infoIAS.DeviceName = ias.DeviceInfo.MacName; - // infoIAS.DeviceEpointName = ias.DeviceInfo.DeviceName; - // infoIAS.DeviceEpointName = ias.DeviceInfo.DeviceName; - // infoIAS.ImgVersion = ias.DeviceInfo.ImgVersion; - // infoIAS.HwVersion = ias.DeviceInfo.HwVersion; - // infoIAS.IsOnline = ias.DeviceInfo.IsOnline; - // infoIAS.DriveCode = ias.DeviceInfo.DriveCode; - // infoIAS.IasDeviceType = ias.DeviceInfo.DeviceType; - // infoIAS.Profile = ias.DeviceInfo.Profile; - // infoIAS.ImgTypeId = ias.DeviceInfo.ImgTypeId; - // infoIAS.InClusterList = ias.DeviceInfo.InClusterList; - // infoIAS.OutClusterList = ias.DeviceInfo.OutClusterList; - // infoIAS.AttributeStatus = ias.DeviceInfo.AttributeStatus; - // infoIAS.DeviceInfo = ias.DeviceInfo; - // //ias.ReSave(); - // } - // DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}"); - // break; - //case DeviceType.OtaDevice: - //case DeviceType.OtaPanelDevice: - //var ota = new OTADevice() { Time = jobject.Value<int>("Time"), DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID }; - //ota.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceInfoData>(jobject["Data"].ToString()); - //if (ota.DeviceInfo == null) - //{ - // return; - //} - //var infoOta = DeviceList.Find(obj => obj.DeviceID == ota.DeviceID && obj.DeviceAddr == ota.DeviceAddr && obj.DeviceEpoint == ota.DeviceEpoint); - //if (infoOta == null) - //{ - // DeviceList.Add(ota); - // ota.DeviceName = ota.DeviceInfo.MacName; - // ota.DeviceEpointName = ota.DeviceInfo.DeviceName; - // ota.ImgVersion = ota.DeviceInfo.ImgVersion; - // ota.HwVersion = ota.DeviceInfo.HwVersion; - // ota.IsOnline = ota.DeviceInfo.IsOnline; - // ota.DriveCode = ota.DeviceInfo.DriveCode; - // ota.IasDeviceType = ota.DeviceInfo.DeviceType; - // ota.Profile = ota.DeviceInfo.Profile; - // ota.ImgTypeId = ota.DeviceInfo.ImgTypeId; - // ota.InClusterList = ota.DeviceInfo.InClusterList; - // ota.OutClusterList = ota.DeviceInfo.OutClusterList; - // ota.AttributeStatus = ota.DeviceInfo.AttributeStatus; - // //ota.Save(); - //} - //else - //{ - // infoOta.DeviceName = ota.DeviceInfo.MacName; - // infoOta.DeviceEpointName = ota.DeviceInfo.DeviceName; - // infoOta.DeviceEpointName = ota.DeviceInfo.DeviceName; - // infoOta.ImgVersion = ota.DeviceInfo.ImgVersion; - // infoOta.HwVersion = ota.DeviceInfo.HwVersion; - // infoOta.IsOnline = ota.DeviceInfo.IsOnline; - // infoOta.DriveCode = ota.DeviceInfo.DriveCode; - // infoOta.IasDeviceType = ota.DeviceInfo.DeviceType; - // infoOta.Profile = ota.DeviceInfo.Profile; - // infoOta.ImgTypeId = ota.DeviceInfo.ImgTypeId; - // infoOta.InClusterList = ota.DeviceInfo.InClusterList; - // infoOta.OutClusterList = ota.DeviceInfo.OutClusterList; - // infoOta.AttributeStatus = ota.DeviceInfo.AttributeStatus; - // infoOta.DeviceInfo = ota.DeviceInfo; - // //ota.ReSave(); - //} - //DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}"); - //break; - //case DeviceType.Thermostat: - //var thermostat = new ThermostatObj() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gateway.getGatewayBaseInfo.gwID }; - //thermostat.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<ThermostatObj.DeviceInfoData>(jobject["Data"].ToString()); - //if (thermostat.DeviceInfo == null) - //{ - // return; - //} - //var ther = gateway.DeviceList.Find(obj => obj.DeviceID == thermostat.DeviceID && obj.DeviceAddr == thermostat.DeviceAddr && obj.DeviceEpoint == thermostat.DeviceEpoint); - //if (ther == null) - //{ - // gateway.DeviceList.Add(thermostat); - // thermostat.DeviceName = thermostat.DeviceInfo.DeviceName; - // IO.LocalFileUtils.SaveDeviceInfo(thermostat, thermostat.DeviceEpoint.ToString()); - //} - //else - //{ - // ther.DeviceName = thermostat.DeviceInfo.DeviceName; - // ther.DeviceInfo = thermostat.DeviceInfo; - // ZigBee.IO.LocalFileUtils.SaveDeviceInfo(ther, ther.DeviceEpoint.ToString()); - //} - //break; - //case DeviceType.TemperatureSensor: - //var temperatureSensor = new TemperatureSensor() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gateway.getGatewayBaseInfo.gwID }; - //temperatureSensor.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<TemperatureSensor.DeviceInfoData>(jobject["Data"].ToString()); - //if (temperatureSensor.DeviceInfo == null) - //{ - // return; - //} - //var ts = gateway.DeviceList.Find(obj => obj.DeviceID == temperatureSensor.DeviceID && obj.DeviceAddr == temperatureSensor.DeviceAddr && obj.DeviceEpoint == temperatureSensor.DeviceEpoint); - //if (ts == null) - //{ - // gateway.DeviceList.Add(temperatureSensor); - // temperatureSensor.DeviceName = temperatureSensor.DeviceInfo.DeviceName; - // IO.LocalFileUtils.SaveDeviceInfo(temperatureSensor, temperatureSensor.DeviceEpoint.ToString()); - //} - //else - //{ - // ts.DeviceName = temperatureSensor.DeviceInfo.DeviceName; - // ts.DeviceInfo = temperatureSensor.DeviceInfo; - // IO.LocalFileUtils.SaveDeviceInfo(ts, ts.DeviceEpoint.ToString()); - //} - //break; - - } - } - else if (topic == gatewayID + "/" + "DeviceInfoResponEnd") - { - canBreak = true; - } - }; - - Actions += action; - DebugPrintLog("DeviceInfo Actions 鍚姩" + "_" + System.DateTime.Now.ToString()); - - try - { - var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 93 } }; - Send("GetDeviceInfo", jObject.ToString()); - } - catch { } - - while (canBreak == false && (DateTime.Now - dateTime).TotalMilliseconds < 6000) - { - await System.Threading.Tasks.Task.Delay(10); - } - - Actions -= action; - DebugPrintLog("DeviceInfo_Actions 閫�鍑�" + System.DateTime.Now.ToString()); - return DeviceList; - })); } #endregion @@ -3054,22 +2604,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 +2714,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 +2893,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); }); @@ -3382,6 +2926,22 @@ RemoteMqttClient.UseConnectedHandler(async (e) => { DebugPrintLog($"杩滅▼杩炴帴鎴愬姛"); + + if (Config.Instance.Home.IsOthreShare == true) + { + //璁㈤槄涓�涓垚鍛樿鍒犻櫎鐨勪富棰� + string myGuid = Config.Instance.Guid; + 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"); + await initGateWayBaseInfomation(); Shared.Phone.UserCenter.HdlGatewayLogic.Current.CheckGatewayByConnectChanged(Shared.Phone.UserCenter.GatewayConnectMode.Remote); //娌℃湁涓荤綉鍏虫椂涓诲姩璇诲彇锛岃幏鍙栦富缃戝叧淇℃伅 @@ -3436,7 +2996,9 @@ ["RequestVersion"] = CommonPage.RequestVersion, ["RequestSource"] = 0, ["LoginAccessToken"] = Config.Instance.Token, - ["RequestProtocolType"] = 0 + ["RequestProtocolType"] = 0, + ["PlatformStr"] = "h",//杩欎袱涓�煎鏋滀笉璁剧疆,鍒欎簯绔笉鍙戝竷涓婚 + ["PublishPayloadJsonStr"] = "1" }; var bytes = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(jsonData)); result = await CommonPage.Instance.DoRequestZigbeeHttpsInterface("https://global.hdlcontrol.com/HangZhouHdlCloudApi/EmqMqtt/GetConnMqttInfo", bytes, Config.Instance.Token); @@ -3451,7 +3013,9 @@ ["LoginAccessToken"] = Config.Instance.Token, ["RequestProtocolType"] = 0, ["MainUserDistributedMark"] = Config.Instance.Home.MainUserDistributedMark, - ["HomeId"] = Config.Instance.Home.Id + ["HomeId"] = Config.Instance.Home.Id, + ["PlatformStr"] = "h",//杩欎袱涓�煎鏋滀笉璁剧疆,鍒欎簯绔笉鍙戝竷涓婚 + ["PublishPayloadJsonStr"] = "1" }; var bytes = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(jsonData)); result = await CommonPage.Instance.DoRequestZigbeeHttpsInterface("https://global.hdlcontrol.com/HangZhouHdlCloudApi/EmqMqtt/ShareMemberConnMqttInfo", bytes, Config.Instance.Token); @@ -3465,6 +3029,9 @@ AllowRemoteCtrl = false; return; } + //铏界劧涓嶇煡閬撳鎸や笅绾块偅涓�鍧楁湁娌℃湁鐢�,涓嶈繃鍏堣繖涔堝紕 + await System.Threading.Tasks.Task.Delay(1500); + var responseData = jobject["ResponseData"]; if (responseData != null) { @@ -3472,6 +3039,8 @@ var connEmqClientId = responseData["ConnEmqClientId"]?.ToString(); var connEmqUserName = responseData["ConnEmqUserName"]?.ToString(); var connEmqPwd = responseData["ConnEmqPwd"]?.ToString(); + //璁板綍璧峰綋鍓嶇殑瀹㈡埛绔疘D + Config.Instance.ConnEmqClientId = connEmqClientId; var connEmqDomainPorts = connEmqDomainPort.Replace("//", "").Split(':'); var domain = connEmqDomainPorts[1]; @@ -3874,7 +3443,10 @@ epoint = topic.Split('/')[3]; cluID = topic.Split('/')[4]; attrId = topic.Split('/')[5]; - } + } + + //鍏ㄥ眬鎺ユ敹缃戝叧鎺ㄩ�佺殑鐨勯�昏緫(涓轰簡鎵ц閫熷害,灏藉彲鑳界殑鍒姞鑰楁椂鐨勬搷浣�) + Shared.Phone.UserCenter.HdlGatewayReceiveLogic.Current.GatewayOverallMsgReceive(gatewayID, topic, reportStatus, message); var gwa = GateWayList.Find(obj => obj.getGatewayBaseInfo.gwID == gatewayID); if (gwa == null) @@ -3906,9 +3478,6 @@ { jobject = Newtonsoft.Json.Linq.JObject.Parse(message); } - - //鍏ㄥ眬鎺ユ敹缃戝叧鎺ㄩ�佺殑鐨勯�昏緫(涓轰簡鎵ц閫熷害,灏藉彲鑳界殑鍒姞鑰楁椂鐨勬搷浣�) - Shared.Phone.UserCenter.HdlGatewayReceiveLogic.Current.GatewayOverallMsgReceive(gatewayID, topic, reportStatus, jobject); #region 杩滅▼,涓荤綉鍏充笂鎶ラ�氱煡 if (IsRemote) @@ -3981,8 +3550,7 @@ DebugPrintLog("DeviceInComingRespon宸茬粡閫氱煡"); gwa.ReportAction("DeviceInComingRespon", tempDevice.getNewDeviceInfo); } - UpdateDeviceInfo(tempDevice, "DeviceInComingRespon"); - UpdateDeviceStatus(gwa); + UpdateDeviceInfo(tempDevice, "DeviceInComingRespon"); } #endregion #region 璁惧鍦ㄧ嚎鐘舵�佹洿鏂板弽棣� @@ -4000,7 +3568,6 @@ if (infoTempDevice == null) { gwa.DeviceList.Add(tempDevice); - UpdateDeviceStatus(tempDevice); UpdateDeviceInfo(tempDevice, "OnlineStatusChange"); } else @@ -4010,7 +3577,6 @@ infoTempDevice.DeviceInfo.IsOnline = infoTempDevice.IsOnline; } UpdateDeviceInfo(infoTempDevice, "OnlineStatusChange"); - UpdateDeviceStatus(infoTempDevice); } } #endregion @@ -4036,7 +3602,6 @@ } else { - UpdateDeviceStatus(tempDevice); UpdateDeviceInfo(tempDevice, "RemoveDeviceRespon"); if (tempDevice.removeDeviceResponseData.Result == 0) { @@ -4064,7 +3629,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 @@ -4086,7 +3650,6 @@ DebugPrintLog("DoorLockProgrammingEventNotificationCommand宸茬粡閫氱煡"); gwa.ReportAction("DoorLockProgrammingEventNotificationCommand", doorLock); } - UpdateDeviceStatus(doorLock); UpdateDeviceInfo(doorLock, "DoorLockProgrammingEventNotificationCommand"); break; } @@ -4110,7 +3673,6 @@ DebugPrintLog("DoorLockProgrammingEventNotificationCommand宸茬粡閫氱煡"); gwa.ReportAction("DoorLockProgrammingEventNotificationCommand", doorLock); } - UpdateDeviceStatus(doorLock); UpdateDeviceInfo(doorLock, "DoorLockProgrammingEventNotificationCommand"); break; } @@ -4132,8 +3694,6 @@ //ias.Save(); gwa.ReportAction("IASInfoReport", ias.iASInfo); } - - UpdateDeviceStatus(ias); UpdateDeviceInfo(ias, "IASInfoReport"); break; } @@ -4248,37 +3808,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 妯″紡瀹夐槻鍔ㄤ綔琚渶缁堟縺娲绘椂鍙戦�佹姤璀︿俊鎭� @@ -4352,18 +3912,15 @@ #region 璁惧璇锋眰APP鑾峰彇鍗囩骇鏁版嵁 else if (topic == gatewayID + "/" + "ZbDataPassthrough") { - var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") }; - gatewayTemp.clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString()); - if (gatewayTemp.clientDataPassthroughResponseData == null) - { - return; - } - //涓婃姤绫诲瀷閫氱煡 if (gwa.ReportAction != null) - { - DebugPrintLog("DeviceRequestAcUpdateData"); - gwa.ReportAction("DeviceRequestAcUpdateData", gatewayTemp.clientDataPassthroughResponseData); + { + var clientDataPassthrough = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString()); + if (clientDataPassthrough != null) + { + DebugPrintLog("DeviceRequestAcUpdateData"); + gwa.ReportAction("DeviceRequestAcUpdateData", clientDataPassthrough); + } } } #endregion -- Gitblit v1.8.0