bashrc/.bashrc.d/cn-progload.bash

47 lines
1.3 KiB
Bash
Raw Normal View History

2019-12-11 17:46:30 +00:00
cn-progload() {
local addr="$1"
local project="$2" # /foo/bar/baz.bunk
local ext="${project##*.}" # bunk
local projfname="${project%.*}" # /foo/bar/baz
local projfnamebase="${projfname##*/}" # baz
local zigstash
zigstash="$(mktemp /tmp/$projfnamebase.XXXX.zig)"
2019-12-11 17:46:30 +00:00
# Add a zero in front of the 3rd arg
local slot="0${3}"
# expand only to the last 2 digits of $slot
slot="${slot: -2}"
case $ext in
vtz)
if [[ -n $slot ]]; then
2019-12-11 17:46:30 +00:00
echo "==NOTICE== Ignoring slot number for touchpanel project..."
fi
printf 'put %q %q' "$project" "/display/"| cnsftp "$addr"
cnssh "$addr" projectload
2019-12-11 17:46:30 +00:00
;;
lpz)
if [[ -z $slot ]]; then
echo "==NOTICE== No target program slot defined. Assuming Slot 01..."
slot=01
fi
# Stop and delete current program in $slot
cnssh "$addr" killprog -P$slot
# Upload
printf 'put %q %q' "$project" "/Program$slot" | cnsftp "$addr"
# Load the program
cnssh "$addr" progload -p:$slot
# Zip up the sig file in a temporary location
zip -j - "$projfname.sig" > "$zigstash"
# Upload the zig
printf 'put %q %q' "$zigstash" "/Program$slot/$projfnamebase.zig" | cnsftp "$addr"
2019-12-11 17:46:30 +00:00
;;
*)
echo "Error: Bad file type. Currently only supports vtz and lpz projects."
;;
esac
}