From 3f6685c77beeb12baf840733fb890860f4c26e7c Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期四, 25 七月 2024 17:25:59 +0800
Subject: [PATCH] 2024年07月25日17:24:45

---
 HDL_ON/UI/UI2/FuntionControlView/HisenseTV /Send.cs |  162 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 156 insertions(+), 6 deletions(-)

diff --git a/HDL_ON/UI/UI2/FuntionControlView/HisenseTV /Send.cs b/HDL_ON/UI/UI2/FuntionControlView/HisenseTV /Send.cs
index 0e5cd5a..f4873e7 100644
--- a/HDL_ON/UI/UI2/FuntionControlView/HisenseTV /Send.cs
+++ b/HDL_ON/UI/UI2/FuntionControlView/HisenseTV /Send.cs
@@ -1,5 +1,8 @@
 锘縰sing System;
 using System.Collections.Generic;
+using System.Net;
+using System.Net.Sockets;
+using System.Text;
 using HDL_ON.DAL.Server;
 using HDL_ON.Entity;
 using HDL_ON.UI.UI2.FuntionControlView.VideoDoorLock;
@@ -28,6 +31,96 @@
             }
 
         }
+        /// <summary>
+        /// 鎵撳紑娴蜂俊鐢佃
+        /// </summary>
+        /// <param name="deviceMac">鐢佃mac</param>
+        public void Open(string deviceMac)
+        {
+            CommonMethod.Current.SunThread(() =>
+            {
+                // 鍒涘缓UdpClient瀹炰緥
+                UdpClient udpClient = new UdpClient();
+                try
+                {
+                    // 璁剧疆鍙戦�佸拰鎺ユ敹鏁版嵁鐨処P鍜岀鍙�
+                    IPEndPoint iPEndPoint = new IPEndPoint(IPAddress.Parse("255.255.255.255"), 9);
+                    // 鍙戦�佹暟鎹�
+                    //byte[] data = System.Text.Encoding.ASCII.GetBytes("Hello, UDP Server!");
+                    byte[] data = StrToToHexByte(deviceMac);
+                    for (int i = 0; i < 16; i++)
+                    {
+                        udpClient.Send(data, data.Length, iPEndPoint);
+                        //Console.WriteLine("鏁版嵁宸插彂閫�");
+                    }
+                    //// 鎺ユ敹鏁版嵁
+                    //IPEndPoint remoteEP = new IPEndPoint(IPAddress.Any, 0);
+                    //byte[] receivedData = udpClient.Receive(ref remoteEP);
+                    //string receivedMessage = System.Text.Encoding.ASCII.GetString(receivedData);
+                    //Console.WriteLine("鎺ユ敹鍒扮殑鏁版嵁锛�" + receivedMessage);
+                }
+                catch (Exception e)
+                {
+                    Console.WriteLine("鍙戠敓閿欒锛�" + e.Message);
+                }
+                finally
+                {
+                    // 鍏抽棴UdpClient杩炴帴
+                    udpClient.Close();
+                }
+            }, TipType.none);
+
+        }
+
+        /// <summary>
+        /// 鍒锋柊璁惧鐘舵��
+        /// </summary>
+        /// <param name="tipType">鏄惁闇�瑕佹彁绀�,榛樿鎻愮ず</param>
+        /// <returns></returns>
+        public bool RefreshDeviceStatus(List<string> functionIds, TipType tipType = TipType.flicker)
+        {
+            try
+            {
+                Dictionary<string, object> d = new Dictionary<string, object>();
+                d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id);
+                d.Add("deviceIds", functionIds);
+                var responsePackNew = RequestServerhomeId(d, NewAPI.Api_Post_RefreshDeviceStatus, "鍒锋柊璁惧鐘舵��");
+                if (!this.DataChecking(responsePackNew, tipType))
+                {
+                    return false;
+                }
+                return true;
+            }
+            catch
+            {
+                return false;
+            }
+        }
+
+        /// <summary>
+        /// 鑾峰彇璁惧璇︽儏
+        /// </summary>
+        /// <param name="tipType">鏄惁闇�瑕佹彁绀�,榛樿鎻愮ず</param>
+        /// <returns></returns>
+        public Function GetDeviceInfo(string functionId, TipType tipType = TipType.flicker)
+        {
+            Dictionary<string, object> d = new Dictionary<string, object>();
+            d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id);
+            d.Add("deviceIds", new List<string>() { functionId });
+
+            var responsePackNew = RequestServerhomeId(d, NewAPI.Api_Post_GetDevcieInfoList, "鑾峰彇璁惧璇︽儏");
+            if (!this.DataChecking(responsePackNew, tipType))
+            {
+                return null;
+            }
+            var functionList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Function>>(responsePackNew.Data.ToString());
+            if (functionList != null && functionList.Count > 0)
+            {
+                return functionList[0];
+            }
+            return null;
+
+        }
 
         /// <summary>
         ///鍒犻櫎璁惧
@@ -35,18 +128,75 @@
         /// <param name="deviceId">璁惧id</param>
         /// <param name="action">鎴愬姛杩斿洖true</param>
         /// <param name="tipType">鏄惁闇�瑕佹彁绀�,榛樿鎻愮ず</param>
-        public bool DelDevice(string deviceId,Action<bool>action, TipType tipType = TipType.flicker)
+        public void DelDevice(string deviceId, Action<bool> action, TipType tipType = TipType.flicker)
         {
             Dictionary<string, object> d = new Dictionary<string, object>();
             d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id);
-            d.Add("deviceId", deviceId);//璁惧id
-            var responsePackNew = UI.Music.SendMethod.Current.RequestServerhomeId(d, NewAPI.Api_Post_Aks_KeypadExecute, "鍒犻櫎娴蜂俊鐢佃");
+            d.Add("deviceIds", new List<string> { deviceId });//璁惧id
+            var responsePackNew = UI.Music.SendMethod.Current.RequestServerhomeId(d, NewAPI.Api_Post_UnbindDeviceToHome, "鍒犻櫎娴蜂俊鐢佃");
             if (!this.DataChecking(responsePackNew, tipType))
             {
-                return false;
+                //action?.Invoke(false);
+                return;
             }
-            return true;
+            action?.Invoke(true);
         }
+
+        /// <summary>
+        /// 鍙戦�佹帶鍒跺懡浠�
+        /// </summary>
+        /// <param name="device">褰撳墠璁惧</param>
+        /// <param name="dic">鍙戦�佹帶鍒舵暟鎹�</param>
+        public void SendControlCommand(Function device, Dictionary<string, string> dic,Action<bool> action) 
+        {
+            new System.Threading.Thread(() =>
+            {
+                var result = DriverLayer.Control.Ins.SendWriteCommand(device, dic, false, 0);
+                action?.Invoke(result);
+
+            })
+            { IsBackground = true }.Start();
+        }
+
+        /// <summary>
+        /// 灏�16杩涘埗鐨勫瓧绗︿覆杞负byte[]
+        /// </summary>
+        /// <param name="hexDeviceMacString"></param>
+        /// <returns></returns>
+        private byte[] StrToToHexByte(string hexDeviceMacString)
+        {
+            if (string.IsNullOrEmpty(hexDeviceMacString))
+            {
+                return new byte[] { };
+            }
+            hexDeviceMacString = hexDeviceMacString.Replace(" ", "").Replace("_","");
+            if ((hexDeviceMacString.Length % 2) != 0) {
+                return new byte[] { };
+            }
+            byte[] returnBytes = new byte[hexDeviceMacString.Length / 2];
+            for (int i = 0; i < returnBytes.Length; i++)
+                returnBytes[i] = Convert.ToByte(hexDeviceMacString.Substring(i * 2, 2), 16);
+            return returnBytes;
+        } 
+
+        /// <summary>
+        /// 浜岃繘鍒舵暟缁勮浆鍗佸叚杩涘埗瀛楃涓�
+        /// </summary>
+        /// <param name="btyes"></param>
+        /// <returns></returns>
+        private string Byte2hex(byte[] btyes) 
+        {
+            StringBuilder sb = new StringBuilder(btyes.Length * 2);
+            for (int i = 0; i < btyes.Length; i++)
+            {
+                int hight = ((btyes[i] >> 4) & 0x0f);
+                int low = btyes[i] & 0x0f;
+                sb.Append(hight > 9 ? (char)((hight - 10) + 'a') : (char)(hight + '0'));
+                sb.Append(low > 9 ? (char)((low - 10) + 'a') : (char)(low + '0'));
+            }
+            return sb.ToString();
+        }
+
 
 
         /// <summary>
@@ -80,7 +230,7 @@
             {
                 if (TipType.flicker == tipType)
                 {
-                    if (responsePackNew == null)
+                    if (responsePackNew == null || responsePackNew.Code == "-1")
                     {
                         responsePackNew = new ResponsePackNew { message = "娌″洖澶�,璇风‘璁ょ綉缁滄槸鍚︽甯�.", Code = "-1", };
                     }

--
Gitblit v1.8.0