wxr
2022-08-25 b5444e6e566c2128bcb4fb522bfa636ee2c5b8fb
HDL_ON/DAL/DriverLayer/Control.cs
@@ -29,11 +29,27 @@
        /// 记录接收到的消息,方便zb的工程师调试他们的设备
        /// </summary>
        public List<string> MsgInfoList = new List<string>();
        private bool _LocalTcpClientLogin = false;
        /// <summary>
        /// 本地tcp客户端连接是否成功
        /// 是否登录网关成功
        /// </summary>
        public bool LocalTcpClientLogin = false;
        public bool LocalTcpClientLogin
        {
            get
            {
                return _LocalTcpClientLogin;
            }
            set
            {
                _LocalTcpClientLogin = value;
                if (!value)
                {
                    loginGatewayThread?.Abort();
                    loginGatewayThread = null;
                }
            }
        }
        int _msg_id = 1;
        /// <summary>
@@ -222,8 +238,9 @@
            if (myTcpClient == null)
            {
                myTcpClient = new Control_TcpClient(reportIp);
                myTcpClient.Connect();
            }
            myTcpClient.Connect();
        }
        /// <summary>
@@ -294,9 +311,9 @@
            if(loginGatewayThread== null)
            {
                loginGatewayThread = new System.Threading.Thread(() => {
                    while (true)
                    while (!Ins.myTcpClient.isConnected)
                    {
                        if (Ins.GatewayOnline_Local && myTcpClient.isConnected && LocalTcpClientLogin)
                        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 };
@@ -309,9 +326,28 @@
                        }
                        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();
                }
            }
        }
@@ -880,7 +916,6 @@
        {
            LocalCommunicationData receiveObj = new LocalCommunicationData();
            MainPage.Log($"局域网信息: \r\n{receiveString}");
            var res = receiveString.Split("\r\n\r\n");
@@ -912,9 +947,10 @@
                //}
                receiveObj.BodyDataString = res[1];
                if(receiveObj.Topic == CommunicationTopic.ct.HeartBeat)
                if (receiveObj.Topic == CommunicationTopic.ct.HeartBeat + "_reply")
                {
                    Ins.myTcpClient.ClearHeartBeatLog();
                    MainPage.Log("tcp心跳回复");
                    return null;
                }
@@ -924,7 +960,6 @@
                    //判断当前网关是否开启了本地加密
                    if (IsLocalEncryptAndGetAesKey)
                    {
                        MainPage.Log($"局域网信息 开始解密");
                        if (originalReceiveBytes != null)
                        {
                            //拿到原始Bytes数据去解密
@@ -955,6 +990,10 @@
                            //MainPage.Log($"局域网信息: 解密后:" + receiveObj.BodyDataString);
                        }
                    }
                    else
                    {
                        MainPage.Log($"局域网信息: 明文:" + receiveObj.BodyDataString);
                    }
                }
@@ -1008,7 +1047,6 @@
                        OpenTcpClent();
                        LoginGateway();
                    }
                }
@@ -1058,6 +1096,19 @@
                    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