public bool EndEvent(int sendingNodeID, double time)
        {
            // Returns true if collision occurred

            PriorityQueue<L2NodeEntry, double> tempEvents = new PriorityQueue<L2NodeEntry, double>();
            L2NodeEntry currentEntry;
            double currentTime;
            PriorityQueueItem<L2NodeEntry, double> item;
            bool collided = false;

            while ((SPL_Events.Count > 0) && (SPL_Events.Peek().Priority < -time))
            {
                item = SPL_Events.Dequeue();
                currentTime = -item.Priority;
                currentEntry = item.Value;

                if ((currentEntry.id == sendingNodeID) & (currentEntry.Collision))
                    collided = true;

                ReceiveLevel = ReceiveLevel + currentEntry.BaseReceiveLevel;
                NoiseLevel = NoiseLevel - currentEntry.BaseReceiveLevel;
            }

            while ((SPL_Events.Count > 0) && (SPL_Events.Peek().Priority == time))
            {
                item = SPL_Events.Dequeue();
                if (item.Value.id != sendingNodeID)
                    tempEvents.Enqueue(item);
                else
                {
                    currentEntry = item.Value;

                    if (currentEntry.Collision)
                        collided = true;

                    if (currentID == sendingNodeID)
                    {
                        ReceiveLevel = 0;
                    }
                    else if (ReceiveLevel != 0)
                    {
                        ReceiveLevel = ReceiveLevel + currentEntry.BaseReceiveLevel;
                    }
                    NoiseLevel = NoiseLevel - currentEntry.BaseReceiveLevel;
                }
            }

            while (tempEvents.Count > 0)
            {
                SPL_Events.Enqueue((PriorityQueueItem<L2NodeEntry, double>)tempEvents.Dequeue());
            }

            return collided;
        }
 public L2NodeEntry(int id, SPL bRL, bool collided)
 {
     this.id = id;
     this.BaseReceiveLevel = bRL;
     Collision = collided;
 }
        public void StartEvent(int sendingNodeID, double BaseReceiveLevel, double time, double duration)
        {
            bool thisCollided = false;
            bool prevCollided = false;
            L2NodeEntry l2Entry;

            if (BaseReceiveLevel > NoiseLevel)
            {
                ReceiveLevel = (SPL)BaseReceiveLevel - NoiseLevel;
                NoiseLevel = NoiseLevel + (SPL)BaseReceiveLevel;
                if (isReceiving)
                {
                    prevCollided = true;
                    l2Entry = new L2NodeEntry(currentID, double.NegativeInfinity, prevCollided);
                    SPL_Events.Enqueue(l2Entry, -currentEndTime);
                }

                currentID = sendingNodeID;
                currentEndTime = time + duration;
            }
            else
            {
                ReceiveLevel = ReceiveLevel - (SPL)BaseReceiveLevel;
                NoiseLevel = NoiseLevel + (SPL)BaseReceiveLevel;
            }
            thisCollided = (ReceiveLevel > MinReceiveLevel);
            l2Entry = new L2NodeEntry(sendingNodeID, BaseReceiveLevel, thisCollided);
            SPL_Events.Enqueue(l2Entry, -(time + duration));
        }