mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
Updated tracing with loading static and improved SCHEDULER
- Tracing is by default switched off when using Moose in static mode. - SCHEDULER is now correctly rescheduling when repeating the loop. - Modified the loaders, adding the default trace on in case of dynamic and off in case of static loading.
This commit is contained in:
@@ -1,34 +1,34 @@
|
||||
--- Models time events calling event handing functions.
|
||||
--
|
||||
--
|
||||
-- @{SCHEDULER} class
|
||||
-- ===================
|
||||
-- The @{SCHEDULER} class models time events calling given event handling functions.
|
||||
--
|
||||
--
|
||||
-- SCHEDULER constructor
|
||||
-- =====================
|
||||
-- The SCHEDULER class is quite easy to use:
|
||||
--
|
||||
--
|
||||
-- * @{#SCHEDULER.New}: Setup a new scheduler and start it with the specified parameters.
|
||||
--
|
||||
--
|
||||
-- SCHEDULER timer methods
|
||||
-- =======================
|
||||
-- The SCHEDULER can be stopped and restarted with the following methods:
|
||||
--
|
||||
--
|
||||
-- * @{#SCHEDULER.Start}: (Re-)Start the scheduler.
|
||||
-- * @{#SCHEDULER.Start}: Stop the scheduler.
|
||||
--
|
||||
--
|
||||
-- @module Scheduler
|
||||
-- @author FlightControl
|
||||
|
||||
--- The SCHEDULER class
|
||||
-- @type SCHEDULER
|
||||
-- @field #number ScheduleID the ID of the scheduler.
|
||||
-- @extends Base#BASE
|
||||
SCHEDULER = {
|
||||
ClassName = "SCHEDULER",
|
||||
}
|
||||
|
||||
|
||||
--- Constructor.
|
||||
--- SCHEDULER constructor.
|
||||
-- @param #SCHEDULER self
|
||||
-- @param #table TimeEventObject Specified for which Moose object the timer is setup. If a value of nil is provided, a scheduler will be setup without an object reference.
|
||||
-- @param #function TimeEventFunction The event function to be called when a timer event occurs. The event function needs to accept the parameters specified in TimeEventFunctionArguments.
|
||||
@@ -63,10 +63,10 @@ function SCHEDULER:New( TimeEventObject, TimeEventFunction, TimeEventFunctionArg
|
||||
if StopSeconds then
|
||||
self.StopSeconds = StopSeconds
|
||||
end
|
||||
|
||||
|
||||
|
||||
self.StartTime = timer.getTime()
|
||||
|
||||
|
||||
self:Start()
|
||||
|
||||
return self
|
||||
@@ -77,12 +77,12 @@ end
|
||||
-- @return #SCHEDULER self
|
||||
function SCHEDULER:Start()
|
||||
self:F2( self.TimeEventObject )
|
||||
|
||||
if self.RepeatSecondsInterval ~= 0 then
|
||||
self.Repeat = true
|
||||
end
|
||||
timer.scheduleFunction( self._Scheduler, self, timer.getTime() + self.StartSeconds + .01 )
|
||||
|
||||
|
||||
if self.RepeatSecondsInterval ~= 0 then
|
||||
self.Repeat = true
|
||||
end
|
||||
self.ScheduleID = timer.scheduleFunction( self._Scheduler, self, timer.getTime() + self.StartSeconds + .01 )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
@@ -91,17 +91,20 @@ end
|
||||
-- @return #SCHEDULER self
|
||||
function SCHEDULER:Stop()
|
||||
self:F2( self.TimeEventObject )
|
||||
|
||||
|
||||
self.Repeat = false
|
||||
|
||||
timer.removeFunction( self.ScheduleID )
|
||||
self.ScheduleID = nil
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
-- Private Functions
|
||||
|
||||
--- @param #SCHEDULER self
|
||||
function SCHEDULER:_Scheduler()
|
||||
self:F2( self.TimeEventFunctionArguments )
|
||||
|
||||
|
||||
local ErrorHandler = function( errmsg )
|
||||
|
||||
env.info( "Error in SCHEDULER function:" .. errmsg )
|
||||
@@ -110,27 +113,37 @@ function SCHEDULER:_Scheduler()
|
||||
return errmsg
|
||||
end
|
||||
|
||||
local Status, Result
|
||||
local Status, Result
|
||||
if self.TimeEventObject then
|
||||
Status, Result = xpcall( function() return self.TimeEventFunction( self.TimeEventObject, unpack( self.TimeEventFunctionArguments ) ) end, ErrorHandler )
|
||||
else
|
||||
Status, Result = xpcall( function() return self.TimeEventFunction( unpack( self.TimeEventFunctionArguments ) ) end, ErrorHandler )
|
||||
end
|
||||
|
||||
self:T( { Status, Result, self.StartTime, self.RepeatSecondsInterval, self.RandomizationFactor, self.StopSeconds } )
|
||||
|
||||
|
||||
self:T( { self.TimeEventFunctionArguments, Status, Result, self.StartTime, self.RepeatSecondsInterval, self.RandomizationFactor, self.StopSeconds } )
|
||||
|
||||
if Status and ( ( Result == nil ) or ( Result and Result ~= false ) ) then
|
||||
if self.Repeat and ( not self.StopSeconds or ( self.StopSeconds and timer.getTime() <= self.StartTime + self.StopSeconds ) ) then
|
||||
local ScheduleTime = timer.getTime() + self.RepeatSecondsInterval + math.random( - ( self.RandomizationFactor * self.RepeatSecondsInterval / 2 ), ( self.RandomizationFactor * self.RepeatSecondsInterval / 2 ) ) + 0.01
|
||||
self:T( { timer.getTime(), ScheduleTime } )
|
||||
timer.scheduleFunction(
|
||||
self._Scheduler,
|
||||
self,
|
||||
ScheduleTime
|
||||
)
|
||||
local ScheduleTime =
|
||||
timer.getTime() +
|
||||
self.RepeatSecondsInterval +
|
||||
math.random(
|
||||
- ( self.RandomizationFactor * self.RepeatSecondsInterval / 2 ),
|
||||
( self.RandomizationFactor * self.RepeatSecondsInterval / 2 )
|
||||
) +
|
||||
0.01
|
||||
self:T( { self.TimeEventFunctionArguments, "Repeat:", timer.getTime(), ScheduleTime } )
|
||||
return ScheduleTime -- returns the next time the function needs to be called.
|
||||
else
|
||||
timer.removeFunction( self.ScheduleID )
|
||||
self.ScheduleID = nil
|
||||
end
|
||||
else
|
||||
timer.removeFunction( self.ScheduleID )
|
||||
self.ScheduleID = nil
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
|
||||
@@ -140,3 +153,11 @@ end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user