Register / Login  |  Desktop view  |  Jump to bottom of page

IoAbstraction & TaskManagerIO » TaskManager listing of tasks

Author: jacobez
02/04/2021 13:31:43
Hi Dave,
I've used the tcMenu with i2c LCD & 3 button input on a Mega.
I'm also using a SPI datalogger to log some system temperatures to a SD card.
I use the tcMenu to set the time duration between data saving events like in the code below.

void CALLBACK_FUNCTION onDataSaveInterval(int id) {

    menuDataSaveId = taskManager.scheduleFixedRate(menuDataSave.getCurrentValue()*60, dataLogging, TIME_SECONDS);
    Serial.print("DataSaveInterval from Callback " );  // for debug
    Serial.println(menuDataSave.getCurrentValue());
    Serial.print("menuDataSaveId Callback ");
    Serial.println(menuDataSaveId);
}


What I see from the serial debug is that the data is being saved for every iteration that one increases or reduces the value.
I did check out Serial.println(taskManager.checkAvailableSlots(debugData,sizeof(debugData)));, but that does not help me a lot.

I've also tried the following, but it still seems to be logging for every instance I changed the menu item.
void CALLBACK_FUNCTION onDataSaveInterval(int id) {
   
//    Cancel current scheduling first, then reschedule. menuDataSaveId
    if (appMode != APP_SETUP_MODE) {  // Cannot cancel task in Setup mode as ID's are only allocated at this time
          taskManager.cancelTask(menuDataSaveId);
          Serial.print("Cancel menuDataSaveId = ");
          Serial.println(menuDataSaveId);
    }
    menuDataSaveId = taskManager.scheduleFixedRate(menuDataSave.getCurrentValue()*60, dataLogging, TIME_SECONDS);
    Serial.print("DataSaveInterval from Callback " );
    Serial.println(menuDataSave.getCurrentValue());
    Serial.print("menuDataSaveId Callback ");
    Serial.println(menuDataSaveId);
}



Is there a way that one can see a list of the names of the "functions" scheduled?

Author: jacobez
02/04/2021 13:39:25
Here is a screenshot of the Serial Monitor:

menuDataSaveId Callback 5
DataSaveInterval from Callback 3
menuDataSaveId Callback 6
Save to EEPROM
dataLogging 6 02/04/2021;15:34:43;314;315;298
dataLogging 6 02/04/2021;15:36:29;315;315;297
dataLogging 6 02/04/2021;15:36:32;308;309;293
dataLogging 6 02/04/2021;15:37:00;306;305;289
dataLogging 6 02/04/2021;15:37:04;307;307;291
dataLogging 6 02/04/2021;15:37:32;316;317;298


Author: davetcc
02/04/2021 15:18:32
 
Is there a way that one can see a list of the names of the "functions" scheduled?


Short answer: You can see the task states (what's scheduled basically) but not the function names.

Longer answer: There is not really an easy way to do that, as RTTI (runtime type information) is not enabled on any embedded framework I've used (to reduce memory footprint). The only other way we could do it is by capturing __LINE__ and __FILE__ but that would be hideously expensive adding very high overhead to every task.

There is a function show what the state of each task slot is, but it only shows if it is running, waiting etc.

char* checkAvailableSlots(char* slotData, size_t slotDataSize) const;


Each slot is output in turn, so a trick you could use is to log each ID you get back from creating tasks, each one is an offset in that list of slots.

Author: davetcc
02/04/2021 15:21:29
So BTW if you use the serdebug(..) functions in IoLogging.h you can compile them in / out by defining a variable, you may find it useful.

See https://www.thecoderscorner.com/ref-docs/ioabstraction/html/_io_logging_8h_source.html

Author: davetcc
02/04/2021 15:28:36
What I would do in your case is use scheduleOnce as follows, then it will always use the correct time:

void myTimerTask() {

   // other work to be done

   taskManager.scheduleOnce(menuTime.getCurrentValue(), myTimerTask, TIME_SECONDS);

}


myInitialisation() {
   taskManager.scheduleOnce(menuTime.getCurrentValue(), myTimerTask, TIME_SECONDS);
}

Author: jacobez
02/04/2021 19:02:23
Thanks a mill Dave,
I shall have a look at the suggestions.
Is the high level logic in the second code posting, to cancel the previous scheduled task before scheduling the next?

Author: jacobez
02/04/2021 19:03:37
forgot the "Is it correct?" smilie

Author: davetcc
04/04/2021 18:03:01
You can schedule and cancel in any order, but you're better not relying on cancel for regular operation. It's a very heavy operation that has itself to wait for scheduling. There is no guarantee that it will happen before the next execution.

Cancelling a task involves scheduling a task for immediate execution that will go through the running queue and remove the task that is to be scheduled.

It's better when the event timing changes often to use the schedule once as shown in my example. You could also use a polling event as described in the task manager docs.




Register / Login  |  Desktop view  |  Jump to top of page