private void Link_OnReceivePackage(CommLink sender, LinkEventArgs e)
 {
     while (link.ReceivedPackageQueue.TryDequeue(out LinkPackage package))
     {
         analyzePackage((SBLinkPackage)package);
         //Debug.WriteLine("[Link] Recevie package size= {0} function={1} remain={2}", package.DataSize,package.Function,link.ReceivedPackageQueue.Count);
     }
 }
Exemplo n.º 2
0
        private void parseBuffer()
        {
            isParsingBuffer = true;
            int           offset   = 0;
            bool          flag     = false;
            bool          received = false;
            LinkEventArgs lea      = new LinkEventArgs();
            int           dataused;

            while (offset < bufferSize)
            {
                PackageParseResult res = receivePackage.ReadFromBuffer(buffer, bufferSize, offset, out dataused);
                switch (res)
                {
                case PackageParseResult.NoSTX:
                    offset++;
                    break;

                case PackageParseResult.NoEnoughData:
                    flag = true;
                    break;

                case PackageParseResult.BadCheckSum:
                    offset++;
                    break;

                case PackageParseResult.Yes:
                    offset += dataused;
                    receivePackage.TimeStamp = this.ConnectedTime;
                    //lock (ReceivedPackageQueue)
                    {
                        enqueueHandler.BeginInvoke(receivePackage.Clone(), null, null);
                        //receivedPackageQueue.Enqueue(receivePackage.Clone());
                    }
                    received = true;
                    lea.Package.Add(receivePackage.Clone());
                    break;
                }
                if (flag)
                {
                    break;
                }
            }

            for (int i = offset; i < bufferSize; i++)
            {
                buffer[i - offset] = buffer[i];
            }
            bufferSize     -= offset;
            isParsingBuffer = false;
            if (received)
            {
                OnReceivePackageEvent(this, lea);
            }
        }
Exemplo n.º 3
0
 protected void OnSendPackageEvent(CommLink sender, LinkEventArgs e)
 {
     OnSendPackage?.Invoke(this, e);
 }