wxr
2020-12-17 014abc547ffd1a9f23c58fd7a471dffc5933fdd3
HDL_ON/DAL/DriverLayer/Control_Udp.cs
@@ -29,6 +29,7 @@
        /// 所有对一端口的控制都会放到这个集合里
        /// </summary>
        static List<Control_Udp> controlList = new List<Control_Udp>(50);
        public System.Net.IPEndPoint EndPoint
        {
@@ -65,7 +66,7 @@
        /// <summary>
        /// 重发验证
        /// </summary>
        public void ReceiveRepeatManager(string receiveFlag)
        public static void ReceiveRepeatManager(string receiveFlag,byte []usefulBytes)
        {
            for (int i = 0; i < controlList.Count; i++)
            {
@@ -623,7 +624,7 @@
                {
                    for (int i = 0; i < controlList.Count;)
                    {
                        if (controlList[i] == null || 3 <= controlList[i].Packet.HaveSendCount)
                        if (controlList[i] == null || 3 <= controlList[i].packet.HaveSendCount)
                        {
                            controlList.RemoveAt(i);
                        }
@@ -692,7 +693,7 @@
        void run()
        {
            allDone.Set();
            Packet.HaveSendCount = 4;
            packet.HaveSendCount = 4;
        }
        //数据发送处理
@@ -706,7 +707,7 @@
                new System.Threading.Thread(() =>
                {
                    System.Threading.Thread.Sleep(1000);
                    UdpSocket._BusSocket.Start(6000);
                    UdpSocket._BusSocket.Start(UdpSocket._BusSocket.Port);
                    controlLostCount = 0;
                })
                { IsBackground = true }.Start();
@@ -714,17 +715,17 @@
            try
            {
                MainPage.Log("发送数据:" + SendFlag);
                UdpSocket._BusSocket.AsyncBeginSend(Packet);
                Packet.HaveSendCount--;
                //MainPage.Log("发送数据:" + SendFlag);
                UdpSocket._BusSocket.AsyncBeginSend(packet);
                packet.HaveSendCount--;
                //这里是重发两次
                while (Packet.HaveSendCount < 3)
                while (packet.HaveSendCount < 3)
                {
                    if (Packet.FlagDateTime.AddMilliseconds(1000).Ticks <= DateTime.Now.Ticks)
                    if (packet.FlagDateTime.AddMilliseconds(1000).Ticks <= DateTime.Now.Ticks)
                    {
                        MainPage.Log("重发数据:" + SendFlag);
                        UdpSocket._BusSocket.AsyncBeginSend(Packet);
                        UdpSocket._BusSocket.AsyncBeginSend(packet);
                        controlLostCount++;
                    }
                    System.Threading.Thread.Sleep(100);
@@ -743,7 +744,7 @@
        /// <summary>
        /// 当前数据包
        /// </summary>
        Packet Packet;
        Packet packet;
        /// <summary>
        /// 记录发送数据包
        /// </summary>
@@ -800,14 +801,14 @@
        {
            try
            {
                Packet = new Packet(target.SendBytes, target.IPEndPoint);
                Packet.HaveSendCount = 3 - sendCount;
                packet = new Packet(target.SendBytes, target.IPEndPoint);
                packet.HaveSendCount = 3 - sendCount;
                signPacket(target);
                System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(managerSendCount));
                thread.IsBackground = true;
                thread.Start(Packet);
                thread.Start(packet);
                if (isWait)
                {
@@ -832,11 +833,11 @@
                
                var sendBytes = Control.Ins.ConvertSendBodyData(CommunicationTopic.SearchLoaclGateway, bodyString);
                //组播发送
                Packet = new Packet(sendBytes, new System.Net.IPEndPoint(System.Net.IPAddress.Parse("239.0.168.188"), 8585));
                Packet.HaveSendCount = 4;//ps:没有重发,后期有时间可以增加重发判断
                packet = new Packet(sendBytes, new System.Net.IPEndPoint(System.Net.IPAddress.Parse("239.0.168.188"), 8585));
                packet.HaveSendCount = 4;//ps:没有重发,后期有时间可以增加重发判断
                System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(managerSendCount));
                thread.IsBackground = true;
                thread.Start(Packet);
                thread.Start(packet);
                //wait();不需要等待
            }
            catch (Exception ex)
@@ -844,24 +845,24 @@
                MainPage.Log($"Send bus data error {ex.Message}");
            }
        }
        /// <summary>
        /// 发送udp A协议数据
        /// </summary>
        public void SendLocalHdlLinkData(byte[] sendBytes)
        public void SendLocalHdlLinkData(byte[] sendBytes,string id, bool isWait=false)
        {
            if (controlLostCount > 3)
            {
                UdpSocket._BusSocket.Stop();
                UdpSocket._BusSocket.Start(8585);
                controlLostCount = 0;
            }
            Packet = new Packet(sendBytes, new System.Net.IPEndPoint(System.Net.IPAddress.Parse(Control.Ins.reportIp), 8585));
            Packet.HaveSendCount = 2;//ps:没有重发,后期有时间可以增加重发判断
            packet = new Packet(sendBytes, new System.Net.IPEndPoint(System.Net.IPAddress.Parse(Control.Ins.reportIp), 8585));
            sendFlag = id;
            System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(managerSendCount));
            thread.IsBackground = true;
            thread.Start(Packet);
            controlLostCount++;
            thread.Start(packet);
            if (isWait)
            {
                wait();
            }
            //MainPage.Log($"发送Hdl-Link数据,IP:{Control.Ins.reportIp}:8585");
        }
    }
}