public void ProcessOutput(RegexSurfer Surfer, Terminal Terminal, CancellationToken CancellationToken, SubprocessProgressToken Progress,
                           ProgressControllerFactory ProgressControllerFactory)
 {
     using (IProgressController pc = ProgressControllerFactory.CreateController(Progress))
     {
         pc.SetDescription("Проверка прошивки...");
         pc.SetProgress(0);
         Surfer.SeekForMatches(Terminal, CancellationToken,
                               new DelegateExpectation(
                                   new Regex(@"Complete (?<progress>\d+)%.*0x(?<written>[0-9a-fA-F]+) bytes written by applet",
                                             RegexOptions.Compiled | RegexOptions.Singleline), false,
                                   m => pc.SetProgress(0.01 * int.Parse(m.Groups["progress"].Value))),
                               new DelegateExpectation(
                                   @"Sent file & Memory area content \(address: 0x[0-9a-fA-F]+, size: \d+ bytes\) (?<result>.+) !",
                                   m =>
                                   {
                                       switch (m.Groups["result"].Value)
                                       {
                                           case "match exactly":
                                               return true;
                                           case "do not match":
                                               throw new ComparingFailsSambaException();
                                           default:
                                               throw new ApplicationException("Непонятный вывод:\n\n" + Terminal.Log);
                                       }
                                   }));
     }
 }
예제 #2
0
 public void ProcessOutput(RegexSurfer Surfer, Terminal Terminal, CancellationToken CancellationToken, SubprocessProgressToken Progress,
                           ProgressControllerFactory ProgressControllerFactory)
 {
     using (IProgressController pc = ProgressControllerFactory.CreateController(Progress))
     {
         pc.SetDescription("Стирание FLASH...");
         pc.SetProgress(0);
         Surfer.SeekForMatches(Terminal, CancellationToken, new BarrierExpectation(@"GENERIC::EraseAll"));
     }
 }
예제 #3
0
        protected override void OperateImpl(OperatingContext Context, CancellationToken CancellationToken)
        {
            var transferProgress = new SubprocessProgressToken();
            var checkProgress = new SubprocessProgressToken();

            using (new CompositeProgressManager(Progress, transferProgress, checkProgress))
            {
                Context.Surfer.SeekForMatches(Context.Terminal, CancellationToken,
                                              new CommandExpectation(@"SMDKC100 #", Context.Terminal, "dnw {0:x}", _address));
                Context.Surfer.SeekForMatches(Context.Terminal, CancellationToken,
                                              new AbortExpectation(@"SMDKC100 #", m => new UnexpectedOutputDnwException()),
                                              new BarrierExpectation(@"Insert a OTG cable into the connector!"),
                                              new BarrierExpectation(@"OTG cable Connected!"));

                Thread.Sleep(500);
                using (IProgressController pc = Context.ProgressControllerFactory.CreateController(transferProgress))
                {
                    pc.SetDescription("Подключение к U-Boot по USB...");
                    using (UsbConnection usb = Context.Usb.Connect(_usbConnectionTimeout, CancellationToken, UsbBlockSize))
                    {
                        pc.SetDescription(string.Format("Отправка {0} по USB {{0:P0}}", _dataName), transferProgress);
                        Context.Surfer.SeekForMatches(Context.Terminal, CancellationToken,
                                                      new AbortExpectation(@"SMDKC100 #", m => new UnexpectedOutputDnwException()),
                                                      new BarrierExpectation(@"Now, Waiting for DNW to transmit data"));
                        Thread.Sleep(500);
                        usb.Write(_data, _address, transferProgress, CancellationToken);
                    }
                }

                using (IProgressController pc = Context.ProgressControllerFactory.CreateController(checkProgress))
                {
                    pc.SetDescription(string.Format("Подсчёт контрольной суммы {0} {{0:P0}}", _dataName), checkProgress);
                    int i = 0;
                    Context.Surfer.SeekForMatches(Context.Terminal, CancellationToken,
                                                  new BarrierExpectation(@"Checksum is being calculated"));

                    Context.Surfer.SeekForMatches(Context.Terminal, CancellationToken,
                                                  new AbortExpectation(@"SMDKC100 #", m => new UnexpectedOutputDnwException()),
                                                  new DelegateExpectation(@"^\.$", false,
                                                                          match => pc.SetProgress((double)(++i) * 1041360 / _data.Length)),
                                                  new DelegateExpectation(@"Checksum (?<result>.*)\n", true,
                                                                          match =>
                                                                          {
                                                                              if (match.Groups["result"].Value != "O.K.")
                                                                              {
                                                                                  throw new UsbTransmitChecksumMismatchDnwBurningException(
                                                                                      match.Groups["result"].Value);
                                                                              }
                                                                          }, SurfingMethod.ByCharacter));
                }
            }
        }
예제 #4
0
 public void ProcessOutput(RegexSurfer Surfer, Terminal Terminal, CancellationToken CancellationToken, SubprocessProgressToken Progress,
                           ProgressControllerFactory ProgressControllerFactory)
 {
     using (IProgressController pc = ProgressControllerFactory.CreateController(Progress))
     {
         pc.SetDescription("Передача прошивки {0:P0}", Progress);
         int written = 0;
         Surfer.SeekForMatches(Terminal, CancellationToken,
                               new DelegateExpectation(
                                   new Regex(@"Complete (?<progress>\d+)%.*0x(?<written>[0-9a-fA-F]+) bytes written by applet",
                                             RegexOptions.Compiled | RegexOptions.Singleline),
                                   m =>
                                   {
                                       pc.SetProgress(0.01 * int.Parse(m.Groups["progress"].Value));
                                       written += int.Parse(m.Groups["written"].Value, NumberStyles.HexNumber);
                                       return written >= _fileSize;
                                   }));
     }
 }
예제 #5
0
        public void Execute(CancellationToken CancellationToken, IProgressToken ProgressToken, string BoardName, params ISambaAction[] Actions)
        {
            var initializationProgressToken = new SubprocessProgressToken(0);
            Dictionary<ISambaAction, SubprocessProgressToken> actionsProgressTokens = Actions.ToDictionary(a => a, a => new SubprocessProgressToken(a.Weight));

            using (new CompositeProgressManager(ProgressToken, new[] { initializationProgressToken }.Concat(actionsProgressTokens.Values).ToList()))
            {
                using (TemporaryFile scriptFile = CreateScriptFile(Actions))
                {
                    Process p = _toolLauncher.Execute(_toolBody,
                                                      new ProgrammerParameter(ProgrammerPath),
                                                      new BoardNameParameter(BoardName),
                                                      new ScriptPathParameter(scriptFile.FileInfo));

                    using (CancellationToken.Register(p.Kill))
                    {
                        var rs = new RegexSurfer();
                        using (var terminal = new Terminal(new ProcessTerminalCore(p)))
                        {
                            using (IProgressController pc = _progressControllerFactory.CreateController(initializationProgressToken))
                            {
                                pc.SetDescription("Инициализация программатора...");
                                rs.SeekForMatches(terminal, CancellationToken,
                                                  new BarrierExpectation(@"Command line mode : Execute script file"),
                                                  new AbortExpectation(@"-E- Invalid device or board!", m => new DeviceIsNotConnectedSambaException()),
                                                  new AbortExpectation(@"-E- Connection (?<programmer>.*) not found",
                                                                       m => new ProgrammerIsNotConnectedSambaException(m.Groups["programmer"].Value)));
                            }

                            foreach (ISambaAction action in Actions)
                                action.ProcessOutput(rs, terminal, CancellationToken, actionsProgressTokens[action], _progressControllerFactory);
                        }
                    }
                }
            }
        }
예제 #6
0
 protected OperationBase(double ProgressWeight)
 {
     Progress = new SubprocessProgressToken(ProgressWeight);
 }