예제 #1
0
 internal void MarkASDUAsConfirmed(int index, long timestamp)
 {
     if (asduQueue != null)
     {
         asduQueue.MarkASDUAsConfirmed(index, timestamp);
     }
 }
예제 #2
0
        private bool CheckSequenceNumber(int seqNo)
        {
            lock (sentASDUs)
            {
                /* check if received sequence number is valid */

                bool seqNoIsValid            = false;
                bool counterOverflowDetected = false;
                int  oldestValidSeqNo        = -1;

                if (oldestSentASDU == -1)
                { /* if k-Buffer is empty */
                    if (seqNo == sendCount)
                    {
                        seqNoIsValid = true;
                    }
                }
                else
                {
                    // Two cases are required to reflect sequence number overflow
                    if (sentASDUs[oldestSentASDU].seqNo <= sentASDUs[newestSentASDU].seqNo)
                    {
                        if ((seqNo >= sentASDUs[oldestSentASDU].seqNo) &&
                            (seqNo <= sentASDUs[newestSentASDU].seqNo))
                        {
                            seqNoIsValid = true;
                        }
                    }
                    else
                    {
                        if ((seqNo >= sentASDUs[oldestSentASDU].seqNo) ||
                            (seqNo <= sentASDUs[newestSentASDU].seqNo))
                        {
                            seqNoIsValid = true;
                        }

                        counterOverflowDetected = true;
                    }

                    if (sentASDUs[oldestSentASDU].seqNo == 0)
                    {
                        oldestValidSeqNo = 32767;
                    }
                    else
                    {
                        oldestValidSeqNo = sentASDUs[oldestSentASDU].seqNo - 1;
                    }

                    if (oldestValidSeqNo == seqNo)
                    {
                        seqNoIsValid = true;
                    }
                }

                if (seqNoIsValid == false)
                {
                    DebugLog("Received sequence number out of range");
                    return(false);
                }

                if (oldestSentASDU != -1)
                {
                    /* remove confirmed messages from list */
                    do
                    {
                        /* skip removing messages if confirmed message was already removed */
                        if (counterOverflowDetected == false)
                        {
                            if (seqNo < sentASDUs[oldestSentASDU].seqNo)
                            {
                                break;
                            }
                        }

                        if (seqNo == oldestValidSeqNo)
                        {
                            break;
                        }

                        /* remove from server (low-priority) queue if required */
                        if (sentASDUs[oldestSentASDU].queueIndex != -1)
                        {
                            asduQueue.MarkASDUAsConfirmed(sentASDUs[oldestSentASDU].queueIndex,
                                                          sentASDUs[oldestSentASDU].entryTime);
                        }

                        if (sentASDUs[oldestSentASDU].seqNo == seqNo)
                        {
                            /* we arrived at the seq# that has been confirmed */

                            if (oldestSentASDU == newestSentASDU)
                            {
                                oldestSentASDU = -1;
                            }
                            else
                            {
                                oldestSentASDU = (oldestSentASDU + 1) % maxSentASDUs;
                            }

                            break;
                        }

                        oldestSentASDU = (oldestSentASDU + 1) % maxSentASDUs;

                        int checkIndex = (newestSentASDU + 1) % maxSentASDUs;

                        if (oldestSentASDU == checkIndex)
                        {
                            oldestSentASDU = -1;
                            break;
                        }
                    } while (true);
                }
            }

            return(true);
        }