From 25429f085093d89d543a0b90e30d0d62d1b7dac9 Mon Sep 17 00:00:00 2001
From: hxb <hxb@hdlchina.com.cn>
Date: 星期二, 30 八月 2022 09:37:38 +0800
Subject: [PATCH] 合并了IOS的代码

---
 ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceAirConditionerLogic.cs |  981 +++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 838 insertions(+), 143 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceAirConditionerLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceAirConditionerLogic.cs
old mode 100755
new mode 100644
index c0de009..98dc9ef
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceAirConditionerLogic.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceAirConditionerLogic.cs
@@ -1,143 +1,838 @@
-锘縰sing System;
-using System.Collections.Generic;
-using System.Text;
-using System.Threading.Tasks;
-using ZigBee.Device;
-
-namespace Shared.Phone.UserCenter
-{
-    /// <summary>
-    /// 绌鸿皟鐨勯�昏緫
-    /// </summary>
-    public class HdlDeviceAirConditionerLogic
-    {
-        #region 鈻� 鍙橀噺澹版槑___________________________
-
-        /// <summary>
-        /// 绌鸿皟鐨勯�昏緫
-        /// </summary>
-        private static HdlDeviceAirConditionerLogic m_Current = null;
-        /// <summary>
-        /// 绌鸿皟鐨勯�昏緫
-        /// </summary>
-        public static HdlDeviceAirConditionerLogic Current
-        {
-            get
-            {
-                if (m_Current == null)
-                {
-                    m_Current = new HdlDeviceAirConditionerLogic();
-                }
-                return m_Current;
-            }
-        }
-
-        #endregion
-
-        #region 鈻� 鎵撳紑绌鸿皟___________________________
-
-        /// <summary>
-        /// 鎵撳紑绌鸿皟
-        /// </summary>
-        /// <param name="device">绌鸿皟瀵硅薄</param>
-        /// <returns></returns>
-        public async Task<bool> OpenAirConditioner(AC device)
-        {
-            var result = await device.Open();
-            //妫�娴嬬綉鍏宠繑鍥炵殑鍏遍�氶敊璇姸鎬佺爜
-            string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
-            if (error != null)
-            {
-                this.ShowTipMsg(error);
-                return false;
-            }
-            if (result == null || result.setWritableValueResponData == null || result.setWritableValueResponData.Status != 0)
-            {
-                //鎵撳紑绌鸿皟澶辫触
-                string msg = Language.StringByID(R.MyInternationalizationString.uOpenAirConditionerFail);
-                //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg
-                msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
-                this.ShowTipMsg(msg);
-                return false;
-            }
-            if (result.setWritableValueResponData.Status != 0)
-            {
-                //鎵撳紑绌鸿皟澶辫触
-                string msg = Language.StringByID(R.MyInternationalizationString.uOpenAirConditionerFail);
-                this.ShowTipMsg(msg);
-                return false;
-            }
-            return true;
-        }
-
-        #endregion
-
-        #region 鈻� 鎵撳紑绌鸿皟___________________________
-
-        /// <summary>
-        /// 鎵撳紑绌鸿皟
-        /// </summary>
-        /// <param name="device">绌鸿皟瀵硅薄</param>
-        /// <returns></returns>
-        public async Task<bool> CloseAirConditioner(AC device)
-        {
-            var result = await device.Close();
-            //妫�娴嬬綉鍏宠繑鍥炵殑鍏遍�氶敊璇姸鎬佺爜
-            string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
-            if (error != null)
-            {
-                this.ShowTipMsg(error);
-                return false;
-            }
-            if (result == null || result.setWritableValueResponData == null || result.setWritableValueResponData.Status != 0)
-            {
-                //鍏抽棴绌鸿皟澶辫触
-                string msg = Language.StringByID(R.MyInternationalizationString.uCloseAirConditionerFail);
-                //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg
-                msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
-                this.ShowTipMsg(msg);
-                return false;
-            }
-            if (result.setWritableValueResponData.Status != 0)
-            {
-                //鍏抽棴绌鸿皟澶辫触
-                string msg = Language.StringByID(R.MyInternationalizationString.uCloseAirConditionerFail);
-                this.ShowTipMsg(msg);
-                return false;
-            }
-            return true;
-        }
-
-        #endregion
-
-        #region 鈻� 涓�鑸柟娉昣__________________________
-
-        /// <summary>
-        /// 鏄剧ず閿欒淇℃伅绐楀彛
-        /// </summary>
-        /// <param name="msg"></param>
-        private void ShowErrorMsg(string msg)
-        {
-            Application.RunOnMainThread(() =>
-            {
-                var contr = new ShowMsgControl(ShowMsgType.Error, msg);
-                contr.Show();
-            });
-        }
-
-        /// <summary>
-        /// 鏄剧ずTip淇℃伅绐楀彛
-        /// </summary>
-        /// <param name="msg"></param>
-        private void ShowTipMsg(string msg)
-        {
-            Application.RunOnMainThread(() =>
-            {
-                var contr = new ShowMsgControl(ShowMsgType.Tip, msg);
-                contr.Show();
-            });
-        }
-
-        #endregion
-    }
-}
+锘縰sing Newtonsoft.Json.Linq;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading.Tasks;
+using ZigBee.Device;
+
+namespace Shared.Phone.UserCenter
+{
+    /// <summary>
+    /// 绌鸿皟鐨勯�昏緫
+    /// </summary>
+    public class HdlDeviceAirConditionerLogic
+    {
+        #region 鈻� 鍙橀噺澹版槑___________________________
+
+        /// <summary>
+        /// 绌鸿皟鐨勯�昏緫
+        /// </summary>
+        private static HdlDeviceAirConditionerLogic m_Current = null;
+        /// <summary>
+        /// 绌鸿皟鐨勯�昏緫
+        /// </summary>
+        public static HdlDeviceAirConditionerLogic Current
+        {
+            get
+            {
+                if (m_Current == null)
+                {
+                    m_Current = new HdlDeviceAirConditionerLogic();
+                }
+                return m_Current;
+            }
+        }
+
+        #endregion
+
+        #region 鈻� 鎵撳紑绌鸿皟___________________________
+
+        /// <summary>
+        /// 鎵撳紑绌鸿皟
+        /// </summary>
+        /// <param name="device">绌鸿皟瀵硅薄</param>
+        /// <returns></returns>
+        public async Task<bool> OpenAirConditioner(AC device)
+        {
+            var result = await device.Open();
+            //妫�娴嬬綉鍏宠繑鍥炵殑鍏遍�氶敊璇姸鎬佺爜
+            string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
+            if (error != null)
+            {
+                this.ShowTipMsg(error);
+                return false;
+            }
+            if (result == null || result.setWritableValueResponData == null || result.setWritableValueResponData.Status != 0)
+            {
+                //鎵撳紑绌鸿皟澶辫触
+                string msg = Language.StringByID(R.MyInternationalizationString.uOpenAirConditionerFail);
+                //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg
+                msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
+                this.ShowTipMsg(msg);
+                return false;
+            }
+            if (result.setWritableValueResponData.Status != 0)
+            {
+                //鎵撳紑绌鸿皟澶辫触
+                string msg = Language.StringByID(R.MyInternationalizationString.uOpenAirConditionerFail);
+                this.ShowTipMsg(msg);
+                return false;
+            }
+            return true;
+        }
+
+        #endregion
+
+        #region 鈻� 鍏抽棴绌鸿皟___________________________
+
+        /// <summary>
+        /// 鍏抽棴绌鸿皟
+        /// </summary>
+        /// <param name="device">绌鸿皟瀵硅薄</param>
+        /// <returns></returns>
+        public async Task<bool> CloseAirConditioner(AC device)
+        {
+            var result = await device.Close();
+            //妫�娴嬬綉鍏宠繑鍥炵殑鍏遍�氶敊璇姸鎬佺爜
+            string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
+            if (error != null)
+            {
+                this.ShowTipMsg(error);
+                return false;
+            }
+            if (result == null || result.setWritableValueResponData == null || result.setWritableValueResponData.Status != 0)
+            {
+                //鍏抽棴绌鸿皟澶辫触
+                string msg = Language.StringByID(R.MyInternationalizationString.uCloseAirConditionerFail);
+                //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg
+                msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
+                this.ShowTipMsg(msg);
+                return false;
+            }
+            if (result.setWritableValueResponData.Status != 0)
+            {
+                //鍏抽棴绌鸿皟澶辫触
+                string msg = Language.StringByID(R.MyInternationalizationString.uCloseAirConditionerFail);
+                this.ShowTipMsg(msg);
+                return false;
+            }
+            return true;
+        }
+
+        #endregion
+
+        #region 鈻� 璁剧疆绌鸿皟鐨勮嚜瀹氫箟妯″紡_______________
+
+        /// <summary>
+        /// 璁剧疆绌鸿皟鐨勮嚜瀹氫箟妯″紡 鈽嗏槅鈽嗏槅鈽�
+        /// </summary>
+        /// <param name="device">绌鸿皟瀵硅薄</param>
+        /// <param name="data">浠庝簩杩涘埗杞崲鐨勫崄杩涘埗鍊�</param>
+        /// <returns></returns>
+        public bool SetAcModeSupport(AC device, int data)
+        {
+            //濡傛灉鏄櫄鎷熶綇瀹�
+            if (Common.Config.Instance.Home.IsVirtually == true)
+            {
+                //鐩存帴娣诲姞缂撳瓨
+                TemplateData.TemplateDeviceDataLogic.Current.SetAcModeSupport(device, data, null);
+                return true;
+            }
+            //鍙戦�佹暟鎹�
+            string sendData = HdlDeviceAttributeLogic.Current.GetWriteDeviceAttributeText(device.DeviceAddr, device.DeviceEpoint, 513, 4099, 25, data);
+            var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "SetWritableValue", sendData, "SetWritableValue_Respon");
+            if (result.ErrorMsg != null)
+            {
+                this.ShowTipMsg(result.ErrorMsg);
+                return false;
+            }
+            if (result.ErrorMsgDiv == 0)
+            {
+                //璁剧疆绌鸿皟妯″紡澶辫触
+                string msg = Language.StringByID(R.MyInternationalizationString.uSetAcModeFail);
+                //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg
+                msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
+                this.ShowTipMsg(msg); ;
+                return false;
+            }
+
+            var responeData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.SetWritableValueResponData>(result.ReceiptData);
+            if (responeData.Status != 0)
+            {
+                //璁剧疆绌鸿皟妯″紡澶辫触
+                string msg = Language.StringByID(R.MyInternationalizationString.uSetAcModeFail);
+                this.ShowTipMsg(msg);
+                return false;
+            }
+
+            //娣诲姞缂撳瓨
+            TemplateData.TemplateDeviceDataLogic.Current.SetAcModeSupport(device, data, result.JsonData[0]);
+
+            return true;
+        }
+
+        #endregion
+
+        #region 鈻� 璁剧疆鍚敤绌鸿皟鐨勬憜椋庡姛鑳絖____________
+
+        /// <summary>
+        /// 璁剧疆鍚敤绌鸿皟鐨勬憜椋庡姛鑳� 鈽嗏槅鈽嗏槅鈽�
+        /// </summary>
+        /// <param name="device">绌鸿皟瀵硅薄</param>
+        /// <param name="data">浠庝簩杩涘埗杞崲鐨勫崄杩涘埗鍊�</param>
+        /// <returns></returns>
+        public bool SetUseAcSwingFunctionStatu(AC device, int data)
+        {
+            //濡傛灉鏄櫄鎷熶綇瀹�
+            if (Common.Config.Instance.Home.IsVirtually == true)
+            {
+                //鐩存帴娣诲姞缂撳瓨
+                TemplateData.TemplateDeviceDataLogic.Current.SetAcSwingModeSupport(device, data, null);
+                return true;
+            }
+            //鍙戦�佹暟鎹�
+            string sendData = HdlDeviceAttributeLogic.Current.GetWriteDeviceAttributeText(device.DeviceAddr, device.DeviceEpoint, 514, 4097, 25, data);
+            var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "SetWritableValue", sendData, "SetWritableValue_Respon");
+            if (result.ErrorMsg != null)
+            {
+                this.ShowTipMsg(result.ErrorMsg);
+                return false;
+            }
+            if (result.ErrorMsgDiv == 0)
+            {
+                //璁剧疆绌鸿皟鎽嗛澶辫触
+                string msg = Language.StringByID(R.MyInternationalizationString.uSetAirConditionerSwingFunctionFail);
+                //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg
+                msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
+                this.ShowTipMsg(msg);
+                return false;
+            }
+
+            var responeData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.SetWritableValueResponData>(result.ReceiptData);
+            if (responeData.Status != 0)
+            {
+                //璁剧疆绌鸿皟鎽嗛澶辫触
+                string msg = Language.StringByID(R.MyInternationalizationString.uSetAirConditionerSwingFunctionFail);
+                this.ShowTipMsg(msg);
+                return false;
+            }
+
+            //娣诲姞缂撳瓨
+            TemplateData.TemplateDeviceDataLogic.Current.SetAcSwingModeSupport(device, data, result.JsonData[0]);
+
+            return true;
+        }
+
+        #endregion
+
+        #region 鈻� 涓�鑸柟娉昣__________________________
+
+        /// <summary>
+        /// 鏄剧ず閿欒淇℃伅绐楀彛
+        /// </summary>
+        /// <param name="msg"></param>
+        private void ShowErrorMsg(string msg)
+        {
+            Application.RunOnMainThread(() =>
+            {
+                var contr = new ShowMsgControl(ShowMsgType.Error, msg);
+                contr.Show();
+            });
+        }
+
+        /// <summary>
+        /// 鏄剧ずTip淇℃伅绐楀彛
+        /// </summary>
+        /// <param name="msg"></param>
+        private void ShowTipMsg(string msg)
+        {
+            Application.RunOnMainThread(() =>
+            {
+                var contr = new ShowMsgControl(ShowMsgType.Tip, msg);
+                contr.Show();
+            });
+        }
+
+        #endregion
+
+
+        #region 鈻� 鍗囩骇绌鸿皟绗笁鏂规ā鍧楃殑鎺ュ彛___________
+
+        #region 璇诲彇IRACC妯″潡鍥轰欢鐗堟湰锛圓PP -> Zigbee MCU锛�
+        ///<summary >
+        ///璇诲彇IRACC妯″潡鍥轰欢鐗堟湰
+        /// </summary>
+        public async System.Threading.Tasks.Task<ReadACFirewareVersionResponAllData> ReadACFirewareVersionAsync(CommonDevice device)
+        {
+            ReadACFirewareVersionResponAllData result = null;
+            var Gateway = device.Gateway;
+            if (Gateway == null)
+            {
+                result = new ReadACFirewareVersionResponAllData { errorMessageBase = "褰撳墠娌℃湁缃戝叧" };
+                return result;
+            }
+            return await System.Threading.Tasks.Task.Run(async () =>
+            {
+                Action<string, string> action = (topic, message) =>
+                {
+                    var gatewayID = topic.Split('/')[0];
+                    var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
+
+                    if (topic == gatewayID + "/" + "ZbDataPassthrough")
+                    {
+                        var clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ClientDataPassthroughResponseData>(jobject["Data"].ToString());
+
+                        if (clientDataPassthroughResponseData == null)
+                        {
+                            result = new ReadACFirewareVersionResponAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
+                        }
+                        else
+                        {
+                            if (clientDataPassthroughResponseData?.PassData != null)
+                            {
+                                var data = clientDataPassthroughResponseData.PassData;
+                                var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString();
+                                if (command == "0259")
+                                {
+                                    var tempD = new ReadACFirewareVersionResponData();
+                                    tempD.Status = Convert.ToInt32(data[10].ToString() + data[11].ToString(), 16);
+                                    if (data.Length == 82)
+                                    {
+                                        var firewareString = data.Substring(12);
+                                        var aa = firewareString.Length;
+                                        firewareVersion = firewareString;
+                                        var bytes = new byte[firewareString.Length / 2];
+                                        for (int i = 0; i < bytes.Length; i++)
+                                        {
+                                            bytes[i] = Convert.ToByte(firewareString.Substring(i * 2, 2), 16);
+                                        }
+
+                                        var firewareVersionTemp = System.Text.Encoding.ASCII.GetString(bytes);
+                                        tempD.FirewareVersion = firewareVersionTemp.Replace('\0', ' ').Trim();
+                                    }
+                                    result = new ReadACFirewareVersionResponAllData { readACFirewareVersionResponData = tempD };
+                                    System.Console.WriteLine($"UI鏀跺埌閫氱煡鍚庣殑涓婚_command:0258_{topic}");
+                                }
+                            }
+                        }
+                    }
+                };
+
+                Gateway.Actions += action;
+                System.Console.WriteLine("ClientDataPassthrough_Actions 鍚姩" + System.DateTime.Now.ToString());
+
+                try
+                {
+                    var passData = ReadACFirewareVersionData("01");
+                    var jObject = new JObject { { "DeviceAddr", device.DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
+                    var data = new JObject { { "PassData", passData } };
+                    jObject.Add("Data", data);
+                    Gateway.Send(("ClientDataPassthrough"), jObject.ToString());
+                }
+                catch { }
+
+                var dateTime = DateTime.Now;
+                while ((DateTime.Now - dateTime).TotalMilliseconds < 3000)
+                {
+                    await System.Threading.Tasks.Task.Delay(10);
+                    if (result != null)
+                    {
+                        break;
+                    }
+                }
+                if ((DateTime.Now - dateTime).TotalMilliseconds > 3000)
+                {
+                    result = new ReadACFirewareVersionResponAllData { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" };
+                }
+                Gateway.Actions -= action;
+                System.Console.WriteLine("ClientDataPassthrough_Actions 閫�鍑�" + System.DateTime.Now.ToString());
+
+                return result;
+            });
+        }
+
+        /// <summary>
+        /// 璇诲彇IRACC妯″潡鍥轰欢鐗堟湰
+        /// </summary>
+        string ReadACFirewareVersionData(string reserve)
+        {
+            string data = "";
+            string dataLength = "05";
+            string dataComand1 = "58";
+            string dataComand2 = "02";
+            string dataSerialNum = "01";
+            string addDataLength = "01";
+            string reserveData = reserve;
+
+            try
+            {
+                data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
+                    reserveData;
+            }
+            catch { };
+
+            return data;
+        }
+
+        /// <summary>
+        /// IRACC妯″潡鍥轰欢鐗堟湰,缃戝叧鍙嶉淇℃伅
+        /// </summary>
+        public ReadACFirewareVersionResponAllData readACFirewareVersionResponAllData;
+        /// <summary>
+        /// IRACC妯″潡鍥轰欢鐗堟湰,缃戝叧鍙嶉淇℃伅
+        /// </summary>
+        [System.Serializable]
+        public class ReadACFirewareVersionResponAllData
+        {
+            /// <summary>
+            /// 閿欒淇℃伅
+            /// </summary>
+            public string errorMessageBase;
+            /// <summary>
+            /// 缃戝叧淇℃伅閿欒鍙嶉
+            /// <para>褰撶綉鍏虫帴鏀跺埌瀹㈡埛绔俊鎭悗锛屽嚭鐜颁互涓嬪紓甯告儏鍐靛皢鍙嶉閿欒銆�</para>
+            /// </summary>
+            public CommonDevice.ErrorResponData errorResponData;
+            /// <summary>
+            /// IRACC妯″潡鍥轰欢鐗堟湰淇℃伅
+            /// </summary>
+            public ReadACFirewareVersionResponData readACFirewareVersionResponData;
+        }
+
+        /// <summary>
+        /// IRACC妯″潡鍥轰欢鐗堟湰鐨勬暟鎹�
+        /// </summary>
+        [System.Serializable]
+        public class ReadACFirewareVersionResponData
+        {
+            /// <summary>
+            /// 鐘舵��
+            ///<para>0--鎴愬姛</para>
+            ///<para>1--澶辫触</para>
+            ///<para>ff--鏃犳晥</para>
+            /// </summary>
+            public int Status;
+            /// <summary>
+            /// 鍥轰欢鐗堟湰
+            /// </summary>
+            public string FirewareVersion;
+        }
+        #endregion
+
+        #region 鍗囩骇IRACC妯″潡閫氱煡锛圓PP -> Zigbee MCU锛�
+        ///<summary >
+        ///鍗囩骇IRACC妯″潡閫氱煡
+        /// <para>firewareVer:鍥轰欢鐗堟湰</para>
+        /// <para>firewareSize:鍥轰欢澶у皬</para>
+        /// </summary>
+        public async System.Threading.Tasks.Task<ResponseAllData> UpggradeACNotificationAsync(CommonDevice device, string firewareVer, long firewareSize)
+        {
+            ResponseAllData result = null;
+            var Gateway = device.Gateway;
+            if (Gateway == null)
+            {
+                result = new ResponseAllData { errorMessageBase = "褰撳墠娌℃湁缃戝叧" };
+                return result;
+            }
+            return await System.Threading.Tasks.Task.Run(async () =>
+            {
+                Action<string, string> action = (topic, message) =>
+                {
+                    var gatewayID = topic.Split('/')[0];
+                    var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
+
+                    if (topic == gatewayID + "/" + "ZbDataPassthrough")
+                    {
+                        var clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ClientDataPassthroughResponseData>(jobject["Data"].ToString());
+
+                        if (clientDataPassthroughResponseData == null)
+                        {
+                            result = new ResponseAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
+                        }
+                        else
+                        {
+                            if (clientDataPassthroughResponseData?.PassData != null)
+                            {
+                                var data = clientDataPassthroughResponseData.PassData;
+                                var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString();
+                                if (command == "025b")
+                                {
+                                    var tempD = new ResponseData();
+                                    if (data.Length == 12)
+                                    {
+                                        tempD.status = Convert.ToInt32(data[10].ToString() + data[11].ToString(), 16);
+                                    }
+                                    result = new ResponseAllData { responseData = tempD };
+                                    System.Console.WriteLine($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
+                                }
+                            }
+                        }
+                    }
+                };
+
+                Gateway.Actions += action;
+                System.Console.WriteLine("ClientDataPassthrough_Actions 鍚姩" + System.DateTime.Now.ToString());
+
+                try
+                {
+                    var passData = UpggradeACNotificationData(firewareVer, firewareSize);
+                    var jObject = new JObject { { "DeviceAddr", device.DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
+                    var data = new JObject { { "PassData", passData } };
+                    jObject.Add("Data", data);
+                    Gateway.Send(("ClientDataPassthrough"), jObject.ToString());
+                }
+                catch { }
+
+                var dateTime = DateTime.Now;
+                while ((DateTime.Now - dateTime).TotalMilliseconds < 3000)
+                {
+                    await System.Threading.Tasks.Task.Delay(10);
+                    if (result != null)
+                    {
+                        break;
+                    }
+                }
+                if ((DateTime.Now - dateTime).TotalMilliseconds > 3000)
+                {
+                    result = new ResponseAllData { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" };
+                }
+                Gateway.Actions -= action;
+                System.Console.WriteLine("ClientDataPassthrough_Actions 閫�鍑�" + System.DateTime.Now.ToString());
+
+                return result;
+            });
+        }
+
+        private string firewareVersion = string.Empty;
+        /// <summary>
+        /// 鍗囩骇IRACC妯″潡閫氱煡杩斿洖
+        /// </summary>
+        string UpggradeACNotificationData(string firewareVer, long firewareSize)
+        {
+            string data = "";
+            string dataLength = "2C";
+            string dataComand1 = "5A";
+            string dataComand2 = "02";
+            string dataSerialNum = "01";
+            string addDataLength = "28";
+            string deviceUpgradeMethod = "01";
+            string firewareVersionData = "";
+            string firewareSizeData = "";
+
+            try
+            {
+                //鍥轰欢鐗堟湰
+                var firewareVerBytes = System.Text.Encoding.ASCII.GetBytes(firewareVer);
+                for (int i = 0; i < firewareVerBytes.Length; i++)
+                {
+                    var fw = Convert.ToString(firewareVerBytes[i], 16);
+                    if (fw.Length == 1)
+                    {
+                        fw = "0" + fw;
+                    }
+                    firewareVersionData += fw;
+                }
+
+                var aa = firewareVersionData.Length;
+                firewareVersionData = firewareVersionData.PadRight(70, '0');
+
+                //鍥轰欢灏哄
+                var tempFwSize = Convert.ToString(firewareSize, 16);
+                tempFwSize = tempFwSize.PadLeft(8, '0');
+                for (int i = 6; i >= 0; i = i - 2)
+                {
+                    firewareSizeData += tempFwSize.Substring(i, 2);
+                }
+
+                data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
+                     deviceUpgradeMethod + firewareVersionData + firewareSizeData;
+
+            }
+            catch { };
+
+            return data;
+        }
+
+        /// <summary>
+        ///鍗囩骇IRACC妯″潡閫氱煡鍥炲
+        /// </summary>
+        public ResponseAllData keyColorDataResponseAllData;
+        [System.Serializable]
+        public class ResponseAllData
+        {
+            /// <summary>
+            /// 閿欒淇℃伅
+            /// </summary>
+            public string errorMessageBase;
+            /// <summary>
+            /// 缃戝叧淇℃伅閿欒鍙嶉
+            /// <para>褰撶綉鍏虫帴鏀跺埌瀹㈡埛绔俊鎭悗锛屽嚭鐜颁互涓嬪紓甯告儏鍐靛皢鍙嶉閿欒銆�</para>
+            /// </summary>
+            public CommonDevice.ErrorResponData errorResponData;
+            /// <summary>
+            /// 鍗囩骇IRACC妯″潡閫氱煡淇℃伅
+            /// </summary>
+            public ResponseData responseData;
+        }
+
+        /// <summary>
+        /// 鍗囩骇IRACC妯″潡閫氱煡鍥炲锛圸igbee MCU -> APP锛�
+        /// </summary>
+        [System.Serializable]
+        public class ResponseData
+        {
+            /// <summary>
+            /// 鐘舵�佸��
+            /// <para>0--鐗堟湰鍙蜂笉涓�鑷达紙鍙互鍗囩骇</para>
+            /// <para>1--鐗堟湰鍙蜂竴鑷达紙涓嶇敤鍗囩骇</para>
+            /// <para>2--棰勭暀锛堟殏鏃朵笉鐢ㄥ埌</para>
+            /// <para>ff--鏃犳晥锛堟殏鏃朵笉鐢ㄥ埌锛�</para>
+            /// </summary>
+            public int status = -1;
+        }
+        #endregion
+
+        #region 璁惧璇锋眰APP鑾峰彇鍗囩骇鏁版嵁 锛圸igbee MCU -> APP,涓诲姩涓婃姤锛�
+        /// <summary>
+        ///璁惧璇锋眰APP鑾峰彇鍗囩骇鏁版嵁锛圸igbee MCU -> APP,涓诲姩涓婃姤锛�
+        /// </summary>
+        [System.Serializable]
+        public class DeviceRequestUpgradeResponseData
+        {
+            /// <summary>
+            /// 鏁版嵁鍋忕Щ閲忥紝姣忎釜鍒嗗寘鍋忕Щ閲�+锛�1-43锛�
+            /// </summary>
+            public string offset = string.Empty;
+            /// <summary>
+            /// 鏁版嵁闀垮害len
+            /// </summary>
+            public int dataLength = -1;
+        }
+        #endregion
+
+        #region 鍙戝崌绾ф暟鎹埌璁惧锛圓PP -> Zigbee MCU锛�
+        ///<summary >
+        ///璇诲彇IRACC妯″潡鍥轰欢鐗堟湰
+        /// <para>reserve:0-ff</para>
+        /// </summary>
+        public void UpgradeAsync(CommonDevice device, SendUpgradeData upgradeData)
+        {
+            var Gateway = device.Gateway;
+            if (Gateway == null)
+            {
+                return;
+            }
+            Action<string, string> action = (topic, message) => { };
+            Gateway.Actions += action;
+            System.Console.WriteLine("ClientDataPassthrough_Actions 鍚姩" + System.DateTime.Now.ToString());
+
+            try
+            {
+                string passData = "";
+                if (upgradeData != null)
+                {
+                    passData = SendUpgrade(upgradeData);
+                }
+
+                var jObject = new JObject { { "DeviceAddr", device.DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
+                var data = new JObject { { "PassData", passData } };
+                jObject.Add("Data", data);
+                Gateway.Send(("ClientDataPassthrough"), jObject.ToString());
+            }
+            catch { }
+
+            Gateway.Actions -= action;
+            System.Console.WriteLine("ClientDataPassthrough_Actions 閫�鍑�" + System.DateTime.Now.ToString());
+        }
+
+        /// <summary>
+        /// 鍙戝崌绾ф暟鎹埌璁惧
+        /// </summary>
+        string SendUpgrade(SendUpgradeData upgradeData)
+        {
+            string data = "";
+            string dataLength = "";
+            string dataComand1 = "5D";
+            string dataComand2 = "02";
+            string dataSerialNum = "01";
+            string addDataLength = "";
+
+            string status = "";
+            string offset = "";
+            string upgradeDataLength = "";
+            string dataString = "";
+
+            try
+            {
+                var len = 4 + 1 + 4 + 1 + upgradeData.dataLength;
+                dataLength = Convert.ToString(len, 16);
+                if (dataLength.Length == 1)
+                {
+                    dataLength = "0" + dataLength;
+                }
+
+                addDataLength = Convert.ToString(6 + upgradeData.dataLength, 16);
+                if (addDataLength.Length == 1)
+                {
+                    addDataLength = "0" + addDataLength;
+                }
+
+                if (upgradeData.status == 0)
+                {
+                    status = "00";
+                }
+                else if (upgradeData.status == 1)
+                {
+                    status = "01";
+                }
+                else
+                {
+                    status = "ff";
+                }
+
+
+                offset = upgradeData.offset;
+
+                var dl = Convert.ToString(upgradeData.dataLength, 16);
+                if (dl.Length == 1)
+                {
+                    upgradeDataLength = "0" + dl;
+                }
+                else
+                {
+                    upgradeDataLength = dl;
+                }
+
+                for (int i = 0; i < upgradeData.databytes.Length; i++)
+                {
+                    var dataB = Convert.ToString(upgradeData.databytes[i], 16);
+                    if (dataB.Length == 1)
+                    {
+                        dataB = "0" + dataB;
+                    }
+                    dataString += dataB;
+                }
+
+                data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
+                status + offset + upgradeDataLength + dataString;
+            }
+            catch { };
+
+            return data;
+        }
+
+        /// <summary>
+        /// 鍙戦�佸崌绾ф暟鎹埌璁惧锛圓PP -> Zigbee MCU锛�
+        /// </summary>
+        [System.Serializable]
+        public class SendUpgradeData
+        {
+            /// <summary>
+            /// 0--鎴愬姛
+            ///<para>1--澶辫触</para>
+            ///<para>ff--鏃犳晥</para>
+            /// </summary>
+            public int status = 0;
+            /// <summary>
+            /// 鏁版嵁鍋忕Щ閲忥紝姣忎釜鍒嗗寘鍋忕Щ閲�+锛�1-43锛�
+            /// </summary>
+            public string offset;
+            /// <summary>
+            /// 鏁版嵁闀垮害len
+            /// </summary>
+            public int dataLength = -1;
+
+            /// <summary>
+            /// 鍒嗗寘鏁版嵁
+            /// </summary>
+            public byte[] databytes;
+        }
+        #endregion
+
+        #region 鍒嗗寘缁撴潫锛圸igbee MCU -> APP,涓诲姩涓婃姤锛�
+        /// <summary>
+        /// 璁惧璇锋眰APP鑾峰彇鍒嗗寘缁撴潫鍛戒护锛圸igbee MCU -> APP锛�
+        /// </summary>
+        [System.Serializable]
+        public class DeviceRequestFinishResponseData
+        {
+            /// <summary>
+            /// 0-ff
+            /// </summary>
+            public int reserve = -1;
+        }
+        #endregion
+
+        #region 鍒嗗寘缁撴潫锛圓PP -> Zigbee MCU锛�
+        ///<summary >
+        ///璇诲彇IRACC妯″潡鍥轰欢鐗堟湰
+        /// <para>status:0--鎴愬姛;1--澶辫触;ff--鏃犳晥 .</para>
+        /// </summary>
+        public void SendFinishAsync(CommonDevice device, int status)
+        {
+            var Gateway = device.Gateway;
+            if (Gateway == null)
+            {
+                return;
+            }
+            Action<string, string> action = (topic, message) => { };
+            Gateway.Actions += action;
+            System.Console.WriteLine("ClientDataPassthrough_Actions 鍚姩" + System.DateTime.Now.ToString());
+
+            try
+            {
+                var passData = SendFinishDataString(status);
+                var jObject = new JObject { { "DeviceAddr", device.DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
+                var data = new JObject { { "PassData", passData } };
+                jObject.Add("Data", data);
+                Gateway.Send(("ClientDataPassthrough"), jObject.ToString());
+            }
+            catch { }
+
+            Gateway.Actions -= action;
+            System.Console.WriteLine("ClientDataPassthrough_Actions 閫�鍑�" + System.DateTime.Now.ToString());
+        }
+
+        /// <summary>
+        /// 鍙戝崌绾ф暟鎹埌璁惧
+        /// </summary>
+        string SendFinishDataString(int status)
+        {
+            string data = "";
+            string dataLength = "05";
+            string dataComand1 = "5F";
+            string dataComand2 = "02";
+            string dataSerialNum = "01";
+            string addDataLength = "01";
+            string statusString = "";
+            try
+            {
+                if (status == 0)
+                {
+                    statusString = "00";
+                }
+                else if (status == 1)
+                {
+                    statusString = "01";
+                }
+                else
+                {
+                    statusString = "ff";
+                }
+                data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
+                statusString;
+            }
+            catch { };
+
+            return data;
+        }
+
+        /// <summary>
+        /// 鍒嗗寘缁撴潫杩斿洖锛圓PP -> Zigbee MCU
+        /// </summary>
+        //[System.Serializable]
+        public class SendFinishData
+        {
+            /// <summary>
+            /// 鐘舵�侊細鎴愬姛/澶辫触
+            ///<para>0--鎴愬姛<<para>
+            ///<para>1--澶辫触<<para>
+            ///<para>ff--鏃犳晥<<para>
+            /// </summary>
+            public int status = -1;
+        }
+
+        #endregion
+        #endregion
+    }
+}

--
Gitblit v1.8.0