From 19d0e070e128daf855beaf72e00f55334be9f87b Mon Sep 17 00:00:00 2001
From: wei <kaede@kaededeMacBook-Air.local>
Date: 星期六, 28 八月 2021 13:47:25 +0800
Subject: [PATCH] 1

---
 HDL_ON/DAL/DriverLayer/Control.cs |  162 ++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 144 insertions(+), 18 deletions(-)

diff --git a/HDL_ON/DAL/DriverLayer/Control.cs b/HDL_ON/DAL/DriverLayer/Control.cs
index 913c52a..85ebba3 100644
--- a/HDL_ON/DAL/DriverLayer/Control.cs
+++ b/HDL_ON/DAL/DriverLayer/Control.cs
@@ -26,7 +26,6 @@
     public class Control
     {
        
-
         static Control _control;
         public static Control Ins
         {
@@ -323,6 +322,15 @@
                 }
             }
         }
+        /// <summary>
+        /// 瀹夐槻鎺у埗
+        /// </summary>
+        public void ControlArm()
+        {
+            DAL.Server.HttpServerRequest httpServer = new DAL.Server.HttpServerRequest();
+            //var pack = httpServer.GetSecurityAlarmLogList
+        }
+
 
         /// <summary>
         /// 鍙戦�佸懡浠�
@@ -434,12 +442,32 @@
                 //杩滅▼閫氳
                 else
                 {
+                    //Bug淇锛氫竴绔彛杩滅▼鎺у埗璋冨厜璁惧鐨勮皟鍏夊睘鎬ф椂锛屾棤娉曟帶鍒跺埌0锛屽弽澶嶆í璺炽��
+                    //鍥犱负On + 杩滅▼鎺у埗鍙戦�佺粰浜戠浣跨敤鐨勬槸link鍗忚鏁版嵁锛屾潹娑涗腑杞粰楂樿儨澶勭悊鏃跺�欓�昏緫涓婃湁鍐茬獊锛屽鑷存棤娉曞崟鐙帶鍒朵寒搴﹀�硷紝闇�瑕佸悓鏃跺彂閫佸紑鍏冲�间笌浜害鍊笺��
+                    if (DB_ResidenceData.Instance.GatewayType == 0)
+                    {
+                        if (commandDictionary.Count == 1)
+                        {
+                            if (commandDictionary.ContainsKey(FunctionAttributeKey.Brightness))
+                            {
+                                commandDictionary.Add(FunctionAttributeKey.OnOff, commandDictionary[FunctionAttributeKey.Brightness] == "0" ? "off" : "on");
+                            }
+                        }
+                        if(function.spk == SPK.LightCCT)
+                        {
+                            if (!commandDictionary.ContainsKey(FunctionAttributeKey.CCT))
+                            {
+                                commandDictionary.Add(FunctionAttributeKey.CCT, function.GetAttrState(FunctionAttributeKey.CCT));
+                            }
+                        }
+                    }
                     DAL.Server.HttpServerRequest httpServer = new DAL.Server.HttpServerRequest();
                     //ALink鎺у埗銆丅us鎺у埗浣跨敤鍚屼竴涓帴鍙f帶鍒讹紝鐢变簯绔礋璐hВ鏋�
                     var apiControlData = function.GetApiControlData(commandDictionary);
                     var actionObjs = new List<ApiAlinkControlActionObj>();
                     actionObjs.Add(apiControlData);
                     var pack = httpServer.ControlDevice(actionObjs);
+                    MainPage.Log($"杩滅▼鎺у埗鍙嶉:{pack.message}");
                 }
 
             }
@@ -467,28 +495,41 @@
             }
 
             var count = 0;
-            var logString = open ? "鎵撳紑\r\n" : "鍏抽棴\r\n";
             List<ApiAlinkControlActionObj> actionObjs = new List<ApiAlinkControlActionObj>();
             Dictionary<string, string> d = new Dictionary<string, string>();
             d.Add(FunctionAttributeKey.OnOff, open ? "on" : "off");
             var pm = new DAL.Server.HttpServerRequest();
-            foreach (var temp in functions)
+            //涓�绔彛鍏ㄥ紑鍏ㄥ叧闇�瑕佸欢鏃跺彂閫�
+            if (DB_ResidenceData.Instance.GatewayType == 0)
             {
-                logString += temp.spk + ":" + temp.sid + "\r\n";
-                var apiControlData = temp.GetApiControlData(d);
-                actionObjs.Add(apiControlData);
-                count++;
-                if (count > 9)
+                new System.Threading.Thread(() =>
                 {
-                    var result = pm.ControlDevice(actionObjs);
-                    actionObjs = new List<ApiAlinkControlActionObj>();
-                    count = 0;
-                    MainPage.Log(logString);
-                    logString = "";
-                }
+                    foreach (var temp in functions)
+                    {
+                        var apiControlData = temp.GetApiControlData(d);
+                        var result = pm.ControlDevice(new List<ApiAlinkControlActionObj>() { apiControlData });
+                        System.Threading.Thread.Sleep(100);
+                    }
+                })
+                { IsBackground = true }.Start();
             }
-            var pack = pm.ControlDevice(actionObjs);
-            MainPage.Log(logString);
+            else
+            {
+                foreach (var temp in functions)
+                {
+                    var apiControlData = temp.GetApiControlData(d);
+                    actionObjs.Add(apiControlData);
+                    count++;
+                    if (count > 9)
+                    {
+                        var result = pm.ControlDevice(actionObjs);
+                        actionObjs = new List<ApiAlinkControlActionObj>();
+                        count = 0;
+                        System.Threading.Thread.Sleep(100);
+                    }
+                }
+                var pack = pm.ControlDevice(actionObjs);
+            }
         }
 
         public void SendApiReadCommand(List<string> functionIds)
@@ -578,6 +619,41 @@
                     var pm = new DAL.Server.HttpServerRequest();
                     var pack = pm.RefreshDeviceStatus(new List<string>() { function.deviceId });
                 }
+            }
+        }
+
+        /// <summary>
+        /// 瀹夐槻鎺у埗
+        /// </summary>
+        public void ControlSecurity(SecurityAlarm securityAlarm,string state)
+        {
+            if (!Ins.GatewayOnline_Local)//缃戝叧鏈湴涓嶅湪绾�
+            {
+                var pm = new DAL.Server.HttpServerRequest();
+                var result = pm.SetSecurityStatus(new List<SecurityState>() { new SecurityState() {
+                 gatewayId = DB_ResidenceData.Instance.HomeGateway.gatewayId,
+                  sid = securityAlarm.sid, status = state, userSecurityId = securityAlarm.userSecurityId
+                } });
+                MainPage.Log($"瀹夐槻鎺у埗缁撴灉:{result.Code}");
+            }
+            else
+            {
+                Dictionary<string, string> keys = new Dictionary<string, string>();
+                keys.Add("sid", securityAlarm.sid);
+                keys.Add("status", state);
+                keys.Add("alarm", securityAlarm.alarm.ToString());
+                var aLinkData = new AlinkReadFunctionStatusObj()
+                {
+                    id = Ins.msg_id.ToString(),
+                    objects = new List<Dictionary<string, string>>()
+                        {
+                            keys
+                        },
+                    time_stamp = Utlis.GetTimestamp()
+                };
+                var aLinkJson = Newtonsoft.Json.JsonConvert.SerializeObject(aLinkData);
+                var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ControlSeurity, aLinkJson);
+                new Control_Udp().SendLocalHdlLinkData(sendBytes, aLinkData.id);
             }
         }
 
@@ -673,8 +749,9 @@
                 //}
                 receiveObj.BodyDataString = res[1];
 
-                if (receiveObj.Topic == CommunicationTopic.SearchLoaclGatewayReply)
+                if (receiveObj.Topic == CommunicationTopic.SearchLoaclGatewayReply || receiveObj.Topic == CommunicationTopic.GatewayBroadcast)
                 {
+                   
                     var bodyJObj = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePack>(res[1]);
                     if (bodyJObj == null)
                     {
@@ -704,6 +781,37 @@
                 {
                     //TODO 鏆傛椂涓嶄紶姝g‘鐨勬暟鎹笂鍘伙紝濡傛灉鍚庨潰瑕佷紭鍖栧墠闈㈣繖浜涗唬鐮�
                     UpdataFunctionStatus(receiveObj.BodyDataString, null);
+                }
+                else if (receiveObj.Topic == CommunicationTopic.ct.ControlSeurity +"_reply"
+                    || receiveObj.Topic == CommunicationTopic.ct.ReadSecurityStatus + "_reply"
+                    || receiveObj.Topic == CommunicationTopic.ct.SecurityStatusUp)
+                {
+                    try
+                    {
+                        MainPage.Log($"灞�鍩熺綉瀹夐槻淇℃伅: {receiveObj.Topic}  : 鍐呭: {res[1]}");
+                        var tt = "";
+                        lock (tt) {
+                            var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<SecurityStatusObj>(receiveObj.BodyDataString);
+                            if (temp != null)
+                            {
+                                Control_Udp.ReceiveRepeatManager(temp.id, null);
+                                foreach (var updataSecurity in temp.objects)
+                                {
+                                    var updataLocalSecurity = FunctionList.List.securities.Find((obj) => obj.sid == updataSecurity.sid);
+                                    if (updataLocalSecurity != null)
+                                    {
+                                        updataLocalSecurity.status = updataSecurity.status;
+                                        updataLocalSecurity.alarm = updataSecurity.alarm;
+                                        ArmCenterPage.LoadEvent_RefreshSecurityStatus(updataLocalSecurity);
+                                    }
+                                }
+                                HomePage.LoadEvent_RefreshSecurityStatus();
+                            }
+                        }
+                    }
+                    catch (Exception ex){
+                        MainPage.Log($"瀹夐槻灞�鍩熺綉寮傚父锛歿ex.Message}");
+                    }
                 }
                 else
                 {
@@ -759,7 +867,7 @@
                                 return;
                             }
                         }
-                        MainPage.Log($"A鍗忚鏇存柊鐘舵��:{revString}");
+                        //MainPage.Log($"A鍗忚鏇存柊鐘舵��:{revString}");
                         foreach (var attr in updateTemp.status)
                         {
                             localFunction.time_stamp = temp.time_stamp;
@@ -770,6 +878,9 @@
                         Function localObj = null;
                         switch (localFunction.spk)
                         {
+                            case SPK.AirSwitch:
+                                AirSwitchPage.UpdataState(localFunction);
+                                break;
                             case SPK.ElectricEnergy:
                                 EnergyMainPage.UpdataStatus(localFunction);
                                 break;
@@ -853,6 +964,7 @@
                                 }
                                 break;
                             case SPK.FloorHeatStandard:
+                                localFunction.lastState = "";
                                 switch (localFunction.GetAttrState(FunctionAttributeKey.Mode))
                                 {
                                     case "normal":
@@ -889,6 +1001,19 @@
                                 }
                                 EnvironmentalPage.LoadEvent_UpdataStatus(localFunction);
                                 break;
+                            case SPK.SensorEnvironment:
+                            case SPK.SensorEnvironment2:
+                            case SPK.SensorEnvironment3:
+                                if (localFunction.GetAttributes().Contains(FunctionAttributeKey.Temperature))
+                                {
+                                    HomePage.LoadEvent_RefreshEnvirIndoorTemp();
+                                }
+                                if (localFunction.GetAttributes().Contains(FunctionAttributeKey.Humidity))
+                                {
+                                    HomePage.LoadEvent_RefreshEnvirIndoorHumi();
+                                }
+                                EnvironmentalPage.LoadEvent_UpdataStatus(localFunction);
+                                break;
                             case SPK.ElectricSocket:
                                 SocketPage.UpdataState(localFunction);
                                 break;
@@ -905,6 +1030,7 @@
                             case SPK.ClothesHanger:
                             case SPK.AcIr:
                             case SPK.SenesorMegahealth:
+                            case SPK.AirFreshStandard:
                                 //璁惧鐘舵�佹帹閫�
                                 //鐘舵�佹洿鏂�
                                 Stan.HdlDeviceStatuPushLogic.Current.UpdateDeviceStatu(updateTemp.sid, updateTemp.status);

--
Gitblit v1.8.0