Tasten-Kommando-Mapping für Linphone

Aus Grannophone
Zur Navigation springenZur Suche springen

Tasten-Kommando-Mapping für Linphone“

Grundproblem

Anders als baresip kennt linphone keine Tastenkürzel zur Fernsteuerung. Es können lediglich über linphone-cli Kommandos an ein laufendes linphone gesendet werden, zum Beispiel die Rufannahme mittels linphone-cli "answer" und das Auflegen mittels linphone-cli "terminate"

Lösungsansatz

Über UDEV die einzelnen Tasten, die wir über die config.txt bestimmten GPIOs und damit bestimmten Tastern (Gabelumschalter etc.) zugewiesen haben, auf die linphone-cli-Kommandos mappen.

Achtung, die folgende Lösung stammt aus den Antworten eines LLM, und ist ungetestet

Grundsätzliche Einrichtung

sudo apt update && sudo apt install linphone-cli evtest

Für Systemd

/usr/local/bin/linphone-gpio-hook.sh

#!/bin/bash
# Expose the correct PipeWire runtime pathway to the linphone-cli commands
export XDG_RUNTIME_DIR=/run/user/1000

# Exit if no input device passed from udev
DEVICE="$1"
if [ -z "$DEVICE" ]; then
    exit 1
fi

# Use evtest to block and monitor input packets continuously
# It looks for lines matching KEY_A or KEY_H with value 1 (key down / pressed)
evtest "$DEVICE" | while read -r line; do
    if echo "$line" | grep -q "code 30 (KEY_A), value 1"; then
        logger "Linphone Hook: Button A pressed. Answering call."
        linphone-cli "answer"
    elif echo "$line" | grep -q "code 35 (KEY_H), value 1"; then
        logger "Linphone Hook: Button H pressed. Terminating call."
        linphone-cli "terminate"
    fi
done

Ausführbar machen

sudo chmod +x /usr/local/bin/linphone-gpio-hook.sh

/etc/udev/rules.d/99-linphone-gpio.rules

# Matches the specific gpio-keys layout framework populated by config.txt overlays
SUBSYSTEM=="input", KERNEL=="event*", SUBSYSTEMS=="platform", DRIVERS=="gpio-keys", ACTION=="add", RUN+="/usr/bin/systemctl start linphone-gpio-monitor@%k.service"

/etc/systemd/system/linphone-gpio-monitor@.service

[Unit]
Description=Linphone GPIO Input Event Monitor on %I
After=linphone-daemon.service

[Service]
Type=simple
User=pi
ExecStart=/usr/local/bin/linphone-gpio-hook.sh /dev/input/%I
Restart=on-failure

[Install]
WantedBy=multi-user.target

Zum Aktivieren

sudo udevadm control --reload-rules && sudo systemctl daemon-reload


Für SysVinit

/usr/local/bin/linphone-gpio-hook.sh

#!/bin/bash
export XDG_RUNTIME_DIR=/run/user/1000

DEVICE="$1"
PIDFILE="/var/run/linphone-gpio-hook.pid"

# If called with "stop", kill the running evtest monitor loop
if [ "$2" = "stop" ]; then
    if [ -f "$PIDFILE" ]; then
        kill $(cat "$PIDFILE") 2>/dev/null
        rm -f "$PIDFILE"
    fi
    exit 0
fi

# Exit if no device path is valid
if [ -z "$DEVICE" ] || [ ! -e "$DEVICE" ]; then
    exit 1

# Use evtest to block and monitor input packets continuously
# It looks for lines matching KEY_A or KEY_H with value 1 (key down / pressed)
evtest "$DEVICE" | while read -r line; do
    if echo "$line" | grep -q "code 30 (KEY_A), value 1"; then
        logger "Linphone Hook: Button A pressed. Answering call."
        linphone-cli "answer"
    elif echo "$line" | grep -q "code 35 (KEY_H), value 1"; then
        logger "Linphone Hook: Button H pressed. Terminating call."
        linphone-cli "terminate"
    fi
done

/etc/init.d/linphone-gpio-monitor

#!/bin/sh
### BEGIN INIT INFO
# Provides:          linphone-gpio-monitor
# Required-Start:    $local_fs linphone-daemon
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Classic SysVinit Monitor for GPIO Keys
### END INIT INFO

SCRIPT=/usr/local/bin/linphone-gpio-hook.sh
PIDFILE=/var/run/linphone-gpio-hook.pid

# Dynamically find the event handle belonging to your gpio-keys device tree setup
find_device() {
    for dev in /dev/input/event*; do
        if [ -e "$dev" ] && udevadm info --query=property --name="$dev" | grep -q "ID_INPUT_KEYBOARD=1"; then
            echo "$dev"
            return 0
        fi
    done
    # Fallback to scanning platform subsystems directly if properties aren't populated yet
    echo "/dev/input/by-path/platform-gpio-keys-event"
}

case "$1" in
    start)
        DEVICE=$(find_device)
        if [ ! -e "$DEVICE" ]; then
            echo "GPIO Input Device not found yet. Postponing hook..."
            exit 1
        fi
        echo "Starting Linphone GPIO Monitor on $DEVICE..."
        start-stop-daemon --start --background --make-pidfile --pidfile "$PIDFILE" --chuid pi --exec "$SCRIPT" -- "$DEVICE"
        ;;
    stop)
        echo "Stopping Linphone GPIO Monitor..."
        $SCRIPT "" "stop"
        start-stop-daemon --stop --pidfile "$PIDFILE" --retry 5
        rm -f "$PIDFILE"
        ;;
    restart)
        $0 stop
        sleep 1
        $0 start
        ;;
    *)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
        ;;
esac

exit 0

Ausführbar machen und beim Systemstart starten

sudo chmod +x /etc/init.d/linphone-gpio-monitor
sudo update-rc.d linphone-gpio-monitor defaults 99

/etc/udev/rules.d/99-linphone-gpio.rules

# Triggers the classic init script asynchronously whenever the gpio-keys kernel profile maps at boot
SUBSYSTEM=="input", KERNEL=="event*", SUBSYSTEMS=="platform", DRIVERS=="gpio-keys", ACTION=="add", RUN+="/etc/init.d/linphone-gpio-monitor start"

Zum Aktivieren

sudo udevadm control --reload-rules