arduino-lmic icon indicating copy to clipboard operation
arduino-lmic copied to clipboard

Added method to retrieve time to next time critical job

Open oseiler2 opened this issue 4 years ago • 1 comments

In the context of the discussion here https://github.com/mcci-catena/arduino-lmic/discussions/640 I thought it's useful to get the time to the next critical job to help determine idle/sleep time on the node without having to guess using os_queryTimeCriticalJobs()

oseiler2 avatar Dec 11 '20 07:12 oseiler2

Awesome idea!

I think it would make sense to also query OS.runnablejobs, making the function look like this:

ostime_t os_timeToNextTimeCriticalJob() {
    if(OS.runnablejobs) return 0;
    
    if (!OS.scheduledjobs) return 0x7FFFFFFFl; //ostime_t_max;
    return OS.scheduledjobs->deadline - os_getTime();
}

See the OS loop function, it checks OS.runnablejobs as well: https://github.com/mcci-catena/arduino-lmic/blob/master/src/lmic/oslmic.c#L146-L154

cnmicha avatar Jun 16 '21 18:06 cnmicha