WarpClock (FB)

FUNCTION_BLOCK WarpClock IMPLEMENTS Util.IDateTimeProvider

“warp” clock is providing development / debugging control on the application time line.

Certain application domains base their functionality / algorithms on real world wall clock date/time. To develop such functionality it is helpful to have control on the application timeline to speedup testing or doesnt loose control on the timeline sitting on breakpoints. WarpClock provides such a control if needed. It allows to:

  • run the clock in real time UTC

  • run the clock with a given “warp” factor

  • start at a certain start time - no matter if UTC or local

  • reset time to a a certain (start) time

  • step forward in time by a given increment

To compute the “warp” factor use ComputeWarpFactor. “warp” forward in time needs some knowledge about application cycle time. Of course there is cycle time jitter, and the application can obtain only the cycle time of last cycle. But for “warp” forward in time this is not so important, approximate cycle time information is sufficient for this use case.

If udiWarpFactor is set to 1 and the WarpClock is enabled (xEnable:=TRUE) uliTime is representing UTC system time.

InOut:

Scope

Name

Type

Initial

Comment

Input

xEnable

BOOL

TRUE

Run the clock at real time or “warp time” (system time increments multiplied by “warp” factor). If the clock is running dont use AddTime() and tTimeAdd<>T#0S.

uliStartDateTime

ULINT

Start time in ms since the epoch 1.1.1970 00:00:00.0, default is the epoch

udiWarpFactor

UDINT

1

“Warp” factor, 1 => run at real time UTC

tTimeAdd

TIME

TIME#0ms

Time to add at WarpClock function block call, if clock is not running at real time or “warp time”. Alternatively you might want to use AddTime when appropriate.

xReset

BOOL

FALSE

Reset the clock to tStart

Output

itfDateTimeProvider

Util.IDateTimeProvider

Output to connect THIS to other function block inputs

uliDateTime

ULINT

Clock output time in ms since the epoch 1.1.1970 00:00:00.0

xError

BOOL

Error indication

eErrorID

Error

Error ID

Methods:

Structure: