|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecttuwien.auto.calimero.dptxlator.DPTXlator
tuwien.auto.calimero.dptxlator.DPTXlatorDateTime
public class DPTXlatorDateTime
Translator for KNX DPTs with main number 19, type date with time.
The KNX data type width is 8 bytes.
The type contains date information (month, day of month, day of week), time information
(hour, minute, second), additional time information (work-day, daylight saving time
(DST)) and clock information (faulty clock, external clock synchronization signal). The
field usage of work-day, year, date, time, day of week field is optional.
By default, on setting date/time information, only general range checks are performed,
no check is done whether the information corresponds to a valid calendar time (see
validate()
. All field-methods behave in non-lenient time value mode, i.e. no
value overflow is allowed and values are not normalized or adjusted using the next,
larger field. (e.g. February, 29th will not result in March, 1st on no leap year).
This type permits the hour set to 24 (with minute and second only valid if 0),
representing midnight of the old day, to handle time information used in schedule
programs.
The default return value after creation is the calendar value equal to
1900/1/1 00:00:00
(year/month/day hh:mm:ss), no clock fault, not in
daylight saving time, no external clock synchronization signal, day of week and work
day fields are not used.
Field Summary | |
---|---|
static int |
CLOCK_FAULT
Field number to query or change the clock fault information. |
static int |
CLOCK_SYNC
Field number to query or change the external clock synchronization signal information. |
static int |
DATE
Field number for get and set indicating whether the
date field (month and day of month) is used. |
static int |
DAY_OF_WEEK
Field number for get and set indicating whether the
day of week field is used. |
static int |
DAYLIGHT
Field number to query or change the daylight saving time (DST) information. |
static DPT |
DPT_DATE_TIME
DPT ID 19.001, Date with time; values from 1900, 01/01 00:00:00 to 2155, 12/31 24:00:00. |
static int |
MAX_YEAR
Maximum year representable by this type, year = 2155. |
static int |
MIN_YEAR
Minimum year representable by this type, year = 1900. |
static int |
TIME
Field number for get and set indicating whether the
time field (hour, minute and second) is used. |
static int |
WORKDAY
Field number for get and set indicating whether the
work-day field is used; furthermore it is used to change the corresponding work-day
value. |
static int |
YEAR
Field number for get and set indicating whether the
year field is used. |
Fields inherited from class tuwien.auto.calimero.dptxlator.DPTXlator |
---|
appendUnit, data, dpt, LOG_SERVICE, logger, typeSize |
Constructor Summary | |
---|---|
DPTXlatorDateTime(DPT dpt)
Creates a translator for the given datapoint type. |
|
DPTXlatorDateTime(java.lang.String dptID)
Creates a translator for the given datapoint type ID. |
Method Summary | |
---|---|
java.lang.String[] |
getAllValues()
Returns all translation items as strings currently contained in this translator. |
byte[] |
getData(byte[] dst,
int offset)
Copies KNX DPT value items stored by this translator into dst ,
starting at offset . |
boolean |
getDateTimeFlag(int field)
Returns the information value of field . |
byte |
getDay()
Returns the day of month information. |
byte |
getDayOfWeek()
Returns the day of week information. |
byte |
getHour()
Returns the hour information. |
byte |
getMinute()
Returns the minute information. |
byte |
getMonth()
Returns the month information. |
byte |
getSecond()
Returns the second information. |
java.util.Map |
getSubTypes()
Returns all available, implemented subtypes for the translator. |
protected static java.util.Map |
getSubTypesStatic()
|
long |
getValueMilliseconds()
Returns the date and time information of the first date/time item in UTC milliseconds, using the system default Calendar . |
short |
getYear()
Returns the year information. |
boolean |
isFaultyClock()
Returns whether the date/time information is marked as corrupted. |
boolean |
isValidField(int field)
Returns whether a field is valid, i.e. supported and used for date/time information. |
void |
setData(byte[] data,
int offset)
Sets the data array with KNX datapoint type items for translation. |
void |
setDate(int year,
int month,
int day)
Sets year, month and day of month information of the first date/time item. |
void |
setDateTimeFlag(int field,
boolean value)
Sets date/time information for the given field of the first date/time item. |
void |
setDayOfWeek(int day)
Sets the day of week of the first date/time item. |
void |
setFaultyClock(boolean fault)
Sets the clock fault information field of the first date/time item. |
void |
setTime(int hour,
int minute,
int second)
Sets the hour, minute and second information for the first date/time item. |
void |
setValidField(int field,
boolean valid)
Sets a date/time field of the first translation item to valid or not valid. |
void |
setValue(long milliseconds)
Sets the date/time for the first date/time item using UTC millisecond information. |
protected void |
toDPT(java.lang.String value,
short[] dst,
int index)
Translates a string value representation into KNX data type according the current DPT and stores the result into dst . |
void |
useValueFormat(boolean extended)
Specifies the formatting to use for date/time string representations returned by the translator. |
boolean |
validate()
Does a complete validity check on the contained date/time items. |
Methods inherited from class tuwien.auto.calimero.dptxlator.DPTXlator |
---|
getData, getItems, getType, getTypeSize, getValue, setAppendUnit, setData, setTypeID, setValue, setValues, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int CLOCK_FAULT
A clock fault indicates one or more corrupted date/time fields, for example due to power down of device, not configured clock, no reception of synchronization message, ... .
setDateTimeFlag(int, boolean)
,
getDateTimeFlag(int)
,
Constant Field Valuespublic static final int CLOCK_SYNC
In string values, this information can be specified by using "in sync" or "no sync" to set clock synchronization. Omitting this information defaults to no external clock synchronization signal.
setDateTimeFlag(int, boolean)
,
getDateTimeFlag(int)
,
Constant Field Valuespublic static final int DATE
get
and set
indicating whether the
date field (month and day of month) is used.
setValidField(int, boolean)
,
isValidField(int)
,
Constant Field Valuespublic static final int DAY_OF_WEEK
get
and set
indicating whether the
day of week field is used.
setValidField(int, boolean)
,
isValidField(int)
,
Constant Field Valuespublic static final int DAYLIGHT
This field is for user information solely, any DST offset is already considered in the time field (i.e. the hour field contains the adjusted value).
If daylight saving time is used, this information can be specified in string values by using "DST" to denote daylight saving time.
setDateTimeFlag(int, boolean)
,
getDateTimeFlag(int)
,
Constant Field Valuespublic static final DPT DPT_DATE_TIME
public static final int MAX_YEAR
public static final int MIN_YEAR
public static final int TIME
get
and set
indicating whether the
time field (hour, minute and second) is used.
setValidField(int, boolean)
,
isValidField(int)
,
Constant Field Valuespublic static final int WORKDAY
get
and set
indicating whether the
work-day field is used; furthermore it is used to change the corresponding work-day
value.
The work-day information can be specified in string values by using "workday" to denote a working day.
setValidField(int, boolean)
,
isValidField(int)
,
setDateTimeFlag(int, boolean)
,
getDateTimeFlag(int)
,
Constant Field Valuespublic static final int YEAR
get
and set
indicating whether the
year field is used.
setValidField(int, boolean)
,
isValidField(int)
,
Constant Field ValuesConstructor Detail |
---|
public DPTXlatorDateTime(DPT dpt) throws KNXFormatException
dpt
- the requested datapoint type
KNXFormatException
- on not supported or not available DPTpublic DPTXlatorDateTime(java.lang.String dptID) throws KNXFormatException
dptID
- available implemented datapoint type ID
KNXFormatException
- on wrong formatted or not expected (available)
dptID
Method Detail |
---|
public java.lang.String[] getAllValues()
DPTXlator
The items are ordered the same way handed to the translator in the first place (FIFO, increasing byte index).
getAllValues
in class DPTXlator
DPTXlator.getValue()
public byte[] getData(byte[] dst, int offset)
DPTXlator
dst
,
starting at offset
.
The number of items copied depends on the usable dst
range, i.e. how
much items completely fit into dst.length - offset
. If the usable
range is too short, no item is copied at all, and dst
is not
modified.
Datapoint types shorter than 1 bytes only change the affected lower bit positions,
leaving the upper (high) bits of dst
bytes untouched.
getData
in class DPTXlator
dst
- byte array for storing DPT valuesoffset
- offset into dst
from where to start, 0 <= offset
< dst.length
dst
public final boolean getDateTimeFlag(int field)
field
.
Allowed fields are CLOCK_FAULT
, CLOCK_SYNC
, WORKDAY
and DAYLIGHT
.
field
- field number to query
true
if set, false
otherwisepublic final byte getDay()
The first day of month equals 1.
public final byte getDayOfWeek()
The return of 0 corresponds to "any day", indicating the day of week is variable (used in scheduling). The first day of week is Monday with a value of 1.
public final byte getHour()
An hour value of 24 represents midnight of the old day, the corresponding minute and second are always 0.
public final byte getMinute()
public final byte getMonth()
public final byte getSecond()
public java.util.Map getSubTypes()
DPTXlator
A subtype, identified through a sub number, specifies the available dimension,
consisting of range and unit attributes. Together with the main type information
this uniquely defines a datapoint type.
The datapoint type information is contained in a DPT
object.
New or modified DPT information can be made available to the translator by adding
entries to the map, likewise map entries might be removed. In other words, the map
returned is the same used by the translators of one main type for DPT lookup.
Changes to the map influence all translators of the same main type.
Changes of the DPT currently used by the translator take effect on the next new
translator created using that DPT.
The map itself is not synchronized.
getSubTypes
in class DPTXlator
Map
, key is the subtype ID of type string, value of
type DPT
protected static java.util.Map getSubTypesStatic()
DPTXlator.getSubTypesStatic()
public final long getValueMilliseconds() throws KNXFormatException
Calendar
.
The method uses the year, month, day, DST and, optionally, hour, minute, second and
day of week field for calculation.
On unused time field, 00:00:00 is used. If year, month or day field is unused (see
isValidField(int)
, or the field values do not represent a valid calendar
time, an exception is thrown. If time equals 24:00:00, it is represented as
23:59:59.999, since the time ambiguity of midnight is resolved as midnight
belonging to the next day (00:00:00) in the used calendar. However, no field values
itself is changed permanently.
The used calendar is obtained by Calendar.getInstance()
, and the
calculation is done in non-lenient mode.
KNXFormatException
- on required, but not set fields, if date/time
information does not represent a valid calendar time,public final short getYear()
public final boolean isFaultyClock()
It should always queried first, before accessing further date/time information, to assure correct values.
true
on clock fault, false
otherwisegetDateTimeFlag(int)
,
CLOCK_FAULT
public final boolean isValidField(int field)
Only data of valid fields are required to be set or examined. A field set to not
valid shall be ignored, it is not supported and contains no valid data.
Possible fields allowed to be set valid or not valid are YEAR
,
DATE
, TIME
, DAY_OF_WEEK
and WORKDAY
.
field
- field number
true
if field is supported and in use, false
otherwisepublic void setData(byte[] data, int offset)
DPTXlator
The data
array contains at least one DPT item, the new item(s) will
replace any other items set in the translator before.
The number of items (KNX data values) for translation in data
is
inferred from the length of the usable data
range:
items = (data.length - offset) / (length of KNX data type)
In general, the KNX data type width is implicitly known in the context where a
translator is invoked (e.g. by appropriate DP configuration), therefore
data.length
will satisfy the minimum acceptable length. If this is
not the case, KNXIllegalArgumentException
has to be caught and handled in
the caller's context.
setData
in class DPTXlator
data
- byte array containing KNX DPT item(s)offset
- offset into data
from where to start, 0 <= offset
< data.length
public final void setDate(int year, int month, int day)
This method does not reset other item data or discard other translation items.
year
- year value, 1900 <= year <= 2155month
- month value, 1 <= month <= 12day
- day value, 1 <= day <= 31public final void setDateTimeFlag(int field, boolean value)
Allowed fields are CLOCK_FAULT
, CLOCK_SYNC
, WORKDAY
and DAYLIGHT
.
This method does not reset other item data or discard other translation items.
field
- field numbervalue
- true
to set the information flag, false
to clearpublic final void setDayOfWeek(int day)
A day of week value of 0 corresponds to "any day", indicating the day of week is
variable (used in scheduling). The first day of week is Monday with a value of 1.
This method does not reset other item data or discard other translation items.
day
- day of week value, 0 <= day <= 7public final void setFaultyClock(boolean fault)
Equal to invoking setDateTimeFlag(int, boolean)
with field
CLOCK_FAULT
.
This method does not reset other item data or discard other translation items.
fault
- true
if clock is faulty, false
otherwisesetDateTimeFlag(int, boolean)
,
CLOCK_FAULT
public final void setTime(int hour, int minute, int second)
On a hour value of 24, values of minute and second have to be 0.
This method does not reset other item data or discard other translation items.
hour
- hour value, 0 <= hour <= 24minute
- minute value, 0 <= minute <= 59second
- second value, 0 <= second <= 59public final void setValidField(int field, boolean valid)
A field which is valid, i.e. contains valid data, has to be set true
,
otherwise the field should be set not valid with false
.
Possible fields allowed to be set valid or not valid are YEAR
,
DATE
, TIME
, DAY_OF_WEEK
and WORKDAY
.
field
- field numbervalid
- true
if field is supported and contains valid data,
false
otherwisepublic final void setValue(long milliseconds)
Following fields are set: year, month, day, day of week, hour, minute, second,
daylight time. All according fields are set to used state.
The value
is interpreted by a calendar obtained by
Calendar.getInstance()
.
The new value item replaces any other items contained in this translator.
milliseconds
- time value in milliseconds, as used by Calendar
protected void toDPT(java.lang.String value, short[] dst, int index) throws KNXFormatException
DPTXlator
dst
. The index parameter specifies
the item index of the value. The translated KNX data is stored at the corresponding
array offset in dst
. Calculation of offset:
offset = index * KNX data type size
.
toDPT
in class DPTXlator
value
- value to translatedst
- destination array for resulting KNX dataindex
- item index in destination array
KNXFormatException
- if value
can't be translated due to wrong
formatted content, or if value
doesn't fit into KNX data
typepublic final void useValueFormat(boolean extended)
A string in extended format contains all valid information of the date/time type. In extended format, additionally the day of week, daylight time, work-day and clock synchronization signal information is considered in the output format. Otherwise this fields are always ignored, i.e only clock fault, year, month, day, hour, minute and second will get used, if valid.
The used format is extended by default.
extended
- string format to use, true
for extended formatpublic final boolean validate()
An item is valid if all used fields correspond to a valid calendar time. The check
is only performed if at least year and date fields are used.
After modifying date/time fields, this method has to be called again if validation
is required.
It returns the result of the validity checks performed on the date/time items.
Comparison of the two kinds of validity:
When setting individual parts of a date/time, only the KNX requirements for the DPT
are checked, as requested by the DPT specification. For example, this includes a
common range check of a value. So set items always match these KNX value ranges.
This validation method checks if the date/time fields represent a valid calendar
time, which is a much stronger requirement.
true
if date/times are valid, false
otherwise
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |