#!/bin/bash

# Make sure that the SLPI DSP test signature is there otherwise px4 cannot run
# on the DSP
if /bin/ls /usr/lib/rfsa/adsp/testsig-*.so &> /dev/null; then
    /bin/echo "Found DSP signature file"
else
    /bin/echo "Error, could not find DSP signature file"
    # Look for the DSP signature generation script
    if [ -f /share/modalai/qrb5165-slpi-test-sig/generate-test-sig.sh ]; then
        /bin/echo "Attempting to generate the DSP signature file"
        # Automatically generate the test signature so that px4 can run on SLPI DSP
        /share/modalai/qrb5165-slpi-test-sig/generate-test-sig.sh
    else
        /bin/echo "Could not find the DSP signature file generation script"
        exit 0
    fi
fi

# Make sure to setup all of the needed px4 aliases.
cd /usr/bin
/bin/ln -f -s px4 px4-muorb
cd -

DAEMON=" "
S="OFF"

while getopts "ds" flag
do
    case "${flag}" in
        # Use -d to put PX4 into daemon mode
        d) DAEMON="-d";;
        # Use -s to run self tests
        s) S="ON";;
    esac
done

TESTMODE=$S px4 $DAEMON -s /etc/modalai/voxl-px4.config
