예제 #1
0
        public static void Main()
        {
            switch (SystemUpdate.GetMode())
            {
            case SystemUpdate.SystemUpdateMode.NonFormatted:
                SystemUpdate.EnableBootloader();
                break;

            case SystemUpdate.SystemUpdateMode.Bootloader:
                throw new InvalidOperationException("We must be in application mode!");
            }

            SystemUpdate.AlwaysRunBootloader(true);

            _led = new Led(LedPin);

            Debug.Print("App v1.0");
            _led.BlinkOn(1500);

            //Debug.Print("App v2.0");
            //_led.BlinkOn(500);

            _ldrButton              = new InterruptPort(LdrPin, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
            _ldrButton.OnInterrupt += (d1, d2, t) => SystemUpdate.AccessBootloader();

            Thread.Sleep(Timeout.Infinite);
        }
예제 #2
0
    void Awake()
    {
        self    = this;
        systems = new List <IUpdate>(32);
        systems.Add(new Simulation_OOP.FloatUpdate(4096 * 8));

        jobs = new List <IJobUpdate>(32);
        jobs.Add(new LinearMovement());
        jobs.Add(new AcceleratedMovement());
    }
예제 #3
0
 public void ExecuteScheduledAction(ScheduledAction scheduledAction)
 {
     using var client = SshManager.CreateSshClient(System);
     if (scheduledAction.ScheduledActionType == ScheduledActionType.Packages)
     {
         Packages.UpdatePackages(client, scheduledAction);
     }
     else if (scheduledAction.ScheduledActionType == ScheduledActionType.System)
     {
         SystemUpdate.ExecuteUpdate(client, scheduledAction);
     }
 }
예제 #4
0
        private void SaveSoftwareFilePathToDbstring(string version, string type, string url, string plistUrl)
        {
            var systemUpdateService = new SystemUpdateService();
            var systemUpdate        = new SystemUpdate
            {
                Version    = version,
                Type       = type,
                Url        = url,
                UpdateTime = DateTime.Now,
                PlistUrl   = plistUrl
            };

            systemUpdateService.AddSystemUpdate(systemUpdate);
            systemUpdateService.Save();
        }
예제 #5
0
        public async Task <IActionResult> Create([Bind(PKey.SUPram)] SystemUpdate systemUpdate)
        {
            if (ModelState.IsValid)
            {
                systemUpdate.Guid       = Guid.NewGuid();
                systemUpdate.CreateTime = DateTime.Now;
                systemUpdate.UpdateTime = DateTime.Now;
                systemUpdate.Time       = DateTime.Now;
                context.Add(systemUpdate);
                await context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(systemUpdate));
        }
예제 #6
0
        public static void Main()
        {
            bool switchToBootLoader = false;

            var mode = SystemUpdate.GetMode();

            if (mode == SystemUpdate.SystemUpdateMode.NonFormatted)
            {
                // This erases the application!
                Debug.Print("SystemUpdate.EnableBootLoader - formatting !!!!!!");
                SystemUpdate.EnableBootloader();
            }

            if (mode == SystemUpdate.SystemUpdateMode.Bootloader)
            {
                // Switch to application mode.
                Debug.Print("SystemUpdate.AccessApplication");
                SystemUpdate.AccessApplication();
            }

            if (mode == SystemUpdate.SystemUpdateMode.Application)
            {
                // Developer use only: Switch to BootLoader
                if (switchToBootLoader)
                {
                    SystemUpdate.AccessBootloader();
                }
            }

            // LED - Flashing for 5 seconds.
            LED.State = LED.LedState.FlashingData;
            Thread.Sleep(5000);

            // LED - switch on.
            LED.State = LED.LedState.On;

            // Start PDA comms thread.
            PDA.Start();

            // Start meter comms thread.
            EMR3.Start();

            while (true)
            {
                // Sleep a second
                Thread.Sleep(1000);
            }
        }
예제 #7
0
        public static void Main()
        {
            if (SystemUpdate.GetMode() != SystemUpdate.SystemUpdateMode.Bootloader)
            {
                throw new InvalidOperationException("We must be in bootloader mode!");
            }

            Debug.EnableGCMessages(false);

            InitializeLed();
            InitializeLoaderButton();
            InitializeBootloader();
            InitializeWatchdog();
            InitializeRadio();

            Debug.Print("Waiting for data");
            Thread.Sleep(Timeout.Infinite);
        }
예제 #8
0
 private static void InitializeWatchdog()
 {
     _watchdog = new Timer(s =>
     {
         if (_bootloader.Started)
         {
             Debug.Print(_bootloader.CurrentProgress + "%");
             _watchdog.Change(5000, -1);
         }
         else
         {
             Debug.Print("Exiting bootloader");
             _watchdog.Dispose();
             _radio.Disable();
             _bootloader.Stop();
             _led.BlinkOff();
             _led.Off();
             SystemUpdate.AccessApplication();
         }
     },
                           null, 5000, -1);
 }
예제 #9
0
        public Dictionary <string, string> GetSystemInformation()
        {
            using var sshClient = SshManager.CreateSshClient(System);
            using var dbContext = DbContextFactory.CreateDbContext();
            var hasNotFinishedScheduledActions = dbContext.ScheduledActions.SystemHasNotFinishedUpdate(System);

            var packagesActions = ActionsProvider.GetPackagesActions(sshClient, hasNotFinishedScheduledActions).ToList();

            var vulnerablePackages = Audit.GetVulnerablePackages(sshClient);
            var systemUpdateInfo   = SystemUpdate.GetUpdateInfo(sshClient);

            System.PackageActions           = packagesActions.Count;
            System.HasSystemUpdateAvailable = systemUpdateInfo.HasUpdate;
            System.UpdatesFetchedAt         = DateTime.Now;

            if (!string.IsNullOrEmpty(vulnerablePackages?.Trim()))
            {
                System.AddProblem("Found vulnerable packages!!!");
            }

            var result = new Dictionary <string, string>
            {
                { "Hostname", new Hostname().GetHostname(sshClient) },
                { "Logged users", Uptime.CurrentLoggedUsers(sshClient) },
                {
                    "Kernel\nUserland\nRunning",
                    $"{SystemVersion.GetKernel(sshClient)}{SystemVersion.GetUserland(sshClient)}{SystemVersion.GetRunning(sshClient)}"
                },
                { "Vulnerable packages", vulnerablePackages },
                { $"Packages actions ({System.PackageActions})", string.Join("\n", packagesActions) },
            };

            if (System.HasSystemUpdateAvailable)
            {
                result.Add("Has system update", System.HasSystemUpdateAvailable.ToString());
            }

            return(result);
        }
예제 #10
0
        /// <summary>
        /// Determines which method to run based on Boot Mode & Device
        /// </summary>
        public static void Main()
        {
            // Create instance of API
            API = new PyxisAPI();

            // Handle Emulator
            if (API.ActiveDevice == PyxisAPI.DeviceType.Emulator)
            {
                BootProcess();
                Thread.Sleep(-1);
            }

            // Handle Boot Modes
            switch (SystemUpdate.GetMode())
            {
            case SystemUpdate.SystemUpdateMode.NonFormatted:

                // Display IFU Prep Screen
                bAniBoot = true;
                Thread thBoot = new Thread(PrepBootScreen);
                thBoot.Priority = ThreadPriority.Highest;
                thBoot.Start();

                SystemUpdate.EnableBootloader();
                break;

            case SystemUpdate.SystemUpdateMode.Bootloader:
                throw new Exception("Invalid Boot Mode!");

            case SystemUpdate.SystemUpdateMode.Application:
                BootProcess();
                break;
            }


            // Keep thread alive
            Thread.Sleep(-1);
        }
예제 #11
0
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="entity">修改类</param>
        /// <returns></returns>
        public ReturnModel Update(SystemUpdate entity)
        {
            //结果对象
            ReturnModel returnModel = new ReturnModel();

            try
            {
                //生成对象
                SystemModel model = _mapper.Map <SystemModel>(entity);
                //非空验证
                returnModel.msg = systemDal.Validation(model, DbOperType.Insert);
                if (!string.IsNullOrWhiteSpace(returnModel.msg))
                {
                    returnModel.code = ReturnCode.is_null;
                    return(returnModel);
                }
                //重复验证
                if (systemDal.IsExists(model.system_name))
                {
                    returnModel.code = ReturnCode.is_repeat;
                    returnModel.msg  = "系统名称已经存在";
                    return(returnModel);
                }

                model.system_id = Guid.NewGuid().ToString();
                systemDal.Insert(model);
                returnModel.succeded = true;
                returnModel.data     = model.system_id;
                returnModel.code     = ReturnCode.success;
                return(returnModel);
            }
            catch (Exception ex)
            {
                returnModel.code = ReturnCode.abnormal;
                returnModel.msg  = ex.Message;
                return(returnModel);
            }
        }
예제 #12
0
 private static void InitializeLoaderButton()
 {
     Debug.Print("Initializing loader button...");
     _ldrButton              = new InterruptPort(LdrPin, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
     _ldrButton.OnInterrupt += (d1, d2, t) => SystemUpdate.AccessApplication();
 }
예제 #13
0
 public virtual void OnSystemUpdate(SystemUpdateEventArgs e)
 {
     SystemUpdate?.Invoke(this, e);
 }
예제 #14
0
 public SystemUpdateInfo GetInformationAboutSystemUpdate()
 {
     using var client = SshManager.CreateSshClient(System);
     return(SystemUpdate.GetUpdateInfo(client));
 }
예제 #15
0
        public static void ProcessMessage(string message)
        {
            lock (lockObj)
            {
                try
                {
                    string json = "{\"Command\": \"\", \"Result\": -99}";

                    Debug.Print("Received: " + message);

                    // Check EMR3 thread is running.
                    while (EMR3.IsRunning() == false)
                    {
                        Thread.Sleep(250);
                    }

                    // Check message is valid.
                    string[] parts = message.Split(new char[] { ',' });

                    // Check there is at least one part
                    if (parts.Length >= 1)
                    {
                        switch (parts[0])
                        {
                        case "BL":      // Bootloader.
                            SystemUpdate.AccessBootloader();
                            break;

                        case "Gv":      // Get Version.
                            json = "{\"Command\": \"Gv\", \"Result\": 0, \"Version\": " + Program.MajorVersion + "." + Program.MinorVersion + ", \"Model\": \"" + Program.Model + "\"}";
                            break;

                        case "Gf":      // Get features.
                            EMR3.GetFeatures(out json);
                            break;

                        case "Gt":      // Get temperature.
                            EMR3.GetTemperature(out json);
                            break;

                        case "Gs":      // Get status.
                            EMR3.GetStatus(out json);
                            break;

                        case "Gpl":      // Get preset litres.
                            EMR3.GetPreset(out json);
                            break;

                        case "Grl":      // Get realtime litres.
                            EMR3.GetRealtime(out json);
                            break;

                        case "Gtc":      // Get transaction count
                            EMR3.GetTranCount(out json);
                            break;

                        case "Gtr":      // Get transaction record
                            if (parts.Length == 2)
                            {
                                EMR3.GetTran(parts[1], out json);
                            }
                            break;

                        case "Spl":     // Set polling.
                            if (parts.Length == 2)
                            {
                                EMR3.SetPolling(parts[1], out json);
                            }
                            break;

                        case "Sp":      // Set preset.
                            if (parts.Length == 2)
                            {
                                EMR3.SetPreset(parts[1], out json);
                            }
                            break;

                        case "NOP":
                            json = "{\"Command\": \"NOP\", \"Result\": 0}";
                            break;

                        default:
                            json = "{\"Command\": \"" + parts[0] + "\", \"Result\": -99}";
                            break;
                        }
                    }

                    // Send reply to PDA.
                    SendMessage(json);

                    Debug.Print("PDA sent: " + json);
                }
                catch (Exception ex)
                {
                    Debug.Print("PDA.ProcessMessage: Exception " + ex.Message);
                }
            }
        }