From f75a1ba69f5922cab8d2ab43f4447b74bd9b9ea9 Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期四, 26 五月 2022 09:52:34 +0800
Subject: [PATCH] 备份

---
 HDL_ON/DAL/DriverLayer/Control.cs |  246 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 232 insertions(+), 14 deletions(-)

diff --git a/HDL_ON/DAL/DriverLayer/Control.cs b/HDL_ON/DAL/DriverLayer/Control.cs
index 4a6ad64..5672c7a 100644
--- a/HDL_ON/DAL/DriverLayer/Control.cs
+++ b/HDL_ON/DAL/DriverLayer/Control.cs
@@ -1,6 +1,7 @@
 锘縰sing System;
 using System.Collections.Generic;
 using System.Text;
+using HDL_ON.DAL.Server;
 using HDL_ON.Entity;
 using HDL_ON.UI;
 using Shared;
@@ -25,7 +26,7 @@
 
     public class Control
     {
-       
+
         static Control _control;
         public static Control Ins
         {
@@ -93,7 +94,7 @@
             }
             set
             {
-                if (_GatewayOnline_Local != value)
+                //if (_GatewayOnline_Local != value)
                 {
                     _GatewayOnline_Local = value;
                     if (value)
@@ -128,7 +129,7 @@
             }
             set
             {
-                if (_GatewayOnline_Cloud != value)
+                //if (_GatewayOnline_Cloud != value)
                 {
                     _GatewayOnline_Cloud = value;
                     if(GatewayOnline_Local)
@@ -359,10 +360,11 @@
         /// <param name="function"></param>
         /// <param name="useRemote">鏄惁鐩存帴浣跨敤杩滅▼鍙戦��</param>
         /// <returns></returns>
-        public void SendWriteCommand(Function function, Dictionary<string, string> commandDictionary, bool useRemote = false,int resend = 3)
+        public bool SendWriteCommand(Function function, Dictionary<string, string> commandDictionary, bool useRemote = false,int resend = 3)
         {
             function.controlCounter++;
             function.refreshTime = DateTime.Now;
+
 
             //濡傛灉鏄帶鍒惰皟鍏夌殑寮�鏃讹紝浜害鍊间笉鑳戒负0
             if (commandDictionary.Count > 2)
@@ -403,7 +405,7 @@
                 upDataObj.objects.Add(asd);
                 revString = Newtonsoft.Json.JsonConvert.SerializeObject(upDataObj);
                 UpdataFunctionStatus(revString, null, true);
-                return;
+                return true;
             }
 
 
@@ -458,6 +460,7 @@
                         var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ControlFunctionTopic, functionControlDataJson);
                         new Control_Udp().SendLocalHdlLinkData(sendBytes, functionControlDataObj.id,resend);
                         MainPage.Log($"鏈湴閫氳 鍙戦�丠DL-Link鏁版嵁:{functionControlDataJson}");
+                        //Control.Ins.MsgInfoList.Add($"鏈湴閫氳 鍙戦�丠DL-Link鏁版嵁:{functionControlDataJson}"+"\r\n");
                     }
                 }
                 //杩滅▼閫氳
@@ -492,6 +495,8 @@
                 }
 
             }
+
+            return true;
         }
         /// <summary>
         /// 鍏ㄥ紑鍏ㄥ叧鍔熻兘
@@ -503,11 +508,18 @@
             {
                 new System.Threading.Thread(() =>
                 {
-                    foreach (var temp in functions)
+                    foreach (var function in functions)
                     {
                         Dictionary<string, string> d1 = new Dictionary<string, string>();
                         d1.Add(FunctionAttributeKey.OnOff, open ? "on" : "off");
-                        SendWriteCommand(temp, d1);
+                         if (function.spk == SPK.PanelSocket)
+                        {
+                            if (function.attributes.Find((obj) => obj.key == "on_off_usb") != null)
+                            {
+                                d1.Add("on_off_usb", function.trait_on_off.curValue.ToString());
+                            }
+                        }
+                        SendWriteCommand(function, d1);
                         System.Threading.Thread.Sleep(100);
                     }
                 })
@@ -644,6 +656,79 @@
         }
 
         /// <summary>
+        /// 鍙戦�佽鍙栧懡浠�
+        /// 鑷姩鍒ゆ柇鏄惁涓篈鍗忚璁惧
+        /// </summary>
+        public void SendReadCommand(List<Function> functions, bool forceRemote = false)
+        {
+            List<string> sids = new List<string>();
+            foreach (Function function in functions)
+            {
+                sids.Add(function.sid);
+                function.refreshTime = DateTime.Now;
+            }
+            if (forceRemote)
+            {
+
+                var pm = new DAL.Server.HttpServerRequest();
+                var pack = pm.RefreshDeviceStatus(sids);
+            }
+            else
+            {
+                if (Ins.GatewayOnline_Local)
+                {
+
+                    if (DB_ResidenceData.Instance.GatewayType == 0)
+                    {
+                        try
+                        {
+                            var busClient = new Control_Udp();
+                            foreach (Function function in functions)
+                            {
+                                busClient.ReadBusData(function);
+                            }
+                            
+                        }
+                        catch (Exception ex)
+                        {
+                            MainPage.Log($"鍙戦�佹暟鎹紓甯�: {ex.Message}");
+                        }
+                    }
+                    else
+                    {
+                        var objects = new List<Dictionary<string, string>>();
+
+
+                        foreach (Function function in functions)
+                        {
+                            var readKey = new Dictionary<string, string>();
+                            readKey.Add("sid", function.sid);
+                            objects.Add(readKey);
+                        }
+
+
+                        var readDataObj = new AlinkReadFunctionStatusObj()
+                        {
+                            id = Ins.msg_id.ToString(),
+                            objects = objects,
+                            time_stamp = Utlis.GetTimestamp()
+                        };
+                        var functionControlDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(readDataObj);
+                        var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ReadStatus, functionControlDataJson);
+                        MainPage.Log($"鏈湴閫氳 鍙戦�丠DL-Link鏁版嵁:{functionControlDataJson}");
+                        new Control_Udp().SendLocalHdlLinkData(sendBytes, readDataObj.id);
+                    }
+                }
+                else
+                {
+                    var pm = new DAL.Server.HttpServerRequest();
+                    var pack = pm.RefreshDeviceStatus(sids);
+                }
+            }
+        }
+
+
+        /// <summary>
         /// 瀹夐槻鎺у埗
         /// </summary>
         public void ControlSecurity(SecurityAlarm securityAlarm,string state)
@@ -655,7 +740,7 @@
                  gatewayId = DB_ResidenceData.Instance.HomeGateway.gatewayId,
                   sid = securityAlarm.sid, status = state, userSecurityId = securityAlarm.userSecurityId
                 } });
-                MainPage.Log($"瀹夐槻鎺у埗缁撴灉:{result.Code}");
+                MainPage.Log($"瀹夐槻鎺у埗缁撴灉:code锛歿result.Code}锛沵sg锛歿result.message}");
             }
             else
             {
@@ -761,8 +846,8 @@
             topicAndLengthBytes.CopyTo(sendDataBytes, 0);
             bodyBytes.CopyTo(sendDataBytes, topicAndLengthBytes.Length);
 
-            //var sendDataString = Encoding.UTF8.GetString(sendDataBytes);
-            //MainPage.Log($"杞崲HDL-Link鏁版嵁\r\n{sendDataString}\r\n");
+            var sendDataString = Encoding.UTF8.GetString(sendDataBytes);
+            MainPage.Log($"杞崲HDL-Link鏁版嵁\r\n{sendDataString}\r\n");
             //***************************************************************
 
             return sendDataBytes;
@@ -835,7 +920,7 @@
                             var revString = Encoding.UTF8.GetString(receiveBytes);
                             receiveObj.BodyDataString = revString;
                             MainPage.Log($"灞�鍩熺綉淇℃伅: 瑙e瘑鍚庯細" + receiveObj.BodyDataString);
-                            //if(receiveObj.Topic.EndsWith("/thing/property/up"))
+                            //if (receiveObj.Topic.EndsWith("/thing/property/up"))
                             //{
                             //    MsgInfoList.Add(revString + "\r\n");
                             //}
@@ -858,7 +943,7 @@
 
                 if (receiveObj.Topic == CommunicationTopic.SearchLoaclGatewayReply || receiveObj.Topic == CommunicationTopic.GatewayBroadcast)
                 {
-                   
+
                     var bodyJObj = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePack>(res[1]);
                     if (bodyJObj == null)
                     {
@@ -940,6 +1025,7 @@
         /// <summary>
         /// 鏇存柊璁惧鐘舵��
         /// A鍗忚鏁版嵁
+        /// Tag Link鐘舵�佸鐞�
         /// </summary>
         /// <param name="updateBytes"></param>
         public void UpdataFunctionStatus(string revString, byte[] usefulBytes,bool isCloudData = false)
@@ -974,19 +1060,34 @@
                         {
                             continue;
                         }
+                        MainPage.Log(localFunction.name);
+
                         if (Ins.GatewayOnline_Local && isCloudData)//鏈湴閾炬帴锛岄櫎浜嗘秱楦﹁澶囨暟鎹箣澶栫殑浜戠鏁版嵁涓嶅鐞�
                         {
-                            if (!SPK.Get3tySpk(SPK.BrandType.All3tyBrand).Contains(localFunction.spk))
+                            if (!SPK.Get3tySpk(SPK.BrandType.All3tyBrand).Contains(localFunction.spk) && !SPK.MusicSpkList().Contains( localFunction.spk))
                             {
                                 //MainPage.Log($"A鍗忚鏇存柊鐘舵��:鏈湴閾炬帴锛岄櫎浜嗘秱楦﹁澶囨暟鎹箣澶栫殑浜戠鏁版嵁涓嶅鐞�........");
+
                                 return;
                             }
                         }
+
+                        //if (SPK.MusicSpkList().Contains(localFunction.spk))
+                        //{
+                        //    if (updateTemp.status.Count < 3)
+                        //    {
+                        //        ///鏄煶涔愬姛鑳界殑
+                        //        ///涓婃姤灞炴�у皯3鏉′笉鍋氬鐞�
+                        //        return;
+                        //    }
+                        //}
                         //MainPage.Log($"A鍗忚鏇存柊鐘舵��:{revString}");
                         foreach (var attr in updateTemp.status)
                         {
                             localFunction.time_stamp = temp.time_stamp;
                             localFunction.SetAttrState(attr.key, attr.value);
+                            //Console.WriteLine("闊充箰鎾斁鍣ㄦ坊鍔犵紦瀛樻暟鎹�=======" + revString);
+
                         }
 
                         //鏇存柊鐣岄潰鐘舵��
@@ -1039,6 +1140,10 @@
                                 RollingShutterPage.UpdataState(localFunction);
                                 break;
                             case SPK.CurtainShades:
+                                break;
+                            case SPK.HvacCac:
+                                Stan.HdlDeviceStatuPushLogic.Current.UpdateDeviceStatu(updateTemp.sid, updateTemp.status);
+                               
                                 break;
                             case SPK.AcStandard:
                             case SPK.HvacAC:
@@ -1142,6 +1247,7 @@
                             case SPK.ElectricSocket:
                             case SPK.PanelSocket:
                                 SocketPage.UpdataState(localFunction);
+                                SocketPage_InstantaneousValue.UpdataView(localFunction);
                                 break;
                             case SPK.ElectricTV:
                                 break;
@@ -1163,9 +1269,16 @@
                             case SPK.AirFreshStandard:
                             case SPK.HvacAirFresh:
                             case SPK.SensorGas:
+                            case SPK.SensorHelp:
                                 //璁惧鐘舵�佹帹閫�
                                 //鐘舵�佹洿鏂�
                                 Stan.HdlDeviceStatuPushLogic.Current.UpdateDeviceStatu(updateTemp.sid, updateTemp.status);
+                                break;
+                            case SPK.AvMusic:
+                            case SPK.MusicStandard:
+                                //UI.Music.MusicMain.mMusicMain.RefreshView(updateTemp);
+                                //Console.WriteLine("闊充箰鎾斁鍣ㄦ樉绀虹姸鎬�======="+ revString);
+                                //wjc
                                 break;
                         }
 
@@ -1183,5 +1296,110 @@
             }
         }
 
+
+
+        #region 闂ㄩ攣
+
+        /// <summary>
+        /// //涓�閿紙杩滅▼锛夊紑閿�
+        /// </summary>
+        public void OneKeyUnlocking(Function doorlock,string extStr)
+        {
+            if (Ins.GatewayOnline_Local)
+            {
+                Dictionary<string, string> dic = new Dictionary<string, string>();
+                var functionControlDataObj = doorlock.GetGatewayAlinkDoorlockData(UserInfo.Current.ID,extStr);
+                var functionControlDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(functionControlDataObj);
+                var sendBytes = Ins.ConvertSendBodyData($"/base/{Control.Ins.GatewayId}/thing/service/doorRemoteOpen/down", functionControlDataJson);
+                new Control_Udp().SendLocalHdlLinkData(sendBytes, functionControlDataObj.id, 0);
+            }
+            else
+            {
+                ConfirmUnlocking(doorlock.deviceId, extStr);
+            }
+        }
+        /// <summary>
+        /// 纭寮�閿�
+        /// </summary>
+        /// <param name="functionId"></param>
+        /// <param name="pwd"></param>
+        public void ConfirmUnlocking(string functionId,string pwd)
+        {
+            Loading loading = new Loading();
+            MainPage.BaseView.AddChidren(loading);
+            loading.BackgroundColor = 0x88000000;
+            loading.LodingBackgroundColor = UI.CSS.CSS_Color.BackgroundColor;
+            loading.Start(Language.StringByID(StringId.PleaseWait));
+            new System.Threading.Thread(() =>
+            {
+                try
+                {
+                    Dictionary<string, object> d = new Dictionary<string, object>();
+                    d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id);
+                    d.Add("deviceId", functionId);
+                    d.Add("pwd", pwd);
+                    var requestJson = HttpUtil.GetSignRequestJson(d);
+                    var pack = HttpUtil.RequestHttpsPost("/home-wisdom/app/device/door/pwdConfirm", requestJson);
+                    if (pack.Code == StateCode.SUCCESS)
+                    {
+                        Newtonsoft.Json.Linq.JObject pairs = Newtonsoft.Json.Linq.JObject.Parse(pack.Data.ToString());
+                        var scrip = pairs.GetValue("scrip");
+
+                        d = new Dictionary<string, object>();
+                        d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id);
+                        d.Add("deviceId", functionId);
+                        d.Add("scrip", scrip);
+                        requestJson = HttpUtil.GetSignRequestJson(d);
+                        pack = HttpUtil.RequestHttpsPost("/home-wisdom/app/device/door/remoteOpen", requestJson);
+                        //if(pack.Code == StateCode.SUCCESS)
+                        //{
+                        //    return true;
+                        //}
+                        //else
+                        //{
+                        //    return false;
+                        //}
+                        if (pack.Code != StateCode.SUCCESS) {
+                            Application.RunOnMainThread(() => {
+                                new PublicAssmebly().TipMsg(Language.StringByID(StringId.Tip), pack.message);
+                                UserInfo.Current.doorPasswordString = "";//
+                                UserInfo.Current.LastTimeOpenDoor = DateTime.MinValue;
+                            });
+                        }
+                    }
+                    if (pack.Code != StateCode.SUCCESS)
+                    {
+                        Application.RunOnMainThread(() => {
+                            if(string.IsNullOrEmpty(pack.message))
+                            {
+                                new PublicAssmebly().TipMsg(Language.StringByID(StringId.Tip),
+                                    Language.StringByID(StringId.OperationFailed));
+                            }
+                            else
+                            {
+                                new PublicAssmebly().TipMsg(Language.StringByID(StringId.Tip), pack.message);
+                            }
+                        });
+                    }
+                }
+                catch (Exception ex)
+                {
+
+                }
+                finally
+                {
+                    Application.RunOnMainThread(() =>
+                    {
+                        loading.Hide();
+                        loading.RemoveFromParent();
+                    });
+                }
+            })
+            { IsBackground = true }.Start();
+        }
+        //瀵嗙爜鍐荤粨
+        //瀵嗙爜楠岃瘉
+
+        #endregion
     }
-}
\ No newline at end of file
+}

--
Gitblit v1.8.0