public byte [ ] getMessageBuffer ( ) { ByteArrayOutputStream resultByteBuffer = new ByteArrayOutputStream ( ) ; byte [ ] result ; resultByteBuffer . write ( ( byte ) 0x01 ) ; int messageLength = messagePayload . length + ( this . messageClass == SerialMessageClass . SendData && this . messageType == SerialMessageType . Request ? 5 : 3 ) ; // calculate and set length resultByteBuffer . write ( ( byte ) messageLength ) ; resultByteBuffer . write ( ( byte ) messageType . ordinal ( ) ) ; resultByteBuffer . write ( ( byte ) messageClass . getKey ( ) ) ; try { resultByteBuffer . write ( messagePayload ) ; } catch ( IOException e ) { } // callback ID and transmit options for a Send Data message. if ( this . messageClass == SerialMessageClass . SendData && this . messageType == SerialMessageType . Request ) { resultByteBuffer . write ( transmitOptions ) ; resultByteBuffer . write ( callbackId ) ; } resultByteBuffer . write ( ( byte ) 0x00 ) ; result = resultByteBuffer . toByteArray ( ) ; result [ result . length - 1 ] = 0x01 ; result [ result . length - 1 ] = calculateChecksum ( result ) ; logger . debug ( "Assembled message buffer = " + SerialMessage . bb2hex ( result ) ) ; return result ; }
Gets the SerialMessage as a byte array .