-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (38 loc) · 1001 Bytes
/
main.go
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
package main
import (
"log"
"math/rand"
"os"
"time"
"github.com/byuoitav/scurvy/atlona5x2"
"github.com/spf13/pflag"
)
// Jitter represents the number of seconds of random jitter allowed
const _jitter = 5
// MinimumWait represents the minimum number of seconds between commands
const _minimumWait = 30
func main() {
var (
address string
)
pflag.StringVarP(&address, "address", "a", "", "The address of the switcher to test")
pflag.Parse()
if len(address) == 0 {
log.Printf("No address given for a switcher to test")
os.Exit(1)
}
// Seed the random number generator
rand.Seed(time.Now().UnixNano())
d := atlona5x2.New(address)
log.Printf("Starting to dispatch events to %s...", address)
for {
cmd, err := d.RandomDispatch()
if err != nil {
log.Printf("Dispatch error!: %s", err)
} else {
log.Printf("Dispatch successful! Command: %s", cmd)
}
sleepDelay := _minimumWait + rand.Intn(_jitter)
time.Sleep(time.Duration(sleepDelay) * time.Second)
}
}