From 865adc2fcda3d369e8a8863d11d60a3f342e90af Mon Sep 17 00:00:00 2001 From: Cameron Thompson <50184035+iamromulan@users.noreply.github.com> Date: Sat, 13 Jul 2024 23:23:20 -0400 Subject: [PATCH] Add atcmd11 Separate commands for separate AT streams --- .../scripts/update_socat-at-bridge.sh | 3 + socat-at-bridge/atcmd11 | 69 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 socat-at-bridge/atcmd11 diff --git a/simpleupdates/scripts/update_socat-at-bridge.sh b/simpleupdates/scripts/update_socat-at-bridge.sh index 917c9db..51858d4 100644 --- a/simpleupdates/scripts/update_socat-at-bridge.sh +++ b/simpleupdates/scripts/update_socat-at-bridge.sh @@ -88,6 +88,7 @@ install_at_socat() { wget https://raw.githubusercontent.com/$GITUSER/quectel-rgmii-toolkit/$GITTREE/socat-at-bridge/socat-armel-static wget https://raw.githubusercontent.com/$GITUSER/quectel-rgmii-toolkit/$GITTREE/socat-at-bridge/killsmd7bridge wget https://raw.githubusercontent.com/$GITUSER/quectel-rgmii-toolkit/$GITTREE/socat-at-bridge/atcmd + wget https://raw.githubusercontent.com/$GITUSER/quectel-rgmii-toolkit/$GITTREE/socat-at-bridge/atcmd11 cd $SOCAT_AT_SYSD_DIR wget https://raw.githubusercontent.com/$GITUSER/quectel-rgmii-toolkit/$GITTREE/socat-at-bridge/systemd_units/socat-smd11.service wget https://raw.githubusercontent.com/$GITUSER/quectel-rgmii-toolkit/$GITTREE/socat-at-bridge/systemd_units/socat-smd11-from-ttyIN.service @@ -102,9 +103,11 @@ install_at_socat() { chmod +x socat-armel-static chmod +x killsmd7bridge chmod +x atcmd + chmod +x atcmd11 # Link new command for AT Commands from the shell ln -sf $SOCAT_AT_DIR/atcmd /bin + ln -sf $SOCAT_AT_DIR/atcmd11 /bin # Install service units echo -e "\033[0;32mAdding AT Socat Bridge systemd service units...\033[0m" diff --git a/socat-at-bridge/atcmd11 b/socat-at-bridge/atcmd11 new file mode 100644 index 0000000..f18f78e --- /dev/null +++ b/socat-at-bridge/atcmd11 @@ -0,0 +1,69 @@ +#!/bin/bash + +DEVICE=/dev/ttyOUT +BAUD=115200 + +# Function to setup device communication parameters +setup_device() { + stty -F $DEVICE cs8 $BAUD ignbrk -brkint -icrnl -imaxbel \ + -opost -onlcr -isig -icanon -iexten -echo -echoe -echok \ + -echoctl -echoke noflsh -ixon -crtscts +} + +# Function to send AT command and capture the output +send_at_command() { + local command="$1" + + # Clear the device buffer before sending a new command + echo -n > $DEVICE + + # Send the AT command, preserving the integrity of the input + echo -e "$command\r" > $DEVICE + + # Use a temporary file to capture the command output + tmpfile=$(mktemp) + + # Start reading the device output to the temporary file + cat $DEVICE > "$tmpfile" & + CAT_PID=$! + + # Monitor the output file for "OK" or "ERROR" + while ! grep -qe "OK" -e "ERROR" "$tmpfile"; do + sleep 1 + done + + # Kill the `cat` process after capturing the response + kill $CAT_PID + wait $CAT_PID 2>/dev/null + + # Display the response + cat "$tmpfile" | while IFS= read -r line; do + echo -e "\033[0;32m$line\033[0m" + done + + # Clean up + rm "$tmpfile" +} + +# Prepare the device for communication +setup_device + +# Check if an AT command is provided as an argument +if [ $# -gt 0 ]; then + # Concatenate all arguments to handle commands with spaces and/or quotes correctly + FULL_CMD="$*" + send_at_command "$FULL_CMD" +else + 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 + + if [[ "$user_input" == "exit" ]]; then + echo -e "\033[0;32mExiting...\033[0m" + break + fi + + send_at_command "$user_input" + done +fi