public void SynchronizeComponent(FirmwareComponent Component, PackageInformation FirmwareInformation, IProgressAcceptor GlobalProgressAcceptor = null, IProgressAcceptor LocalProgressAcceptor = null) { // Проверяем, можно ли применить программный компонент к данной прошивке if (!Component.Targets.Any(ct => CanApply(ct, Session.Device))) throw new CanUpdateComponentMismatchException(); bool forceReplace = false; #if DEBUG forceReplace = true; #endif PostProgressMessage(GlobalProgressAcceptor, "Получение списка файлов"); var filesOnDevice = Session.ListFiles(); _logger.Debug("FILES:{0}", string.Join("", filesOnDevice.Select(f => String.Format("{3} {0,-16} {1:N0} Bytes [0x{2:x4}]", f.FileName, f.FileSize, f.ControlSum, Environment.NewLine)))); var filesInComponent = Component.Files; var filesToRemove = filesOnDevice.Where(df => filesInComponent.All(cf => cf.RelativePath != df.FileName)).ToList(); var filesToReplace = filesInComponent.Select(componentFile => new { componentFile, deviceFile = filesOnDevice.FirstOrDefault(f => f.FileName == componentFile.RelativePath) }) .Where( pair => pair.deviceFile == null || forceReplace || pair.deviceFile.ControlSum != FudpCrc.CalcCrc(pair.componentFile.Content)) .ToList(); int transferWeight = filesToReplace.Sum(pair => pair.componentFile.Content.Length); try { PostProgressMessage(GlobalProgressAcceptor, "Передача прошивки {0:P0}"); foreach (var fileToRemove in filesToRemove) { PostProgressMessage(LocalProgressAcceptor, "Удаление файла " + fileToRemove.FileName); RemoveFile(fileToRemove); _logger.Info("Файл {0} удалён с устройства", fileToRemove.FileName); } double totalTransferred = 0; foreach (var filePairToReplace in filesToReplace) { IProgressAcceptor subProgressAcceptor = null; if (GlobalProgressAcceptor != null) { subProgressAcceptor = new SubprogressAcceptorRetranslator( GlobalProgressAcceptor, LocalProgressAcceptor, totalTransferred / transferWeight, (double)filePairToReplace.componentFile.Content.Length / transferWeight); } _logger.Info(filePairToReplace.deviceFile == null ? "Создание файла {0}" : "Перезапись файла {0}", filePairToReplace.componentFile); PushFile(filePairToReplace.componentFile, filePairToReplace.deviceFile != null, GlobalProgressAcceptor, subProgressAcceptor); _logger.Info("Файл {0} передан на устройство", filePairToReplace.componentFile); totalTransferred += filePairToReplace.componentFile.Content.Length; } PostProgressMessage(GlobalProgressAcceptor, "Обновление свойств"); Session.SetParam(ParamKeys.MajorVersion, FirmwareInformation.FirmwareVersion.Major); Session.SetParam(ParamKeys.MinorVersion, FirmwareInformation.FirmwareVersion.Minor); Session.SetParam(ParamKeys.LastUpgrateDate, DateTimeFormatter.ToUnixTime(DateTime.Now)); Session.SetParam(ParamKeys.GlobalChecksum, GetGlobalChecksum(Component)); Session.SetParam(ParamKeys.VersionLabel, LabelEncoder.Default.Encode(FirmwareInformation.FirmwareVersionLabel)); _logger.Info("Свойства загрузчика обновлены"); } catch (CanProgFileopException exc) { throw new CanUpdateFileOperationException(exc); } }
public OneTargetUpdater(ComponentTarget Target, FirmwareComponent Component, PackageInformation Information) { this.Target = Target; this.Component = Component; this.Information = Information; }
/// <summary>Вычисляет общую контрольную сумму для всех файлов компонента</summary> private static UInt16 GetGlobalChecksum(FirmwareComponent Component) { return Component.Files.Aggregate((UInt16)0, (sum, file) => (UInt16)(sum ^ FudpCrc.CalcCrc(file.Content))); }
public ModuleProject(ModuleInformation Information, PackageInformation FirmwareInformation, FirmwareComponent FirmwareContent) { this.Information = Information; this.FirmwareInformation = FirmwareInformation; this.FirmwareContent = FirmwareContent; }