Exemplo n.º 1
0
        internal void Run(FirmwaringProgressViewModel GlobalProgress, FirmwaringProgressViewModel LocalProgress)
        {
            if (GlobalProgress == null) throw new ArgumentNullException("GlobalProgress");
            GlobalProgress.MessageFormat = "Поиск модулей...";

            var componentsAndTargets = Firmware.Components.SelectMany(c => c.Targets.Select(t => new { Component = c, Target = t }));
            foreach (var cnt in componentsAndTargets)
            {
                var updater = new OneTargetUpdater(cnt.Target, cnt.Component, Firmware.Information);
                updater.Run(GlobalProgress, LocalProgress);
            }
            GlobalProgress.MessageFormat = "Готово";
        }
Exemplo n.º 2
0
        public MainViewModel()
        {
            Progress = new FirmwaringProgressViewModel();
            SubProgress = new FirmwaringProgressViewModel();
            Source = new ManualFirmwareSource(new Dialogs.DialogFileSelector());
            OpenFirmwareCommand = new ActionCommand<String[]>(OpenFirmware, CanOpenFirmware);
            UpdateFirmwareCommand = new ActionCommand(UpdateFirmware, CanUpdateFirmware);
            OpenLogDirectoryCommand = new ActionCommand(OpenLogDirectory);

            var startupFile = GetStartupFile();
            if (startupFile != null)
                Source.OpenFirmware(startupFile);
        }
Exemplo n.º 3
0
        public void FlashDevice(DeviceTicket Ticket, CanPort port, FirmwaringProgressViewModel GlobalProgress, FirmwaringProgressViewModel LocalProgress)
        {
            _logger.Info("-----");
            _logger.Info("Подключаемся к {0}", Ticket);
            PostProgress(GlobalProgress,
                         string.Format("Подключение к модулю (№{0}/{1})...", Ticket.BlockSerialNumber, Ticket.Channel));

            using (CanProg session = CanProg.Connect(port, Ticket))
            {
                _logger.Info("Подключились и начинаем передачу прошивки на {0}", Ticket);
                PostProgress(GlobalProgress, "Передача прошивки {0:P0}", 0);

                var updater = new ComponentUpdater(
                    session);
                updater.SynchronizeComponent(Component, Information, GlobalProgress, LocalProgress);
                PostProgress(GlobalProgress, "Применение изменений...");
                SubmitAckStatus submitStatus = session.Submit(SubmitStatus.Submit);
                _logger.Info("Завершили программирование {0}, статус: {1}", Ticket, submitStatus);
                if (submitStatus != SubmitAckStatus.SubmitSuccessed)
                    throw new SubmitFailsException();
            }
        }
Exemplo n.º 4
0
        public void Run(FirmwaringProgressViewModel GlobalProgress, FirmwaringProgressViewModel LocalProgress)
        {
            _logger.Info("Начинаем обновлять цель {0}", Target);
            while (true)
            {
                try
                {
                    using (AppiDev appi = GetAndConfigureAppiDev(GlobalProgress))
                    {
                        AppiCanPort port = appi.CanPorts[AppiLine.Can1];

                        PostProgress(GlobalProgress, string.Format("Поиск модулей (ПК{0})...", Target.Channel));

                        int counter = Settings.Default.OverlocateCount;
                        var devices = new List<DeviceTicket>();
                        do
                        {
                            List<DeviceTicket> newDevices = new DeviceLocator(port).LocateDevices(GetTicketFor(Target),
                                                                                                  Settings.Default.DeviceLocationTimeoutMs);
                            if (newDevices.Any())
                                devices.AddRange(newDevices);
                            if (devices.Any())
                                counter--;
                            Thread.Yield();
                        } while (!devices.Any() || counter > 0);
                        devices = devices.Distinct().ToList();

                        _logger.Info("Нашли {0} устройств: {1}", devices.Count, string.Join(", ", devices.Select(d => d.ToString())));

                        if (GlobalProgress != null) GlobalProgress.Busy = false;
                        foreach (DeviceTicket dev in devices)
                        {
                            while (true)
                            {
                                try
                                {
                                    FlashDevice(dev, port, GlobalProgress, LocalProgress);
                                    break;
                                }
                                catch (CanProgException) { }
                                catch (FudpException) { }
                                // TODO: Нужно подумать, не стоит ли обрабатывать AppiException здесь, и переподключаться к АППИ внутри этого цикла...
                            }
                        }
                    }
                    break;
                }
                catch (AppiException) { }
            }
        }
Exemplo n.º 5
0
 private static void PostProgress(FirmwaringProgressViewModel Progress, String Message, Boolean IsBusy = true,
                                  Double Value = 0)
 {
     if (Progress != null)
     {
         Progress.MessageFormat = Message;
         Progress.Busy = IsBusy;
         Progress.Value = Value;
     }
 }
Exemplo n.º 6
0
 private static void PostProgress(FirmwaringProgressViewModel Progress, String Message,
                                  Double Value)
 {
     PostProgress(Progress, Message, false, Value);
 }
Exemplo n.º 7
0
        private static AppiDev GetAndConfigureAppiDev(FirmwaringProgressViewModel progress = null)
        {
            PostProgress(progress, "Поиск АППИ");
            AppiDeviceSlot slot;
            do
            {
                slot = WinusbAppiDev.GetDevices().FirstOrDefault();
            } while (slot == null);

            PostProgress(progress, "Подключение к АППИ");
            AppiDev dev = slot.OpenDevice(true);

            PostProgress(progress, "Конфигурация АППИ");
            // Установка скорости в для всех портов
            dev.CanPorts[AppiLine.Can1].BaudRate = App.CurrentApp.Parameters.Can1BaudRate;
            dev.CanPorts[AppiLine.Can2].BaudRate = App.CurrentApp.Parameters.Can2BaudRate;

            return dev;
        }