Major Toolkit Update: socat and TTYd

-Both SMD11 and SMD7 are now used to create 2 separate AT command flows/streams
   -SMD11 is linked to ttyOUT
   -SMD7 is linked to ttyOUT2
-ttyOUT is intended for use with automated AT commands like the modem status parse script
-ttyOUT2 is intended for user initiated AT commands like the AT Commands page in simpleadmin or the new atcmd shell command

-Entware installation has been improved for better compatibility and smoother install.

-Added the option to try out TTYd
   -This is a web based shell console you can access via http on port 443
   -More improvements to come
This commit is contained in:
iamromulan
2024-03-17 00:10:18 -04:00
parent a2d3bc2d87
commit 7d5d9fe74f
12 changed files with 563 additions and 228 deletions

55
socat-at-bridge/atcmd Normal file
View File

@@ -0,0 +1,55 @@
#!/bin/bash
DEVICE=/dev/ttyOUT2
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
}
# Prepare the device for communication
setup_device
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
# Clear the device buffer before sending a new command
echo -n > $DEVICE
# Send the AT command
echo -e "$user_input\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"
done

View File

@@ -0,0 +1,4 @@
#!/bin/bash
# Look for the process by its command and kill it so socat can have smd7 instead
pkill -f "/usr/bin/port_bridge smd7 at_usb2 1"

View File

@@ -0,0 +1,9 @@
[Unit]
Description=Kill port_bridge process on boot
[Service]
Type=oneshot
ExecStart=/usrdata/socat-at-bridge/killsmd7bridge
[Install]
WantedBy=multi-user.target

View File

@@ -1,10 +1,10 @@
[Unit]
Description=Read from /dev/ttyIN and write to smd7
Description=Read from /dev/ttyIN2 and write to smd7
BindsTo=socat-smd7.service
After=socat-smd7.service
[Service]
ExecStart=/bin/bash -c "/bin/cat /dev/ttyIN > /dev/smd7"
ExecStart=/bin/bash -c "/bin/cat /dev/ttyIN2 > /dev/smd7"
ExecStartPost=/bin/sleep 2s
StandardInput=tty-force
Restart=always

View File

@@ -1,10 +1,10 @@
[Unit]
Description=Read from /dev/smd7 and write to ttyIN
Description=Read from /dev/smd7 and write to ttyIN2
BindsTo=socat-smd7.service
After=socat-smd7.service
[Service]
ExecStart=/bin/bash -c "/bin/cat /dev/smd7 > /dev/ttyIN"
ExecStart=/bin/bash -c "/bin/cat /dev/smd7 > /dev/ttyIN2"
ExecStartPost=/bin/sleep 2s
StandardInput=tty-force
Restart=always

View File

@@ -3,7 +3,7 @@ Description=Socat Serial Emulation for smd7
After=ql-netd.service
[Service]
ExecStart=/usrdata/socat-at-bridge/socat-armel-static -d -d pty,link=/dev/ttyIN,raw,echo=0 pty,link=/dev/ttyOUT,raw,echo=1
ExecStart=/usrdata/socat-at-bridge/socat-armel-static -d -d pty,link=/dev/ttyIN2,raw,echo=0 pty,link=/dev/ttyOUT2,raw,echo=1
# Add a delay to prevent the clients from starting too early
ExecStartPost=/bin/sleep 2s
Restart=always