update readme, add bash-scripts for mount management

This commit is contained in:
Edward Emelianov
2026-10-19 00:07:20 +03:00
parent 26a14dbe3b
commit 59d5078184
8 changed files with 382 additions and 32 deletions

View File

@@ -0,0 +1,64 @@
#!/bin/bash
# mount_park - send park command and wait until the mount is parked
#
# Environment:
# MOUNT_HOST daemon hostname (default: localhost)
# MOUNT_PORT daemon command port (default: 10001)
# NC_TIMEOUT network timeout per command, seconds (default: 2)
# PARK_TIMEOUT overall wait for Parked, seconds (default: 60)
#
# Exit status: 0 = parked, 1 = error or timeout.
MOUNT_HOST="${MOUNT_HOST:-localhost}"
MOUNT_PORT="${MOUNT_PORT:-10001}"
NC_TIMEOUT="${NC_TIMEOUT:-2}"
PARK_TIMEOUT="${PARK_TIMEOUT:-60}"
send_cmd() {
printf '%s\n' "$1" | nc -N -w "$NC_TIMEOUT" "$MOUNT_HOST" "$MOUNT_PORT"
}
reply=$(send_cmd "park")
# issue the park command
for attempt in 1 2 3; do
if [ -n "$reply" ] && [ "$reply" == "OK" ]; then
break
fi
echo "Attempt $attempt failed (reply: '${reply:-no reply}')" >&2
sleep 1
done
if [ -n "$reply" ] && [ "$reply" != "OK" ]; then
echo "Error: failed to park!" >&2; exit 1
fi
echo "Wait for parking"
sleep 2
# wait until the mount reach parking position
start=$(date +%s)
while :; do
reply=$(send_cmd "status")
if [ -z "$reply" ]; then
echo "Daemon not responding" >&2
exit 1
fi
st=$(printf '%s\n' "$reply" | sed -n 's/^status=//p' | tr -d "'")
case "$st" in
Stopped)
echo "OK: Parked"
exit 0
;;
Error|Off)
echo "Mount reported '$st' status while parking" >&2
exit 1
;;
esac
now=$(date +%s)
if [ $((now - start)) -ge "$PARK_TIMEOUT" ]; then
echo "Timeout waiting for Parked (last status: '${st:-no reply}')" >&2
exit 1
fi
echo "Status: $st"
sleep 2
done

View File

@@ -0,0 +1,37 @@
#!/bin/bash
# mount_refresh - force the daemon to refresh weather/time data on the mount
#
# The "update" command sets an internal "needcorr" flag; the main loop then
# calls mount_corrdata() on its next iteration (if the mount is not Off).
# If the mount is Off the daemon returns an error, so we check the status
# to distinguish success from failure.
#
# Up to 3 attempts are made.
#
# Environment:
# MOUNT_HOST daemon hostname (default: localhost)
# MOUNT_PORT daemon command port (default: 10001)
# NC_TIMEOUT network timeout per command, seconds (default: 2)
#
# Exit status: 0 = update queued, 1 = all attempts failed.
MOUNT_HOST="${MOUNT_HOST:-localhost}"
MOUNT_PORT="${MOUNT_PORT:-10001}"
NC_TIMEOUT="${NC_TIMEOUT:-2}"
send_cmd() {
printf '%s\n' "$1" | nc -N -w "$NC_TIMEOUT" "$MOUNT_HOST" "$MOUNT_PORT"
}
for attempt in 1 2 3; do
reply=$(send_cmd "update")
if [ -n "$reply" ] && [ "$reply" == "OK" ]; then
echo "OK"
exit 0
fi
echo "Attempt $attempt failed (reply: '${reply:-no reply}')" >&2
sleep 1
done
echo "Failed to refresh mount data after 3 attempts" >&2
exit 1

View File

@@ -0,0 +1,63 @@
#!/bin/bash
# mount_shutdown - power the mount off via a two-step handshake
#
# Step 1: send "shutdown" (no argument) -> daemon returns a key
# Step 2: send "shutdown = <key>" -> daemon sends the power-off command
# Step 3: poll status until the mount reports Off (or the daemon dies)
# Step 4: wait 45 s for the mount to fully discharge
#
# Environment:
# MOUNT_HOST daemon hostname (default: localhost)
# MOUNT_PORT daemon command port (default: 10001)
# NC_TIMEOUT network timeout per command, seconds (default: 2)
# SHUTDOWN_WAIT timeout for the mount to report Off, seconds (default: 60)
#
# Exit status: 0 = mount off, 1 = error or timeout.
MOUNT_HOST="${MOUNT_HOST:-localhost}"
MOUNT_PORT="${MOUNT_PORT:-10001}"
NC_TIMEOUT="${NC_TIMEOUT:-2}"
SHUTDOWN_WAIT="${SHUTDOWN_WAIT:-60}"
send_cmd() {
printf '%s\n' "$1" | nc -N -w "$NC_TIMEOUT" "$MOUNT_HOST" "$MOUNT_PORT"
}
# step 1: request a shutdown key
reply=$(send_cmd "shutdown")
if [ -z "$reply" ]; then
echo "No response from daemon" >&2
exit 1
fi
key=$(printf '%s\n' "$reply" | sed -n 's/^shutdown=//p')
if [ -z "$key" ]; then
echo "Unexpected reply: $reply" >&2
exit 1
fi
# step 2: send the key back
send_cmd "shutdown = $key"
# step 3: wait until the mount reports Off (or the daemon goes away)
start=$(date +%s)
while :; do
reply=$(send_cmd "status")
if [ -z "$reply" ]; then
# daemon is gone: assume the mount has powered off
break
fi
st=$(printf '%s\n' "$reply" | sed -n 's/^status=//p' | tr -d "'")
if [ "$st" = "Off" ]; then
break
fi
now=$(date +%s)
if [ $((now - start)) -ge "$SHUTDOWN_WAIT" ]; then
echo "Timeout waiting for Off (last status: '${st:-no reply}')" >&2
exit 1
fi
sleep 2
done
echo "Wait until the computer turns off..."
# step 4: final settling delay
sleep 45

View File

@@ -0,0 +1,30 @@
#!/bin/bash
# mount_status - print the current mount status as returned by the daemon
#
# Output: one line, the status string without surrounding quotes
# (e.g. Tracking, Slewing or going to stop, Parked, Off, ...)
#
# Environment:
# MOUNT_HOST daemon hostname (default: localhost)
# MOUNT_PORT daemon command port (default: 10001)
# NC_TIMEOUT network timeout, seconds (default: 2)
#
# Exit status: 0 = status printed, 1 = daemon not responding or bad reply.
MOUNT_HOST="${MOUNT_HOST:-localhost}"
MOUNT_PORT="${MOUNT_PORT:-10001}"
NC_TIMEOUT="${NC_TIMEOUT:-2}"
reply=$(printf 'status\n' | nc -N -w "$NC_TIMEOUT" "$MOUNT_HOST" "$MOUNT_PORT" 2>/dev/null)
if [ -z "$reply" ]; then
echo "Mount daemon is not responding at $MOUNT_HOST:$MOUNT_PORT" >&2
exit 1
fi
st=$(printf '%s\n' "$reply" | sed -n 's/^status=//p' | tr -d "'")
if [ -z "$st" ]; then
echo "Unexpected reply from daemon: $reply" >&2
exit 1
fi
echo "$st"

View File

@@ -0,0 +1,124 @@
#!/bin/bash
# send_coords - command the mount to slew to given coordinates and track
#
# Usage:
# send_coords --ra <hours> --dec <degrees>
# send_coords --ra <hours> --ha <hours>
#
# Environment:
# MOUNT_HOST daemon hostname (default: localhost)
# MOUNT_PORT daemon command port (default: 10001)
# NC_TIMEOUT network timeout per command, seconds (default: 2)
# POLL_TIMEOUT overall wait for Tracking, seconds (default: 60)
#
# Exit status: 0 = tracking, 1 = error or timeout.
# For UNIX-sockets: nc -N -U -w ... <socket>
MOUNT_HOST="${MOUNT_HOST:-localhost}"
MOUNT_PORT="${MOUNT_PORT:-10001}"
NC_TIMEOUT="${NC_TIMEOUT:-2}"
POLL_TIMEOUT="${POLL_TIMEOUT:-60}"
send_cmd() {
printf '%s\n' "$1" | nc -N -w "$NC_TIMEOUT" "$MOUNT_HOST" "$MOUNT_PORT"
}
usage() {
echo "Usage: $0 --dec <deg> (--ra <hours> | --ha <hours>)" >&2
exit 1
}
# --- no arguments: display current telescope coordinates -------------------
if [ $# -eq 0 ]; then
# Send three commands in one batch. Without -N the daemon never sees
# EOF until the -w timer expires, but that is fine: each line is
# processed and answered as it arrives, so the replies are collected
# long before the connection closes.
reply=$(printf 'format=1\ntelra\nteldec\n' \
| nc -w "$NC_TIMEOUT" "$MOUNT_HOST" "$MOUNT_PORT" 2>/dev/null)
if [ -z "$reply" ]; then
echo "Mount daemon is not responding at $MOUNT_HOST:$MOUNT_PORT" >&2
exit 1
fi
ra=$(printf '%s\n' "$reply" | sed -n 's/^telra=//p')
dec=$(printf '%s\n' "$reply" | sed -n 's/^teldec=//p')
if [ -z "$ra" ] || [ -z "$dec" ]; then
# The daemon suppresses telra/teldec when the mount is Off, in
# Error state, or the weather feed is lost.
echo "Telescope coordinates not available (mount Off or in Error state?)" >&2
exit 1
fi
printf 'RA: %s\n' "$ra"
printf 'Dec: %s\n' "$dec"
exit 0
fi
RA=""
DEC=""
HA=""
GOTO=""
while [ $# -gt 0 ]; do
case "$1" in
--ra) [ $# -ge 2 ] || usage; RA="$2"; shift 2 ;;
--dec) [ $# -ge 2 ] || usage; DEC="$2"; shift 2 ;;
--ha) [ $# -ge 2 ] || usage; HA="$2"; shift 2 ;;
-h|--help) usage ;;
*) echo "Unknown option: $1" >&2; usage ;;
esac
done
[ -n "$DEC" ] || { echo "Error: --dec is required" >&2; exit 1; }
if [ -z "$RA" ] && [ -z "$HA" ]; then
echo "Error: --ra or --ha is required" >&2; exit 1;
fi
if [ -n "$RA" ] && [ -n "$HA" ]; then
echo "Error: --ra and --ha are mutually exclusive" >&2; exit 1
fi
if [ -z "$DEC" ] && [ -z "$HA" ]; then
echo "Error: either --dec or --ha is required" >&2; exit 1
fi
# send coordinates
send_cmd "tagdec = $DEC"
if [ -n "$RA" ]; then
send_cmd "tagra = $RA"
GOTO="gotord"
else
send_cmd "tagha = $HA"
GOTO="gotorh"
fi
# trigger the goto
ans=$(send_cmd "$GOTO")
if [ -z $ans ] || [ "$ans" != "OK" ]; then
echo "Error: can't go to given position" >&2; exit 1
fi
echo "Wait for slewing"
sleep 3
# poll status until Tracking
start=$(date +%s)
while :; do
reply=$(send_cmd "status")
st=$(printf '%s\n' "$reply" | sed -n 's/^status=//p' | tr -d "'")
case "$st" in
Tracking)
echo "OK: Tracking"
exit 0
;;
Error|Off)
echo "Mount reported '$st' status" >&2
exit 1
;;
esac
now=$(date +%s)
if [ $((now - start)) -ge "$POLL_TIMEOUT" ]; then
echo "Timeout waiting for Tracking (last status: '${st:-no reply}')" >&2
exit 1
fi
echo "Status: $st"
sleep 2
done