コード例 #1
0
        protected override void ProcessIncomingData(byte[] data, int start, int len)
        {
            //if (data.Length > 0)
            if (len > 0)
            {
                var type = (Utilities.PackType)data[start];
                switch (type)
                {
                case Utilities.PackType.Udp:
                    var realdata = new byte[len - 1];    //todo , try to reuse
                    Array.Copy(data, start + 1, realdata, 0, realdata.Length);
                    if (Incoming != null)
                    {
                        Incoming.Enqueue(realdata);
                    }
                    break;

                case Utilities.PackType.Kcp:
                    base.ProcessIncomingData(data, start + 1, len - 1);
                    break;

                default:
                    //unknown packtype, drop it
                    debug($"unknown packtype, drop it. typeid = {type}");
                    break;
                }
            }
        }
コード例 #2
0
ファイル: RS232Server.cs プロジェクト: jonmelcher/Capstone
        // *****************************************************************************************************
        //  method  :   private void ReaderProcess()
        //  purpose :   provide a continuous method to run in a parallel thread method which will read in data
        //              from the open Port and place it in the Incoming Queue
        //  notes   :   -1 (STOP_BIT) will be enqueued into Incoming if the end of stream is met
        // *****************************************************************************************************
        private void ReaderProcess()
        {
            while (_isRunning)
            {
                try
                {
                    Incoming.Enqueue((byte)Port.ReadChar());
                }
                catch (TimeoutException) { }

                Thread.Sleep(DEFAULT_READ_DELAY_MS);
            }
        }
コード例 #3
0
 protected override bool QueueOrDiscardPendingPackages(EndPoint endPoint, PendingPacket packet)
 {
     foreach (var pending in pendingPackets)
     {
         if (pending.Key < RemoteSequence)
         {
             Incoming.Enqueue(pending.Value);
         }
     }
     if (!base.QueueOrDiscardPendingPackages(endPoint, packet))
     {
         pendingPackets.Add(packet.Sequence, packet);
         return(false);
     }
     return(true);
 }
コード例 #4
0
ファイル: RFIDScanner.cs プロジェクト: jonmelcher/GarageITron
        private void ProcessRead(byte read)
        {
            switch (read)
            {
            case START_TRANSMISSION:
                Incoming.Clear();
                break;

            case STOP_TRANSMISSION:
                ProcessTransmission();
                break;

            default:
                Incoming.Enqueue(read);
                break;
            }
        }
コード例 #5
0
        public override PendingPacket QueueIncomingPacket(EndPoint endPoint, Packet packet)
        {
            PendingPacket pendingPacket = base.QueueIncomingPacket(endPoint, packet);

            foreach (var pending in pendingPackets)
            {
                if (!base.QueueOrDiscardPendingPackages(pending.Value.RemoteEndPoint, pending.Value))
                {
                    break;
                }
                Incoming.Enqueue(pending.Value);
            }
            long now = DateTime.Now.Ticks;

            for (int i = pendingPackets.Count - 1; i >= 0; i--)
            {
                if (pendingPackets.Keys[i] < RemoteSequence || (now - pendingPackets.Values[0].Sent > PacketExpire.Ticks))
                {
                    pendingPackets.RemoveAt(i);
                }
            }
            return(pendingPacket);
        }
コード例 #6
0
        /// <summary>
        /// Initializes the events
        /// </summary>
        private void InitEvents()
        {
            OnMessage += (message) => {
                TCPFileCode code = (TCPFileCode)message.Content[0];
                string      json = Encoding.UTF8.GetString(message.Content.Skip(1).ToArray());

                if (code == TCPFileCode.Enqueue)
                {
                    TCPFileTransferData data = JsonConvert.DeserializeObject <TCPFileTransferData>(json);

                    Incoming.Enqueue(new TCPFileProgress()
                    {
                        Cache        = new TCPFileCache(data.FullFileName),
                        TransferData = data
                    });

                    using (MemoryStream ms = new MemoryStream()) {
                        TCPReaderWriter.WriteNumber(ms, data.ID, false);
                        Send(TCPFileCode.Reply, ms.ToArray());
                    }
                }
            };
        }