Repository URL to install this package:
|
Version:
0.1.8 ▾
|
#!/usr/bin/env bash
# GNSS Settings for SimCOM modules
set -euo pipefail
DEVICE="/dev/ttyUSB2"
MAX_WAIT=120 # maximum seconds to wait for modem detection
# helper: send AT and optionally print immediate response lines (non-blocking)
send_at() {
local cmd="$1"
printf "%s\r" "$cmd" > "$DEVICE"
timeout 1 cat "$DEVICE" 2>/dev/null || true
}
# handle restart command
if [ "${1:-}" = "restart" ]; then
echo "Restarting modem..."
if [ ! -e "$DEVICE" ]; then
echo "Error: device $DEVICE not found." >&2
exit 2
fi
send_at "AT+CFUN=1,1"
echo "Modem restart command sent. Restarting service..."
exit 0
fi
# handle start command (default behavior)
if [ "${1:-start}" != "start" ]; then
echo "Usage: $0 {start|restart}" >&2
exit 1
fi
# check if SimTech modem is present
echo "Checking for SimTech modem..."
ELAPSED=0
SIMTECH_FOUND=false
while [ $ELAPSED -lt $MAX_WAIT ]; do
if lsusb | grep -iq "simtech"; then
echo "SimTech modem detected in lsusb."
SIMTECH_FOUND=true
break
fi
echo -n "."
sleep 2
ELAPSED=$((ELAPSED + 2))
done
if [ "$SIMTECH_FOUND" = false ]; then
echo ""
echo "Error: No SimTech modem detected after ${MAX_WAIT}s. Exiting." >&2
exit 1
fi
# wait for USB device to appear
echo "Waiting for $DEVICE to appear..."
ELAPSED=0
while [ $ELAPSED -lt $MAX_WAIT ]; do
if [ -e "$DEVICE" ]; then
echo "$DEVICE found."
break
fi
echo -n "."
sleep 2
ELAPSED=$((ELAPSED + 2))
done
if [ $ELAPSED -ge $MAX_WAIT ]; then
echo ""
echo "Error: Timeout waiting for $DEVICE after ${MAX_WAIT}s." >&2
exit 2
fi
sleep 10
# stop GNSS if running
echo "Stopping GNSS..."
send_at "AT+CGPS=0"
send_at "AT+CGPS?"
send_at "AT+CGPSAUTO=0"
send_at "AT+CGPSAUTO?"
sleep 0.5
# set SUPL server
echo "Setting SUPL server..."
send_at 'AT+CGPSURL="supl.google.com:7275"'
send_at 'AT+CGPSURL?'
sleep 0.5
# enable XTRA
echo "Enabling XTRA..."
send_at 'AT+CGPSXE=1'
send_at 'AT+CGPSXE?'
send_at 'AT+CGPSXDAUTO=1'
send_at 'AT+CGPSXDAUTO?'
sleep 0.5
# configure GNSS
echo "Configuring GNSS..."
echo "GPS + GLONASS"
send_at 'AT+CGNSSMODE=1,0'
send_at 'AT+CGNSSMODE?'
sleep 1
# start GNSS
echo "Starting GPS with UE-based mode..."
send_at "AT+CGPS=1,2"
send_at "AT+CGPS?"
sleep 0.5
exit 0