wei
2021-10-28 270b3d8539f6b4a991a9ebf3b3a9eceb436d61d5
HDL_ON/DAL/DriverLayer/Control.cs
@@ -279,6 +279,7 @@
                        else if (DB_ResidenceData.Instance.GatewayType == 1)
                        {
                            new Control_Udp().SearchLocalGateway();
                            new Control_Udp().SearchLocalGateway(true);
                        }
                        System.Threading.Thread.Sleep(500);
                    }
@@ -702,6 +703,21 @@
            }
        }
        /// <summary>
        /// 网关进入配网模式
        /// </summary>
        public void AuthGateway()
        {
            var objects1 = new { spk = "", time = "180" };
            //{"objects":[{"spk":"","time":"180"}],"id":"8","time_stamp":"1635241216669"}
            var sendId = Ins.msg_id.ToString();
            var sendObj = new { objects = objects1, id = sendId, time_stamp = Utlis.GetTimestamp() };
            var aLinkJson = Newtonsoft.Json.JsonConvert.SerializeObject(sendObj);
            var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.AuthGateway, aLinkJson);
            new Control_Udp().SendLocalHdlLinkData(sendBytes, Ins.msg_id.ToString());
        }
        /// <summary>
        /// 转换发送数据
        /// </summary>
        /// <param name="topic">主题</param>
@@ -723,7 +739,7 @@
            //1.拼接头
            string topicString = "Topic:" + topic + "\r\n";
            //2.Body字符串转为byte数组
            byte[] bodyBytes = Encoding.ASCII.GetBytes(bodyDataString);
            byte[] bodyBytes = Encoding.UTF8.GetBytes(bodyDataString);
            //判断是否需加密Body数据
            if (isEncryption && IsLocalEncryptAndGetAesKey)
            {
@@ -734,7 +750,7 @@
            //3.拼接body的Length长度数据
            string lengthString = "Length:" + bodyBytes.Length.ToString() + "\r\n" + "\r\n";
            string topicAndLengthString = topicString + lengthString;
            byte[] topicAndLengthBytes = Encoding.ASCII.GetBytes(topicAndLengthString);
            byte[] topicAndLengthBytes = Encoding.UTF8.GetBytes(topicAndLengthString);
            //4.拼接合并 Topic 和 body的byte数组数据
            byte[] sendDataBytes = new byte[topicAndLengthBytes.Length + bodyBytes.Length];
            topicAndLengthBytes.CopyTo(sendDataBytes, 0);
@@ -750,10 +766,10 @@
        /// 转换接收到的数据
        /// </summary>
        /// <returns></returns>
        public void ConvertReceiveData(byte[] receiveBytes)
        public void ConvertReceiveData(byte[] receiveBytes,string ip)
        {
            var reString = Encoding.UTF8.GetString(receiveBytes);
            AnalysisReceiveData(reString, receiveBytes);
            AnalysisReceiveData(reString, receiveBytes,ip);
        }
        /// <summary>
        /// 转换接收到的数据
@@ -761,7 +777,7 @@
        /// <param name="receiveString">转String后的数据</param>
        /// <param name="originalReceiveBytes"原始Bytes数据</param>
        /// <returns></returns>
        public LocalCommunicationData AnalysisReceiveData(string receiveString, byte[] originalReceiveBytes)
        public LocalCommunicationData AnalysisReceiveData(string receiveString, byte[] originalReceiveBytes , string sIp = null)
        {
            LocalCommunicationData receiveObj = new LocalCommunicationData();
@@ -854,6 +870,10 @@
                        {
                            Ins.GatewayId = device.device_mac;
                        }
                        if (!string.IsNullOrEmpty(sIp))
                        {
                            device.ip_address = sIp;
                        }
                        reportIp = device.ip_address;//主播地址也能控制设备//"239.0.168.188";//
                        //2021-09-23 新增获取当前网关是否本地加密
                        Ins.IsLocalEncrypt = device.isLocalEncrypt;