Exemple #1
0
        protected bool ProcessMissedPage(int page)
        {
            if (page == _missedPage)
            {
                _missedPageCount++;
            }
            else
            {
                _missedPage      = page;
                _missedPageCount = 1;
            }

            // decide how to proceed
            if (_missedPageCount <= 5)
            {
                // request packet again
                MachineFunctions.JumpToStep("Transfer Packet", WorkerStateMachine);
                return(StepReturn.JumpCommandUsed);
            }

            // failed the upload, jump to end
            SetTransferState(TransferState.FailedLostPackets);

            MachineFunctions.JumpToLast(WorkerStateMachine);
            return(StepReturn.JumpCommandUsed);
        }
        /// <summary>
        /// Process the received data from the attached BinarySocket
        /// </summary>
        /// <param name="page">Which page was returned</param>
        /// <param name="data">The data that was written to the page</param>
        public void ReceiveData(ushort page, List <byte> data)
        {
            _receivedData.Clear();
            _receivedData.AddRange(DataConversions.ConvertUInt16ToList(page));
            _receivedData.AddRange(data.CloneList());

            if (_payload.SequenceEqual(_receivedData))
            {
                // housekeeping variables
                _pointer     += _readLength;
                _currentPage += PagesTransmitted;

                // determine next step
                if (_pointer == _workingFile.Count)
                {
                    // we have reached the end of the file, so tell the system we are done
                    _binarySocketRef.SendBinaryCommand(_bootloaderCommand);

                    // end state machine
                    SetTransferState(TransferState.Succeeded);
                    Stop();
                    return;
                }

                // not done with file, send the next page
                MachineFunctions.JumpToStep("Transfer Packet", WorkerStateMachine);
                return;
            }

            // process the missed packet count
            ProcessMissedPage(_currentPage);
        }
Exemple #3
0
        /// <summary>
        /// Process the data received by the attached BinarySocket
        /// </summary>
        /// <param name="page">Which page was returned</param>
        /// <param name="data">The data that was written to the page</param>
        public void ReceiveData(ushort page, List <byte> data)
        {
            _receivedData.Clear();
            _receivedData.AddRange(DataConversions.ConvertUInt16ToList(page));
            _receivedData.AddRange(data.CloneList());

            if (_payload.SequenceEqual(_receivedData))
            {
                // housekeeping variables
                _pointer     += _readLength;
                _currentPage += PagesTransmitted;

                // send the next page
                MachineFunctions.JumpToStep("Transfer Packet", WorkerStateMachine);
                return;
            }

            // process the missed packet count
            ProcessMissedPage(_currentPage);
        }
        /// <summary>
        /// Process the data received data from the attached BinarySocket
        /// </summary>
        /// <param name="page">Which page was returned</param>
        /// <param name="data">The data that was written to the page</param>
        public void ReceiveData(ushort page, List <byte> data)
        {
            if (page == _currentPage)
            {
                if (data.Count > 0)
                {
                    // we have a page
                    _logs.Add(new LogData(data));
                    _currentPage++;
                    MachineFunctions.JumpToStep("Transfer Packet", WorkerStateMachine);
                    return;
                }

                // transfer complete, set state
                SetTransferState(TransferState.Succeeded);

                // end the transfer
                Stop();
                return;
            }

            // we had a bad packet, try again
            ProcessMissedPage(_currentPage);
        }
 /// <summary>
 /// Change the connection mode of the ThreadedComPortBase.
 /// </summary>
 /// <param name="mode">The new mode to use for selection of the ComPorts.</param>
 /// <param name="selectionRule">The new rule to use for selecting ComPorts when mode = SelectionRule.</param>
 public void ChangeMode(ConnectionMode mode, Func <ComPortInfo, bool> selectionRule = null)
 {
     TargetSelectionRule = selectionRule;
     TargetMode          = mode;
     MachineFunctions.JumpToStep("Searching", WorkerStateMachine);
 }