/**
   * Gets a SerialMessage with the PROTECTION_SET command
   *
   * @return the serial message, or null if the supported command is not supported.
   */
  public SerialMessage setValueMessage(LocalProtectionType localMode, RfProtectionType rfMode) {
    logger.debug("NODE {}: Creating new message for command PROTECTION_SET", getNode().getNodeId());

    SerialMessage result =
        new SerialMessage(
            getNode().getNodeId(),
            SerialMessageClass.SendData,
            SerialMessageType.Request,
            SerialMessageClass.SendData,
            SerialMessagePriority.Set);

    LocalProtectionType newLocalMode = localMode != null ? localMode : currentLocalMode;

    ByteArrayOutputStream outputData = new ByteArrayOutputStream();
    if (getVersion() < 2 || rfMode == null) {
      outputData.write(getNode().getNodeId());
      outputData.write(3);
      outputData.write(getCommandClass().getKey());
      outputData.write(PROTECTION_SET);
      outputData.write(newLocalMode.ordinal());
    } else {
      outputData.write(getNode().getNodeId());
      outputData.write(4);
      outputData.write(getCommandClass().getKey());
      outputData.write(PROTECTION_SET);
      outputData.write(newLocalMode.ordinal());
      outputData.write(rfMode.ordinal());
    }
    result.setMessagePayload(outputData.toByteArray());
    return result;
  }