tuwien.auto.calimero.dptxlator
Class DPTXlator2ByteFloat

java.lang.Object
  extended by tuwien.auto.calimero.dptxlator.DPTXlator
      extended by tuwien.auto.calimero.dptxlator.DPTXlator2ByteFloat

public class DPTXlator2ByteFloat
extends DPTXlator

Translator for KNX DPTs with main number 9, type 2-byte float.

The KNX data type width is 2 bytes.
This type is a two byte floating format with a maximum usable range of -671088.64 to +670760.96. DPTs adjust the usable range to reasonable limits for its values, the translator will check and enforce those DPT specific limits in all methods working with java values (e.g. setValue(float)). Data methods for KNX data (e.g. DPTXlator.setData(byte[]) accept all data within the maximum usable range.
In value methods expecting a string type, the value is a float type representation.

The default return value after creation is 0.0.
Note, that the floating type structure specified by this data type isn't really precise, especially for bigger floating numbers, so you have to expect certain rounding deviations.


Field Summary
static DPT DPT_AIR_PRESSURE
          DPT ID 9.006, Air pressure; values from 0 to +670760 Pa.
static DPT DPT_AIRQUALITY
          DPT ID 9.008, Air quality; values from 0 to +670760 ppm.
static DPT DPT_ELECTRICAL_CURRENT
          DPT ID 9.021, Electrical current; value range +/-670760 mA.
static DPT DPT_HUMIDITY
          DPT ID 9.007, Humidity; values from 0 to +670760 %.
static DPT DPT_INTENSITY_OF_LIGHT
          DPT ID 9.004, Intensity of light (Lux); values from 0 to +670760 lx.
static DPT DPT_KELVIN_PER_PERCENT
          DPT ID 9.023, Kelvin/percent; value range +/-670760 K/%.
static DPT DPT_POWER
          DPT ID 9.024, Power; value range +/-670760 kW.
static DPT DPT_POWERDENSITY
          DPT ID 9.022, Power density; value range +/-670760 W/m2.
static DPT DPT_TEMPERATURE
          DPT ID 9.001, Temperature; values from -273 to +670760 °C.
static DPT DPT_TEMPERATURE_DIFFERENCE
          DPT ID 9.002, Temperature difference; value range +/-670760 K.
static DPT DPT_TEMPERATURE_GRADIENT
          DPT ID 9.003, Temperature gradient; value range +/-670760 K/h.
static DPT DPT_TIME_DIFFERENCE1
          DPT ID 9.010, Time difference in seconds; value range +/-670760 s.
static DPT DPT_TIME_DIFFERENCE2
          DPT ID 9.011, Time difference in milliseconds; value range +/-670760 ms.
static DPT DPT_VOLTAGE
          DPT ID 9.020, Voltage; value range +/-670760 mV.
static DPT DPT_WIND_SPEED
          DPT ID 9.005, Wind speed; values from 0 to +670760 m/s.
 
Fields inherited from class tuwien.auto.calimero.dptxlator.DPTXlator
appendUnit, data, dpt, LOG_SERVICE, logger, typeSize
 
Constructor Summary
DPTXlator2ByteFloat(DPT dpt)
          Creates a translator for the given datapoint type.
DPTXlator2ByteFloat(java.lang.String dptID)
          Creates a translator for dptID.
 
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.
 java.util.Map getSubTypes()
          Returns all available, implemented subtypes for the translator.
protected static java.util.Map getSubTypesStatic()
           
 float getValueFloat()
          Returns the first translation item formatted as float.
 void setData(byte[] data, int offset)
          Sets the data array with KNX datapoint type items for translation.
 void setValue(float value)
          Sets the translation value from a float.
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.
 
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

DPT_AIR_PRESSURE

public static final DPT DPT_AIR_PRESSURE
DPT ID 9.006, Air pressure; values from 0 to +670760 Pa.


DPT_AIRQUALITY

public static final DPT DPT_AIRQUALITY
DPT ID 9.008, Air quality; values from 0 to +670760 ppm.


DPT_ELECTRICAL_CURRENT

public static final DPT DPT_ELECTRICAL_CURRENT
DPT ID 9.021, Electrical current; value range +/-670760 mA.


DPT_HUMIDITY

public static final DPT DPT_HUMIDITY
DPT ID 9.007, Humidity; values from 0 to +670760 %.


DPT_INTENSITY_OF_LIGHT

public static final DPT DPT_INTENSITY_OF_LIGHT
DPT ID 9.004, Intensity of light (Lux); values from 0 to +670760 lx.

Note: the unit of measure symbol used here is "lx", and not "Lux" as originally proposed for this DPT.


DPT_KELVIN_PER_PERCENT

public static final DPT DPT_KELVIN_PER_PERCENT
DPT ID 9.023, Kelvin/percent; value range +/-670760 K/%.


DPT_POWER

public static final DPT DPT_POWER
DPT ID 9.024, Power; value range +/-670760 kW.


DPT_POWERDENSITY

public static final DPT DPT_POWERDENSITY
DPT ID 9.022, Power density; value range +/-670760 W/m2.


DPT_TEMPERATURE

public static final DPT DPT_TEMPERATURE
DPT ID 9.001, Temperature; values from -273 to +670760 °C.


DPT_TEMPERATURE_DIFFERENCE

public static final DPT DPT_TEMPERATURE_DIFFERENCE
DPT ID 9.002, Temperature difference; value range +/-670760 K.


DPT_TEMPERATURE_GRADIENT

public static final DPT DPT_TEMPERATURE_GRADIENT
DPT ID 9.003, Temperature gradient; value range +/-670760 K/h.


DPT_TIME_DIFFERENCE1

public static final DPT DPT_TIME_DIFFERENCE1
DPT ID 9.010, Time difference in seconds; value range +/-670760 s.


DPT_TIME_DIFFERENCE2

public static final DPT DPT_TIME_DIFFERENCE2
DPT ID 9.011, Time difference in milliseconds; value range +/-670760 ms.


DPT_VOLTAGE

public static final DPT DPT_VOLTAGE
DPT ID 9.020, Voltage; value range +/-670760 mV.


DPT_WIND_SPEED

public static final DPT DPT_WIND_SPEED
DPT ID 9.005, Wind speed; values from 0 to +670760 m/s.

Constructor Detail

DPTXlator2ByteFloat

public DPTXlator2ByteFloat(DPT dpt)
                    throws KNXFormatException
Creates a translator for the given datapoint type.

Parameters:
dpt - the requested datapoint type
Throws:
KNXFormatException - on not supported or not available DPT

DPTXlator2ByteFloat

public DPTXlator2ByteFloat(java.lang.String dptID)
                    throws KNXFormatException
Creates a translator for dptID.

Parameters:
dptID - available implemented datapoint type ID
Throws:
KNXFormatException - on wrong formatted or not expected (available) DPT
Method Detail

getAllValues

public java.lang.String[] getAllValues()
Description copied from class: DPTXlator
Returns all translation items as strings currently contained in this translator.

The items are ordered the same way handed to the translator in the first place (FIFO, increasing byte index).

Specified by:
getAllValues in class DPTXlator
Returns:
an array of strings with values represented as strings
See Also:
DPTXlator.getValue()

getData

public byte[] getData(byte[] dst,
                      int offset)
Description copied from class: DPTXlator
Copies KNX DPT value items stored by this translator into 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.

Specified by:
getData in class DPTXlator
Parameters:
dst - byte array for storing DPT values
offset - offset into dst from where to start, 0 <= offset < dst.length
Returns:
dst

getSubTypes

public java.util.Map getSubTypes()
Description copied from class: DPTXlator
Returns all available, implemented subtypes for the translator.

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.

Specified by:
getSubTypes in class DPTXlator
Returns:
subtypes as Map, key is the subtype ID of type string, value of type DPT

getSubTypesStatic

protected static java.util.Map getSubTypesStatic()
Returns:
the subtypes of the 2-byte float translator type
See Also:
DPTXlator.getSubTypesStatic()

getValueFloat

public final float getValueFloat()
Returns the first translation item formatted as float.

Returns:
value as float

setData

public void setData(byte[] data,
                    int offset)
Description copied from class: DPTXlator
Sets the data array with KNX datapoint type items for translation.

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.

Specified by:
setData in class DPTXlator
Parameters:
data - byte array containing KNX DPT item(s)
offset - offset into data from where to start, 0 <= offset < data.length

setValue

public void setValue(float value)
              throws KNXFormatException
Sets the translation value from a float.

If succeeded, any other items in the translator are discarded.

Parameters:
value - the float value
Throws:
KNXFormatException - if valuedoesn't fit into KNX data type

toDPT

protected void toDPT(java.lang.String value,
                     short[] dst,
                     int index)
              throws KNXFormatException
Description copied from class: DPTXlator
Translates a string value representation into KNX data type according the current DPT and stores the result into 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.

Specified by:
toDPT in class DPTXlator
Parameters:
value - value to translate
dst - destination array for resulting KNX data
index - item index in destination array
Throws:
KNXFormatException - if value can't be translated due to wrong formatted content, or if valuedoesn't fit into KNX data type