protected static byte[] buildPayload(SendMessageType sendMessageType,MedtronicCNLSession pumpSession,byte[] payload) throws EncryptionException {
  byte payloadLength=(byte)(payload == null ? 0 : payload.length);
  ByteBuffer sendPayloadBuffer=ByteBuffer.allocate(ENCRYPTED_ENVELOPE_SIZE + payloadLength + CRC_SIZE);
  sendPayloadBuffer.order(ByteOrder.BIG_ENDIAN);
  sendPayloadBuffer.put(sendSequenceNumber(sendMessageType));
  sendPayloadBuffer.putShort(sendMessageType.value);
  if (payloadLength != 0) {
    sendPayloadBuffer.put(payload);
  }
  sendPayloadBuffer.putShort((short)MessageUtils.CRC16CCITT(sendPayloadBuffer.array(),0xffff,0x1021,ENCRYPTED_ENVELOPE_SIZE + payloadLength));
  ByteBuffer payloadBuffer=ByteBuffer.allocate(ENVELOPE_SIZE + sendPayloadBuffer.capacity());
  payloadBuffer.order(ByteOrder.LITTLE_ENDIAN);
  payloadBuffer.putLong(pumpSession.getPumpMAC());
  payloadBuffer.put((byte)pumpSession.getMedtronicSequenceNumber());
  payloadBuffer.put((byte)0x10);
  payloadBuffer.put((byte)sendPayloadBuffer.capacity());
  payloadBuffer.put(encrypt(pumpSession.getKey(),pumpSession.getIV(),sendPayloadBuffer.array()));
  return payloadBuffer.array();
}

protected static byte [ ] buildPayload ( SendMessageType sendMessageType , MedtronicCNLSession pumpSession , byte [ ] payload ) throws EncryptionException { byte payloadLength = ( byte ) ( payload == null ? 0 : payload . length ) ; ByteBuffer sendPayloadBuffer = ByteBuffer . allocate ( ENCRYPTED_ENVELOPE_SIZE + payloadLength + CRC_SIZE ) ; sendPayloadBuffer . order ( ByteOrder . BIG_ENDIAN ) ; sendPayloadBuffer . put ( sendSequenceNumber ( sendMessageType ) ) ; sendPayloadBuffer . putShort ( sendMessageType . value ) ; if ( payloadLength != 0 ) { sendPayloadBuffer . put ( payload ) ; } sendPayloadBuffer . putShort ( ( short ) MessageUtils . CRC16CCITT ( sendPayloadBuffer . array ( ) , 0xffff , 0x1021 , ENCRYPTED_ENVELOPE_SIZE + payloadLength ) ) ; ByteBuffer payloadBuffer = ByteBuffer . allocate ( ENVELOPE_SIZE + sendPayloadBuffer . capacity ( ) ) ; payloadBuffer . order ( ByteOrder . LITTLE_ENDIAN ) ; payloadBuffer . putLong ( pumpSession . getPumpMAC ( ) ) ; payloadBuffer . put ( ( byte ) pumpSession . getMedtronicSequenceNumber ( ) ) ; payloadBuffer . put ( ( byte ) 0x10 ) ; payloadBuffer . put ( ( byte ) sendPayloadBuffer . capacity ( ) ) ; payloadBuffer . put ( encrypt ( pumpSession . getKey ( ) , pumpSession . getIV ( ) , sendPayloadBuffer . array ( ) ) ) ; return payloadBuffer . array ( ) ; }
medtronicsendmessage : + - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + | le long pumpmac | byte medtronicsequencenumber | byte unknown | byte payload size | byte [ ] encrypted payload bytes | + - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + < p / > medtronicsendmessage ( decrypted payload ) : + - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - + | byte sendsequencenumber | be short sendmessagetype | byte [ ] payload bytes | be short ccitt crc | + - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - +
