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/DAL/DriverLayer/Control.cs |  110 +++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 86 insertions(+), 24 deletions(-)

diff --git a/HDL_ON/DAL/DriverLayer/Control.cs b/HDL_ON/DAL/DriverLayer/Control.cs
index e60e1ae..10b0a31 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.Mqtt;
 using HDL_ON.DAL.Server;
 using HDL_ON.Entity;
 using HDL_ON.UI;
@@ -173,7 +174,16 @@
                             MainPage.Log($"缃戝叧浜戠鍦ㄧ嚎锛屽埛鏂拌澶囩姸鎬�");
                             new System.Threading.Thread(() =>
                             {
-                                System.Threading.Thread.Sleep(1000);
+                                int count = 20;
+                                while (true)
+                                {
+                                    System.Threading.Thread.Sleep(500);
+                                    if (MqttClient.isSubscribeSuccess || count<1)
+                                    {
+                                        break;
+                                    }
+                                    count--;
+                                }
                                 FunctionList.List.ReadAllFunctionStatus();
                             })
                             { IsBackground = true, Priority = System.Threading.ThreadPriority.AboveNormal }.Start();
@@ -251,6 +261,7 @@
         /// </summary>
         public void OpenTcpClent()
         {
+            return;
             if (myTcpClient == null)
             {
                 myTcpClient = new Control_TcpClient(reportIp);
@@ -325,6 +336,7 @@
         /// </summary>
         public void LoginGateway()
         {
+            return;//tcp鎺у埗瀛樺湪闂锛屼絾鏄厛涓嶇敤tcp鎺у埗浜嗭紝瑕佺粡杩囨祴璇曞厛  2023-07-29 10:14:32
             if (loginGatewayThread == null)
             {
                 loginGatewayThread = new System.Threading.Thread(() =>
@@ -524,7 +536,7 @@
                         var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ControlFunctionTopic, functionControlDataJson);
                         new Control_Udp().SendLocalHdlLinkData(sendBytes, functionControlDataObj.id, resend);
                         MainPage.Log($"鏈湴閫氳 鍙戦�丠DL-Link鏁版嵁:{functionControlDataJson}");
-                            Ins.myTcpClient.SendMessage(sendBytes);
+                            //Ins.myTcpClient.SendMessage(sendBytes);
                     }
                 }
                 //杩滅▼閫氳
@@ -614,6 +626,10 @@
             {
                 foreach (var temp in functions)
                 {
+                    if((temp.trait_on_off.state.ToString() ==  "on" && open)|| temp.trait_on_off.state.ToString() == "off"&& !open)
+                    {
+                        continue;
+                    }
                     var apiControlData = temp.GetApiControlData(d);
                     actionObjs.Add(apiControlData);
                     count++;
@@ -625,7 +641,10 @@
                         System.Threading.Thread.Sleep(100);
                     }
                 }
-                var pack = pm.ControlDevice(actionObjs);
+                if (actionObjs.Count > 0)
+                {
+                    var pack = pm.ControlDevice(actionObjs);
+                }
             }
         }
 
@@ -713,8 +732,18 @@
                 }
                 else
                 {
-                    var pm = new DAL.Server.HttpServerRequest();
-                    var pack = pm.RefreshDeviceStatus(new List<string>() { function.deviceId });
+                    var pm = new HttpServerRequest();
+                    try
+                    {
+                        pm.RefreshDeviceStatus(new List<string>() { function.deviceId });
+                    }catch(Exception ex)
+                    {
+                        MainPage.Log($"杩滅▼璇诲彇璁惧鐘舵�佸紓甯�:{ex.Message}");
+                    }
+                    finally
+                    {
+                        pm = null;
+                    }
                 }
             }
         }
@@ -851,7 +880,7 @@
                         },
                     time_stamp = Utlis.GetTimestamp()
                 };
-                var aLinkJson = Newtonsoft.Json.JsonConvert.SerializeObject(aLinkData);
+                var aLinkJson = JsonConvert.SerializeObject(aLinkData);
                 var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ControlScene, aLinkJson);
                 new Control_Udp().SendLocalHdlLinkData(sendBytes, aLinkData.id, 0);
             }
@@ -1000,7 +1029,7 @@
 
                 if (receiveObj.Topic == CommunicationTopic.ct.HeartBeat + "_reply")
                 {
-                    Ins.myTcpClient.ClearHeartBeatLog();
+                    //Ins.myTcpClient.ClearHeartBeatLog();
                     MainPage.Log("tcp蹇冭烦鍥炲");
                     return null;
                 }
@@ -1096,7 +1125,7 @@
                         Ins.IsLocalEncrypt = device.isLocalEncrypt;
                         //MainPage.Log("缃戝叧鏈湴鍔犲瘑鐘舵�侊細" + device.local_encrypt.ToString());
                         //鐧诲綍缃戝叧Tcp
-                        OpenTcpClent();
+                        //OpenTcpClent();
 
 
                     }
@@ -1108,6 +1137,7 @@
                     receiveObj.Topic.Contains(CommunicationTopic.ct.GatewayUpSortTopic))
                 {
                     //TODO 鏆傛椂涓嶄紶姝g‘鐨勬暟鎹笂鍘伙紝濡傛灉鍚庨潰瑕佷紭鍖栧墠闈㈣繖浜涗唬鐮�
+                    //Console.WriteLine($"{receiveObj.Topic}\r\n{receiveObj.BodyDataString}");
                     UpdataFunctionStatus(receiveObj.BodyDataString, null);
                 }
                 else if (receiveObj.Topic == CommunicationTopic.ct.ControlSeurity + "_reply"
@@ -1198,7 +1228,7 @@
 
 
         /// <summary>
-        /// 鏇存柊璁惧鐘舵��
+        /// 鏇存柊缇ゆ帶璁惧鐘舵��
         /// A鍗忚鏁版嵁
         /// </summary>
         public void UpdataGroupControlStatus(string revString, byte[] usefulBytes, bool isCloudData = false)
@@ -1217,7 +1247,7 @@
                         {
                             continue;
                         }
-                        MainPage.Log($"鏀跺埌鏁版嵁:{revString}");
+                        MainPage.Log($"鏀跺埌缇ゆ帶鏁版嵁:{revString}");
                         foreach (var attr in updateTemp.status)
                         {
                             localFunction.time_stamp = temp.time_stamp;
@@ -1260,7 +1290,7 @@
             //    return;
             //}
 
-            var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<AlinkFunctionStatusObj>(revString);
+            var temp = JsonConvert.DeserializeObject<AlinkFunctionStatusObj>(revString);
             if (temp != null)
             {
                 Control_Udp.ReceiveRepeatManager(temp.id, usefulBytes);
@@ -1293,16 +1323,6 @@
                         }
                         MainPage.Log(localFunction.name);
 
-                        if (Ins.GatewayOnline_Local && isCloudData)//鏈湴閾炬帴锛岄櫎浜嗘秱楦﹁澶囨暟鎹箣澶栫殑浜戠鏁版嵁涓嶅鐞�
-                        {
-                            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)
@@ -1317,8 +1337,17 @@
                         {
                             localFunction.time_stamp = temp.time_stamp;
                             localFunction.SetAttrState(attr.key, attr.value);
-
+                            
                         }
+                        if(localFunction.spk == SPK.AirSwitchP3)
+                        {
+                            localFunction.online = updateTemp.online;
+                        }
+                        if (SPK.LightSpkList().Contains(localFunction.spk))
+                        {
+                            localFunction.updateTime = DateTime.Now;
+                        }
+                       
 
                         //鏇存柊鐣岄潰鐘舵��
                         switch (localFunction.spk)
@@ -1336,6 +1365,10 @@
                                 {
                                     EnergyMainPage.UpdataStatus(localFunction);
                                 }
+                                break;
+                            case SPK.AirSwitchP3:
+                                AirSwitchP3Page.UpdataState(localFunction);
+                                AirSwitchP3SubloopEnergyPage.UpdataStatus(localFunction);
                                 break;
                             case SPK.ElectricEnergy:
                                 EnergyMainPage.UpdataStatus(localFunction);
@@ -1459,11 +1492,13 @@
                                 FloorHeatingPage.UpdataStates(localFunction);
                                 break;
                             case SPK.SensorPm25:
+                            case SPK.SensorPm10:
                             case SPK.SensorCO2:
                             case SPK.SensorTVOC:
                             case SPK.SensorTemperature:
                             case SPK.SensorHumidity:
                             case SPK.SensorHcho:
+                            case SPK.SensorLight:
                                 if (localFunction.spk == SPK.SensorTemperature)
                                 {
                                     HomePage.LoadEvent_RefreshEnvirIndoorTemp();
@@ -1504,7 +1539,6 @@
                             case SPK.ElectricTuyaWeepRobot2:
                             case SPK.ElectricTuyaWaterValve:
                             case SPK.ElectricTuyaWaterValve2:
-                            case SPK.SensorPir:
                             case SPK.SensorDoorWindow:
                             case SPK.SensorSmoke:
                             case SPK.SensorWater:
@@ -1519,6 +1553,22 @@
                                 //鐘舵�佹洿鏂�
                                 Stan.HdlDeviceStatuPushLogic.Current.UpdateDeviceStatu(updateTemp.sid, updateTemp.status);
                                 break;
+                            case SPK.SensorPir:
+                            case SPK.SensorPirHold:
+                                var tempPirStatus = localFunction.attributes.Find((sta) => sta.key == "people_status");
+                                if (tempPirStatus != null)
+                                {
+                                    if(tempPirStatus.state == "true")
+                                    {
+                                        localFunction.lastState = Language.StringByID(StringId.Someone);
+                                    }
+                                    else
+                                    {
+                                        localFunction.lastState = Language.StringByID(StringId.wuren);
+                                    }
+                                }
+                                Stan.HdlDeviceStatuPushLogic.Current.UpdateDeviceStatu(updateTemp.sid, updateTemp.status);
+                                break;
                             case SPK.SenesorMegahealth:
                             case SPK.SenesorMegahealth2:
                             case SPK.SensorMmvPose:
@@ -1530,7 +1580,7 @@
                                     switch (tempStatus.state)
                                     {//0绌猴紝1璧帮紝2璺戯紝3鍧愶紝4璺屽�掞紝5绔�
                                         case "0":
-                                            localFunction.lastState = Language.StringByID(StringId.SensorNormalState);
+                                            localFunction.lastState = Language.StringByID(StringId.wuren);
                                             break;
                                         case "1":
                                             localFunction.lastState = Language.StringByID(StringId.SomeoneIn);
@@ -1567,6 +1617,17 @@
                             case SPK.MusicStandard:
                                 //UI.Music.MusicMain.mMusicMain.RefreshView(updateTemp);
                                 Console.WriteLine("闊充箰鎾斁鍣ㄦ樉绀虹姸鎬�=======" + revString);
+                                foreach (var music in UI.Music.A31MusicModel.A31MusicModelList)//姣忔鏀跺埌鏁版嵁閮借鏇存柊涓�涓嬫椂闂�
+                                {
+                                    if (music.functionMusic.sid == localFunction.sid)
+                                    {
+                                        music.LastDateTime = DateTime.Now;
+                                    }
+                                }
+                                if (UI.Music.A31MusicModel.Current != null)
+                                {
+                                    UI.Music.A31MusicModel.Current.LastDateTime = DateTime.Now;
+                                }
                                 //wjc
                                 break;
                             case SPK.Inverter:
@@ -1579,6 +1640,7 @@
                                 break;
                         }
 
+                        
                         HomePage.UpdataFunctionStates(localFunction);
                         RoomPage.UpdataStates(localFunction);
                         FunctionPage.UpdataStates(localFunction);

--
Gitblit v1.8.0