#! /bin/sh

# Debugging tool to display SD card messages.

# Normally the Application receives and processes these messages, so don't run
# sdmon while the Application is running unless you know what you're doing.

while :; do
    msg=$(plethora msg-receive /app-sdinfo)
    msg_type=${msg:0:1}
    cardnum=${msg:1:1}
    info=""
    if [ "${msg:2:1}" = ':' ]; then info=${msg:3}; fi

    case $msg_type in
    F) echo "card $cardnum started formatting" ;;
    f) echo "card $cardnum formatted and mounted on $info" ;;
    I) echo "card $cardnum detected" ;;
    i) echo "card $cardnum mounted on $info" ;;
    r) echo "card $cardnum unmounted" ;;
    p) echo "card $cardnum is $info% complete" ;;
    e) echo "card $cardnum encountered error $info" ;;
    *) echo "unrecognized message: $msg" ;;
    esac
done
