se.lth.cs.realtime
Class Timebase

java.lang.Object
  |
  +--se.lth.cs.realtime.Timebase

public class Timebase
extends java.lang.Object

The time-base class, mapping ticks to time. This class is needed for the following reasons:

Ordinary applications/users: Use default constructor .... this class currently only supports the default System time-base.

See Also:
javax.media.TimeBase, RTEvent

Field Summary
protected  Timebase envTimebase
          The time base of the surrounding system, such as the real world.
protected  int milliRate
          Ticks per milli-second.
protected  int nanoRate
          Ticks per nano-seconds.
protected  int rate
          Ticks per second.
protected  double scale
          Seconds per tick.
protected  long start
          The start of time, in milliseconds relative to beginning of 1970.
 
Constructor Summary
Timebase()
          Constructor for default system time, using ticks for milli-seconds from beginning of 1970 as for System.currentTimeMillis().
Timebase(long origin, long pace)
          Constructor for a time base starting with time zero at origin and with pace system dependent ticks per milliseconds.
 
Method Summary
 long millis(long timestamp)
          Express the timestamp (number of ticks) in milli-seconds.
 long nanos(long timestamp)
          Express the timestamp in nano-seconds.
 long pace()
          Rate of clock ticks per second.
 double physicalSeconds(long timestamp)
          Obtain physical real-world time.
 double seconds(long timestamp)
          Express the timestamp (that is, number of clock ticks) in seconds.
 long time0()
          The start of this time base, possibly relative to an enclosing time base, and expressed in seconds from beginning 1970.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

start

protected final long start
The start of time, in milliseconds relative to beginning of 1970.

scale

protected final double scale
Seconds per tick.

rate

protected final int rate
Ticks per second.

milliRate

protected final int milliRate
Ticks per milli-second.

nanoRate

protected final int nanoRate
Ticks per nano-seconds.

envTimebase

protected Timebase envTimebase
The time base of the surrounding system, such as the real world. If null, the system time is used. That is, System.currentTimeMillis() is valid in the scale of time since this is an ordinary RT application.
Constructor Detail

Timebase

public Timebase()
Constructor for default system time, using ticks for milli-seconds from beginning of 1970 as for System.currentTimeMillis().

Timebase

public Timebase(long origin,
                long pace)
Constructor for a time base starting with time zero at origin and with pace system dependent ticks per milliseconds. To represent the time in an embedded controller without battery supported clock (time realative to start of system) use REL_TIME as the origin argument.
Method Detail

physicalSeconds

public double physicalSeconds(long timestamp)
                       throws java.lang.IllegalStateException
Obtain physical real-world time. In ordinary applications the returned value will be equal to the value returned by seconds; that method should be used except in special cases of simulation, any-time algorithms, self-contioness robots, etc.
See Also:
seconds(long)

seconds

public double seconds(long timestamp)
Express the timestamp (that is, number of clock ticks) in seconds.

millis

public long millis(long timestamp)
Express the timestamp (number of ticks) in milli-seconds.

nanos

public long nanos(long timestamp)
Express the timestamp in nano-seconds. Under construction...

time0

public long time0()
The start of this time base, possibly relative to an enclosing time base, and expressed in seconds from beginning 1970.

pace

public long pace()
Rate of clock ticks per second.