wxr
2023-06-05 753e67c3705dddb8e913bd853db151f94f81d600
HDL_ON/DAL/DriverLayer/Control.cs
@@ -83,8 +83,10 @@
        /// <summary>
        /// 判断是否本地加密并且加密key不为空
        /// </summary>
        public bool IsLocalEncryptAndGetAesKey {
            get {
        public bool IsLocalEncryptAndGetAesKey
        {
            get
            {
                return IsLocalEncrypt && (!string.IsNullOrEmpty(DB_ResidenceData.Instance.CurrentRegion.localSecret));
            }
        }
@@ -136,6 +138,8 @@
            }
            set
            {
                try
                {
                if (_GatewayOnline_Cloud != value)
                {
                    _GatewayOnline_Cloud = value;
@@ -175,6 +179,10 @@
                        //修改主页连接状态
                        HomePage.LoadEvent_CheckLinkStatus();
                    }
                    }
                }catch(Exception ex)
                {
                    MainPage.Log($"Set GatewayCloudOnline Error:{ex.Message}");
                }
            }
        }
@@ -249,7 +257,8 @@
        public void SearchLoaclGateway()
        {
            //2021-01-15 : 住宅没有绑定网关的时候不用搜索,并且不能链接mqtt
            if(DB_ResidenceData.Instance.HomeGateway == null || string.IsNullOrEmpty(DB_ResidenceData.Instance.HomeGateway.gatewayId))
            if (DB_ResidenceData.Instance.HomeGateway == null || string.IsNullOrEmpty(DB_ResidenceData.Instance.HomeGateway.gatewayId) ||
                    !UserInfo.Current.IsLogin)
            {
                return;
            }
@@ -310,7 +319,8 @@
        {
            if(loginGatewayThread== null)
            {
                loginGatewayThread = new System.Threading.Thread(() => {
                loginGatewayThread = new System.Threading.Thread(() =>
                {
                    while (!Ins.myTcpClient.isConnected)
                    {
                        if (Ins.GatewayOnline_Local && myTcpClient.isConnected)
@@ -337,7 +347,8 @@
                try
                {
                    loginGatewayThread?.Abort();
                }catch (Exception ex)
                }
                catch (Exception ex)
                {
                    MainPage.Log($"重启登录网关线程异常:{ex.Message}");
                }
@@ -454,7 +465,6 @@
                return true;
            }
            //MainPage.Log($"发送数据:{Newtonsoft.Json.JsonConvert.SerializeObject(commandDictionary)}");
            ///第三方涂鸦设备统一使用远程控制
@@ -506,6 +516,7 @@
                        var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ControlFunctionTopic, functionControlDataJson);
                        new Control_Udp().SendLocalHdlLinkData(sendBytes, functionControlDataObj.id,resend);
                        MainPage.Log($"本地通讯 发送HDL-Link数据:{functionControlDataJson}");
                            Ins.myTcpClient.SendMessage(sendBytes);
                    }
                }
                //远程通讯
@@ -1079,6 +1090,7 @@
                }
                else if (receiveObj.Topic == CommunicationTopic.ct.ReadStatus + "_reply" ||
                    receiveObj.Topic == CommunicationTopic.ct.ControlFunctionTopic + "_reply" ||
                    receiveObj.Topic == CommunicationTopic.ct.ControlGroupControlTopic + "_reply" ||
                    receiveObj.Topic == CommunicationTopic.ct.GatewayUpStatus ||
                    receiveObj.Topic.Contains(CommunicationTopic.ct.GatewayUpSortTopic))
                {
@@ -1118,7 +1130,8 @@
                        MainPage.Log($"安防局域网异常:{ex.Message}");
                    }
                }
                else if (receiveObj.Topic == $"/user/{GatewayId}/custom/gateway/login_reply") {
                else if (receiveObj.Topic == $"/user/{GatewayId}/custom/gateway/login_reply")
                {
                    var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<JObject>(receiveObj.BodyDataString);
                    if (temp.GetValue("objects").ToString().Contains("success"))
                    {
@@ -1170,11 +1183,62 @@
        }
        /// <summary>
        /// 更新设备状态
        /// A协议数据
        /// </summary>
        /// <param name="updateBytes"></param>
        public void UpdataGroupControlStatus(string revString, byte[] usefulBytes, bool isCloudData = false)
        {
            var temp = JsonConvert.DeserializeObject<AlinkFunctionStatusObj>(revString);
            if (temp != null)
            {
                Control_Udp.ReceiveRepeatManager(temp.id, usefulBytes);
                var allLocalFuntion = FunctionList.List.groupControls;
                foreach (var updateTemp in temp.objects)
                {
                    try
                    {
                        var localFunction = allLocalFuntion.Find((obj) => obj.sid == updateTemp.sid);
                        if (localFunction == null)
                        {
                            continue;
                        }
                        MainPage.Log($"收到数据:{revString}");
                        foreach (var attr in updateTemp.status)
                        {
                            localFunction.time_stamp = temp.time_stamp;
                            localFunction.SetAttrState(attr.key, attr.value);
                        }
                        //更新界面状态
                        switch (localFunction.spk)
                        {
                            case SPK.ElectricEnergy:
                                EnergyMainPage.UpdataStatus(localFunction);
                                break;
                        }
                        HomePage.UpdataFunctionStates(localFunction);
                        RoomPage.UpdataStates(localFunction);
                        FunctionPage.UpdataStates(localFunction);
                        ClassificationPage.UpdataInfo(localFunction);
                    }
                    catch (Exception ex)
                    {
                        MainPage.Log($"A协议更新状态异常:{ex.Message}");
                    }
                }
            }
        }
        /// <summary>
        /// 更新设备状态
        /// A协议数据
        /// </summary>
        public void UpdataFunctionStatus(string revString, byte[] usefulBytes,bool isCloudData = false)
        {
            ////test 云端连接成功时,不适用本地数据更新
@@ -1235,12 +1299,11 @@
                        //        return;
                        //    }
                        //}
                        //MainPage.Log($"A协议更新状态:{revString}");
                        MainPage.Log($"收到数据:{revString}");
                        foreach (var attr in updateTemp.status)
                        {
                            localFunction.time_stamp = temp.time_stamp;
                            localFunction.SetAttrState(attr.key, attr.value);
                            //Console.WriteLine("音乐播放器添加缓存数据=======" + revString);
                        }
@@ -1399,7 +1462,7 @@
                                EnvironmentalPage.LoadEvent_UpdataStatus(localFunction);
                                //A_EnvironmentalDataCenter.LoadEvent_UpdataStatus(localFunction);
                                break;
                            case SPK.SensorEnvironment:
                            case SPK.SensorEnvironment:case SPK.SensorEnvironmentHailin:
                            case SPK.SensorEnvironment2:
                            case SPK.SensorEnvironment3:
                                if (localFunction.GetAttributes().Contains(FunctionAttributeKey.Temperature))
@@ -1490,7 +1553,7 @@
                            case SPK.AvMusic:
                            case SPK.MusicStandard:
                                //UI.Music.MusicMain.mMusicMain.RefreshView(updateTemp);
                                //Console.WriteLine("音乐播放器显示状态======="+ revString);
                                Console.WriteLine("音乐播放器显示状态=======" + revString);
                                //wjc
                                break;
                            case SPK.Inverter:
@@ -1580,8 +1643,10 @@
                        //{
                        //    return false;
                        //}
                        if (pack.Code != StateCode.SUCCESS) {
                            Application.RunOnMainThread(() => {
                        if (pack.Code != StateCode.SUCCESS)
                        {
                            Application.RunOnMainThread(() =>
                            {
                                new PublicAssmebly().TipMsg(Language.StringByID(StringId.Tip), pack.message);
                                UserInfo.Current.doorPasswordString = "";//
                                UserInfo.Current.LastTimeOpenDoor = DateTime.MinValue;
@@ -1590,7 +1655,8 @@
                    }
                    if (pack.Code != StateCode.SUCCESS)
                    {
                        Application.RunOnMainThread(() => {
                        Application.RunOnMainThread(() =>
                        {
                            if(string.IsNullOrEmpty(pack.message))
                            {
                                new PublicAssmebly().TipMsg(Language.StringByID(StringId.Tip),