Beispiel #1
0
        /// <summary>
        /// Start the timer
        /// </summary>
        private void StartTimer(int tickInterval)
        {
            // if no baseline state has been established, do it now
            if (_hardwareState == null)
            {
                _hardwareState = (irobottypes.RoombaState)_state.Clone();
            }

            if (_tickInterval != tickInterval)
            {
                _tickInterval = tickInterval;
            }

            if (_nextTimer == DateTime.MaxValue)
            {
                _nextTimer = DateTime.Now.AddMilliseconds(_tickInterval);
                Activate(Arbiter.Receive(false, TimeoutPort(_tickInterval), TimerHandler));
            }
            else
            {
                // skip any backlog of timer events
                _nextTimer = DateTime.Now.AddMilliseconds(_tickInterval);

                // Don't need to activate because there is still a pending receive.
            }
        }
Beispiel #2
0
        /// <summary>
        /// The Timer Handler fires every _tickInterval milliseconds
        /// </summary>
        /// <param name="time"></param>
        private void TimerHandler(DateTime time)
        {
            // Stop the timer if we are shutting down
            if (_state.Mode == irobottypes.RoombaMode.Shutdown)
            {
                return;
            }

            // ignore timer if the Create is not initialized.
            if (_state.Mode == irobottypes.RoombaMode.Uninitialized)
            {
                WaitForNextTimer();
                return;
            }

            // Is Polling turned off?
            if (_state.PollingInterval < 0)
            {
                WaitForNextTimer();
                return;
            }

            LogVerbose(LogGroups.Console, "Timer: Starting query");
            bool dataChanged = false;

            UpdateHardwareStateFromEntity(_hardwareState);

            // check each block of state for differences
            if (StateIsDifferent(_hardwareState.Pose, _state.Pose))
            {
                SendNotification <irobotupdates.UpdatePose>(_subMgrPort, _hardwareState.Pose);
                dataChanged = true;
            }
            if (StateIsDifferent(_hardwareState.Sensors, _state.Sensors))
            {
                SendNotification <irobotupdates.UpdateBumpsCliffsAndWalls>(_subMgrPort, _hardwareState.Sensors);
                dataChanged = true;
            }
            if (StateIsDifferent(_hardwareState.Power, _state.Power))
            {
                SendNotification <irobotupdates.UpdatePower>(_subMgrPort, _hardwareState.Power);
                dataChanged = true;
            }
            if (StateIsDifferent(_hardwareState.CliffDetail, _state.CliffDetail))
            {
                SendNotification <irobotupdates.UpdateCliffDetail>(_subMgrPort, _hardwareState.CliffDetail);
                dataChanged = true;
            }

            if (dataChanged)
            {
                _state         = _hardwareState;
                _hardwareState = (irobottypes.RoombaState)_state.Clone();
            }
            else
            {
                _state.LastUpdated           = _hardwareState.LastUpdated;
                _state.Pose.Timestamp        = _hardwareState.Pose.Timestamp;
                _state.Power.Timestamp       = _hardwareState.Power.Timestamp;
                _state.Sensors.Timestamp     = _hardwareState.Sensors.Timestamp;
                _state.CliffDetail.Timestamp = _hardwareState.CliffDetail.Timestamp;
                _state.Telemetry.Timestamp   = _hardwareState.Telemetry.Timestamp;
            }

            WaitForNextTimer();
        }