From 2bdbf613e81dc655d711542991f863c7d6d35b4d Mon Sep 17 00:00:00 2001 From: Cameron Thompson <50184035+iamromulan@users.noreply.github.com> Date: Sat, 16 Mar 2024 19:27:40 -0400 Subject: [PATCH] Update atcmd --- socat-at-bridge/atcmd | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/socat-at-bridge/atcmd b/socat-at-bridge/atcmd index 58173ab..8efb075 100644 --- a/socat-at-bridge/atcmd +++ b/socat-at-bridge/atcmd @@ -1,10 +1,27 @@ #!/bin/bash DEVICE=/dev/ttyOUT2 -BAUD=115200 -# Configure device with stty -stty -F $DEVICE $BAUD raw -echo +# Function to setup device communication parameters +setup_device() { + stty -F $DEVICE cs8 115200 ignbrk -brkint -icrnl -imaxbel \ + -opost -onlcr -isig -icanon -iexten -echo -echoe -echok \ + -echoctl -echoke noflsh -ixon -crtscts +} + +# Function to read from device until "OK" or "ERROR" is found +read_response() { + { + while IFS= read -r line; do + echo -e "\033[0;32m$line\033[0m" + if [[ "$line" == *"OK" || "$line" == *"ERROR" ]]; then + break + fi + done < "$DEVICE" + } & + READ_PID=$! + wait $READ_PID +} echo -e "\033[0;36mType 'exit' to end the session.\033[0m" while true; do @@ -16,17 +33,7 @@ while true; do exit 0 fi - # Send the AT command to the device + setup_device echo -e "$user_input\r" > $DEVICE - - # Prepare to capture the response - { - # Keep reading until we find a line ending with OK or ERROR - while IFS= read -r line; do - echo -e "\033[0;32m$line\033[0m" - if [[ "$line" == *OK || "$line" == *ERROR ]]; then - break - fi - done - } < $DEVICE + read_response done