func NewShell() *Shell { sh := &Shell{ shell: liner.NewLiner(), prompt: "mbus> ", hist: filepath.Join(".", ".fcs_lpc_motor_history"), motor: m702.New("134.158.125.223:502"), } sh.shell.SetCtrlCAborts(true) sh.shell.SetCompleter(func(line string) (c []string) { for n := range sh.cmds { if strings.HasPrefix(n, strings.ToLower(line)) { c = append(c, n) } } return }) if f, err := os.Open(sh.hist); err == nil { sh.shell.ReadHistory(f) f.Close() } sh.cmds = map[string]shellCmd{ "dump": sh.cmdDump, "get": sh.cmdGet, "motor": sh.cmdMotor, "quit": sh.cmdQuit, "set": sh.cmdSet, } return sh }
func (sh *Shell) cmdMotor(args []string) error { switch len(args) { case 0: log.Printf("connected to [%s]\n", sh.motor.Addr) return nil case 1: sh.motor = m702.New(args[0]) return nil default: return fmt.Errorf("cmd-motor: too many arguments (%d)", len(args)) } return nil }
func main() { flag.Parse() if flag.NArg() >= 1 { err := dispatch(flag.Arg(0), flag.Args()[1:]) if err != nil { log.Fatalf("error dispatching [%s]: %v\n", flag.Arg(0), err) } log.Printf("\n") log.Printf("bye.\n") os.Exit(0) } m := m702.New("134.158.125.223:502") testParams(m) }
func (srv *webServer) publishData() { status := make([]motorStatus, len(srv.Motors)) copy(status, srv.Motors) for i := range status { data := &status[i] motor := m702.New(data.Addr) for _, p := range srv.params { if i > 0 && (p.Index[0] == 2 || p.Index[0] == 3) { // only motor-0 has slots-2|3 continue } err := motor.ReadParam(&p) if err != nil { log.Printf("error reading %v Pr-%v: %v\n", data.Addr, p, err) continue } data.Params = append(data.Params, newMotorData(p, err)) } } srv.datac <- status }