hybridgroup.gobot/device.go

34 lines
690 B
Go
Raw Normal View History

2013-10-23 07:45:31 +08:00
package gobot
2013-10-24 13:00:03 +08:00
import (
"fmt"
2013-10-25 13:04:58 +08:00
"reflect"
2013-10-24 13:00:03 +08:00
)
2013-10-23 07:45:31 +08:00
type Device struct {
Name string
2013-10-27 07:41:43 +08:00
Interval string
2013-10-25 13:04:58 +08:00
Robot *Robot
Connection *Connection
2013-10-29 09:50:09 +08:00
Driver interface{}
2013-10-24 13:00:03 +08:00
Params map[string]string
2013-10-23 07:45:31 +08:00
}
2013-10-29 09:50:09 +08:00
func NewDevice(driver interface{}, r *Robot) *Device {
d := new(Device)
d.Name = reflect.ValueOf(driver).Elem().FieldByName("Name").String()
d.Robot = r
d.Driver = driver
d.Connection = new(Connection)
return d
2013-10-23 07:45:31 +08:00
}
2013-10-29 09:50:09 +08:00
func (d *Device) Start() {
fmt.Println("Device " + d.Name + " started")
reflect.ValueOf(d.Driver).MethodByName("StartDriver").Call([]reflect.Value{})
2013-10-23 07:45:31 +08:00
}
2013-10-29 09:50:09 +08:00
func (d *Device) Command(method_name string, arguments []string) {
2013-10-24 13:00:03 +08:00
//dt.Driver.Command(method_name, arguments)
2013-10-23 07:45:31 +08:00
}