Update atcmd

This commit is contained in:
Cameron Thompson
2024-03-16 19:13:39 -04:00
committed by GitHub
parent 2f01f9cacc
commit 91b8dde145

View File

@@ -2,39 +2,27 @@
DEVICE=/dev/ttyOUT2
BAUD=115200
TIMEOUT_DURATION=5 # Seconds to wait for a response
# Setup device
stty -F $DEVICE cs8 $BAUD ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts
# Main loop
echo -e "\033[0;36mType 'exit' to end the session.\033[0m"
while true; do
echo -en "\033[0;36mEnter AT Command: \033[0m"
read user_input
# Exit condition
if [[ "$user_input" == "exit" ]]; then
echo -e "\033[0;32mExiting...\033[0m"
break
exit 0
fi
# Send command to device
echo -e "$user_input\r" > $DEVICE &
# Send command to the device
echo -e "$user_input\r" > $DEVICE
# Read output in the background
(cat $DEVICE > /tmp/response & PID=$!
# Wait for "OK" or "ERROR" to appear in the output
while ! grep -qe "OK" -e "ERROR" /tmp/response; do
sleep 0.5
done
# Use timeout to read the device's output and ensure it doesn't hang
response=$(timeout $TIMEOUT_DURATION cat $DEVICE)
# Print the response in green
echo -en "\033[0;32m"
cat /tmp/response
echo -en "\033[0m"
echo -en "\033[0;32m$response\033[0m"
# Cleanup
> /tmp/response
) &
wait $!
done