예제 #1
0
        private void btnInjectTypeError_Click(object sender, EventArgs e)
        {
            int errorNumber = 13;
            int numberOfBit = HammingHelper.GetTotalSize(HammingHelper.HammingDataSplitNumber);

            if (numErrorCorrectible.Validate())
            {
                for (int i = (int)numErrorCorrectible.Value; i > 0; --i)
                {
                    cable.InsertRandomErrors(1, errorNumber * numberOfBit, (errorNumber + 1) * numberOfBit);
                    ++errorNumber;
                }
            }
            if (numErrorDetectable.Validate())
            {
                for (int i = (int)numErrorDetectable.Value; i > 0; --i)
                {
                    cable.InsertRandomErrors(2, errorNumber * numberOfBit, (errorNumber + 1) * numberOfBit);
                    ++errorNumber;
                }
            }
            if (numIrrecoverable.Validate())
            {
                for (int i = (int)numIrrecoverable.Value; i > 0; --i)
                {
                    cable.InsertRandomErrors(3, errorNumber * numberOfBit, (errorNumber + 1) * numberOfBit);
                    ++errorNumber;
                }
            }
        }
예제 #2
0
        public Station(
            Constants.StationId stationType,
            ITransmitter transmitter,
            int bufferSize,
            int timeoutInMs,
            bool detectionOnly,
            FileStream inputFileStream,
            FileStream outputFileStream,
            Constants.ShowFrameDelegate sendFrame)
        {
            this.StationId         = stationType;
            this.transmitter       = transmitter;
            this.BufferSize        = bufferSize;
            InputBuffer            = new Dictionary <int, Frame>();
            OutputBuffer           = new Dictionary <int, Frame>();
            this.TimeoutInMs       = timeoutInMs;
            this.CorrectionMode    = detectionOnly ? HammingHelper.Mode.DETECT : HammingHelper.Mode.CORRECT;
            this.inputFileStream   = inputFileStream;
            this.outputFileStream  = outputFileStream;
            this.sendFrameDelegate = sendFrame;
            StopExecution          = false;
            ExecutionStopped       = new ManualResetEvent(false);

            // Initialize constants
            int frameSizeBeforeHamming = HammingHelper.GetDataSize(Constants.FrameSize * 8) / 8;
            int realBitCount           = HammingHelper.GetTotalSize(frameSizeBeforeHamming * 8);

            EncodedFramePadding = Constants.FrameSize * 8 - realBitCount;
            int frameHeaderSize = Frame.HeaderSize();

            DataSizeInFrame = frameSizeBeforeHamming - frameHeaderSize;
            MaxSequence     = (UInt16)(bufferSize * 2 - 1);

            // Initialize fields
            FirstFrameSent = 0;
            NextFrameToSendSequenceNumber = 0;
            NextFrameToReceive            = 0;

            // Since frames cannot use MaxSequence as a sequence number, we use it for LastFrameSequenceNumberForNak.
            // This is meant to ensure that no Frame matches this field if there was no Nak sent.
            LastFrameSequenceNumberForNak = MaxSequence;

            // Initialise ack timer logic
            AckTimer = new System.Timers.Timer(AckTimeout);
            // When the timer ends, we need to inform the program that we need to send an Ack now. Also stop the timer.
            AckTimer.Elapsed += (sender, e) => { sendAck = true; AckTimer.Stop(); Console.WriteLine("ack timer elapsed"); };
            sendAck           = false;

            HighPriorityFrames = new Queue <Frame>();
            TimeoutTimers      = new ConcurrentDictionary <UInt16, System.Timers.Timer>();
        }
예제 #3
0
 public void TestGetTotalSize()
 {
     Assert.AreEqual(13, HammingHelper.GetTotalSize(8));
     Assert.AreEqual(26, HammingHelper.GetTotalSize(16));
 }