void test_ProcessTasks_should_execute_tasks(void)
{
  ProcessTasks_t process_tasks;

  Blinker_Service_Expect(&process_tasks.blinker);
	Echo_Service_Expect(&process_tasks.echo, &process_tasks.serial);

  ProcessTasks(&process_tasks);
}
void QueueSchedule::Thread(void)
{
	bool temp = false;
	stringstream sstr;
	vector< Room* >::iterator it;
	LoopsCounter = 0;
	do
	{
		if (!_onMacro)
		{
			if (_isRandom)
			{
				for (int i = 0; i < RoomSize; i++)
				{
					Rooms[i]->RandomBehaviour();
				}
			}
			_t1 = high_resolution_clock::now();
			for (int i = 0; i < RoomSize; i++)
			{
				//Check if we have a priority event
				ProcessTasks(Rooms[i]);
			}

			_t2 = high_resolution_clock::now();
			_time_span1 = duration_cast<duration<double>>(_t2 - _t1);
			if ((temp || _printTime) && _time_span1.count() != 0)
			{
				sstr.str(string());
				sstr << "> Loop time: ";
				sstr << _time_span1.count() << endl;
				UI::Print(sstr.str());
				temp = false;
				_printTime = false;
			}

			LoopsCounter++;

			if (_isLoopWait)
			{
				//Loop wait here:
				///delay(50);
			}
		}
	} while (!_isExit);
}
void PrioritySchedule::Thread(void)
{
	bool temp = false;
	stringstream sstr;
	vector< Room* >::iterator it;
	high_resolution_clock::time_point t3;
	LoopsCounter = 0;
	do
	{
		if (!_onMacro)
		{
			if (_isRandom)
			{
				for (int i = 0; i < RoomSize; i++)
				{
					Rooms[i]->RandomBehaviour();
				}
			}
			_t1 = high_resolution_clock::now();
			//1
			sort(Rooms.begin(), Rooms.end(), Sort);

			//2
			for (int i = 0; i < RoomSize; i++)
			{
				//Check if we have a priority event
				if (_onPriorityEvent)
				{
					//LOCK THE VECTOR
					/*if (_autoPrint)
						temp = true; <= SEG FAULT ?!*/
					//Sort the priority vector:
					sort(_eventRooms.begin(), _eventRooms.end(), Sort);
					//Process the priority vector
					it = _eventRooms.begin();
					while (it != _eventRooms.end())
					{
						if ((*it)->GetEmmergencyState() && _autoPrint)
						{
							sstr.str(string());
							sstr << endl << "> The room [";
							sstr << (*it)->GetID();
							sstr << "] is in an emmergency state :: Elapsed time: ";
							t3 = high_resolution_clock::now();
							
							//std::chrono::duration<double> sp = duration_cast<duration<double>>(t3 - (*it)->_emmergencyTriggerTime);
							double tt = (t3 - (*it)->_emmergencyTriggerTime).count();
							sstr << tt << endl;
							//sstr << sp.count() << endl;
							//sstr << (*it)->_emmergencyTriggerTime.time_since_epoch().count() << endl;
							UI::Print(sstr.str());
						}
						ProcessTasks(*it);
						it = _eventRooms.erase(it);
					}
					_onPriorityEvent = false; //Semaphore ?
					//UNLOCK THE VECTOR
				}
				Rooms[i]->UpdateTemperature(); //Always update the temperature
				if (Rooms[i]->Priority == __PRIORITY_LOW)
					break;
				ProcessTasks(Rooms[i]);
			}

			_t2 = high_resolution_clock::now();
			_time_span1 = duration_cast<duration<double>>(_t2 - _t1);
			if ((temp || _printTime) && _time_span1.count() != 0)
			{
				sstr.str(string());
				sstr << "> Loop time: ";
				sstr << _time_span1.count() << endl;
				UI::Print(sstr.str());
				temp = false;
				_printTime = false;
			}

			LoopsCounter++;

			if (_isLoopWait)
			{
				//Loop wait here:
				///delay(50);
			}
		}
	} while (!_isExit);
}
DLLEXPORT void zProcess() {
	ProcessTasks();
}
Beispiel #5
0
void TaskManager::Loop(uint8_t watchdogTimeOutFlag)
{
    uint32_t currentTick = GetTaskTime();
    uint32_t deltaTime = currentTick - _lastTick;

    if (deltaTime >= TaskTimeAccuracy)
    {
        _lastTick = currentTick; // update before calling process
        uint32_t nextWakeTime = ProcessTasks(deltaTime);

        RemoveStoppedTasks();
 
        // if the next task has more time available than the next
        // millisecond interupt, then sleep
        if (nextWakeTime > TaskTimePerMs)
        {
            // for idle sleep mode:
            // due to Millis() using timer interupt at 1 ms, 
            // the cpu will be woke up by that every millisecond 

#if defined(ARDUINO_ARCH_ESP8266)
            // the esp8266 really doesn't have an idle mode
#if defined(USE_WDT)
            // use watchdog timer for failsafe mode, 
            // total task update time should be less than watchdogTimeOutFlag
            wdt_disable();
            wdt_enable(watchdogTimeOutFlag);
#endif

#elif defined(__arm__)
                // Arm support for sleep/idle not implemented yet

#elif defined(ARDUINO_ARCH_AVR)

#if defined(USE_WDT)
            // use watchdog timer for failsafe mode, 
            // total task update time should be less than watchdogTimeOutFlag
            wdt_reset();
            wdt_enable(watchdogTimeOutFlag);
#endif

            // just sleep
            set_sleep_mode(SLEEP_MODE_IDLE);
            cli();
            sleep_enable();
#if defined(BODSE)
            // lower power trick 
            // sleep_bod_disable() - i have seen this method called, but can't find it
            MCUCR |= _BV(BODS) | _BV(BODSE);  // turn on brown-out enable select
            MCUCR &= ~_BV(BODSE);        // this must be done within 4 clock cycles of above
#endif
            sei();
            sleep_cpu(); // will sleep in this call
            sleep_disable(); 
#endif // Arduino Normal
        }
#if defined(USE_WDT)
        else
        {
#if !defined(__arm__) // no arm support for watchdog 
            wdt_reset(); // keep the dog happy
#endif
        }
#endif

    }
}