Skip to content

Instantly share code, notes, and snippets.

@tommyjtl
Created June 9, 2021 05:11
Show Gist options
  • Save tommyjtl/b0e4dee0e8820ed4de01edfa03c64d4c to your computer and use it in GitHub Desktop.
Save tommyjtl/b0e4dee0e8820ed4de01edfa03c64d4c to your computer and use it in GitHub Desktop.
function cocomod() {
# port list all detected ports: python3 -m there detect
# run run local file on module (not send): python3 -m there run [FILE]
# list list file: python3 -m there ls -l [/] python3 -m there run [FILE]
# send send file to module: python3 -m there push [FILE] [/]
# read get source code from file on module: python3 -m there cat [FILE]
# delete delete file from module: python3 -m there rm [FILE]
# repl enter repl: python3 -m there -i
# echo "Usage: burn, goto, port, run, list, send, read, delete, repl"
# `cocomod` tool for mac
# -m: mode
# ai:
# iot:
# -p: port
# -o: operation
# burn:
# repl:
# read:
# push:
# run:
# pull:
# delete:
# ls:
PORT=""
if [ $# -eq 0 ]; then
echo "No arguments provided, use \"help\" to get more information."
exit
else
if [ $1 = "ai" ]; then
echo "AI module mode selected."
# to do
elif [ $1 = "iot" ]; then
echo "IoT module mode selected."
if [ -z $2 ]; then
echo "No port specified"
else
if [ $2 = "default" ]; then
PORT="/dev/cu.SLAB_USBtoUART"
else
if [[ $2 == *"/dev/"* ]]; then
PORT=$2
else
PORT="invalid"
fi
fi
if [ $PORT = "invalid" ]; then
echo "Not a valid port name"
else
echo "Using port: $PORT"
if [ -z $3 ]; then
echo "No operation parameters found"
else
if [ $3 = "burn" ]; then
if [ -z $4 ]; then
echo "Please specify a firmware to burn"
else
if [[ -f $4 ]]; then
esptool.py --chip esp32 --port $PORT erase_flash
esptool.py --chip esp32 --port $PORT --baud 460800 write_flash -z 0x1000 $4
else
echo "Unable to find the firmware file"
fi
fi
elif [ $3 = "repl" ]; then
echo "Entering REPL..."
python -m there -i
elif [ $3 = "push" ]; then
if [ -z $4 ]; then
echo "Please specify a file to send"
else
if [[ -f $4 ]]; then
if [ -z $5 ]; then
echo "Please specify the path you want to send in the module"
else
python -m there push $4 $5
fi
else
echo "Unable to find the code file"
fi
fi
elif [ $3 = "run" ]; then
if [ -z $4 ]; then
echo "Please specify a file to run"
else
if [[ -f $4 ]]; then
python -m there run $4 -t 60
else
echo "Unable to find the code file"
fi
fi
elif [ $3 = "pull" ]; then
if [ -z $4 ]; then
echo "Please specify a file to be pulled from the module"
else
if [ -z $5 ]; then
echo "Please specify the destination path you want place on your computer"
else
python -m there pull $4 $5
fi
fi
elif [ $3 = "read" ]; then
if [ -z $4 ]; then
echo "Please specify a file to be read from the module"
else
python -m there cat $4
fi
elif [ $3 = "delete" ]; then
if [ -z $4 ]; then
echo "Please specify a file to be deleted on the module"
else
python -m there rm $4
fi
elif [ $3 = "ls" ]; then
echo ""
fi
fi
fi
fi
elif [ $1 = "help" ]; then
echo "To be edited."
else
echo "No mode provided, use \"help\" to get more information."
fi
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment