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