protected static byte[] buildPayload(CommandAction commandAction,byte[] payload){
  byte payloadLength=(byte)(payload == null ? 0 : payload.length);
  ByteBuffer payloadBuffer=ByteBuffer.allocate(ENVELOPE_SIZE + payloadLength + CRC_SIZE);
  payloadBuffer.order(ByteOrder.LITTLE_ENDIAN);
  payloadBuffer.put(commandAction.value);
  payloadBuffer.put((byte)(ENVELOPE_SIZE + payloadLength));
  if (payloadLength != 0) {
    payloadBuffer.put(payload != null ? payload : new byte[0]);
  }
  payloadBuffer.putShort((short)MessageUtils.CRC16CCITT(payloadBuffer.array(),0xffff,0x1021,ENVELOPE_SIZE + payloadLength));
  return payloadBuffer.array();
}

protected static byte [ ] buildPayload ( CommandAction commandAction , byte [ ] payload ) { byte payloadLength = ( byte ) ( payload == null ? 0 : payload . length ) ; ByteBuffer payloadBuffer = ByteBuffer . allocate ( ENVELOPE_SIZE + payloadLength + CRC_SIZE ) ; payloadBuffer . order ( ByteOrder . LITTLE_ENDIAN ) ; payloadBuffer . put ( commandAction . value ) ; payloadBuffer . put ( ( byte ) ( ENVELOPE_SIZE + payloadLength ) ) ; if ( payloadLength != 0 ) { payloadBuffer . put ( payload != null ? payload : new byte [ 0 ] ) ; } payloadBuffer . putShort ( ( short ) MessageUtils . CRC16CCITT ( payloadBuffer . array ( ) , 0xffff , 0x1021 , ENVELOPE_SIZE + payloadLength ) ) ; return payloadBuffer . array ( ) ; }
medtronicmessage : + - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - + | commandaction | byte payload size | byte [ ] payload bytes | le short ccitt crc | + - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - +
