public void Burn(FirmwareProject Project, IProgressToken Progress, CancellationToken CancellationToken) { var r = new Random(); Progress.Start(); for (int i = 0; i < 50; i++) { if (r.Next(1000) < 0.7 * 1000 / 50) throw new BurningException(new Exception("Сработала эмуляция ошибки при прошивании")); Progress.SetProgress(i / 50.0); Thread.Sleep(50); } Progress.OnCompleated(); }
public void WriteFuse(Fuses f, IProgressToken ProgressToken, CancellationToken CancellationToken) { var fuses = new[] { new { MemType = AvrDudeMemoryType.HFuse, Data = f.FuseH, ProgressToken = new SubprocessProgressToken() }, new { MemType = AvrDudeMemoryType.LFuse, Data = f.FuseL, ProgressToken = new SubprocessProgressToken() }, new { MemType = AvrDudeMemoryType.EFuse, Data = f.FuseE, ProgressToken = new SubprocessProgressToken() } }; foreach (var fuse in fuses) { string res = LaunchAvrDude(fuse.MemType, AvrDudeMemoryOperationType.Write, String.Format("0x{0:x2}", fuse.Data), AvrDudeInputFormat.Manual, ProgressToken, CancellationToken); } }
public void Write(byte[] Data, uint InRamAddress, IProgressToken ProgressToken, CancellationToken CancellationToken) { try { using (IProgressController pc = _progressControllerFactory.CreateController(ProgressToken)) { DnwPackage package = DnwPacker.EnpackBuffer(Data, InRamAddress); byte[] buff = package.GetBuff(); for (int offset = 0; offset < buff.Length; offset += _blockSize) { CancellationToken.ThrowIfCancellationRequested(); _connection.Write(buff, offset, Math.Min(_blockSize, buff.Length - offset)); pc.SetProgress(Math.Min((double)(offset + _blockSize) / buff.Length, 1)); } } } catch (DeviceNotFoundSautDnwException e) { throw new UsbDeviceNotFoundDnwBurningException(e); } }
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); } } } } }
public void Burn(FirmwareProject Project, IProgressToken Progress, CancellationToken CancellationToken) { }
private string LaunchAvrDude(AvrDudeMemoryType MemoryType, AvrDudeMemoryOperationType Operation, string Input, AvrDudeInputFormat InputFormat, IProgressToken ProgressToken, CancellationToken CancellationToken) { Process p = _toolLauncher.Execute(_toolBody, new ConnectionAvrDudeParameter(AvrIspConnectionType.Usb), new ProgrammerIdAvrDudeParameter(_programmerKind), new IgnoreSignatureAvrDudeParameter(), new ChipIdAvrDudeParameter(_chipPseudoname), new UCommandParameter(MemoryType, Operation, Input, InputFormat)); using (CancellationToken.Register(p.Kill)) { var subtokens = new[] { new SubprocessProgressToken(0.1), new SubprocessProgressToken(1.0), new SubprocessProgressToken(2.0) }; string output = string.Empty; using (new CompositeProgressManager(ProgressToken, subtokens)) { IEnumerator tokensEnumerator = subtokens.GetEnumerator(); IProgressController progressController = null; bool calculatingProgress = false; int counter = 0; while (true) { CancellationToken.ThrowIfCancellationRequested(); int x = p.StandardError.Read(); if (x != -1) { var c = (char)x; output += c; Debug.Write(c); if (c == '|') { if (!calculatingProgress) { bool tokenExists = tokensEnumerator.MoveNext(); calculatingProgress = true; counter = 0; progressController = _progressControllerFactory.CreateController(tokenExists ? (IProgressToken)tokensEnumerator.Current : null); progressController.SetProgress(0); } else { calculatingProgress = false; progressController.Dispose(); } } if (c == '#' && calculatingProgress) { counter++; progressController.SetProgress(counter / 50.0); } } else if (p.HasExited) break; } } CancellationToken.ThrowIfCancellationRequested(); if (output.Contains("did not find any USB device \"usb\"") || output.Contains("device not found")) throw new ProgrammerNotConnectedAvrDudeException(output); if (output.Contains("Invalid device signature")) throw new InvalidDeviceSignatureAvrDudeException(output); if (output.Contains("initialization failed")) throw new DeviceNotConnectedAvrDudeException(output); if (output.Contains("verification error")) throw new VerificationErrorAvrDudeException(output); if (!output.Contains("written") || !output.Contains("verified")) throw new AvrDudeException("Неизвестная ошибка при работе с AVRDude", output); return string.Empty; } }
public void WriteFlash(FileInfo FlashFile, IProgressToken ProgressToken, CancellationToken CancellationToken) { LaunchAvrDude(AvrDudeMemoryType.Flash, AvrDudeMemoryOperationType.Write, FlashFile.FullName, AvrDudeInputFormat.IntelHex, ProgressToken, CancellationToken); }
public void WriteEeprom(FileInfo EepromFile, IProgressToken ProgressToken, CancellationToken CancellationToken) { LaunchAvrDude(AvrDudeMemoryType.Eeprom, AvrDudeMemoryOperationType.Write, EepromFile.FullName, AvrDudeInputFormat.IntelHex, ProgressToken, CancellationToken); }