Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: CLI option for PiCW #5

Open
jacksnodgrass opened this issue Jan 7, 2024 · 1 comment
Open

Feature Request: CLI option for PiCW #5

jacksnodgrass opened this issue Jan 7, 2024 · 1 comment

Comments

@jacksnodgrass
Copy link

Another thought.... I'd like to be able to maybe do some PiCW stuff from a web page. To do that, I think that having a CLI of some sort for PiCW would be nice to have available. Something like:
PiCW --speed=15 --cmd=kb --data="cq cq cq de ka5ojd"
or
PiCW --speed=10 --cmd=xmit --data="/var/www/html/morse_code/cq_cq.cw"
Having this cli would let me have a web page to do a GUI interface with clickable buttons or access my rig from a different room in my home or my laptop.

@ykaw
Copy link
Owner

ykaw commented Jan 8, 2024

As a quick hack, I wrote a shell script that writes PiCW actions specified on the command line to standard output.

$ ./PiCWwrappher.sh --speed 15 --cmd kb --data "Hello, world"
15
KB
Hello, world
$ ./PiCWwrappher.sh --speed 15 --cmd xmit --data "hello.txt"
15
XMIT hello.txt

I think you can control the keyer by piping this output to PiCW.
However, I don't have an actual Raspberry Pi at hand, so I can't actually try it out.
Note that an equal sign is not required between the option and its argument.

#!/bin/sh

# PiCWwrapper.sh - a command line wrapper
#                  for PiCW morse keyer

PROGNAME=${0##*/}
usage () {
    cat <<EOF >&2
Usage: $PROGNAME [options]

options:
  --speed s   :  set speed to s WPM
  --cmd kb    :  execute KB subcommand
  --cmd xmit  :  execut XMIT subcommand
  --data text :  specify a text to send
EOF
}

# parsing command line options
#
while [ -n "$1" ]; do
    case "$1" in
        -h|--help|'X-?')
            opt=h
            opt_h=1
            ;;
        --speed|--cmd|--xmit|--data)
            case "$1" in
                --speed) opt=s;;
                --cmd)   opt=c;;
                --xmit)  opt=x;;
                --data)  opt=d;;
            esac
            shift
            case "$1" in
                -*|'')
                    echo "${1}: no arguments given" >&2
                    usage;
                    exit 1
                    ;;
                *)
                    eval opt_${opt}=\""$1"\"
                    ;;
            esac
            ;;
        *) echo "unknown option: $opt" >&2
           usage;
           exit 1
           ;;
    esac
    shift
done

# help option
if [ -n "$opt_h" ]; then
    usage
    exit
fi

# set speed
#
if [ -n "$opt_s" ]; then
    echo "$opt_s"
fi

# process cmd with data
#
case "$opt_c" in
    kb|xmit)
        if [ -z "$opt_d" ]; then
            echo "no data to kb or xmit" >&2
            usage
            exit 1
        fi
        case "$opt_c" in
            kb)
                echo "KB"
                echo "$opt_d";;
            xmit)
                echo "XMIT ${opt_d}";;
        esac;;
    '') ;;
    *)
        usage
        exit 1;;
esac

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants