Add atcmd11
Separate commands for separate AT streams
This commit is contained in:
@@ -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/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/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/atcmd
|
||||||
|
wget https://raw.githubusercontent.com/$GITUSER/quectel-rgmii-toolkit/$GITTREE/socat-at-bridge/atcmd11
|
||||||
cd $SOCAT_AT_SYSD_DIR
|
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.service
|
||||||
wget https://raw.githubusercontent.com/$GITUSER/quectel-rgmii-toolkit/$GITTREE/socat-at-bridge/systemd_units/socat-smd11-from-ttyIN.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 socat-armel-static
|
||||||
chmod +x killsmd7bridge
|
chmod +x killsmd7bridge
|
||||||
chmod +x atcmd
|
chmod +x atcmd
|
||||||
|
chmod +x atcmd11
|
||||||
|
|
||||||
# Link new command for AT Commands from the shell
|
# Link new command for AT Commands from the shell
|
||||||
ln -sf $SOCAT_AT_DIR/atcmd /bin
|
ln -sf $SOCAT_AT_DIR/atcmd /bin
|
||||||
|
ln -sf $SOCAT_AT_DIR/atcmd11 /bin
|
||||||
|
|
||||||
# Install service units
|
# Install service units
|
||||||
echo -e "\033[0;32mAdding AT Socat Bridge systemd service units...\033[0m"
|
echo -e "\033[0;32mAdding AT Socat Bridge systemd service units...\033[0m"
|
||||||
|
|||||||
69
socat-at-bridge/atcmd11
Normal file
69
socat-at-bridge/atcmd11
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user