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

130 lines
3.3 KiB
Bash
Executable File

#!/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) <command> <type>"
echo " <command>"
echo " start - Start modem73 in selected mode"
echo " update-config - Update configuration for selected mode"
echo ""
echo " <type>"
echo " default - QPSK, normal frames, 1/2 code rate (recommended)"
}
if [[ $# -ne 2 ]]; then
usage
exit 1
fi
MODE=$2
case "${MODE}" in
default)
et-log "Configuration updates not yet implemented."
;;
*)
et-log "Can't started modem73. Mode '${MODE}' not supported"
usage
exit 1
;;
esac
notify_user() {
notify-send \
-t 10000 \
--app-name="EmComm Tools" \
"$1"
}
[ -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
}
case $1 in
start)
start
;;
update-config)
update_config
;;
*)
echo "Invalid command."
usage
exit 1
;;
esac