This repository has been archived by the owner on Apr 21, 2021. It is now read-only.
forked from james-choncholas/sg3100customleds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomleds.tcsh
178 lines (151 loc) · 5.48 KB
/
customleds.tcsh
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/bin/tcsh
#
# This script updates the SG-3100 device's LEDs with WAN and bandwidth status
#
# Usage: customleds.tcsh <mvneta0-2>
# Some notes
# based on gwstatus, set color of first LED
# circle square diamond
# led 2 - led 1 - led 0
# 6 7 8 - 3 4 5 - 0 1 2
#
# mvneta0 is OPT
# mvneta1 is LAN
# mvneta2 is WAN
# gpio device number
# A way to get the gpio device that controls the led lights (its not always 0)
set gdev = `sysctl dev.gpio | grep .led. | cut -d . -f 3 | uniq`
# Some constants
set if = ${1}
set l1 = 900000;
set l2 = 50000000;
set l3 = 90000000;
set l4 = 200000000;
set l5 = 500000000;
switch ($if)
case "mvneta0":
set lednum = 0
set pinr = 0
set ping = 1
set pinb = 2
breaksw
case "mvneta1":
set lednum = 1
set pinr = 3
set ping = 4
set pinb = 5
breaksw
case "mvneta2":
set lednum = 2
set pinr = 6
set ping = 7
set pinb = 8
breaksw
endsw
# disable dark time between light bursts
/sbin/sysctl dev.gpio.$gdev.pin.$pinr.T0=0
/sbin/sysctl dev.gpio.$gdev.pin.$pinr.T4=0
/sbin/sysctl dev.gpio.$gdev.pin.$ping.T0=0
/sbin/sysctl dev.gpio.$gdev.pin.$ping.T4=0
/sbin/sysctl dev.gpio.$gdev.pin.$pinb.T0=0
/sbin/sysctl dev.gpio.$gdev.pin.$pinb.T4=0
### the WAN LED is special in that we can monitor it's link status
### make the LED flash red if the WAN link is down.
### otherwise, do the normal color scheme
### Get WAN state (if needed)
if ($if == "mvneta2") then
echo getting wan things
set gw = `/usr/local/bin/php /usr/local/sbin/pfSsh.php playback gatewaystatus | grep WAN `
set gwping = `echo $gw | awk '{ ORS=" "; print $6 }' `
set gwstatus = `echo $gw | awk '{ ORS=" "; print $7 }' `
else
echo skipping WAN things
set gwstatus = "none"
endif
### Get bandwidth usage
# -w X collects for X seconds
# -q 1 quits after one iteration
set sum = `netstat -w 60 -I $if -q 1 | tail -1 | awk '{ ORS=" "; print $4 }' `
#set outbytes = `netstat -w 60 -I $if -q 1 | tail -1 | awk '{ ORS=" "; print $7 }' `
#@ sum = $inbytes + $outbytes
switch ($gwstatus)
case "none":
case "Online":
### The WAN is up, set the color to bandwidth usage
if ($sum <= $l1) then
echo no traffic, led dark
/sbin/sysctl dev.gpio.$gdev.led.$lednum.pwm=1
/usr/sbin/gpioctl -f /dev/gpioc$gdev $pinr duty 4
/usr/sbin/gpioctl -f /dev/gpioc$gdev $ping duty 4
/usr/sbin/gpioctl -f /dev/gpioc$gdev $pinb duty 4
else if ($sum <= $l2) then
echo low traffic, led solid green
/sbin/sysctl dev.gpio.$gdev.led.$lednum.pwm=1
/usr/sbin/gpioctl -f /dev/gpioc$gdev $pinr duty 0
/usr/sbin/gpioctl -f /dev/gpioc$gdev $ping duty 32
/usr/sbin/gpioctl -f /dev/gpioc$gdev $pinb duty 0
else if ($sum <= $l3) then
echo medium traffic, led solid blue
/sbin/sysctl dev.gpio.$gdev.led.$lednum.pwm=1
/usr/sbin/gpioctl -f /dev/gpioc$gdev $pinr duty 0
/usr/sbin/gpioctl -f /dev/gpioc$gdev $ping duty 0
/usr/sbin/gpioctl -f /dev/gpioc$gdev $pinb duty 32
else if ($sum <= $l4) then
echo medium-high traffic, led slow flashing purple
/sbin/sysctl dev.gpio.$gdev.led.$lednum.pwm=0
/sbin/sysctl dev.gpio.$gdev.led.$lednum.T2=1040
/sbin/sysctl dev.gpio.$gdev.led.$lednum.T1-T3=520
/usr/sbin/gpioctl -f /dev/gpioc$gdev $pinr duty 32
/usr/sbin/gpioctl -f /dev/gpioc$gdev $ping duty 0
/usr/sbin/gpioctl -f /dev/gpioc$gdev $pinb duty 32
else if ($sum <= $l5) then
echo high traffic, led fast flashing bright purple
# Fast flashing purple
/sbin/sysctl dev.gpio.$gdev.led.$lednum.pwm=0
/sbin/sysctl dev.gpio.$gdev.led.$lednum.T2=0
/sbin/sysctl dev.gpio.$gdev.led.$lednum.T1-T3=520
/usr/sbin/gpioctl -f /dev/gpioc$gdev $pinr duty 128
/usr/sbin/gpioctl -f /dev/gpioc$gdev $ping duty 0
/usr/sbin/gpioctl -f /dev/gpioc$gdev $pinb duty 128
else
echo very high traffic, led fast flashing bright orange
/sbin/sysctl dev.gpio.$gdev.led.$lednum.pwm=0
/sbin/sysctl dev.gpio.$gdev.led.$lednum.T2=0
/sbin/sysctl dev.gpio.$gdev.led.$lednum.T1-T3=520
/usr/sbin/gpioctl -f /dev/gpioc$gdev $pinr duty 128
/usr/sbin/gpioctl -f /dev/gpioc$gdev $ping duty 8
/usr/sbin/gpioctl -f /dev/gpioc$gdev $pinb duty 0
endif
breaksw
case "down":
case "Offline":
echo link down, led red
/sbin/sysctl dev.gpio.$gdev.led.$lednum.pwm=0
/sbin/sysctl dev.gpio.$gdev.led.$lednum.T2=520
/sbin/sysctl dev.gpio.$gdev.led.$lednum.T1-T3=520
/usr/sbin/gpioctl -f /dev/gpioc$gdev $pinr duty 128
/usr/sbin/gpioctl -f /dev/gpioc$gdev $ping duty 0
/usr/sbin/gpioctl -f /dev/gpioc$gdev $pinb duty 0
breaksw
case "highloss":
case "loss":
case "highdelay":
case "delay":
case "Warning":
echo link decay, led yellow
/sbin/sysctl dev.gpio.$gdev.led.$lednum.pwm=0
/sbin/sysctl dev.gpio.$gdev.led.$lednum.T2=520
/sbin/sysctl dev.gpio.$gdev.led.$lednum.T1-T3=520
/usr/sbin/gpioctl -f /dev/gpioc$gdev $pinr duty 128
/usr/sbin/gpioctl -f /dev/gpioc$gdev $ping duty 32
/usr/sbin/gpioctl -f /dev/gpioc$gdev $pinb duty 0
breaksw
default:
echo link state unknown, led white
/sbin/sysctl dev.gpio.$gdev.led.$lednum.pwm=0
/sbin/sysctl dev.gpio.$gdev.led.$lednum.T2=520
/sbin/sysctl dev.gpio.$gdev.led.$lednum.T1-T3=520
/usr/sbin/gpioctl -f /dev/gpioc$gdev $pinr duty 128
/usr/sbin/gpioctl -f /dev/gpioc$gdev $ping duty 128
/usr/sbin/gpioctl -f /dev/gpioc$gdev $pinb duty 128
Endsw