Пример #1
0
 private void FromQueueBroker(IList <string> messages)
 {
     foreach (var message in messages)
     {
         if (message.StartsWith('{'))
         {
             try {
                 var messageRequest = JsonConvert.DeserializeObject <VirtualVacuumRobotSqsMessage>(message);
                 if (messageRequest.Id == _id.ToString() || String.IsNullOrEmpty(messageRequest.Id))
                 {
                     if (IsSame(messageRequest.Action, "start") && !_cleaningLoop)
                     {
                         _cleaningLoop = true;
                     }
                     if (IsSame(messageRequest.Action, "stop"))
                     {
                         _cleaningLoop = false;
                     }
                     if (IsSame(messageRequest.Action, "charge") && !_chargingLoop)
                     {
                         _chargingLoop = true;
                     }
                     if (IsSame(messageRequest.Action, "dustbin"))
                     {
                         _runCount = 0;
                     }
                     if (IsSame(messageRequest.Action, "status"))
                     {
                         RaiseMessage(VacuumEvents.STATUS, PowerPecentage.ToString());
                     }
                     if (IsSame(messageRequest.Action, "shutdown"))
                     {
                         Shutdown();
                     }
                     if (IsSame(messageRequest.Action, "teardown"))
                     {
                         Shutdown();
                         DeleteAllSnsTopics();
                         _queueBroker?.DeleteQueuesWithPrefix();
                     }
                 }
             } catch (Exception ex) {
                 _logger.Log(message + ex.GetBaseException().ToString());
                 break;
             }
         }
     }
 }
Пример #2
0
 public void RuntimeLoop()
 {
     RaiseMessage(VacuumEvents.READY, PowerPecentage.ToString());
     while (_runtimeLoop)
     {
         Thread.Sleep(_timeInterval);
         if (_cleaningLoop)
         {
             StartVacuum();
         }
         if (_chargingLoop)
         {
             ChargeVacuum();
         }
     }
 }
Пример #3
0
        public void ChargeVacuum()
        {
            var chargeRate = _rnd.NextDouble() * (3 - .02) + .02;

            RaiseMessage(VacuumEvents.STARTED_CHARGE);
            _cleaningLoop  = false;
            _chargingLoop  = true;
            PowerPecentage = 0; // Consider battery power dead.
            while (_chargingLoop && PowerPecentage < 100)
            {
                Thread.Sleep(_timeInterval);
                PowerPecentage += chargeRate;
                RaiseMessage(VacuumEvents.CHARGING, PowerPecentage.ToString());
            }
            _chargingLoop = false;
            RaiseMessage(VacuumEvents.SLEEPING);
        }
Пример #4
0
        public void StartVacuum()
        {
            _runCount++;
            var powerPercentageDeclineRnd = _rnd.NextDouble() * (1 - .08) + .08;

            RaiseMessage(VacuumEvents.STARTED);
            _cleaningLoop = true;
            _chargingLoop = false;
            while (_cleaningLoop)
            {
                Thread.Sleep(_timeInterval);
                if (PowerPecentage < 5)
                {
                    _chargingLoop = true;
                }
                if (_chargingLoop)
                {
                    break;
                }
                if (IsStuck())
                {
                    RaiseMessage(VacuumEvents.STUCK, PowerPecentage.ToString());
                    _cleaningLoop = false;
                    break;
                }
                if (_runCount > DustBinFullCount)
                {
                    RaiseMessage(VacuumEvents.DUSTBIN_FULL, PowerPecentage.ToString());
                    _cleaningLoop = false;
                    break;
                }
                PowerPecentage -= powerPercentageDeclineRnd;
                RaiseMessage(VacuumEvents.CLEANING, PowerPecentage.ToString());
            }
            _cleaningLoop = false;
            RaiseMessage(VacuumEvents.ENDED);
        }