Esempio n. 1
0
        public bool CloseSession(int timeout)
        {
            switch (_currentState)
            {
            case ReadyForUpload:
                _currentState |= XModemClientStates.EotSent;
                FrameBufferBlock.Stop();
                WriteData(new byte[] { (byte)XModemRecieverTransmisionStatuses.EOT });
                _uploadStateSignal.WaitOne(timeout);
                break;

            case XModemClientStates.Canceled:
                _uploadStateSignal.WaitOne(timeout);
                CancelationMessage = ParseCancelationOutput(_cancelationOutput);
                break;
            }
            return(IsCompleted);
        }
Esempio n. 2
0
        private byte[] ParseRawData(byte val, bool isOutcome, DateTime timeStamp, bool isFromFile)
        {
            switch (_currentState)
            {
            case 0x00:
                if (val == 0x3E)     // '>'
                {
                    "ParseRawData: Bootloader msg received"._DLOG();
                    _currentState |= XModemClientStates.OptionsMsgReceived;
                    _cancelationOutput.Clear();
                    CancelationMessage = string.Empty;
                    _packetNo          = 1;
                    WriteData(new[] { (byte)XModemRunOptions.UploadGbl });
                }
                break;

            case XModemClientStates.OptionsMsgReceived:
                if (val == 0x64)     // 'd'
                {
                    "ParseRawData: 'begin upload' received"._DLOG();
                    _currentState |= XModemClientStates.BeginUploadMsgReceived;
                }
                break;

            case XModemClientStates.OptionsMsgReceived | XModemClientStates.BeginUploadMsgReceived:
                if (val == (byte)XModemHeaderTypes.C)
                {
                    "ParseRawData: C-start received"._DLOG();
                    _currentState |= XModemClientStates.C_startReceived;
                }
                break;

            case XModemClientStates.OptionsMsgReceived | XModemClientStates.BeginUploadMsgReceived | XModemClientStates.C_startReceived:
                if (val == (byte)XModemHeaderTypes.C)
                {
                    $"ParseRawData: C-confirm received"._DLOG();
                    _currentState    |= XModemClientStates.C_confirmedReceived;
                    _runAppRetryCount = 1;
                    FrameBufferBlock.Start();
                    _uploadStateSignal.Set();
                }
                break;

            case ReadyForUpload:
                var parserState = (XModemHeaderTypes)val;
                if (parserState == XModemHeaderTypes.ACK)
                {
                    FrameBufferBlock.Acknowledge(true);
                }
                else if (parserState == XModemHeaderTypes.NACK)
                {
                    "ParseRawData: Bootloader NACK received"._DLOG();
                    FrameBufferBlock.Acknowledge(false);
                }
                else if (parserState == XModemHeaderTypes.CAN)
                {
                    "ParseRawData: Bootloader CAN received"._DLOG();
                    _currentState = XModemClientStates.Canceled;
                    FrameBufferBlock.Stop();
                    FrameBufferBlock.Acknowledge(false);
                }
                break;

            case ReadyForUpload | XModemClientStates.EotSent:
                if (val == (byte)XModemHeaderTypes.ACK)
                {
                    _currentState |= XModemClientStates.EotConfirmed;
                }
                break;

            case Completed:
                if (val == 0x3E && _runAppRetryCount++ < 3)     // '>'
                {
                    "ParseRawData: run uploaded app"._DLOG();
                    WriteData(new[] { (byte)XModemRunOptions.Run });
                    _uploadStateSignal.Set();
                }
                break;

            case XModemClientStates.Canceled:
                _cancelationOutput.Add(val);
                if (val == 0x3E && _runAppRetryCount++ < 3)     // '>'
                {
                    "ParseRawData: upload failed, run old app"._DLOG();
                    WriteData(new[] { (byte)XModemRunOptions.Run });
                    _uploadStateSignal.Set();
                }
                break;

            default:
                break;
            }
            return(null);
        }
Esempio n. 3
0
 internal void TestSetReady()
 {
     _currentState = ReadyForUpload;
     FrameBufferBlock.Start();
     _uploadStateSignal.Set();
 }