public byte[] getData(byte[] dst, int offset)
	{
		final int end = Math.min(data.length, dst.length - offset) & ~0x01;
		for (int i = 0; i < end; ++i)
			dst[offset + i] = (byte) data[i];
		return dst;
	}

	/* (non-Javadoc)
	 * @see tuwien.auto.calimero.dptxlator.DPTXlator#getSubTypes()
	 */
	public Map getSubTypes()
	{
		return types;
	}

	/**
	 * @return the subtypes of the 2-byte float translator type
	 * @see DPTXlator#getSubTypesStatic()
	 */
	protected static Map getSubTypesStatic()
	{
		return types;
	}

	private String makeString(int index)
	{
		return appendUnit(String.valueOf(fromDPT(index)));
	}

	private float fromDPT(int index)
	{
		final int i = 2 * index;
		// DPT bits high byte: MEEEEMMM, low byte: MMMMMMMM
		// left align all mantissa bits
		int v = ((data[i] & 0x80) << 24) | ((data[i] & 0x7) << 28) | (data[i + 1] << 20);
		// normalize
		v >>= 20;
		final int exp = (data[i] & 0x78) >> 3;
		return (float) ((1 << exp) * v * 0.01);
	}

	private void toDPT(float value, short[] dst, int index) throws KNXFormatException
	{
		if (value < min || value > max)
			throw logThrow(LogLevel.WARN, "translation error for " + value,
				"value out of range [" + dpt.getLowerValue() + ".." + dpt.getUpperValue()
					+ "]", Float.toString(value));
		// encoding: value = (0.01*M)*2^E
		float v = value * 100.0f;
		int e = 0;
		for (; v < -2048.0f; v /= 2)
			e++;
		for (; v > 2047.0f; v /= 2)
			e++;
		final int m = Math.round(v) & 0x7FF;
		short msb = (short) (e << 3 | m >> 8);
		if (value < 0.0f)
			msb |= 0x80;
		dst[2 * index] = msb;
		dst[2 * index + 1] = ubyte(m);
	}

	protected void toDPT(String value, short[] dst, int index) throws KNXFormatException
	{
		try {
			toDPT(Float.parseFloat(removeUnit(value)), dst, index);
		}
		catch (final NumberFormatException e) {
			throw logThrow(LogLevel.WARN, "wrong value format " + value, null, value);
		}
	}

	private float getLimit(String limit) throws KNXFormatException
	{
		try {
			final float f = Float.parseFloat(limit);
			if (f >= -671088.64f && f <= 670760.96f)
				return f;
		}
		catch (final NumberFormatException e) {}
		throw logThrow(LogLevel.ERROR, "limit " + limit, "invalid DPT range", limit);
	}
}
public byte [ ] getData ( byte [ ] dst , int offset ) { final int end = Math . min ( data . length , dst . length - offset ) & ~ 0x01 ; for ( int i = 0 ; i < end ; ++ i ) dst [ offset + i ] = ( byte ) data [ i ] ; return dst ; } public Map getSubTypes ( ) { return types ; } protected static Map getSubTypesStatic ( ) { return types ; } private String makeString ( int index ) { return appendUnit ( String . valueOf ( fromDPT ( index ) ) ) ; } private float fromDPT ( int index ) { final int i = 2 * index ; int v = ( ( data [ i ] & 0x80 ) << 24 ) | ( ( data [ i ] & 0x7 ) << 28 ) | ( data [ i + 1 ] << 20 ) ; v >>= 20 ; final int exp = ( data [ i ] & 0x78 ) > > 3 ; return ( float ) ( ( 1 << exp ) * v * 0.01 ) ; } private void toDPT ( float value , short [ ] dst , int index ) throws KNXFormatException { if ( value < min || value > max ) throw logThrow ( LogLevel . WARN , "translation error for " + value , "value out of range [" + dpt . getLowerValue ( ) + ".." + dpt . getUpperValue ( ) + "]" , Float . toString ( value ) ) ; float v = value * 100.0f ; int e = 0 ; for ( ; v < - 2048.0f ; v /= 2 ) e ++ ; for ( ; v > 2047.0f ; v /= 2 ) e ++ ; final int m = Math . round ( v ) & 0x7FF ; short msb = ( short ) ( e << 3 | m > > 8 ) ; if ( value < 0.0f ) msb |= 0x80 ; dst [ 2 * index ] = msb ; dst [ 2 * index + 1 ] = ubyte ( m ) ; } protected void toDPT ( String value , short [ ] dst , int index ) throws KNXFormatException { try { toDPT ( Float . parseFloat ( removeUnit ( value ) ) , dst , index ) ; } catch ( final NumberFormatException e ) { throw logThrow ( LogLevel . WARN , "wrong value format " + value , null , value ) ; } } private float getLimit ( String limit ) throws KNXFormatException { try { final float f = Float . parseFloat ( limit ) ; if ( f >= - 671088.64f && f <= 670760.96f ) return f ; } catch ( final NumberFormatException e ) { } throw logThrow ( LogLevel . ERROR , "limit " + limit , "invalid DPT range" , limit ) ; } }
/* (non-Javadoc)
@see tuwien.auto.calimero.dptxlator.DPTXlator#getData(byte[], int)