Files
emcomm-tools-os-community/overlay/opt/emcomm-tools/bin/et-modem73
T

125 lines
3.3 KiB
Bash
Raw Normal View History

#!/bin/bash
#
# Author : Gaston Gonzalez
# Date : 30 June 2026
# Purpose : Wrapper script for starting modem73 with PnP support
#
# Preconditions:
# 1. Supported radio and audio interface are connected and properly detected
#
# Postconditions:
# 1. modem73 started with sane defaults
MODEM73_CONF_FILE="${HOME}/.config/modem73/settings"
usage() {
echo "usage: $(basename $0) <mode> [options]"
echo " <mode>"
echo " reliability - Max reliability (Slower Speed) [BPSK]"
echo " balanced - Balanced (Reliability and Speed) [QPSK]"
echo " speed - Max speed (Lower Reliability) [8PSK]"
echo ""
echo " [options]"
echo " --headless - Run modem73 headless"
}
HEADLESS=""
MODE=""
for arg in "$@"; do
case "$arg" in
--headless)
HEADLESS="--headless"
;;
reliability|balanced|speed)
if [[ -n "${MODE}" ]]; then
et-log "Only one mode may be specified."
usage
exit 1
fi
MODE="$arg"
;;
*)
echo "Unknown argument: $arg"
usage
exit 1
;;
esac
done
if [[ -z "${MODE}" ]]; then
et-log "Can't started modem73. Mode not specified."
usage
exit 1
fi
[[ -z ${ET_LOG_DIR} ]] && ET_LOG_DIR="${HOME}/.local/share/emcomm-tools"
[[ ! -e ${ET_LOG_DIR} ]] && mkdir -p ${ET_LOG_DIR}
start() {
update_config
if [[ $? -eq 0 ]]; then
systemctl is-active --quiet rigctld
if [[ $? -ne 0 ]]; then
et-log "Can't start modem73. rigctld not running. Ensure radio is selected."
notify_user "Can't start modem73. rigctld not running."
exit 1
fi
ALSA_DEVICE=$(et-system-info et-audio-card)
INPUT_AUDIO=$(modem73 --list-audio | grep input | grep $ALSA_DEVICE | cut -d":" -f3)
OUTPUT_AUDIO=$(modem73 --list-audio | grep output| grep $ALSA_DEVICE | cut -d":" -f3)
CMD="modem73 --input-device ${INPUT_AUDIO} --output-device ${OUTPUT_AUDIO} --ptt rigctl ${HEADLESS}"
et-log "Starting modem73 with: '${CMD}'"
echo
${CMD}
else
et-log "Error updating configuration. Can't start modem73"
exit 1
fi
}
update_config () {
# The modem73 configuration file causes issues when using it in combination with
# command line arguments during manual runs. It is best to remove it before each
# run and drive the modem using only command line arguments.
if [[ -e "${MODEM73_CONF_FILE}" ]]; then
et-log "Removing previous configuration file: ${MODEM73_CONF_FILE}"
rm -v ${MODEM73_CONF_FILE}
fi
et-log "Attempting to start modem73 in mode: '${MODE}'"
[ -z "$ET_USER_CONFIG" ] && ET_USER_CONFIG="${HOME}/.config/emcomm-tools/user.json"
CALLSIGN=$(cat ${ET_USER_CONFIG} | jq -r .callsign)
# 1. Check if the symlink was created by the udev rules
if [ -e /dev/et-audio ]; then
# 2. Check that this device was properly tagged with the ET_AUDIO env variable with a udev rule
APLAY_OUT=$(arecord -l | grep ET_AUDIO)
if [ $? -eq 0 ]; then
# Configure ALSA settings for sound card
/opt/emcomm-tools/bin/et-audio update-config
else
et-log "No ET_AUDIO device detected."
notify_user "Can't start modem73. No ET_AUDIO device detected."
exit 1
fi
else
et-log "No ET_AUDIO device plugged in."
notify_user "Can't start modem73. No supported audio device plugged in."
exit 1
fi
}
start