|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecttuwien.auto.calimero.dptxlator.DPTXlator
public abstract class DPTXlator
DPT translator interface for data conversion between KNX DPTs and java types.
A translator supports translation of more than one values / DPTs at the same time.
After creation, a translator initially contains at least one valid default item (i.e.
value and data) representation for return through a getValue
- or
getData
-like method call.
The naming convention used for translator methods is to use methods comprising "data" in its name for handling KNX data types (usually contained in byte arrays), while methods comprising "value" for handling java types.
A translator shall publish its supported subtypes as constants of type DPT
through its interface.
Although there is no restriction on changing the datapoint type ID of a translator after creation (and consequently adjust all contained translation items to the new subtype), there seems no real requirement for this; therefore it is not implemented nor supported.
DPT translator implementations are not required to be thread safe. All translators provided in this package are not thread safe.
Field Summary | |
---|---|
protected boolean |
appendUnit
Behavior regarding appending a DPT engineering unit. |
protected short[] |
data
Array containing KNX data type values. |
protected DPT |
dpt
The datapoint type set for the translator. |
static java.lang.String |
LOG_SERVICE
Name of the log service used in DPT translators. |
protected static LogService |
logger
Logger object for all translators. |
protected int |
typeSize
Specifies the size of the data type in bytes, set 0 if type size
<= 6 bits. |
Constructor Summary | |
---|---|
DPTXlator(int dataTypeSize)
Creates the new translator and initializes the data type size. |
Method Summary | |
---|---|
abstract java.lang.String[] |
getAllValues()
Returns all translation items as strings currently contained in this translator. |
byte[] |
getData()
Returns a copy of all items stored by this translator translated into DPTs. |
abstract byte[] |
getData(byte[] dst,
int offset)
Copies KNX DPT value items stored by this translator into dst ,
starting at offset . |
int |
getItems()
Returns the number of translation items currently in the translator. |
abstract java.util.Map |
getSubTypes()
Returns all available, implemented subtypes for the translator. |
protected static java.util.Map |
getSubTypesStatic()
Returns all available subtypes for the translator class, equal to getSubTypes() , every DPT translator has to implement this method. |
DPT |
getType()
Returns the datapoint type used by the translator for translation. |
int |
getTypeSize()
Returns the KNX data type size in bytes for one value item. |
java.lang.String |
getValue()
Returns the first value stored by this translator formatted into a string, according to the subtype ID. |
void |
setAppendUnit(boolean append)
Sets the behavior regarding appending a DPT engineering unit to items returned by this translator. |
void |
setData(byte[] data)
See setData(byte[], int) , with offset 0. |
abstract void |
setData(byte[] data,
int offset)
Sets the data array with KNX datapoint type items for translation. |
protected void |
setTypeID(java.util.Map availableTypes,
java.lang.String dptID)
Sets the DPT for the translator to use for translation, doing a lookup before in the translator's map containing the available, implemented datapoint types. |
void |
setValue(java.lang.String value)
Translates the value according to the set datapoint ID. |
void |
setValues(java.lang.String[] values)
Translates the array of strings according to the set datapoint ID. |
protected abstract 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 . |
java.lang.String |
toString()
Returns a string of the used DPT together with all translation items currently contained in this translator. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected boolean appendUnit
Methods capable of returning an item value together the engineering unit of the
DPT, should append the unit on true
, and omit any unit
representation on false
; default setting is true
.
Only relevant for DPTs with an associated engineering unit.
protected short[] data
For every element entry, only the lower byte is allowed to be set. This way, it is
possible to store and access unsigned bytes.
The length of the array indicates how much KNX data values are contained for
conversion.
protected DPT dpt
public static final java.lang.String LOG_SERVICE
protected static final LogService logger
protected final int typeSize
0
if type size
<= 6 bits.
It is used for calculating the number of items in the translator, and also by users for detecting an optimized (short) group structure format.
Constructor Detail |
---|
public DPTXlator(int dataTypeSize)
dataTypeSize
- size in bytes of the KNX data type, use 0 if the type size
<= 6 bitsMethod Detail |
---|
public abstract java.lang.String[] getAllValues()
The items are ordered the same way handed to the translator in the first place (FIFO, increasing byte index).
getValue()
public byte[] getData()
public abstract byte[] getData(byte[] dst, int offset)
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.
dst
- byte array for storing DPT valuesoffset
- offset into dst
from where to start, 0 <= offset
< dst.length
dst
public int getItems()
public abstract java.util.Map getSubTypes()
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.
Map
, key is the subtype ID of type string, value of
type DPT
protected static java.util.Map getSubTypesStatic()
getSubTypes()
, every DPT translator has to implement this method. It is
used for subtype listings without creating a translator object.
Note, since this is a class method, static binding is used.
In particular, the method is invoked without reference to a particular object, and
hidden by declarations with the same signature in a sub type. A correct invocation
is done using the declared type that actually contains the method declaration
returning the available sub types.
Map
, key is the subtype ID of type string, value of
type DPT
public final DPT getType()
The DPT distinguishes between the different subtypes available for a KNX data type. It specifies the dimension, consisting of range and unit attributes.
DPT
public final int getTypeSize()
If the data type size is <= 6 bits, 0 is returned.
public java.lang.String getValue()
If the subtype has a unit of measurement, it is appended after the value according
to setAppendUnit(boolean)
.
getType()
public final void setAppendUnit(boolean append)
Translator methods capable of appending an available DPT unit will act according this setting.
append
- true
to append a DPT unit if any available,
false
to omit any unitpublic final void setData(byte[] data)
setData(byte[], int)
, with offset 0.
data
- byte array containing KNX DPT item(s)public abstract void setData(byte[] data, int offset)
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.
data
- byte array containing KNX DPT item(s)offset
- offset into data
from where to start, 0 <= offset
< data.length
KNXIllegalArgumentException
- if data.length
- offset <
data type width of this DPTXlatorprotected void setTypeID(java.util.Map availableTypes, java.lang.String dptID) throws KNXFormatException
availableTypes
- map of the translator with available, implemented DPTs; the
map key is a dptID string, map value is of type DPT
dptID
- the ID as string of the datapoint type to set
KNXFormatException
- on DPT not availablepublic void setValue(java.lang.String value) throws KNXFormatException
value
according to the set datapoint ID.
If, and only if, value
can successfully be translated, it gets
stored by the translator, replacing any old items. Textual commands contained in
value
are treated case insensitive.
The value
string might have its unit of measure appended (units are
case sensitive).
value
- value represented as string for translation, case insensitive
KNXFormatException
- if value
can't be translated due to wrong
formatted content, or if value
doesn't fit into KNX data typepublic void setValues(java.lang.String[] values) throws KNXFormatException
If, and only if, all items in values
can successfully be translated,
they get stored by the translator, replacing any old items. On
values.length == 0
, no action is performed.
Textual commands contained in values
are treated case insensitive.
values
- string array holding values for translation
KNXFormatException
- if an item in values
can't be translated
due to a wrong formatted content, or if value
doesn't fit
into KNX data typeprotected abstract void toDPT(java.lang.String value, short[] dst, int index) throws KNXFormatException
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
.
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 java.lang.String toString()
The string consists of a list of values in the order they are returned by
getAllValues()
. Adjacent items are separated as specified by
AbstractCollection.toString()
.
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |