From 2e7e5f9af5b32cfe1fc3c6ba40bf7eb984bbd0a4 Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期一, 11 五月 2020 17:52:06 +0800
Subject: [PATCH] ???????

---
 ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs |  810 ++++++++++++++-------------------------------------------
 1 files changed, 200 insertions(+), 610 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs b/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs
index 60c83d9..64b9859 100755
--- a/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs
+++ b/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs
@@ -22,14 +22,7 @@
     [System.Serializable]
     public class ZbGateway : ZbGatewayData
     {
-        public ZbGateway()
-        {
-            this.Type = DeviceType.ZbGateway;
-        }
-
-
-
-        #region 缃戝叧鐗规畩淇℃伅澶勭悊
+        #region 涓�鍫嗗彉閲�
         /// <summary>
         /// 涓荤綉鍏�
         /// </summary>
@@ -71,20 +64,39 @@
         /// </summary>
         /// <value>The file path.</value>
         [Newtonsoft.Json.JsonIgnore]
-        public override string FilePath
+        public string FilePath
         {
             get
             {
-                var deviceType = Type.ToString();
-                var fileName = "Gateway_" + deviceType + "_" + this.getGatewayBaseInfo?.gwID;
+                var fileName = "Gateway_" + DeviceType.ZbGateway.ToString() + "_" + this.getGatewayBaseInfo?.gwID;
                 return fileName;
+            }
+        }
+
+        /// <summary>
+        /// 绛夊緟浠庣綉鍏虫帴鏀舵暟鎹殑鏃堕棿
+        /// </summary>
+        /// <value>The wait receive data time.</value>
+        [Newtonsoft.Json.JsonIgnore]
+        public int WaitReceiveDataTime
+        {
+            get
+            {
+                if (Device.ZbGateway.RemoteMqttClient != null && Device.ZbGateway.RemoteMqttClient.IsConnected)
+                {
+                    return 10000;
+                }
+                else
+                {
+                    return 3000;
+                }
             }
         }
 
         /// <summary>
         /// 灞�鍩熺綉鍔犲瘑瀵嗙爜
         /// </summary>
-        string password;
+        private string password;
         /// <summary>
         /// 灞�鍩熺綉鍔犲瘑瀵嗛挜
         /// </summary>
@@ -101,27 +113,6 @@
             }
         }
 
-        #region variable 
-        /// <summary>
-        /// 杩滅▼杩炴帴鎴愬姛鏃剁殑鏃堕棿
-        /// </summary>
-        public static DateTime LoginRemoteDateTime = DateTime.Now;
-
-        /// <summary>
-        /// 鍚屾鍒拌繙绋嬬殑褰撳墠鏃堕棿鎴�
-        /// </summary>Re
-        public static ulong CurrentTimeStamp
-        {
-            get
-            {
-                return RemoteTimeStamp + (ulong)(DateTime.Now - LoginRemoteDateTime).TotalSeconds;
-            }
-        }
-
-        /// <summary>
-        /// 杩滅▼杩炴帴鎴愬姛鏃剁殑鏃堕棿鎴�
-        /// </summary>
-        public static ulong RemoteTimeStamp;
         /// <summary>
         /// 缃戝叧鏄惁鍔犲瘑
         /// </summary>
@@ -138,37 +129,6 @@
         [Newtonsoft.Json.JsonIgnore]
         public static List<ZbGateway> GateWayList = new List<ZbGateway>();
 
-        //褰撳墠缃戝叧涓殑璁惧鍒楄〃
-        [Newtonsoft.Json.JsonIgnore]
-        public List<CommonDevice> DeviceList = new List<CommonDevice>();
-
-        /// <summary>
-        /// 缃戝叧涓満鏅垪琛�
-        /// 涓�涓満鏅腑鍖呭惈鎵�鏈変俊鎭紝鍖呮嫭鍦烘櫙璁惧淇℃伅
-        /// </summary>
-        [Newtonsoft.Json.JsonIgnore]
-        public static List<Scene.GetSceneAllInfo> AllSceneList = new List<Scene.GetSceneAllInfo>();
-
-        /// <summary>
-        /// 缃戝叧涓満鏅殑璁惧鍒楄〃
-        /// </summary>
-        [Newtonsoft.Json.JsonIgnore]
-        public List<Scene.GetSceneDeviceListInfo> SceneDeviceList = new List<Scene.GetSceneDeviceListInfo>();
-
-        #region action variable
-        /// <summary>
-        /// 鎺ユ敹鏁版嵁鍚庡洖璋�
-        /// </summary>
-        [Newtonsoft.Json.JsonIgnore]
-        Action<object> action;
-        /// <summary>
-        /// 璁剧疆鏁版嵁鍥炶皟
-        /// </summary>
-        public void SetAction(Action<object> action, int timeOut = 1000)
-        {
-            this.action = action;
-        }
-
         /// <summary>
         /// 缃戝叧鎺ㄩ�佹暟鎹�
         /// <para>绗竴涓弬鏁帮細濡傛灉涓� DeviceInComingRespon:璁惧鏂颁笂鎶�</para>
@@ -183,24 +143,15 @@
         /// <para>绗竴涓弬鏁帮細濡傛灉涓� ZoneTriggerReport:闃插尯琚Е鍙戞椂鎶ュ憡</para>
         /// <para>绗竴涓弬鏁帮細濡傛灉涓� LogicExecuteReport:閫昏緫琚皟鐢ㄥ弽棣�</para>
         /// <para>绗竴涓弬鏁帮細濡傛灉涓� TimingWillArrive:鏃堕棿鐐规潯浠舵帹杩熸墽琛�</para>
-        /// para>绗竴涓弬鏁帮細 濡傛灉涓� ModeTriggerReport:妯″紡瀹夐槻鍔ㄤ綔琚渶缁堟縺娲绘椂鍙戦�佹姤璀︿俊鎭�</para>
+        /// <para>绗竴涓弬鏁帮細 濡傛灉涓� ModeTriggerReport:妯″紡瀹夐槻鍔ㄤ綔琚渶缁堟縺娲绘椂鍙戦�佹姤璀︿俊鎭�</para>
         /// <para>绗竴涓弬鏁帮細濡傛灉涓� EnOrWithdrawSucceedReport:閫氳繃澶栭儴鏂瑰紡甯冮槻鎾ら槻鎴愬姛鏃舵姤鍛婃伅</para>
         /// <para>绗竴涓弬鏁帮細濡傛灉涓� PushTargetInfoReport:鑳佽揩瀵嗙爜鎾ら槻鏃剁煭淇℃帹閫�</para>
-        /// <para>绗竴涓弬鏁帮細濡傛灉涓� DeviceDefaultAck:鑺傜偣璁惧榛樿鍙嶉</para>
         /// <para>绗竴涓弬鏁帮細濡傛灉涓� DDevice/IsGetEpointInfo:鏈夋柊璁惧鍔犲叆zigbee缃戠粶鍙嶉</para>璁惧璇锋眰APP鑾峰彇鍗囩骇鏁版嵁
         /// <para>绗竴涓弬鏁帮細濡傛灉涓� Device/DeviceJoinZbNet:鑾峰彇鏂拌澶囨墍鏈夌鐐逛俊鎭槸鍚︽垚鍔熷弽棣�</para>
         /// <para>绗竴涓弬鏁帮細濡傛灉涓� DeviceRequestAcUpdateData: 璁惧璇锋眰绌鸿皟鍙戝崌绾ф暟鎹�</para>
         /// </summary>
         [Newtonsoft.Json.JsonIgnore]
         public Action<string, object> ReportAction;
-        /// <summary>
-        /// 浜戠閫氳閿欒鏁版嵁涓婃姤
-        ///<para>"ForwardGatewayNoOnLine", "褰撳墠鎿嶄綔鐨勭綉鍏充笉鍦ㄧ嚎"</para>
-        ///<para>"AppTimeOut", "浠庝簯绔幏鍙栨暟鎹秴鏃讹紝璇烽噸鏂拌幏鍙�"</para>
-        ///<para>"AppNoLogin", "鐧诲綍杩囨湡锛岃閲嶆柊鐧诲綍"</para>
-        /// </summary>
-        [Newtonsoft.Json.JsonIgnore]
-        public Action<string, string> CloudErrorAction;
 
         /// <summary>
         /// 缃戝叧鏂囦欢娴佸唴瀹归�氱煡
@@ -219,8 +170,7 @@
         /// </summary>
         [Newtonsoft.Json.JsonIgnore]
         public Action<string, string> Actions;
-        #endregion
-        #endregion
+
         #endregion
 
         #region 缃戝叧API
@@ -241,8 +191,7 @@
 
                     if (topic == gatewayID + "/" + "Error_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
-                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
 
                         if (temp == null)
                         {
@@ -250,24 +199,21 @@
                         }
                         else
                         {
-                            d = new GetGwVersionAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+                            d = new GetGwVersionAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
                         }
                     }
 
                     if (topic == gatewayID + "/" + "GetZbGwVersionRespon")
                     {
-                        var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
-                        gatewayTemp.getGwVersion = Newtonsoft.Json.JsonConvert.DeserializeObject<GetGwVersionData>(jobject["Data"].ToString());
+                        var getGwVersion = Newtonsoft.Json.JsonConvert.DeserializeObject<GetGwVersionData>(jobject["Data"].ToString());
 
-                        if (gatewayTemp.getGwVersion == null)
+                        if (getGwVersion == null)
                         {
                             d = new GetGwVersionAllData { errorMessageBase = "缃戝叧閿欒鍥炲锛屼笖鏁版嵁鏄┖" };
                         }
                         else
                         {
-                            d = new GetGwVersionAllData { getGwVersion = gatewayTemp.getGwVersion };
-                            AppVersion = gatewayTemp.getGwVersion.AppVersion;
-                            ZigbeeVersion = gatewayTemp.getGwVersion.ZigbeeVersion;
+                            d = new GetGwVersionAllData { getGwVersion = getGwVersion };
                             //Save();
                             DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{topic}");
                         }
@@ -319,16 +265,15 @@
                     if (topic == gatewayID + "/" + "GetZbGwInfo_Respon")
                     {
                         var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
-                        var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID };
-                        gatewayTemp.getGwInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<GetGwData>(jobject["Data"].ToString());
+                        var getGwInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<GetGwData>(jobject["Data"].ToString());
 
-                        if (gatewayTemp.getGwInfo == null)
+                        if (getGwInfo == null)
                         {
                             data = new GetGwAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
                         }
                         else
                         {
-                            data = new GetGwAllData { getGwData = gatewayTemp.getGwInfo };
+                            data = new GetGwAllData { getGwData = getGwInfo };
                             DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{topic}");
                         }
                     }
@@ -373,8 +318,7 @@
 
                     if (topic == gatewayID + "/" + "Error_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
-                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
 
                         if (temp == null)
                         {
@@ -382,13 +326,12 @@
                         }
                         else
                         {
-                            d = new GetMacResponData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+                            d = new GetMacResponData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
                         }
                     }
 
                     if (topic == gatewayID + "/" + "ZbGw/GetMac_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
                         var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<MacAddrData>(jobject["Data"].ToString());
 
                         if (tempData == null)
@@ -443,8 +386,7 @@
 
                     if (topic == gatewayID + "/" + "Error_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
-                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
 
                         if (temp == null)
                         {
@@ -452,22 +394,21 @@
                         }
                         else
                         {
-                            d = new GwReNameAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+                            d = new GwReNameAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
                         }
                     }
 
                     if (topic == gatewayID + "/" + "GwReName_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
-                        gatewayTemp.gwRename = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.GwReNameData>(jobject["Data"].ToString());
+                        var gwRename = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.GwReNameData>(jobject["Data"].ToString());
 
-                        if (gatewayTemp.gwRename == null)
+                        if (gwRename == null)
                         {
                             d = new GwReNameAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
                         }
                         else
                         {
-                            d = new GwReNameAllData { gwReNameData = gatewayTemp.gwRename };
+                            d = new GwReNameAllData { gwReNameData = gwRename };
                             DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
                         }
                     }
@@ -526,8 +467,7 @@
 
                     if (topic == gatewayID + "/" + "Error_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
-                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
 
                         if (temp == null)
                         {
@@ -535,21 +475,20 @@
                         }
                         else
                         {
-                            d = new GwSetHomeIdAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+                            d = new GwSetHomeIdAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
                         }
                     }
 
                     if (topic == gatewayID + "/" + "GwSetHomeId_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
-                        gatewayTemp.gwSetHomeId = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.GwSetHomeIdData>(jobject["Data"].ToString());
-                        if (gatewayTemp.gwSetHomeId == null)
+                        var gwSetHomeId = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.GwSetHomeIdData>(jobject["Data"].ToString());
+                        if (gwSetHomeId == null)
                         {
                             d = new GwSetHomeIdAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
                         }
                         else
                         {
-                            d = new GwSetHomeIdAllData { gwSetHomeIdData = gatewayTemp.gwSetHomeId };
+                            d = new GwSetHomeIdAllData { gwSetHomeIdData = gwSetHomeId };
                             DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
                         }
                     }
@@ -597,82 +536,6 @@
 
                 Actions -= action;
                 DebugPrintLog("GwReName_Actions 閫�鍑�" + System.DateTime.Now.ToString());
-
-                return d;
-            });
-        }
-        #endregion
-
-        #region 鑾峰彇缃戝叧璁板綍鐨勮澶囧睘鎬х姸鎬�
-        /// <summary>
-        ///鑾峰彇缃戝叧璁板綍鐨勮澶囧睘鎬х姸鎬�
-        /// </summary>
-        public async System.Threading.Tasks.Task<GetStatusRecordAllInfo> GetStatusRecordAsync(string deviceAddr, int deviceEpoint)
-        {
-            return await System.Threading.Tasks.Task.Run(async () =>
-            {
-                GetStatusRecordAllInfo d = null;
-                Action<string, string> action = (topic, message) =>
-                {
-                    var gatewayID = topic.Split('/')[0];
-                    var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
-
-                    if (topic == gatewayID + "/" + "Error_Respon")
-                    {
-                        var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
-                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
-
-                        if (temp == null)
-                        {
-                            d = new GetStatusRecordAllInfo { errorMessageBase = "缃戝叧閿欒鍥炲锛屼笖鏁版嵁鏄┖" };
-                        }
-                        else
-                        {
-                            d = new GetStatusRecordAllInfo { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
-                        }
-                    }
-
-                    if (topic == gatewayID + "/" + "GetStatusRecord_Respon")
-                    {
-                        var gatewayTemp = new ZbGateway() { 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 };
-                        gatewayTemp.getStatusRecordInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.GetStatusRecordInfo>(jobject["Data"].ToString());
-
-                        if (gatewayTemp.getStatusRecordInfo == null)
-                        {
-                            d = new GetStatusRecordAllInfo { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
-                        }
-                        else
-                        {
-                            d = new GetStatusRecordAllInfo { getStatusRecordInfo = gatewayTemp.getStatusRecordInfo };
-                            DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
-                        }
-                    }
-                };
-                Actions += action;
-                DebugPrintLog("GetStatusRecord_Actions 鍚姩" + System.DateTime.Now.ToString());
-                try
-                {
-                    var jObject = new JObject { { "DeviceAddr", deviceAddr }, { "Epoint", deviceEpoint }, { "Cluster_ID", 0 }, { "Command", 80 } };
-                    Send("GetStatusRecord", jObject.ToString());
-
-                }
-                catch { }
-
-                var dateTime = DateTime.Now;
-                while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
-                {
-                    await System.Threading.Tasks.Task.Delay(10);
-                    if (d != null)
-                    {
-                        break;
-                    }
-                }
-                if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
-                {
-                    d = new GetStatusRecordAllInfo { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" };
-                }
-                Actions -= action;
-                DebugPrintLog("GetStatusRecord_Actions 閫�鍑�" + System.DateTime.Now.ToString());
 
                 return d;
             });
@@ -743,8 +606,7 @@
 
                     if (topic == gatewayID + "/" + "Error_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
-                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
 
                         if (temp == null)
                         {
@@ -752,13 +614,12 @@
                         }
                         else
                         {
-                            d = new GwLinuxResetResponData { errorMessageBase = ErrorMess(temp.Error) };
+                            d = new GwLinuxResetResponData { errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
                         }
                     }
 
                     if (topic == gatewayID + "/" + "GwLinuxReset_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { 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 };
                         var result = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"].ToString());
 
                         if (result == null)
@@ -821,8 +682,7 @@
 
                     if (topic == gatewayID + "/" + "Error_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
-                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
 
                         if (temp == null)
                         {
@@ -830,13 +690,12 @@
                         }
                         else
                         {
-                            d = new GwRebootResponAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+                            d = new GwRebootResponAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
                         }
                     }
 
                     if (topic == gatewayID + "/" + "GwReboot_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { 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 };
                         var result = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"].ToString());
 
                         if (result == null)
@@ -897,8 +756,7 @@
 
                     if (topic == gatewayID + "/" + "Error_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
-                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
 
                         if (temp == null)
                         {
@@ -906,22 +764,21 @@
                         }
                         else
                         {
-                            d = new SaveNVFileResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+                            d = new SaveNVFileResponseAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
                         }
                     }
 
                     if (topic == gatewayID + "/" + "ZbGwOperation/SaveNVFile_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
-                        gatewayTemp.zbGwOperationSaveNVFileData = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.SaveNVFileResponseData>(jobject["Data"].ToString());
+                        var zbGwOperationSaveNVFileData = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.SaveNVFileResponseData>(jobject["Data"].ToString());
 
-                        if (gatewayTemp.zbGwOperationSaveNVFileData == null)
+                        if (zbGwOperationSaveNVFileData == null)
                         {
                             d = new SaveNVFileResponseAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
                         }
                         else
                         {
-                            d = new SaveNVFileResponseAllData { saveNVFileResponseData = gatewayTemp.zbGwOperationSaveNVFileData };
+                            d = new SaveNVFileResponseAllData { saveNVFileResponseData = zbGwOperationSaveNVFileData };
                             DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
                         }
                     }
@@ -975,8 +832,7 @@
 
                     if (topic == gatewayID + "/" + "Error_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
-                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
 
                         if (temp == null)
                         {
@@ -984,14 +840,13 @@
                         }
                         else
                         {
-                            d = new RestoreNVAllDtta { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+                            d = new RestoreNVAllDtta { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
                         }
                     }
 
 
                     if (topic == gatewayID + "/" + "ZbGwOperation/RestoreNV_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
                         var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.RestoreNVDtta>(jobject["Data"].ToString());
 
                         if (tempData == null)
@@ -1055,21 +910,19 @@
 
                     if (topic == gatewayID + "/" + "Error_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
-                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
                         if (temp == null)
                         {
                             d = new GwGetChannelResponData { errorMessageBase = "缃戝叧閿欒鍥炲锛屼笖鏁版嵁鏄┖" };
                         }
                         else
                         {
-                            d = new GwGetChannelResponData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+                            d = new GwGetChannelResponData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
                         }
                     }
 
                     if (topic == gatewayID + "/" + "ZbGw/GetChannel_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
                         var channel = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["Channel"].ToString());
                         d = new GwGetChannelResponData { channel = channel };
                         DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
@@ -1123,8 +976,7 @@
 
                     if (topic == gatewayID + "/" + "Error_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
-                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
 
                         if (temp == null)
                         {
@@ -1132,13 +984,12 @@
                         }
                         else
                         {
-                            d = new ChangeChannelResponAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+                            d = new ChangeChannelResponAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
                         }
                     }
 
                     if (topic == gatewayID + "/" + "ZbGw/ChangeChannel_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
                         var tempInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<ChangeChannelResponData>(jobject["Data"].ToString());
 
                         if (tempInfo == null)
@@ -1217,8 +1068,11 @@
         /// </summary>
         public async System.Threading.Tasks.Task<Panel.PanelSwitchLevelInfo> ClientDataPassthroughBytesAsync(string deviceAddr, int devicePoint, long dataLength, byte[] passData)
         {
+            var myDevice = Shared.Common.LocalDevice.Current.GetDevice(deviceAddr, devicePoint);
+
             Panel.PanelSwitchLevelInfo result = null;
-            if (Gateway == null)
+
+            if (myDevice.Gateway == null)
             {
                 result = new Panel.PanelSwitchLevelInfo { errorMessageBase = "褰撳墠娌℃湁缃戝叧" };
                 return result;
@@ -1232,8 +1086,7 @@
 
                     if (topic == gatewayID + "/" + "Error_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
-                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
 
                         if (temp == null)
                         {
@@ -1242,24 +1095,23 @@
 
                         else
                         {
-                            result = new Panel.PanelSwitchLevelInfo { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+                            result = new Panel.PanelSwitchLevelInfo { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
                         }
                     }
 
                     if (topic == gatewayID + "/" + "ZbDataPassthrough")
                     {
-                        var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
-                        gatewayTemp.clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString());
+                        var clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ClientDataPassthroughResponseData>(jobject["Data"].ToString());
 
-                        if (gatewayTemp.clientDataPassthroughResponseData == null)
+                        if (clientDataPassthroughResponseData == null)
                         {
                             result = new Panel.PanelSwitchLevelInfo { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
                         }
                         else
                         {
-                            if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null)
+                            if (clientDataPassthroughResponseData?.PassData != null)
                             {
-                                var data = gatewayTemp.clientDataPassthroughResponseData.PassData;
+                                var data = clientDataPassthroughResponseData.PassData;
                                 if (data.Length == 14)
                                 {
                                     var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString();
@@ -1276,7 +1128,7 @@
                     }
                 };
 
-                Gateway.Actions += action;
+                myDevice.Gateway.Actions += action;
                 System.Console.WriteLine("ClientDataPassthrough_Actions 鍚姩" + System.DateTime.Now.ToString());
 
                 try
@@ -1317,7 +1169,7 @@
                 {
                     result = new Panel.PanelSwitchLevelInfo { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" };
                 }
-                Gateway.Actions -= action;
+                myDevice.Gateway.Actions -= action;
                 System.Console.WriteLine("ClientDataPassthrough_Actions 閫�鍑�" + System.DateTime.Now.ToString());
 
                 return result;
@@ -1346,8 +1198,7 @@
 
                     if (topic == gatewayID + "/" + "Error_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { 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 };
-                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
 
                         if (temp == null)
                         {
@@ -1355,24 +1206,16 @@
                         }
                         else
                         {
-                            d = new PassthroughAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+                            d = new PassthroughAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
                         }
                     }
 
                     if (topic == gatewayID + "/" + "ZbDataPassthrough")
                     {
-                        var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
                         var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<string>(jobject["Data"].ToString());
 
-                        if (gatewayTemp.getGwVersion == null)
-                        {
-                            d = new PassthroughAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
-                        }
-                        else
-                        {
-                            d = new PassthroughAllData { passData = temp };
-                            DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
-                        }
+                        d = new PassthroughAllData { passData = temp };
+                        DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
                     }
                 };
                 Actions += action;
@@ -1425,8 +1268,7 @@
 
                     if (topic == gatewayID + "/" + "Error_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
-                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
 
                         if (temp == null)
                         {
@@ -1435,13 +1277,12 @@
 
                         else
                         {
-                            d = new LinuxUpgradeAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+                            d = new LinuxUpgradeAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
                         }
                     }
 
                     if (topic == gatewayID + "/" + "ZbGwOperation/LinuxUpgrade_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
                         var result = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["Result"].ToString());
                         d = new LinuxUpgradeAllData { Result = result };
                         DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
@@ -1502,8 +1343,7 @@
 
                     if (topic == gatewayID + "/" + "Error_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID };
-                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
 
                         if (temp == null)
                         {
@@ -1512,22 +1352,21 @@
 
                         else
                         {
-                            d = new ZbGwOperationUpgradeAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+                            d = new ZbGwOperationUpgradeAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
                         }
                     }
 
                     if (topic == gatewayID + "/" + "ZbGwOperation/Upgrade_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
-                        gatewayTemp.zbGwOperationUpgradeData = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ZbGwOperationUpgradeData>(jobject["Data"].ToString());
+                        zbGwOperationUpgradeData = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ZbGwOperationUpgradeData>(jobject["Data"].ToString());
 
-                        if (gatewayTemp.zbGwOperationUpgradeData == null)
+                        if (zbGwOperationUpgradeData == null)
                         {
                             d = new ZbGwOperationUpgradeAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
                         }
                         else
                         {
-                            d = new ZbGwOperationUpgradeAllData { bGwOperationUpgradeData = gatewayTemp.zbGwOperationUpgradeData };
+                            d = new ZbGwOperationUpgradeAllData { bGwOperationUpgradeData = zbGwOperationUpgradeData };
                             DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
                         }
                     }
@@ -1573,11 +1412,11 @@
         /// <returns>The file async.</returns>
         /// <param name="distributedMark">Distributed mark:鍥轰欢鍞竴鏍囪瘑</param>
         /// <param name="imageName">Image name:鍥轰欢鐗堟湰</param>
-        public async System.Threading.Tasks.Task<DownloadFileResponAllData> DownloadFileAsync(string distributedMark, string imageName)
+        public async System.Threading.Tasks.Task<CommonDevice.DownloadFileResponAllData> DownloadFileAsync(string distributedMark, string imageName)
         {
             return await System.Threading.Tasks.Task.Run(async () =>
             {
-                DownloadFileResponAllData d = null; ;
+                CommonDevice.DownloadFileResponAllData d = null; ;
                 Action<string, string> action = (topic, message) =>
                 {
                     var gatewayID = topic.Split('/')[0];
@@ -1585,32 +1424,30 @@
 
                     if (topic == gatewayID + "/" + "Error_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID };
-                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
 
                         if (temp == null)
                         {
-                            d = new DownloadFileResponAllData { errorMessageBase = "缃戝叧閿欒鍥炲锛屼笖鏁版嵁鏄┖" };
+                            d = new CommonDevice.DownloadFileResponAllData { errorMessageBase = "缃戝叧閿欒鍥炲锛屼笖鏁版嵁鏄┖" };
                         }
 
                         else
                         {
-                            d = new DownloadFileResponAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+                            d = new CommonDevice.DownloadFileResponAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
                         }
                     }
 
                     if (topic == gatewayID + "/" + "DownloadFile_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
-                        gatewayTemp.downloadFileResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<DownloadFileResponData>(jobject["Data"].ToString());
+                        var downloadFileResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.DownloadFileResponData>(jobject["Data"].ToString());
 
-                        if (gatewayTemp.downloadFileResponData == null)
+                        if (downloadFileResponData == null)
                         {
-                            d = new DownloadFileResponAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
+                            d = new CommonDevice.DownloadFileResponAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
                         }
                         else
                         {
-                            d = new DownloadFileResponAllData { downloadFileResponData = gatewayTemp.downloadFileResponData };
+                            d = new CommonDevice.DownloadFileResponAllData { downloadFileResponData = downloadFileResponData };
                             DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
                         }
                     }
@@ -1641,7 +1478,7 @@
                 }
                 if ((DateTime.Now - dateTime).TotalMilliseconds > 30 * 1000)
                 {
-                    d = new DownloadFileResponAllData { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" };
+                    d = new CommonDevice.DownloadFileResponAllData { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" };
 
                 }
                 Actions -= action;
@@ -1668,8 +1505,7 @@
 
                     if (topic == gatewayID + "/" + "Error_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID };
-                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
 
                         if (temp == null)
                         {
@@ -1678,22 +1514,21 @@
 
                         else
                         {
-                            d = new CheckVDDriveCodeResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+                            d = new CheckVDDriveCodeResponseAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
                         }
                     }
 
                     if (topic == gatewayID + "/" + "VirtualDrive/CatDriveCode_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
-                        gatewayTemp.vDriveDriveCodeResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<VDriveDriveCodeResponData>(jobject["Data"].ToString());
+                        var vDriveDriveCodeResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<VDriveDriveCodeResponData>(jobject["Data"].ToString());
 
-                        if (gatewayTemp.vDriveDriveCodeResponData == null)
+                        if (vDriveDriveCodeResponData == null)
                         {
                             d = new CheckVDDriveCodeResponseAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
                         }
                         else
                         {
-                            d = new CheckVDDriveCodeResponseAllData { vDriveDriveCodeResponData = gatewayTemp.vDriveDriveCodeResponData };
+                            d = new CheckVDDriveCodeResponseAllData { vDriveDriveCodeResponData = vDriveDriveCodeResponData };
                             DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
                         }
                     }
@@ -1748,8 +1583,7 @@
 
                     if (topic == gatewayID + "/" + "Error_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID };
-                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
 
                         if (temp == null)
                         {
@@ -1758,22 +1592,21 @@
 
                         else
                         {
-                            d = new VirtualDriveUpgradeResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+                            d = new VirtualDriveUpgradeResponseAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
                         }
                     }
 
                     if (topic == gatewayID + "/" + "VirtualDrive/Upgrade_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
-                        gatewayTemp.virtualDriveUpgradeResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<VirtualDriveUpgradeResponData>(jobject["Data"].ToString());
+                        virtualDriveUpgradeResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<VirtualDriveUpgradeResponData>(jobject["Data"].ToString());
 
-                        if (gatewayTemp.virtualDriveUpgradeResponData == null)
+                        if (virtualDriveUpgradeResponData == null)
                         {
                             d = new VirtualDriveUpgradeResponseAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
                         }
                         else
                         {
-                            d = new VirtualDriveUpgradeResponseAllData { virtualDriveUpgradeResponData = gatewayTemp.virtualDriveUpgradeResponData };
+                            d = new VirtualDriveUpgradeResponseAllData { virtualDriveUpgradeResponData = virtualDriveUpgradeResponData };
                             DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{topic}");
                         }
                     }
@@ -1811,115 +1644,6 @@
 
         #endregion
 
-        //#region 涓婁紶绉佹湁鏁版嵁
-        //private bool backupSuccess = false;
-        /// <summary>
-        /// 涓婁紶绉佹湁鏁版嵁
-        /// </summary>
-        /// <returns>The data to gateway.</returns>
-        /// <param name="fileName">File name.</param>
-        /// <param name="dev">Dev.</param>
-        //public async System.Threading.Tasks.Task<SendFileResponseAllData> BackupDataToGateway(string fileName, CommonDevice dev)
-        //{
-        //    return await System.Threading.Tasks.Task.Run(async () =>
-        //    {
-        //        SendFileResponseAllData backUpStatus = null;
-        //        var file = await System.Threading.Tasks.Task.Factory.StartNew(() => Newtonsoft.Json.JsonConvert.SerializeObject(dev));
-        //        var data = System.Text.Encoding.UTF8.GetBytes(file);
-        //        //缃戝叧涓垱寤哄瓨鍌ㄦ暟鎹殑鏂囦欢
-        //        var saveFileName = await dev.Gateway.CreateFileAsync(fileName);
-        //        if (saveFileName != null && saveFileName.Result == 0)
-        //        {
-        //            backupSuccess = false;
-        //            //涓婁紶鏁版嵁鍒扮綉鍏�
-        //            var saveData = await dev.Gateway.SendFileAsync(data);
-        //            if (saveData != null)
-        //            {
-        //                backUpStatus = new SendFileResponseAllData { Result = saveData.Result };
-        //            }
-        //        }
-        //        var dateTime = DateTime.Now;
-        //        while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
-        //        {
-        //            await System.Threading.Tasks.Task.Delay(10);
-        //            if (backUpStatus != null)
-        //            {
-        //                break;
-        //            }
-        //        }
-        //        if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
-        //        {
-        //            backUpStatus = new SendFileResponseAllData { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" };
-        //         };
-        //        return backUpStatus;
-        //    });
-        //}
-
-        /// <summary>
-        /// 涓嬭浇绉佹湁鏁版嵁
-        /// </summary>
-        /// <returns>The data from gateway.</returns>
-        /// <param name="fileName">File name.</param>
-        /// <param name="dev">Dev.</param>
-        //public async System.Threading.Tasks.Task<System.Collections.Generic.List<byte>> DownloadDataFromGateway(string fileName, CommonDevice dev)
-        //{
-        //    return await System.Threading.Tasks.Task.Run(async () =>
-        //    {
-        //        byteSource.Clear();
-        //        System.Collections.Generic.List<byte> backUpData = null;
-        //        var dateTime = DateTime.Now;
-        //        //鑾峰彇褰撳墠鏂囦欢鐨勫叿浣撲俊鎭�
-        //        //var getFileSize = await currentKey.Gateway.GetCurrentFileInfoAsync(fileName);
-        //        //涓嬭浇鏂囦欢
-        //        var saveFileName = await dev.Gateway.SetDownloadFileAsync(fileName);
-        //        Action<string, byte[]> action = (topic, dataContent) =>
-        //        {
-        //            if (topic.Split('/')[0] + "/" + topic.Split('/')[1] + "/" + topic.Split('/')[2] == topic.Split('/')[0] + "/" + "FileTransfer/DownloadFile")
-        //            {
-        //                dateTime = DateTime.Now;
-        //                byte[] fileBytes = dataContent;
-        //                if (fileBytes[5] != 1)
-        //                {
-        //                    if (fileBytes.Length == 2056)
-        //                    {
-        //                        var tempBytes = new byte[2048];
-        //                        System.Array.Copy(fileBytes, 8, tempBytes, 0, 2048);
-        //                        byteSource.AddRange(tempBytes);
-        //                    }
-        //                    else
-        //                    {
-        //                        var tempBytes = new byte[fileBytes.Length - 8];
-        //                        System.Array.Copy(fileBytes, 8, tempBytes, 0, tempBytes.Length);
-        //                        byteSource.AddRange(tempBytes);
-        //                    }
-        //                }
-        //                else
-        //                {
-        //                    var tempBytes = new byte[fileBytes.Length - 8];
-        //                    System.Array.Copy(fileBytes, 8, tempBytes, 0, tempBytes.Length);
-        //                    byteSource.AddRange(tempBytes);
-
-        //                    if (byteSource != null )
-        //                    {
-        //                        backUpData = byteSource;
-        //                    }
-        //                }
-
-        //            }
-        //        };
-        //        dev.Gateway.FileContentAction += action;
-
-        //        while ((DateTime.Now - dateTime).TotalMilliseconds < 2000)
-        //        {
-        //            await System.Threading.Tasks.Task.Delay(10);
-        //        }
-        //        dev.Gateway.FileContentAction -= action;
-        //        return byteSource;
-        //    });
-        //}
-
-        //#endregion
-
         #region 瀹㈡埛绔笂浼犳枃浠跺埌缃戝叧.
         /// <summary>
         /// 瀹㈡埛绔笂浼犳枃浠跺埌缃戝叧
@@ -1940,8 +1664,7 @@
 
                     if (topic == gatewayID + "/" + "Error_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID };
-                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ErrorResponData>(jobject["Data"].ToString());
+                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
 
                         if (temp == null)
                         {
@@ -1949,13 +1672,12 @@
                         }
                         else
                         {
-                            dataRes = new CreateFileResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+                            dataRes = new CreateFileResponseAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
                         }
                     }
 
                     if (topic == gatewayID + "/" + "FileTransfer/CreateFile_Respon")
                     {
-                        var security = new ZbGateway() { DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID };
                         var result = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["Result"].ToString());
                         dataRes = new CreateFileResponseAllData { Result = result };
                         DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
@@ -2019,7 +1741,6 @@
 
                     if (topic == gatewayID + "/FileTransfer/SendFile_Respon")
                     {
-                        var gateway = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
                         var result = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["Result"].ToString());
                         dataRes = new SendFileResponseAllData { Result = result };
                         if (result == 0)
@@ -2109,8 +1830,7 @@
 
                     if (topic == gatewayID + "/" + "Error_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID };
-                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ErrorResponData>(jobject["Data"].ToString());
+                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
 
                         if (temp == null)
                         {
@@ -2118,13 +1838,12 @@
                         }
                         else
                         {
-                            dataRes = new FileTransferLsDiResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+                            dataRes = new FileTransferLsDiResponseAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
                         }
                     }
 
                     if (topic == gatewayID + "/" + "FileTransfer/lsDir_Respon")
                     {
-                        var lsDir = new ZbGateway() { DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID };
                         var resultlsDir = Newtonsoft.Json.JsonConvert.DeserializeObject<FileTransferLsDiResponseData>(jobject["Data"].ToString());
                         if (resultlsDir != null)
                         {
@@ -2187,8 +1906,7 @@
 
                     if (topic == gatewayID + "/" + "Error_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID };
-                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ErrorResponData>(jobject["Data"].ToString());
+                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
 
                         if (temp == null)
                         {
@@ -2196,13 +1914,12 @@
                         }
                         else
                         {
-                            dataRes = new FileTransferGetFileInfoResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+                            dataRes = new FileTransferGetFileInfoResponseAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
                         }
                     }
 
                     if (topic == gatewayID + "/" + "FileTransfer/GetFileInfo_Respon")
                     {
-                        var lsDir = new ZbGateway() { DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID };
                         var resultlsDir = Newtonsoft.Json.JsonConvert.DeserializeObject<FileTransferGetFileInfoResponseData>(jobject["Data"].ToString());
                         if (resultlsDir != null)
                         {
@@ -2267,8 +1984,7 @@
 
                     if (topic == gatewayID + "/" + "Error_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID };
-                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ErrorResponData>(jobject["Data"].ToString());
+                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
 
                         if (temp == null)
                         {
@@ -2276,13 +1992,12 @@
                         }
                         else
                         {
-                            dataRes = new SetDownloadFileResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+                            dataRes = new SetDownloadFileResponseAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
                         }
                     }
 
                     if (topic == gatewayID + "/" + "FileTransfer/SetDownloadFile_Respon")
                     {
-                        var lsDir = new ZbGateway() { DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = CurrentGateWayId };
                         var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<SetDownloadFileResponseData>(jobject["Data"].ToString());
                         if (tempData != null)
                         {
@@ -2290,7 +2005,7 @@
                             var tempDa = new SetDownloadFileResponseData();
                             if (tempData.Result == 0)
                             {
-                                ZbGateway.byteSource.Clear();
+                                this.byteSource.Clear();
                             }
                             tempDa.Result = tempData.Result;
                             dataRes.setDownloadFileResponseData = tempDa;
@@ -2338,7 +2053,7 @@
         #endregion
 
         #region 缃戝叧鍙戦�佹枃浠舵祦鍒板鎴风
-        static System.Collections.Generic.List<byte> byteSource = new System.Collections.Generic.List<byte>();
+        private List<byte> byteSource = new List<byte>();
         ///<summary >
         /// 涓嬭浇鏂囦欢涓殑鏁版嵁
         /// </summary>
@@ -2401,8 +2116,7 @@
 
                     if (topic == gatewayID + "/" + "Error_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID };
-                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ErrorResponData>(jobject["Data"].ToString());
+                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
 
                         if (temp == null)
                         {
@@ -2410,13 +2124,12 @@
                         }
                         else
                         {
-                            dataRes = new DelFileOrDirResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+                            dataRes = new DelFileOrDirResponseAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
                         }
                     }
 
                     if (topic == gatewayID + "/" + "FileTransfer/DelFileOrDir_Respon")
                     {
-                        var lsDir = new ZbGateway() { DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = CurrentGateWayId };
                         var resultDelFileOrDir = Newtonsoft.Json.JsonConvert.DeserializeObject<DelFileOrDirResponseData>(jobject["Data"].ToString());
                         if (resultDelFileOrDir != null)
                         {
@@ -2480,8 +2193,7 @@
 
                     if (topic == gatewayID + "/" + "Error_Respon")
                     {
-                        var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID };
-                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ErrorResponData>(jobject["Data"].ToString());
+                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
 
                         if (temp == null)
                         {
@@ -2489,13 +2201,12 @@
                         }
                         else
                         {
-                            dataRes = new CreateDirResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+                            dataRes = new CreateDirResponseAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
                         }
                     }
 
                     if (topic == gatewayID + "/" + "FileTransfer/CreateDir_Respon")
                     {
-                        var lsDir = new ZbGateway() { DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = CurrentGateWayId };
                         var resultCreateDir = Newtonsoft.Json.JsonConvert.DeserializeObject<CreateDirResponseData>(jobject["Data"].ToString());
                         if (resultCreateDir != null)
                         {
@@ -2556,7 +2267,6 @@
                     if (topic == gatewayID + "/" + "SendAESKey_Respon")
                     {
                         var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
-                        var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
                         var result = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["Result"].ToString());
                         sendKeyResponData = new SendKeyResponData { Result = result };
                         DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
@@ -2601,7 +2311,7 @@
         /// <para>杩涘叆褰撳墠鐣岄潰鏃惰娣诲姞</para>
         /// <para>閫�鍑哄綋鍓嶇晫闈㈡椂瑕佸叧闂�</para>
         /// </summary>
-        public static readonly System.Collections.Generic.List<IStatus> StatusList = new System.Collections.Generic.List<IStatus>();
+        public static readonly List<IStatus> StatusList = new List<IStatus>();
 
         /// <summary>
         /// 璁惧淇℃伅鍙樺寲
@@ -2631,6 +2341,7 @@
         /// </summary>
         IMqttClient localMqttClient = new MqttFactory().CreateMqttClient();
         bool localMqttIsConnecting;
+        [Newtonsoft.Json.JsonIgnore]
         public bool localIsConnected;
         /// <summary>
         /// 鎵嬫満鏍囪瘑
@@ -2852,15 +2563,12 @@
         /// 澶栫綉鐨凪QTT鏄惁姝e湪杩炴帴
         /// </summary>
         static bool remoteMqttIsConnecting;
-        static bool IsLoginAgain;
+
         /// <summary>
         /// 杩滅▼MqttClient
         /// </summary>
-        public static IMqttClient RemoteMqttClient= new MqttFactory().CreateMqttClient();
-        static bool remoteIsConnected; 
-        private int IsLogin = 0;
-        [Newtonsoft.Json.JsonIgnore]
-        static Action actionTemp;
+        public static IMqttClient RemoteMqttClient = new MqttFactory().CreateMqttClient();
+        static bool remoteIsConnected;
 
         /// <summary>
         /// 鍚姩杩滅▼Mqtt
@@ -3086,7 +2794,7 @@
                     localIsConnected = false;
                     DebugPrintLog($"Local涓诲姩鏂紑_{s}");
                     //await localMqttClient.DisconnectAsync(new MQTTnet.Client.Disconnecting.MqttClientDisconnectOptions {  }, CancellationToken.None);
-                    await localMqttClient.DisconnectAsync(); 
+                    await localMqttClient.DisconnectAsync();
                 }
             }
             catch (Exception ex)
@@ -3098,7 +2806,7 @@
         /// <summary>
         /// 鏂紑杩滅▼Mqtt鐨勯摼鎺�
         /// </summary>
-        public static async System.Threading.Tasks.Task DisConnectRemoteMqttClient(string s="")
+        public static async System.Threading.Tasks.Task DisConnectRemoteMqttClient(string s = "")
         {
             try
             {
@@ -3117,6 +2825,8 @@
         }
 
         #endregion
+
+        #region 鏁版嵁鍙戦��
 
         /// <summary>
         /// 鍙戦�佹秷鎭埌鏈嶅姟鍣�
@@ -3197,11 +2907,11 @@
                 if (IsRemote)
                 {
                     await SendRemoteMsg(topic, message, retain);
-                    DebugPrintLog($"杩滅▼鈥斺�斿彂閫佸埌缃戝叧鐨勪富棰�:{topic}_鍙戦�佸埌缃戝叧鐨勬暟鎹�:{System.Text.Encoding.UTF8.GetString(message)}_褰撳墠缃戝叧{CurrentGateWayId}");//{System.DateTime.Now.ToString()}");// DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")
+                    DebugPrintLog($"杩滅▼鈥斺�斿彂閫佸埌缃戝叧鐨勪富棰�:{topic}_鍙戦�佸埌缃戝叧鐨勬暟鎹�:{System.Text.Encoding.UTF8.GetString(message)}");//{System.DateTime.Now.ToString()}");// DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")
                 }
                 else
                 {
-                    DebugPrintLog($"灞�鍩熺綉鈥斺�斿彂閫佸埌缃戝叧鐨勪富棰�:{topic}_鍙戦�佸埌缃戝叧鐨勬暟鎹�:{System.Text.Encoding.UTF8.GetString(message)}_褰撳墠缃戝叧{CurrentGateWayId} 鏄惁鍔犲瘑:{IsEncry}");
+                    DebugPrintLog($"灞�鍩熺綉鈥斺�斿彂閫佸埌缃戝叧鐨勪富棰�:{topic}_鍙戦�佸埌缃戝叧鐨勬暟鎹�:{System.Text.Encoding.UTF8.GetString(message)}_鏄惁鍔犲瘑:{IsEncry}");
 
                     if (IsEncry)
                     {
@@ -3217,14 +2927,14 @@
                         {
                             await localMqttClient.PublishAsync(new MqttApplicationMessage { Topic = topic, Payload = message, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce, Retain = retain });
                         }
-                        catch(Exception e)
+                        catch (Exception e)
                         {
                             DebugPrintLog($"Local涓诲姩鏂紑_{e.Message}");
                             await DisConnectLocalMqttClient(e.Message);
                             await StartLocalMqtt("ReConnect");
                             if (localIsConnected)
                             {
-                                DebugPrintLog($"灞�鍩熺綉鈥斺�斾簩娆″彂閫佸埌缃戝叧鐨勪富棰�:{topic}_鍙戦�佸埌缃戝叧鐨勬暟鎹�:{System.Text.Encoding.UTF8.GetString(message)}_褰撳墠缃戝叧{CurrentGateWayId} 鏄惁鍔犲瘑:{IsEncry}");
+                                DebugPrintLog($"灞�鍩熺綉鈥斺�斾簩娆″彂閫佸埌缃戝叧鐨勪富棰�:{topic}_鍙戦�佸埌缃戝叧鐨勬暟鎹�:{System.Text.Encoding.UTF8.GetString(message)}_鏄惁鍔犲瘑:{IsEncry}");
                                 await localMqttClient.PublishAsync(new MqttApplicationMessage { Topic = topic, Payload = message, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce, Retain = retain });
                             }
                         }
@@ -3269,7 +2979,7 @@
                     return;
                 }
 
-                DebugPrintLog($"灞�鍩熺綉鈥斺�斿彂閫佸埌缃戝叧鐨勪富棰�:{topic}_鍙戦�佸埌缃戝叧鐨勬暟鎹�:{System.Text.Encoding.UTF8.GetString(message)}_褰撳墠缃戝叧{CurrentGateWayId} 鏄惁鍔犲瘑:{IsEncry}");
+                DebugPrintLog($"灞�鍩熺綉鈥斺�斿彂閫佸埌缃戝叧鐨勪富棰�:{topic}_鍙戦�佸埌缃戝叧鐨勬暟鎹�:{System.Text.Encoding.UTF8.GetString(message)}_鏄惁鍔犲瘑:{IsEncry}");
 
                 if (IsEncry)
                 {
@@ -3292,7 +3002,7 @@
                         await StartLocalMqtt("ReConnect");
                         if (localIsConnected)
                         {
-                            DebugPrintLog($"灞�鍩熺綉鈥斺�斾簩娆″彂閫佸埌缃戝叧鐨勪富棰�:{topic}_鍙戦�佸埌缃戝叧鐨勬暟鎹�:{System.Text.Encoding.UTF8.GetString(message)}_褰撳墠缃戝叧{CurrentGateWayId} 鏄惁鍔犲瘑:{IsEncry}");
+                            DebugPrintLog($"灞�鍩熺綉鈥斺�斾簩娆″彂閫佸埌缃戝叧鐨勪富棰�:{topic}_鍙戦�佸埌缃戝叧鐨勬暟鎹�:{System.Text.Encoding.UTF8.GetString(message)}_鏄惁鍔犲瘑:{IsEncry}");
                             await localMqttClient.PublishAsync(new MqttApplicationMessage { Topic = topic, Payload = message, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce, Retain = retain });
                         }
                     }
@@ -3304,13 +3014,9 @@
             }
         }
 
-        [Serializable]
-        public class CloudTimeResponse
-        {
-            public string StateCode;
-            public string Info;
-            public string CloudTimestamp;
-        }
+        #endregion
+
+        #region 鏁版嵁鎺ユ敹澶勭悊
 
         /// <summary>
         /// 鎺ユ敹杩滅▼鏁版嵁澶勭悊
@@ -3423,7 +3129,7 @@
         /// <param name="topic">Topic.</param>
         /// <param name="message">Message.</param>
         /// <param name="e">E.</param>
-        static void ReceiveMessage(string topic, string message, byte []payload)
+        static void ReceiveMessage(string topic, string message, byte[] payload)
         {
             try
             {
@@ -3461,7 +3167,6 @@
                 }
 
                 gwa.GwResDataAction?.Invoke(topic, message);
-                gwa.CurrentGateWayId = gatewayID;
 
                 var jobject = new Newtonsoft.Json.Linq.JObject();
                 if (topic.Split('/')[0] + "/" + topic.Split('/')[1] == topic.Split('/')[0] + "/" + "FileTransfer")
@@ -3505,121 +3210,13 @@
                 }
 
                 #endregion
-                #region 璁惧鏂颁笂鎶�
-                //姝ラ1锛夌綉鍏冲憡鐭ュ鎴风鏈夋柊璁惧鍔犲叆zigbee缃戠粶銆�
-                if (topic == gatewayID + "/" + "Device/DeviceJoinZbNet_Respon")
-                {
-                    var gatewayTemp = new ZbGateway() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
-                    gatewayTemp.deviceDeviceJoinZbNetResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceDeviceJoinZbNetResponData>(jobject["Data"].ToString());
-                    if (gatewayTemp.deviceDeviceJoinZbNetResponData == null)
-                    {
-                        return;
-                    }
-                    //涓婃姤绫诲瀷閫氱煡
-                    if (gwa.ReportAction != null)
-                    {
-                        DebugPrintLog("Device/DeviceJoinZbNet宸茬粡閫氱煡");
-                        gatewayTemp.CurrentGateWayId = gatewayID;//杩欓噷鐨凜urrentGateWayId鏄綋鍓嶆柊new ZbGateway鐨勫��
-                        gwa.ReportAction("Device/DeviceJoinZbNet", gatewayTemp);
-                    }
-                }
-                //姝ラ2锛夌綉鍏冲憡鐭ュ鎴风鑾峰彇鏂拌澶囨墍鏈夌鐐逛俊鎭槸鍚︽垚鍔�
-                if (topic == gatewayID + "/" + "Device/IsGetEpointInfo_Respon")
-                {
-                    var gatewayTemp = new ZbGateway() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
-                    gatewayTemp.deviceIsGetEpointInfoResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceIsGetEpointInfoResponData>(jobject["Data"].ToString());
-                    if (gatewayTemp.deviceIsGetEpointInfoResponData == null)
-                    {
-                        return;
-                    }
-                    //涓婃姤绫诲瀷閫氱煡
-                    if (gwa.ReportAction != null)
-                    {
-                        DebugPrintLog("Device/IsGetEpointInfo宸茬粡閫氱煡");
-                        gatewayTemp.CurrentGateWayId = gatewayID;//杩欓噷鐨凜urrentGateWayId鏄綋鍓嶆柊new ZbGateway鐨勫��
-                        gwa.ReportAction("Device/IsGetEpointInfo", gatewayTemp);
-                    }
-                }
-                //姝ラ3锛夌綉鍏充笂鎶ヨ妭鐐硅澶囨墍鏈夌鐐逛俊鎭�
-                if (topic == gatewayID + "/" + "DeviceInComingRespon")
-                {
-                    //鏂拌澶囦笂鎶ワ紝閲嶆柊鍙戣幏鍙栨墍鏈夌殑璁惧
-                    var tempDevice = new CommonDevice() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
-                    tempDevice.getNewDeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.NewDeviceInfoData>(jobject["Data"].ToString());
-                    if (gwa.ReportAction != null)
-                    {
-                        DebugPrintLog("DeviceInComingRespon宸茬粡閫氱煡");
-                        gwa.ReportAction("DeviceInComingRespon", tempDevice.getNewDeviceInfo);
-                    }
-                    UpdateDeviceInfo(tempDevice, "DeviceInComingRespon");
-                }
-                #endregion
-                #region 璁惧鍦ㄧ嚎鐘舵�佹洿鏂板弽棣�
-                else if (topic == gatewayID + "/" + "OnlineStatusChange_Respon")
-                {
-                    var tempDevice = new CommonDevice() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
-                    tempDevice.IsOnline = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["IsOnline"].ToString());
-
-                    if (gwa.ReportAction != null)
-                    {
-                        DebugPrintLog("OnlineStatusChange宸茬粡閫氱煡");
-                        gwa.ReportAction("OnlineStatusChange", tempDevice);
-                    }
-                    var infoTempDevice = gwa.DeviceList.Find(obj => obj.DeviceID == tempDevice.DeviceID && obj.DeviceAddr == tempDevice.DeviceAddr);
-                    if (infoTempDevice == null)
-                    {
-                        gwa.DeviceList.Add(tempDevice);
-                        UpdateDeviceInfo(tempDevice, "OnlineStatusChange");
-                    }
-                    else
-                    {
-                        if (infoTempDevice.DeviceInfo != null)
-                        {
-                            infoTempDevice.DeviceInfo.IsOnline = infoTempDevice.IsOnline;
-                        }
-                        UpdateDeviceInfo(infoTempDevice, "OnlineStatusChange");
-                    }
-                }
-                #endregion
-                #region 璁惧琚垹闄や笂鎶�
-                else if (topic == gatewayID + "/" + "RemoveDeviceRespon")
-                {
-                    var gatewayTemp = new ZbGateway() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
-                    gatewayTemp.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.RemoveDeviceResponseData>(jobject["Data"].ToString());
 
-                    if (gatewayTemp.removeDeviceResponseData != null)
-                    {
-                        try
-                        {
-                            if (gatewayTemp.removeDeviceResponseData.Result == 0)
-                            {
-                                foreach (var delD in gatewayTemp.removeDeviceResponseData.DeviceList)
-                                {
-                                    var tempDevice = new CommonDevice() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
-                                    tempDevice.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.RemoveDeviceResponseData>(jobject["Data"].ToString());
-                                    if (tempDevice.removeDeviceResponseData == null)
-                                    {
-                                        return;
-                                    }
-                                    else
-                                    {
-                                        UpdateDeviceInfo(tempDevice, "RemoveDeviceRespon");
-                                        if (tempDevice.removeDeviceResponseData.Result == 0)
-                                        {
-                                            var infoTempDevice = gwa.DeviceList.Find((CommonDevice obj) => obj.DeviceID == tempDevice.DeviceID && obj.DeviceAddr == tempDevice.DeviceAddr && obj.DeviceEpoint == tempDevice.DeviceEpoint);
-                                            if (infoTempDevice != null)
-                                            {
-                                                gwa.DeviceList.Remove(infoTempDevice);
-                                            }
-                                        }
-                                    }
-                                }
-                            }
-                        }
-                        catch { }
-                    }
-                }
+                #region 璁惧鍦ㄧ嚎鐘舵�佹洿鏂板弽棣�
+
+                //2020.05.11 鍒犻櫎
+
                 #endregion
+
                 #region 璁惧鐘舵�佷笂鎶�
                 else if (topic == gatewayID + "/" + "DeviceStatusReport" + "/" + addr + "/" + epoint + "/" + cluID + "/" + attrId)
                 {
@@ -3628,7 +3225,7 @@
                     var tempEpoint = jobject.Value<int>("Epoint");
                     var dataId = jobject.Value<int>("Data_ID");
 
-                    var tempDevice = new CommonDevice { DeviceID = deviceID, DeviceAddr = deviceAddr, DeviceEpoint = tempEpoint, DataID = dataId };
+                    var tempDevice = new CommonDevice { DeviceID = deviceID, DeviceAddr = deviceAddr, DeviceEpoint = tempEpoint };
                     tempDevice.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.DeviceStatusReportData>(jobject["Data"].ToString());
                     UpdateDeviceInfo(tempDevice, "DeviceStatusReport");
                 }
@@ -3640,7 +3237,7 @@
                     switch ((DeviceType)(deviceID))
                     {
                         case DeviceType.DoorLock:
-                            var doorLock = new DoorLock() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
+                            var doorLock = new DoorLock() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
                             var OperatingEventNotificationDatad = Newtonsoft.Json.JsonConvert.DeserializeObject<ZigBee.Device.DoorLock.DoorLockOperatingEventNotificationCommand>(jobject["Data"].ToString());
                             if (OperatingEventNotificationDatad != null)
                             {
@@ -3663,7 +3260,7 @@
                     switch ((DeviceType)(deviceID))
                     {
                         case DeviceType.DoorLock:
-                            var doorLock = new DoorLock() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
+                            var doorLock = new DoorLock() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
                             var ProgrammingEventNotificationData = Newtonsoft.Json.JsonConvert.DeserializeObject<ZigBee.Device.DoorLock.DoorLockProgrammingEventNotificationCommand>(jobject["Data"].ToString());
                             if (ProgrammingEventNotificationData != null)
                             {
@@ -3677,35 +3274,18 @@
                             UpdateDeviceInfo(doorLock, "DoorLockProgrammingEventNotificationCommand");
                             break;
                     }
-                }
+                }
                 #endregion
                 #region IAS瀹夐槻淇℃伅涓婃姤
-                else if (topic == gatewayID + "/" + "IASInfoReport")
-                {
-                    var deviceID = jobject.Value<int>("Device_ID");
-                    switch ((DeviceType)(deviceID))
-                    {
-                        case DeviceType.IASZone:
-                            var ias = new IASZone() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
-                            ias.iASInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<IASZone.IASInfoData>(jobject["Data"].ToString());
-                            //涓婃姤绫诲瀷閫氱煡锛屽繀闇�鍏堣皟鐢紝鐒跺悗鎵嶆湁閫氱煡锛屽惁鍒欐槸绌轰笉浼氶�氱煡鐨�
-                            if (gwa.ReportAction != null)
-                            {
-                                DebugPrintLog("IASInfoReport宸茬粡閫氱煡");
-                                //ias.Save();
-                                gwa.ReportAction("IASInfoReport", ias.iASInfo);
-                            }
-                            UpdateDeviceInfo(ias, "IASInfoReport");
-                            break;
-                    }
-                }
+
+                //2020.05.11 鍒犻櫎
+
                 #endregion
                 #region 涓嬭浇杩涘害涓婃姤
                 else if (topic == gatewayID + "/" + "DownloadFile_Progress")
                 {
-                    var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
-                    gatewayTemp.downloadFileProgressResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<DownloadFileProgressResponData>(jobject["Data"].ToString());
-                    if (gatewayTemp.downloadFileProgressResponData == null)
+                    gwa.downloadFileProgressResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.DownloadFileProgressResponData>(jobject["Data"].ToString());
+                    if (gwa.downloadFileProgressResponData == null)
                     {
                         return;
                     }
@@ -3713,15 +3293,13 @@
                     if (gwa.ReportAction != null)
                     {
                         DebugPrintLog("DownloadFileProgress");
-                        gatewayTemp.CurrentGateWayId = gatewayID;//杩欓噷鐨凜urrentGateWayId鏄綋鍓嶆柊new ZbGateway鐨勫��
-                        gwa.ReportAction("DownloadFileProgress", gatewayTemp);
+                        gwa.ReportAction("DownloadFileProgress", gwa);
                     }
                 }
                 else if (topic == gatewayID + "/" + "ZbGwOperation/Upgrade_Respon")
                 {
-                    var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
-                    gatewayTemp.zbGwOperationUpgradeData = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGwOperationUpgradeData>(jobject["Data"].ToString());
-                    if (gatewayTemp.zbGwOperationUpgradeData == null)
+                    gwa.zbGwOperationUpgradeData = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGwOperationUpgradeData>(jobject["Data"].ToString());
+                    if (gwa.zbGwOperationUpgradeData == null)
                     {
                         return;
                     }
@@ -3729,16 +3307,14 @@
                     if (gwa.ReportAction != null)
                     {
                         DebugPrintLog("鍗忚皟鍣ㄥ崌绾х櫨鍒嗘瘮");
-                        gatewayTemp.CurrentGateWayId = gatewayID;//杩欓噷鐨凜urrentGateWayId鏄綋鍓嶆柊new ZbGateway鐨勫��
-                        gwa.ReportAction("CordinatorUpgradePercent", gatewayTemp);
+                        gwa.ReportAction("CordinatorUpgradePercent", gwa);
                     }
                 }
                 else if (topic == gatewayID + "/" + "OTA/Schedule_Respon")
                 {
-                    var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
-                    gatewayTemp.oTAScheduleResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<OTAScheduleResponData>(jobject["Data"].ToString());
+                    gwa.oTAScheduleResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.OTAScheduleResponData>(jobject["Data"].ToString());
 
-                    if (gatewayTemp.oTAScheduleResponData == null)
+                    if (gwa.oTAScheduleResponData == null)
                     {
                         return;
                     }
@@ -3747,16 +3323,14 @@
                     if (gwa.ReportAction != null)
                     {
                         DebugPrintLog("鑺傜偣璁惧鍗囩骇鐧惧垎姣�");
-                        gatewayTemp.CurrentGateWayId = gatewayID;//杩欓噷鐨凜urrentGateWayId鏄綋鍓嶆柊new ZbGateway鐨勫��
-                        gwa.ReportAction("DeviceUpgradePercent", gatewayTemp);
+                        gwa.ReportAction("DeviceUpgradePercent", gwa);
                     }
                 }
                 else if (topic == gatewayID + "/" + "VirtualDrive/Upgrade_Respon")
                 {
-                    var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
-                    gatewayTemp.virtualDriveUpgradeResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<VirtualDriveUpgradeResponData>(jobject["Data"].ToString());
+                    gwa.virtualDriveUpgradeResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<VirtualDriveUpgradeResponData>(jobject["Data"].ToString());
 
-                    if (gatewayTemp.virtualDriveUpgradeResponData == null)
+                    if (gwa.virtualDriveUpgradeResponData == null)
                     {
                         return;
                     }
@@ -3764,18 +3338,16 @@
                     if (gwa.ReportAction != null)
                     {
                         DebugPrintLog("铏氭嫙椹卞姩鍗囩骇鐧惧垎姣�");
-                        gatewayTemp.CurrentGateWayId = gatewayID;//杩欓噷鐨凜urrentGateWayId鏄綋鍓嶆柊new ZbGateway鐨勫��
-                        gwa.ReportAction("VirtualDriveUpgrade", gatewayTemp);
+                        gwa.ReportAction("VirtualDriveUpgrade", gwa);
                     }
                 }
                 #endregion
                 #region 閲嶅惎缃戝叧绯荤粺
                 else if (topic == gatewayID + "/" + "GwReboot_Respon")
                 {
-                    var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID") };
-                    gatewayTemp.gwRebootResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<GwRebootResponData>(jobject["Data"].ToString());
+                    var gwRebootResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<GwRebootResponData>(jobject["Data"].ToString());
 
-                    if (gatewayTemp.gwRebootResponData == null)
+                    if (gwRebootResponData == null)
                     {
                         return;
                     }
@@ -3783,8 +3355,7 @@
                     if (gwa.ReportAction != null)
                     {
                         DebugPrintLog("GwReboot_Respon宸茬粡閫氱煡");
-                        gatewayTemp.CurrentGateWayId = gatewayID;//杩欓噷鐨凜urrentGateWayId鏄綋鍓嶆柊new ZbGateway鐨勫��
-                        gwa.ReportAction("GwReboot_Respon", gatewayTemp);
+                        gwa.ReportAction("GwReboot_Respon", gwRebootResponData);
                     }
                 }
                 #endregion
@@ -3893,22 +3464,6 @@
                     }
                 }
                 #endregion
-                #region 鑺傜偣璁惧榛樿鍙嶉
-                else if (topic == gatewayID + "/" + "DeviceDefaultAck")
-                {
-                    var deviceDefaultAck = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
-                    if (deviceDefaultAck == null)
-                    {
-                        return;
-                    }
-                    //涓婃姤绫诲瀷閫氱煡
-                    if (gwa.ReportAction != null)
-                    {
-                        DebugPrintLog("DeviceDefaultAck");
-                        gwa.ReportAction("DeviceDefaultAck", deviceDefaultAck);
-                    }
-                }
-                #endregion
 
                 #region 璁惧璇锋眰APP鑾峰彇鍗囩骇鏁版嵁
                 else if (topic == gatewayID + "/" + "ZbDataPassthrough")
@@ -3916,7 +3471,7 @@
                     //涓婃姤绫诲瀷閫氱煡
                     if (gwa.ReportAction != null)
                     {
-                        var clientDataPassthrough = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString());
+                        var clientDataPassthrough = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ClientDataPassthroughResponseData>(jobject["Data"].ToString());
                         if (clientDataPassthrough != null)
                         {
                             DebugPrintLog("DeviceRequestAcUpdateData");
@@ -3932,5 +3487,40 @@
             }
 
         }
+
+        #endregion
+
+        #region 淇濆瓨缂撳瓨
+
+        /// <summary>
+        /// 閲嶆柊淇濆瓨璁惧
+        /// </summary>
+        public void ReSave()
+        {
+            Global.WriteFileByBytesByHomeId(FilePath, System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)));
+        }
+        #endregion
+
+        #region 璋冭瘯鎵撳嵃
+
+        /// <summary>
+        /// 璋冭瘯鏃舵墦寮�鎵撳嵃淇℃伅锛宼rue:鎵撳嵃锛宖alse:涓嶆墦鍗�
+        /// </summary>
+        /// <param name="msg">Message.</param>
+        /// <param name="flage">If set to <c>true</c> flage.</param>
+        public static void DebugPrintLog(string msg, bool flage = true)
+        {
+#if DEBUG
+            if (flage == true)
+            {
+                if (msg.Contains("DeviceStatusReport") == false)
+                {
+                    System.Console.WriteLine(msg + "  " + System.DateTime.Now.ToLongTimeString() + " " + System.DateTime.Now.Millisecond);
+                }
+            }
+#endif
+        }
+
+        #endregion
     }
 }

--
Gitblit v1.8.0