#!/bin/bash
# Usage:
#
# ./teleop/ziod/tools/rti_dds_ping.sh -domainId 2 -pub -qosProfile tools_qos::tools_secure
# ./teleop/ziod/tools/rti_dds_ping.sh -domainId 2 -sub -qosProfile tools_qos::tools_secure
#
# NDDS_DISCOVERY_PEERS=5.6.7.8 PUBLIC_IP_ADDRESS=1.2.3.4 ./teleop/ziod/tools/rti_dds_ping.sh -domainId 2 -pub -qosProfile tools_qos::tools_secure_nat
# ./teleop/ziod/tools/rti_dds_ping.sh  -domainId 2 -sub -qosProfile tools_qos::tools_secure

set -euo pipefail

# Find workspace and set up env
workspace=$(bazel info workspace)
cd ${workspace}
source "${workspace}/scripts/shell/bazel/function.sh"

# Set root of the repo since the qos file needs it for certs
export ZOOX_WORKSPACE_ROOT=${workspace}

# A profile needs the public address in an environemnt variable
export PUBLIC_IP_ADDRESS=${PUBLIC_IP_ADDRESS:-"127.0.0.1"}

"${NDDSHOME}/bin/rtiddsping" "-qosFile" "${ZOOX_WORKSPACE_ROOT}/teleop/ziod/qos/TOOLS_QOS_PROFILES.xml" "${@}"
