WIP robeaux support
This commit is contained in:
parent
409756ca04
commit
396c9cf466
|
@ -1,10 +1,10 @@
|
||||||
package gobot
|
package gobot
|
||||||
|
|
||||||
type Adaptor struct {
|
type Adaptor struct {
|
||||||
Name string
|
Name string `json:"name"`
|
||||||
Port string
|
Port string `json:"port"`
|
||||||
Connected bool
|
Connected bool `json:"Connected"`
|
||||||
Params map[string]interface{}
|
Params map[string]interface{} `json:"params"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AdaptorInterface interface {
|
type AdaptorInterface interface {
|
||||||
|
|
18
api.go
18
api.go
|
@ -42,8 +42,24 @@ func Api(bot *Master) {
|
||||||
return toJson(bot.FindRobot(params["robotname"]).GetDevices())
|
return toJson(bot.FindRobot(params["robotname"]).GetDevices())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
type jsonDevice struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Driver string `json:"driver"`
|
||||||
|
Connection map[string]interface{} `json:"connection"`
|
||||||
|
Commands []string `json:"commands"`
|
||||||
|
}
|
||||||
|
|
||||||
m.Get("/robots/:robotname/devices/:devicename", func(params martini.Params) string {
|
m.Get("/robots/:robotname/devices/:devicename", func(params martini.Params) string {
|
||||||
return toJson(bot.FindRobotDevice(params["robotname"], params["devicename"]))
|
device := bot.FindRobotDevice(params["robotname"], params["devicename"])
|
||||||
|
jsonDevice := new(jsonDevice)
|
||||||
|
jsonDevice.Name = device.Name
|
||||||
|
jsonDevice.Driver = FieldByNamePtr(device.Driver, "Name").Interface().(string)
|
||||||
|
jsonDevice.Connection = make(map[string]interface{})
|
||||||
|
jsonDevice.Connection["name"] = FieldByNamePtr(FieldByNamePtr(device.Driver, "Adaptor").Interface().(AdaptorInterface), "Name").Interface().(string)
|
||||||
|
jsonDevice.Connection["port"] = FieldByNamePtr(FieldByNamePtr(device.Driver, "Adaptor").Interface().(AdaptorInterface), "Port").Interface().(string)
|
||||||
|
jsonDevice.Connection["adaptor"] = FieldByNamePtr(FieldByNamePtr(device.Driver, "Adaptor").Interface().(AdaptorInterface), "Name").Interface().(string)
|
||||||
|
jsonDevice.Commands = FieldByNamePtr(device.Driver, "Commands").Interface().([]string)
|
||||||
|
return toJson(jsonDevice)
|
||||||
})
|
})
|
||||||
|
|
||||||
m.Get("/robots/:robotname/devices/:devicename/commands", func(params martini.Params) string {
|
m.Get("/robots/:robotname/devices/:devicename/commands", func(params martini.Params) string {
|
||||||
|
|
|
@ -5,8 +5,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type connection struct {
|
type connection struct {
|
||||||
Name string
|
Name string `json:"name"`
|
||||||
Adaptor AdaptorInterface
|
Adaptor AdaptorInterface `json:"adaptor"`
|
||||||
Port string `json:"-"`
|
Port string `json:"-"`
|
||||||
Robot *Robot `json:"-"`
|
Robot *Robot `json:"-"`
|
||||||
Params map[string]interface{} `json:"-"`
|
Params map[string]interface{} `json:"-"`
|
||||||
|
|
|
@ -5,10 +5,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type device struct {
|
type device struct {
|
||||||
Name string
|
Name string `json:"name"`
|
||||||
Interval string `json:"-"`
|
Interval string `json:"-"`
|
||||||
Robot *Robot `json:"-"`
|
Robot *Robot `json:"-"`
|
||||||
Driver DriverInterface
|
Driver DriverInterface `json:"driver"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Device interface {
|
type Device interface {
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package gobot
|
package gobot
|
||||||
|
|
||||||
type Driver struct {
|
type Driver struct {
|
||||||
Interval string
|
Interval string `json:"interval"`
|
||||||
Pin string
|
Pin string `json:"pin"`
|
||||||
Name string
|
Name string `json:"name"`
|
||||||
Commands []string
|
Commands []string `json:"commands"`
|
||||||
Events map[string]chan interface{} `json:"-"`
|
Events map[string]chan interface{} `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
8
robot.go
8
robot.go
|
@ -8,11 +8,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Robot struct {
|
type Robot struct {
|
||||||
Connections []Connection
|
Connections []Connection `json:"connections"`
|
||||||
Devices []Device
|
Devices []Device `json:"devices"`
|
||||||
Name string
|
Name string `json:"name"`
|
||||||
Commands map[string]interface{} `json:"-"`
|
Commands map[string]interface{} `json:"-"`
|
||||||
RobotCommands []string `json:"Commands"`
|
RobotCommands []string `json:"commands"`
|
||||||
Work func() `json:"-"`
|
Work func() `json:"-"`
|
||||||
connections []*connection `json:"-"`
|
connections []*connection `json:"-"`
|
||||||
devices []*device `json:"-"`
|
devices []*device `json:"-"`
|
||||||
|
|
Loading…
Reference in New Issue