mac
2024-07-25 3f6685c77beeb12baf840733fb890860f4c26e7c
HDL_ON/DAL/DriverLayer/Control.cs
@@ -1,29 +1,16 @@
using 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;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Shared;
namespace HDL_ON.DriverLayer
{
    /// <summary>
    /// 通讯方式
    /// </summary>
    public enum CommunicationMode
    {
        none,
        /// <summary>
        /// 本地udp
        /// </summary>
        local_BusUdp,
        /// <summary>
        /// 本地tcp客户端
        /// </summary>
        tcp_local_client,
    }
    public class Control
    {
@@ -43,6 +30,27 @@
        /// 记录接收到的消息,方便zb的工程师调试他们的设备
        /// </summary>
        public List<string> MsgInfoList = new List<string>();
        private bool _LocalTcpClientLogin = false;
        /// <summary>
        /// 本地tcp客户端连接是否成功
        /// 是否登录网关成功
        /// </summary>
        public bool LocalTcpClientLogin
        {
            get
            {
                return _LocalTcpClientLogin;
            }
            set
            {
                _LocalTcpClientLogin = value;
                if (!value)
                {
                    loginGatewayThread?.Abort();
                    loginGatewayThread = null;
                }
            }
        }
        int _msg_id = 1;
        /// <summary>
@@ -76,8 +84,10 @@
        /// <summary>
        /// 判断是否本地加密并且加密key不为空
        /// </summary>
        public bool IsLocalEncryptAndGetAesKey {
            get {
        public bool IsLocalEncryptAndGetAesKey
        {
            get
            {
                return IsLocalEncrypt && (!string.IsNullOrEmpty(DB_ResidenceData.Instance.CurrentRegion.localSecret));
            }
        }
@@ -115,6 +125,10 @@
                        HomePage.LoadEvent_CheckLinkStatus();
                    }
                }
                else
                {
                    MainPage.Log($"状态一致,不更新数据(本地)");
                }
            }
        }
        bool _GatewayOnline_Cloud = false;
@@ -129,45 +143,64 @@
            }
            set
            {
                if (_GatewayOnline_Cloud != value)
                try
                {
                    _GatewayOnline_Cloud = value;
                    if(GatewayOnline_Local)
                    if (_GatewayOnline_Cloud != value)
                    {
                        return;
                    }
                    if (value)
                    {
                        if (DB_ResidenceData.Instance.HomeGateway == null)
                        _GatewayOnline_Cloud = value;
                        if (GatewayOnline_Local)
                        {
                            return;
                        }
                        if (!DB_ResidenceData.Instance.HomeGateway.gatewayStatus)//远程情况下,网关未链接服务器不能修改主页网关状态
                        if (value)
                        {
                            if (DB_ResidenceData.Instance.HomeGateway == null)
                            {
                                return;
                            }
                            if (!DB_ResidenceData.Instance.HomeGateway.gatewayStatus)//远程情况下,网关未链接服务器不能修改主页网关状态
                            {
                                new System.Threading.Thread(() =>
                                {
                                    System.Threading.Thread.Sleep(3000);
                                    var pm = new DAL.Server.HttpServerRequest();
                                    pm.GetGatewayInfo();
                                })
                                { IsBackground = true }.Start();
                                return;
                            }
                            //修改主页连接状态
                            HomePage.LoadEvent_CheckLinkStatus();
                            MainPage.Log($"网关云端在线,刷新设备状态");
                            new System.Threading.Thread(() =>
                            {
                                System.Threading.Thread.Sleep(3000);
                                var pm = new DAL.Server.HttpServerRequest();
                                pm.GetGatewayInfo();
                                int count = 20;
                                while (true)
                                {
                                    System.Threading.Thread.Sleep(500);
                                    if (MqttClient.isSubscribeSuccess || count<1)
                                    {
                                        break;
                                    }
                                    count--;
                                }
                                FunctionList.List.ReadAllFunctionStatus();
                            })
                            { IsBackground = true }.Start();
                            return;
                            { IsBackground = true, Priority = System.Threading.ThreadPriority.AboveNormal }.Start();
                        }
                        //修改主页连接状态
                        HomePage.LoadEvent_CheckLinkStatus();
                        MainPage.Log($"网关云端在线,刷新设备状态");
                        new System.Threading.Thread(() =>
                        else
                        {
                            System.Threading.Thread.Sleep(1000);
                            FunctionList.List.ReadAllFunctionStatus();
                        })
                        { IsBackground = true, Priority = System.Threading.ThreadPriority.AboveNormal }.Start();
                            //修改主页连接状态
                            HomePage.LoadEvent_CheckLinkStatus();
                        }
                    }
                    else
                    {
                        //修改主页连接状态
                        HomePage.LoadEvent_CheckLinkStatus();
                        MainPage.Log($"状态一致,不更新数据(云端)");
                    }
                }catch(Exception ex)
                {
                    MainPage.Log($"Set GatewayCloudOnline Error:{ex.Message}");
                }
            }
        }
@@ -200,11 +233,6 @@
        public Control_Udp myUdp1 = null;
        /// <summary>
        /// 通讯方式
        /// </summary>
        public CommunicationMode communicationMode;
        /// <summary>
        /// 打开tcp服务端
        /// </summary>
        public void OpenTcpServer()
@@ -233,11 +261,13 @@
        /// </summary>
        public void OpenTcpClent()
        {
            return;
            if (myTcpClient == null)
            {
                myTcpClient = new Control_TcpClient(reportIp);
                myTcpClient.Connect();
            }
            myTcpClient.Connect();
        }
        /// <summary>
@@ -246,7 +276,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;
            }
@@ -265,6 +296,7 @@
            }
            else if (MainPage.InternetStatus == 2)
            {
                DAL.Mqtt.MqttClient.InitState();
                OpenUdp(DB_ResidenceData.Instance.GatewayType == 0 ? 6000 : 8585);
                //重置搜索网关标志
                IsSearchLocalGatewaySuccessful = false;
@@ -291,11 +323,64 @@
                        System.Threading.Thread.Sleep(500);
                    }
                    DAL.Mqtt.MqttClient.InitState();
                })
                { IsBackground = true }.Start();
            }
        }
        private System.Threading.Thread loginGatewayThread;
        /// <summary>
        /// 登录网关
        /// </summary>
        public void LoginGateway()
        {
            return;//tcp控制存在问题,但是先不用tcp控制了,要经过测试先  2023-07-29 10:14:32
            if (loginGatewayThread == null)
            {
                loginGatewayThread = new System.Threading.Thread(() =>
                {
                    while (!Ins.myTcpClient.isConnected)
                    {
                        if (Ins.GatewayOnline_Local && myTcpClient.isConnected)
                        {
                            var sendData = new { clientType = "app", version = "1.0" };
                            var sendJob = new { id = Control.Ins.msg_id.ToString(), time_stamp = Utlis.GetTimestamp(), objects = sendData };
                            var bodyString = JsonConvert.SerializeObject(sendJob);
                            var sendBytes = ConvertSendBodyData($"/user/{GatewayId}/custom/gateway/login", bodyString);
                            Ins.myTcpClient.SendMessage(sendBytes);
                        }
                        System.Threading.Thread.Sleep(2000);
                    }
                    //loginGatewayThread?.Abort();
                    //loginGatewayThread = null;
                });
                loginGatewayThread.Start();
            }
            else
            {
                try
                {
                    loginGatewayThread?.Abort();
                }
                catch (Exception ex)
                {
                    MainPage.Log($"重启登录网关线程异常:{ex.Message}");
                }
                finally
                {
                    loginGatewayThread = null;
                    LoginGateway();
                }
            }
        }
        /// <summary>
        /// 场景控制入口
@@ -303,9 +388,9 @@
        public void ControlScene(Scene scene)
        {
            //体验模式
            if(MainPage.NoLoginMode)
            if (MainPage.NoLoginMode)
            {
                foreach(var sceneFunction in scene.functions)
                foreach (var sceneFunction in scene.functions)
                {
                    var revString = "";
                    var upDataObj = new AlinkFunctionStatusObj();
@@ -342,15 +427,6 @@
                }
            }
        }
        /// <summary>
        /// 安防控制
        /// </summary>
        public void ControlArm()
        {
            DAL.Server.HttpServerRequest httpServer = new DAL.Server.HttpServerRequest();
            //var pack = httpServer.GetSecurityAlarmLogList
        }
        /// <summary>
        /// 发送命令
@@ -361,7 +437,7 @@
        /// <param name="function"></param>
        /// <param name="useRemote">是否直接使用远程发送</param>
        /// <returns></returns>
        public bool 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;
@@ -408,7 +484,6 @@
                UpdataFunctionStatus(revString, null, true);
                return true;
            }
            //MainPage.Log($"发送数据:{Newtonsoft.Json.JsonConvert.SerializeObject(commandDictionary)}");
@@ -459,8 +534,9 @@
                        var functionControlDataObj = function.GetGatewayAlinkControlData(commandDictionary);
                        var functionControlDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(functionControlDataObj);
                        var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ControlFunctionTopic, functionControlDataJson);
                        new Control_Udp().SendLocalHdlLinkData(sendBytes, functionControlDataObj.id,resend);
                        new Control_Udp().SendLocalHdlLinkData(sendBytes, functionControlDataObj.id, resend);
                        MainPage.Log($"本地通讯 发送HDL-Link数据:{functionControlDataJson}");
                            //Ins.myTcpClient.SendMessage(sendBytes);
                    }
                }
                //远程通讯
@@ -477,7 +553,7 @@
                                commandDictionary.Add(FunctionAttributeKey.OnOff, commandDictionary[FunctionAttributeKey.Brightness] == "0" ? "off" : "on");
                            }
                        }
                        if(function.spk == SPK.LightCCT)
                        if (function.spk == SPK.LightCCT)
                        {
                            if (!commandDictionary.ContainsKey(FunctionAttributeKey.CCT))
                            {
@@ -501,10 +577,10 @@
        /// <summary>
        /// 全开全关功能
        /// </summary>
        public void SwtichFunctions(bool open,List<Function> functions)
        public void SwtichFunctions(bool open, List<Function> functions)
        {
            //dome模式控制
            if(MainPage.NoLoginMode)
            if (MainPage.NoLoginMode)
            {
                new System.Threading.Thread(() =>
                {
@@ -512,7 +588,7 @@
                    {
                        Dictionary<string, string> d1 = new Dictionary<string, string>();
                        d1.Add(FunctionAttributeKey.OnOff, open ? "on" : "off");
                         if (function.spk == SPK.PanelSocket)
                        if (function.spk == SPK.PanelSocket)
                        {
                            if (function.attributes.Find((obj) => obj.key == "on_off_usb") != null)
                            {
@@ -550,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++;
@@ -561,7 +641,10 @@
                        System.Threading.Thread.Sleep(100);
                    }
                }
                var pack = pm.ControlDevice(actionObjs);
                if (actionObjs.Count > 0)
                {
                    var pack = pm.ControlDevice(actionObjs);
                }
            }
        }
@@ -578,16 +661,16 @@
        {
            var pm = new DAL.Server.HttpServerRequest();
            var pack = pm.GetDeviceInfoList(functionIds);
            if(pack!= null&& pack.Data!=null)
            if (pack != null && pack.Data != null)
            {
                //待测试2021-03-04
                var ddd = Newtonsoft.Json.JsonConvert.DeserializeObject<List<AlinkStatusData>>(pack.Data.ToString());
                if(ddd!= null)
                if (ddd != null)
                {
                    foreach(var function in ddd)
                    foreach (var function in ddd)
                    {
                        var temp = FunctionList.List.GetDeviceFunctionList().Find((obj) => obj.deviceId == function.deviceId);
                        if(temp!= null)
                        if (temp != null)
                        {
                            if (SPK.Get3tySpk(SPK.BrandType.Tuya).Contains(temp.spk))
                            {
@@ -603,7 +686,7 @@
        /// 发送读取命令
        /// 自动判断是否为A协议设备
        /// </summary>
        public void SendReadCommand(Function function ,bool forceRemote = false)
        public void SendReadCommand(Function function, bool forceRemote = false)
        {
            function.refreshTime = DateTime.Now;
            if (forceRemote)
@@ -649,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;
                    }
                }
            }
        }
@@ -687,7 +780,7 @@
                            {
                                busClient.ReadBusData(function);
                            }
                        }
                        catch (Exception ex)
                        {
@@ -731,7 +824,7 @@
        /// <summary>
        /// 安防控制
        /// </summary>
        public void ControlSecurity(SecurityAlarm securityAlarm,string state)
        public void ControlSecurity(SecurityAlarm securityAlarm, string state)
        {
            if (!Ins.GatewayOnline_Local)//网关本地不在线
            {
@@ -787,11 +880,38 @@
                        },
                    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);
                new Control_Udp().SendLocalHdlLinkData(sendBytes, aLinkData.id, 0);
            }
        }
        /// <summary>
        /// 获取音乐目录
        /// </summary>
        public void GetMusicDirectory(Function function)
        {
            if (Ins.GatewayOnline_Local)
            {
                var objects = new List<Dictionary<string, string>>();
                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($"/base/{DB_ResidenceData.Instance.HomeGateway.gatewayId}/thing/service/MusicPlayGroupListGet/down", functionControlDataJson);
                MainPage.Log($"本地通讯 发送HDL-Link数据:{functionControlDataJson}");
                new Control_Udp().SendLocalHdlLinkData(sendBytes, readDataObj.id);
            }
        }
        /// <summary>
        /// 网关进入配网模式
        /// </summary>
@@ -856,10 +976,14 @@
        /// 转换接收到的数据
        /// </summary>
        /// <returns></returns>
        public void ConvertReceiveData(byte[] receiveBytes,string ip)
        public void ConvertReceiveData(byte[] receiveBytes, string ip)
        {
            if (!UserInfo.Current.IsLogin)
            {
                return;
            }
            var reString = Encoding.UTF8.GetString(receiveBytes);
            AnalysisReceiveData(reString, receiveBytes,ip);
            AnalysisReceiveData(reString, receiveBytes, ip);
        }
        /// <summary>
        /// 转换接收到的数据
@@ -867,11 +991,11 @@
        /// <param name="receiveString">转String后的数据</param>
        /// <param name="originalReceiveBytes"原始Bytes数据</param>
        /// <returns></returns>
        public LocalCommunicationData AnalysisReceiveData(string receiveString, byte[] originalReceiveBytes , string sIp = null)
        public LocalCommunicationData AnalysisReceiveData(string receiveString, byte[] originalReceiveBytes, string sIp = null)
        {
            LocalCommunicationData receiveObj = new LocalCommunicationData();
            MainPage.Log($"局域网信息: \r\n{receiveString}");
            var res = receiveString.Split("\r\n\r\n");
@@ -903,13 +1027,19 @@
                //}
                receiveObj.BodyDataString = res[1];
                if (receiveObj.Topic == CommunicationTopic.ct.HeartBeat + "_reply")
                {
                    //Ins.myTcpClient.ClearHeartBeatLog();
                    MainPage.Log("tcp心跳回复");
                    return null;
                }
                //2021-09-23 过滤不需要解密的主题 目前搜索网关主题不加密
                if (receiveObj.Topic != CommunicationTopic.SearchLoaclGatewayReply)
                {
                    //判断当前网关是否开启了本地加密
                    if (IsLocalEncryptAndGetAesKey)
                    {
                        MainPage.Log($"局域网信息 开始解密");
                        if (originalReceiveBytes != null)
                        {
                            //拿到原始Bytes数据去解密
@@ -941,8 +1071,27 @@
                        }
                    }
                    else
                    {
                        MainPage.Log($"局域网信息: 明文:" + receiveObj.BodyDataString);
                    }
                }
                try
                {
                    var idMsg = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePack>(res[1]);
                    var hasProcess = hasItBeenProcessed(idMsg.id);
                    if (hasProcess)
                    {
                        return null;
                    }
                    MainPage.Log($"处理局域网数据id:{idMsg.id}");
                }
                catch (Exception ex)
                {
                    MainPage.Log($"解析局域网数据异常{ex.Message}");
                }
                if (receiveObj.Topic == CommunicationTopic.SearchLoaclGatewayReply || receiveObj.Topic == CommunicationTopic.GatewayBroadcast)
                {
@@ -975,17 +1124,23 @@
                        //2021-09-23 新增获取当前网关是否本地加密
                        Ins.IsLocalEncrypt = device.isLocalEncrypt;
                        //MainPage.Log("网关本地加密状态:" + device.local_encrypt.ToString());
                        //登录网关Tcp
                        //OpenTcpClent();
                    }
                }
                else if (receiveObj.Topic == CommunicationTopic.ct.ReadStatus + "_reply" ||
                    receiveObj.Topic == CommunicationTopic.ct.ControlFunctionTopic + "_reply" ||
                    receiveObj.Topic == CommunicationTopic.ct.ControlFunctionTopic + "_reply" ||
                    receiveObj.Topic == CommunicationTopic.ct.ControlGroupControlTopic + "_reply" ||
                    receiveObj.Topic == CommunicationTopic.ct.GatewayUpStatus ||
                    receiveObj.Topic.Contains( CommunicationTopic.ct.GatewayUpSortTopic))
                    receiveObj.Topic.Contains(CommunicationTopic.ct.GatewayUpSortTopic))
                {
                    //TODO 暂时不传正确的数据上去,如果后面要优化前面这些代码
                    //Console.WriteLine($"{receiveObj.Topic}\r\n{receiveObj.BodyDataString}");
                    UpdataFunctionStatus(receiveObj.BodyDataString, null);
                }
                else if (receiveObj.Topic == CommunicationTopic.ct.ControlSeurity +"_reply"
                else if (receiveObj.Topic == CommunicationTopic.ct.ControlSeurity + "_reply"
                    || receiveObj.Topic == CommunicationTopic.ct.ReadSecurityStatus + "_reply"
                    || receiveObj.Topic == CommunicationTopic.ct.SecurityStatusUp)
                {
@@ -993,7 +1148,8 @@
                    {
                        MainPage.Log($"局域网安防信息: {receiveObj.Topic}  : 内容: {res[1]}");
                        var tt = "";
                        lock (tt) {
                        lock (tt)
                        {
                            var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<SecurityStatusObj>(receiveObj.BodyDataString);
                            if (temp != null)
                            {
@@ -1012,8 +1168,30 @@
                            }
                        }
                    }
                    catch (Exception ex){
                    catch (Exception ex)
                    {
                        MainPage.Log($"安防局域网异常:{ex.Message}");
                    }
                }
                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"))
                    {
                        LocalTcpClientLogin = true;
                        try
                        {
                            loginGatewayThread?.Abort();
                        }
                        catch (Exception ex)
                        {
                            MainPage.Log($"终止登录网关tcp异常:{ex.Message}");
                        }
                        finally
                        {
                            loginGatewayThread = null;
                        }
                        MainPage.Log("局域网tcp连接登录网关成功");
                    }
                }
                else
@@ -1025,12 +1203,86 @@
            return receiveObj;
        }
        private List<string> processedDataList = new List<string>();
        /// <summary>
        /// 是否已经处理过数据
        /// </summary>
        /// <returns></returns>
        private bool hasItBeenProcessed(string msgId)
        {
            if (processedDataList.Contains(msgId))
            {
                return true;
            }
            else
            {
                if (processedDataList.Count > 50)
                {
                    processedDataList.RemoveAt(0);
                }
                return false;
            }
        }
        /// <summary>
        /// 更新群控设备状态
        /// A协议数据
        /// </summary>
        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>
        /// <param name="updateBytes"></param>
        public void UpdataFunctionStatus(string revString, byte[] usefulBytes,bool isCloudData = false)
        public void UpdataFunctionStatus(string revString, byte[] usefulBytes, bool isCloudData = false)
        {
            ////test 云端连接成功时,不适用本地数据更新
            //if (Ins.GatewayOnline_Cloud && !isCloudData)
@@ -1038,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);
@@ -1071,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)
@@ -1090,24 +1332,43 @@
                        //        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);
                        }
                        if(localFunction.spk == SPK.AirSwitchP3)
                        {
                            localFunction.online = updateTemp.online;
                        }
                        if (SPK.LightSpkList().Contains(localFunction.spk))
                        {
                            localFunction.updateTime = DateTime.Now;
                        }
                        //更新界面状态
                        switch (localFunction.spk)
                        {
                            case SPK.AcstParent:
                                AcstParentPage.UpdateAcstParentInfo(localFunction);
                                break;
                            case SPK.AcstSub:
                                AcstParentPage.UpdateAcstSubInfo(localFunction);
                                AcstSubPage.UpdateStatus(localFunction);
                                break;
                            case SPK.AirSwitch:
                                AirSwitchPage.UpdataState(localFunction);
                                if(localFunction.GetAttribute(FunctionAttributeKey.Power)!=null)//如果是带电量的空开也要更新能源界面
                                if (localFunction.GetAttribute(FunctionAttributeKey.Power) != null)//如果是带电量的空开也要更新能源界面
                                {
                                    EnergyMainPage.UpdataStatus(localFunction);
                                }
                                break;
                            case SPK.AirSwitchP3:
                                AirSwitchP3Page.UpdataState(localFunction);
                                AirSwitchP3SubloopEnergyPage.UpdataStatus(localFunction);
                                break;
                            case SPK.ElectricEnergy:
                                EnergyMainPage.UpdataStatus(localFunction);
@@ -1131,6 +1392,8 @@
                                RGBPage.UpdataStates(localFunction);
                                break;
                            case SPK.LightRGBW:
                                localFunction.lastState = Language.StringByID(StringId.Brightness) + " : " + localFunction.GetAttrState(FunctionAttributeKey.Brightness) + "%";
                                RGBWPage.UpdataStates(localFunction);
                                break;
                            case SPK.LightCCT:
                                localFunction.lastState = Language.StringByID(StringId.Brightness) + " : " + localFunction.GetAttrState(FunctionAttributeKey.Brightness) + "%";
@@ -1141,7 +1404,7 @@
                                CurtainModulePage.UpdataState(localFunction);
                                break;
                            case SPK.CurtainDream:
                                if(localFunction.GetAttrState(FunctionAttributeKey.Percent) == "0")
                                if (localFunction.GetAttrState(FunctionAttributeKey.Percent) == "0")
                                {
                                    localFunction.SetAttrState(FunctionAttributeKey.OnOff, "off");
                                }
@@ -1157,6 +1420,8 @@
                                RollingShutterPage.UpdataState(localFunction);
                                break;
                            case SPK.CurtainShades:
                                localFunction.lastState = Language.StringByID(StringId.Open) + localFunction.GetAttrState(FunctionAttributeKey.Percent) + "%";
                                VenetianBlindsPage.UpdataState(localFunction);
                                break;
                            case SPK.AcStandard:
                            case SPK.HvacAC:
@@ -1227,12 +1492,14 @@
                                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:
                                if(localFunction.spk == SPK.SensorTemperature)
                            case SPK.SensorLight:
                                if (localFunction.spk == SPK.SensorTemperature)
                                {
                                    HomePage.LoadEvent_RefreshEnvirIndoorTemp();
                                }
@@ -1243,7 +1510,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))
@@ -1272,7 +1539,6 @@
                            case SPK.ElectricTuyaWeepRobot2:
                            case SPK.ElectricTuyaWaterValve:
                            case SPK.ElectricTuyaWaterValve2:
                            case SPK.SensorPir:
                            case SPK.SensorDoorWindow:
                            case SPK.SensorSmoke:
                            case SPK.SensorWater:
@@ -1281,12 +1547,31 @@
                            case SPK.HvacAirFresh:
                            case SPK.SensorGas:
                            case SPK.HvacCac:
                            case SPK.SensorHelp:
                            case SPK.MechanicalArm:
                                //设备状态推送
                                //状态更新
                                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:
                                var tempStatus = localFunction.attributes.Find((sta) => sta.key == FunctionAttributeKey.TargetStatus);
                                if (tempStatus != null)
@@ -1295,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);
@@ -1331,11 +1616,31 @@
                            case SPK.AvMusic:
                            case SPK.MusicStandard:
                                //UI.Music.MusicMain.mMusicMain.RefreshView(updateTemp);
                                //Console.WriteLine("音乐播放器显示状态======="+ revString);
                                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:
                            case SPK.InverterRst:
                                var status = new Dictionary<string, object> { ["method"] = "status", ["data"] = temp.objects };
                                Application.RunOnMainThread(() =>
                                {
                                    Inverter.Ins.H5Page.CallJS($"nativeToJs(\'{Newtonsoft.Json.JsonConvert.SerializeObject(status)}\')");
                                });
                                break;
                        }
                        HomePage.UpdataFunctionStates(localFunction);
                        RoomPage.UpdataStates(localFunction);
                        FunctionPage.UpdataStates(localFunction);
@@ -1357,12 +1662,12 @@
        /// <summary>
        /// //一键(远程)开锁
        /// </summary>
        public void OneKeyUnlocking(Function doorlock,string extStr)
        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 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);
@@ -1377,7 +1682,7 @@
        /// </summary>
        /// <param name="functionId"></param>
        /// <param name="pwd"></param>
        public void ConfirmUnlocking(string functionId,string pwd)
        public void ConfirmUnlocking(string functionId, string pwd)
        {
            Loading loading = new Loading();
            MainPage.BaseView.AddChidren(loading);
@@ -1413,8 +1718,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;
@@ -1423,8 +1730,9 @@
                    }
                    if (pack.Code != StateCode.SUCCESS)
                    {
                        Application.RunOnMainThread(() => {
                            if(string.IsNullOrEmpty(pack.message))
                        Application.RunOnMainThread(() =>
                        {
                            if (string.IsNullOrEmpty(pack.message))
                            {
                                new PublicAssmebly().TipMsg(Language.StringByID(StringId.Tip),
                                    Language.StringByID(StringId.OperationFailed));