-
Notifications
You must be signed in to change notification settings - Fork 0
/
ectool.go
59 lines (53 loc) · 1.22 KB
/
ectool.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
54
55
56
57
58
59
package main
import (
"flag"
"fmt"
"os"
"time"
)
type cmd func(...string) error
var (
// various commands add themselves to this map as part of
// their init.
commands map[string]cmd
lpcdebug = flag.Bool("lpcdebug", true, "Enable lpc debug prints")
chips = make(map[string]func(ioport, ioaddr, time.Duration, time.Duration, debugf) ec)
defaultChip = flag.String("chip", "lpc", "Which chip to use")
chip = newLPC
)
func debug(s string, v ...interface{}) {
fmt.Printf(s, v...)
}
func main() {
d := debug
flag.Parse()
if !*lpcdebug {
d = nil
}
p, err := newDevPorts(d)
if err != nil {
fmt.Fprintf(os.Stderr, "%v", err)
}
fmt.Printf("p %v\n", p)
if c, ok := chips[*defaultChip]; !ok {
fmt.Fprintf(os.Stderr, "Unknown chip %v: Choices: %v\n", *defaultChip, chips)
os.Exit(1)
} else {
chip = c
}
ec := chip(p, ecLpcAddrHostCmd, time.Second*10, time.Second*10, d)
// valid command?
// TODO: use the command table for real? But what should the type be? interface{}, err?
a := flag.Args()
if len(a) == 0 {
fmt.Printf("usage: ectool command [args]\n")
os.Exit(1)
}
switch a[0] {
case "info":
d, err := info(ec)
fmt.Printf("%v, %v\n", d, err)
default:
fmt.Printf("Unknown: %v", a)
}
}