-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathpistar-mmdvmhshatreset
executable file
·84 lines (75 loc) · 2.82 KB
/
pistar-mmdvmhshatreset
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
#
##############################################################################
# #
# Pi-Star MMDVM HS_HAT Reset Tool #
# #
# Version 1.2, Code, Design and Development by Andy Taylor (MW0MWZ). #
# #
# Make it simple to reset an MMDVM bosard from the CLI on Pi-Star. #
# #
##############################################################################
#
if [ "$(id -u)" != "0" ]; then
echo -e "You need to be root to run this command...\n"
exit 1
fi
# Detect Pi4 Hardware
if [ "$(/usr/local/bin/platformDetect.sh | grep "Pi 4 Model" | wc -l)" -ge 1 ]; then
model="Pi4"
else
model=""
fi
# Make the "boot" option only work on Pi 4 hardware
if [ "${1}" = "boot" ]; then
if [ "${model}" != "Pi4" ]; then
exit 0
fi
fi
if [ -f '/etc/dstar-radio.mmdvmhost' ]; then
# Get the modem that the user has selected.
modemSelected=$(grep 'Hardware=' /etc/dstar-radio.mmdvmhost)
modemSelected=${modemSelected#*=}
# Get the user friendly version of the selected Modem.
modemSelectedHuman=$(grep value=\"${modemSelected}\" /var/www/dashboard/admin/configure.php | head -n 1)
modemSelectedHuman=${modemSelectedHuman#*\">}
modemSelectedHuman=${modemSelectedHuman::-9}
fi
# Get the Port the modem is on
modemPort=$(sed -n '/^\[Modem\]/,/^\[/p' /etc/mmdvmhost | grep ^"UARTPort" | awk -F '=' '{print $2}')
if [ -z "${modemPort}" ]; then
modemPort=$(sed -n '/^\[Modem\]/,/^\[/p' /etc/mmdvmhost | grep ^"Port" | awk -F '=' '{print $2}')
fi
if [ -z "${modemPort}" ] || [ "${modemPort}" != "/dev/ttyAMA0" ]; then
echo -e "Your Modem is not connected to the GPIO"
exit 0
fi
# If there are no arguments (like "boot") then stop the service...
if [ -z "${1}" ]; then
echo -e "Resetting Modem: ${modemSelectedHuman}"
systemctl stop mmdvmhost
fi
# Reset process for MMDVM HS_HAT Board (20,-21,21:-20,21)
echo 20 > /sys/class/gpio/export
echo 21 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio20/direction
echo out > /sys/class/gpio/gpio21/direction
sleep 0.5
echo 0 > /sys/class/gpio/gpio20/value
echo 0 > /sys/class/gpio/gpio21/value
echo 1 > /sys/class/gpio/gpio21/value
sleep 1
echo 0 > /sys/class/gpio/gpio20/value
echo 1 > /sys/class/gpio/gpio20/value
echo 0 > /sys/class/gpio/gpio20/value
sleep 0.5
echo 20 > /sys/class/gpio/unexport
echo 21 > /sys/class/gpio/unexport
sleep 2
message="Modem reset complete"
# If there are no arguments (like "boot") then start the service...
if [ -z "${1}" ]; then
systemctl start mmdvmhost
echo -e ${message}
fi
exit 0