|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.dalsemi.system.Clock
This class provides access to the TINI Real-Time clock. The methods support
setting and getting the clock values. The Real-Time clock on TINI is an 8 byte
register that stores the year, month, date, day, hour, minute, second, and hundredth-second
in BCD format.
There are two basic ways to access TINI's Real-Time clock. The faster method is to
directly use the values year
, month
, etc.
...
com.dalsemi.system.Clock C = new com.dalsemi.system.Clock();
C.getRTC();
System.out.println("The date is : " + C.getDate() + "/" +
C.getMonth() + "/" + C.getYear());
System.out.println("The time is : " + C.getHour() + ":" +
C.getMinute() + ":" + C.getSecond() +
"." + C.getHundredth() + C.getPm() ? " PM" : " AM"));
...
The other method is slower, but provides a mean to translate between the TINI Real-Time
clock and the Java timekeeping methods which require a long
value of
milliseconds that have passed since January 1, 1970. This method is slower, since the
Clock
class must convert from its internal fields into an amount of
milliseconds.
...
com.dalsemi.system.Clock C = new com.dalsemi.system.Clock();
long time = C.getTickCount();
System.out.println(new java.util.Date(time));
...
This class also provides means to set the Real-Time Clock settings. The methods for
setting Clock
values are analogous to the methods for getting, except that
after all fields have been set as desired, programs should call setRTC()
.
The following code sets the TINI Real-Time clock to October 4, 2000 at 1:43 in the
afternoon.
C.setYear(2000);
C.setMonth(10);
C.setDate(4);
C.setHour(13);
C.setPm(true);
C.setMinute(43);
C.setRTC();
System.out.println(new java.util.Date(C.getTickCount()));
Note that the time printed will probably not be 1:43 PM. The time stored is
for GMT. On a TINI with Central Standard Time as the default TimeZone
, this program
prints out:
TINI /> java clockdemo.tini
Wed Oct 4 08:43:59 CST 2000
which is correct because CST during Daylight Savings Time (CDT) is 5 hours behind GMT.
Also note that getRTC()
is not called in the above code example. It is
called internally by getTickCount()
. Any other 'get' accesses should
call getRTC()
first.
Field Summary | |
protected int |
date
Stores the day of the month. |
protected int |
day
Stores the day of the week (1-7). |
protected int |
hour
Stores the hour (1-12 or 0-23). |
protected int |
hundredth
Stores the hundredth-second. |
protected boolean |
is12Hour
This flag signifies if the value stored in hour
is for a 1-12 hour clock that uses AM and PM settings or
a 0-23 hour clock that does not use AM and PM settings. |
protected int |
minute
Stores the minute. |
protected int |
month
Stores the month (1-12). |
protected boolean |
pm
Stores the AM/PM selection. |
protected int |
second
Stores the second. |
protected int |
year
Stores the year mod 100. |
Constructor Summary | |
Clock()
Creates a new Clock instance for accessing
TINI's Real-Time clock. |
Method Summary | |
static int |
bcdToInt(int bcdVal)
Converts a BCD integer byte to its binary integer value. |
static int |
calculateDayOfWeek(int month,
int date,
int fullYear)
Calculates the correct day of the week given the month, day of the month, and year. |
boolean |
get12Hour()
Get the 12/24 Hour mode for the Real-Time Clock. |
int |
getDate()
Get the date (day of month) value for the Real-Time Clock. |
int |
getDay()
Get the day of the week value for the Real-Time Clock. |
int |
getHour()
Get the hour value for the Real-Time Clock. |
int |
getHundredth()
Get the hundredth-second value for the Real-Time Clock. |
int |
getMinute()
Get the minute value for the Real-Time Clock. |
int |
getMonth()
Get the month value for the Real-Time Clock. |
boolean |
getPm()
Get the AM/PM value for the Real Time Clock. |
void |
getRTC()
Reads Real time clock values from hardware clock and places them into Clock instance fields. |
int |
getSecond()
Get the second value for the Real-Time Clock. |
long |
getTickCount()
Get the current time in milliseconds since midnight Jan 1, 1970, UTC. |
int |
getYear()
Get the year value for the Real-Time Clock. |
static byte |
intToBCD(int intVal)
Converts a binary integer byte to its BCD value. |
void |
set12Hour(boolean is12Hour)
Sets the 12/24 hour mode of the Real-Time Clock. |
void |
setDate(int date)
Sets the date (day of the month) value of the Real-Time Clock. |
void |
setDay(int day)
Sets the day of the week value of the Real-Time Clock. |
void |
setHour(int hour)
Sets the hour value of the Real-Time Clock. |
void |
setHundredth(int hundredth)
Sets the hundredth-second value of the Real-Time Clock. |
void |
setMinute(int minute)
Sets the minute value of the Real-Time Clock. |
void |
setMonth(int month)
Sets the month value of the Real-Time Clock. |
void |
setPm(boolean pm)
Sets the AM/PM value of the Real Time Clock. |
void |
setRTC()
Reads the stored values year , month ,
date , etc. |
void |
setSecond(int second)
Sets the second value of the Real-Time Clock. |
void |
setTickCount(long millis)
Set the current time from a value in milliseconds since Jan 1, 1970, UTC. |
void |
setYear(int year)
Sets the year value of the Real-Time Clock. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
protected int year
getRTC()
and
used by the setRTC()
method to set the Real-Time Clock.
used by the setRTC()
method to set the Real-Time Clock.setYear(int)
,
getYear()
protected int month
getRTC()
and
used by the setRTC()
method to set the Real-Time Clock.setMonth(int)
,
getMonth()
protected int day
getRTC()
and
used by the setRTC()
method to set the Real-Time Clock.setDay(int)
,
getDay()
protected int date
getRTC()
and
used by the setRTC()
method to set the Real-Time Clock.setDate(int)
,
getDate()
protected int hour
getRTC()
and
used by the setRTC()
method to set the Real-Time Clock.setHour(int)
,
getHour()
protected int minute
getRTC()
and
used by the setRTC()
method to set the Real-Time Clock.setMinute(int)
,
getMinute()
protected int second
getRTC()
and
used by the setRTC()
method to set the Real-Time Clock.setSecond(int)
,
getSecond()
protected int hundredth
getRTC()
and
used by the setRTC()
method to set the Real-Time Clock.setHundredth(int)
,
getHundredth()
protected boolean pm
setPm(boolean)
,
getPm()
protected boolean is12Hour
hour
is for a 1-12 hour clock that uses AM and PM settings or
a 0-23 hour clock that does not use AM and PM settings.set12Hour(boolean)
,
get12Hour()
Constructor Detail |
public Clock()
Clock
instance for accessing
TINI's Real-Time clock. Also performs a call to
getRTC()
so the fields of this Clock
object initially have valid values.getRTC()
Method Detail |
public void setYear(int year)
setRTC()
should be performed to actually set the Real-Time Clock.year
- the year to be setgetYear()
,
setRTC()
public int getYear()
getRTC()
should be called before this method to refresh
the value from TINI's Real-Time Clock.getRTC()
,
setYear(int)
public void setMonth(int month)
setRTC()
should be performed to actually set the Real-Time Clock.month
- the month to be setgetMonth()
,
setRTC()
public int getMonth()
getRTC()
should be called before this method to refresh
the value from TINI's Real-Time Clock.getRTC()
,
setMonth(int)
public void setDay(int day)
setRTC()
should be performed to actually set the Real-Time Clock. To facilitate
setting the correct day of the week, first call calculateDayOfWeek
which calculates the day of the week depending on the year, month, and date.day
- the day of the week to be setcalculateDayOfWeek(int,int,int)
,
getDay()
,
setRTC()
public int getDay()
getRTC()
should be called before this method to refresh
the value from TINI's Real-Time Clock.getRTC()
,
setDay(int)
public void setDate(int date)
setRTC()
should be performed to actually set the Real-Time Clock.date
- the day of the month to be setgetDate()
,
setRTC()
public int getDate()
getRTC()
should be called before this method to refresh
the value from TINI's Real-Time Clock.getRTC()
,
setDate(int)
public void setHour(int hour)
setRTC()
should be performed to actually set the Real-Time Clock. The value
actually stored in TINI's Real-Time Clock is also determined
by the is12Hour
flag and the pm
flag.hour
- the hour to be setset12Hour(boolean)
,
setPm(boolean)
,
getHour()
,
setRTC()
public int getHour()
getRTC()
should be called before this method to refresh
the value from TINI's Real-Time Clock. The methods get12Hour()
and getPm()
should also be called to find the exact meaning
of the hour
value.getPm()
,
get12Hour()
,
getRTC()
,
setHour(int)
public void setMinute(int minute)
setRTC()
should be performed to actually set the Real-Time Clock.minute
- the minute to be setgetMinute()
,
setRTC()
public int getMinute()
getRTC()
should be called before this method to refresh
the value from TINI's Real-Time Clock.getRTC()
,
setMinute(int)
public void setSecond(int second)
setRTC()
should be performed to actually set the Real-Time Clock.second
- the second to be setgetSecond()
,
setRTC()
public int getSecond()
getRTC()
should be called before this method to refresh
the value from TINI's Real-Time Clock.getRTC()
,
setSecond(int)
public void setHundredth(int hundredth)
setRTC()
should be performed to actually set the Real-Time Clock.hundredth
- the hundredth-second to be setgetHundredth()
,
setRTC()
public int getHundredth()
getRTC()
should be called before this method to refresh
the value from TINI's Real-Time Clock.getRTC()
,
setHundredth(int)
public void setPm(boolean pm)
pm
only matters if is12Hour
is true
.pm
- true
for PM, false
for AMgetPm()
,
setRTC()
,
set12Hour(boolean)
public boolean getPm()
getRTC()
should be called before this method to refresh
the value from TINI's Real-Time Clock. The value of the pm flag is
only relevant if the is12Hour flag is set. If the is12Hour flag is not
set, the value for hour
will range between 0 and 23, and the
pm flag is irrelevant.true
for PM, false
for AMgetRTC()
,
setPm(boolean)
,
get12Hour()
,
getHour()
public void set12Hour(boolean is12Hour)
true
, then the value of the flag pm
matters when setRTC()
is called.is12Hour
- true
for 12 hour clock, false
for 24 hour clocksetRTC()
,
get12Hour()
,
#setPm()
public boolean get12Hour()
getRTC()
should be called before this method to refresh
the value from TINI's Real-Time Clock. If the is12Hour
flag is not
set, the value for hour
will range between 0 and 23, and the
pm
flag is irrelevant. If the is12Hour
flag is set, the value for
hour
will range between 1 and 12, and the pm
flag
will be relevant.true
for 12 hour clock, false
for
24 hour clockgetRTC()
,
getPm()
,
set12Hour(boolean)
,
getHour()
public void getRTC()
Clock
instance fields. This method should be called
to refresh the Clock
instance fields, and before
any 'get' methods are called.setRTC()
public long getTickCount()
Get the current time in milliseconds since midnight Jan 1, 1970, UTC.
This method calls getRTC()
, so it is unnecessary for
callers to do so. The value returned is suitable to be used in
calls to Java classes such as java.util.Date
and
java.util.Calendar
.
Note: This method assumes the current year is the year 2000 or later. Since the Real-Time Clock only stores the 2 least significant digits of the year, this method assumes that the clock represents a time after midnight, January 1, 2000.
setTickCount(long)
public void setTickCount(long millis)
Set the current time from a value in milliseconds since Jan 1, 1970, UTC.
This method calls setRTC()
before exiting. This method
must parse the millisecond value into fields for the year, month, date,
and so on. This is more time consuming than setting the fields
individually.
This method is not written to handle negative values for
millis
. Also note that this method will only store the
2 least significant digits of the year. Subsequent calls to
getTickCount()
will add these 2 digits to the year
2000 to come up with the current year. If you call
setTickCount()
with a value for a date in 1999,
then getTickCount()
will return you a value for
a date in 2099.
millis
- number of milliseconds since midnight, Jan 1, 1970 UTCgetTickCount()
public void setRTC()
year
, month
,
date
, etc. and stores them in TINI's Real-Time Clock.
This method performs bounds checking on all values, however it
does not ensure that invalid dates (February 30) or days of
the week (Friday for October 5 2000) have been entered.getRTC()
public static int calculateDayOfWeek(int month, int date, int fullYear)
month
- the month (1-12)date
- the day of the monthfullYear
- the year (not mod 100)public static int bcdToInt(int bcdVal)
bcdVal
- the BCD integer to convert to a decimal integerintToBCD(int)
public static byte intToBCD(int intVal)
intVal
- decimal value to convert to BCDbcdToInt(int)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |