Java Code Examples for org.apache.mina.core.buffer.IoBuffer#putFloat()

The following examples show how to use org.apache.mina.core.buffer.IoBuffer#putFloat() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ArduinoCodec.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
private void encodeWriteRequest ( final IoBuffer data, final WriteRequestMessage message )
{
    data.putShort ( message.getIndex () );
    final Object value = message.getData ();
    if ( value == null )
    {
        data.put ( (byte)0x00 );
    }
    else if ( value instanceof Boolean )
    {
        data.put ( (byte)0x01 );
        data.put ( (byte) ( (Boolean)value ? 0xFF : 0x00 ) );
    }
    else if ( value instanceof Float || value instanceof Double )
    {
        data.put ( (byte)0x04 );
        data.putFloat ( ( (Number)value ).floatValue () );
    }
    else if ( value instanceof Long )
    {
        data.put ( (byte)0x03 );
        data.putLong ( ( (Number)value ).longValue () );
    }
    else if ( value instanceof Number )
    {
        data.put ( (byte)0x02 );
        data.putInt ( ( (Number)value ).intValue () );
    }
    else if ( value instanceof String )
    {
        data.put ( (byte)0x02 );
        data.putInt ( Integer.parseInt ( (String)value ) );
    }
    else
    {
        throw new RuntimeException ( String.format ( "Unable to write request of type %s", value.getClass () ) );
    }
}
 
Example 2
Source File: FloatFieldTypeHandler.java    From CXTouch with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void encode(Float value, IoBuffer outBuffer) {
    float val = value;
    outBuffer.put(getType());
    outBuffer.putFloat(val);
}
 
Example 3
Source File: DaveHandler.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
@SuppressWarnings ( "unused" )
private void sendWriteFloatData ()
{

    final float f = this.r.nextFloat ();

    logger.info ( "Sending float: {}", f );

    final DaveWriteRequest request = new DaveWriteRequest ();

    this.tix++;

    final IoBuffer data = IoBuffer.allocate ( 4 );
    data.putFloat ( f );
    data.flip ();
    request.addRequest ( new DaveWriteRequest.ByteRequest ( (byte)0x84, (short)1, (short)214, data ) );

    this.session.write ( request );
}