Skip to content

Commit

Permalink
WIP robeaux support
Browse files Browse the repository at this point in the history
  • Loading branch information
zankich committed Jan 27, 2014
1 parent 409756c commit 396c9cf
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 19 deletions.
8 changes: 4 additions & 4 deletions adaptor.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package gobot

type Adaptor struct {
Name string
Port string
Connected bool
Params map[string]interface{}
Name string `json:"name"`
Port string `json:"port"`
Connected bool `json:"Connected"`
Params map[string]interface{} `json:"params"`
}

type AdaptorInterface interface {
Expand Down
18 changes: 17 additions & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,24 @@ func Api(bot *Master) {
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 {
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 {
Expand Down
4 changes: 2 additions & 2 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
)

type connection struct {
Name string
Adaptor AdaptorInterface
Name string `json:"name"`
Adaptor AdaptorInterface `json:"adaptor"`
Port string `json:"-"`
Robot *Robot `json:"-"`
Params map[string]interface{} `json:"-"`
Expand Down
8 changes: 4 additions & 4 deletions device.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
)

type device struct {
Name string
Interval string `json:"-"`
Robot *Robot `json:"-"`
Driver DriverInterface
Name string `json:"name"`
Interval string `json:"-"`
Robot *Robot `json:"-"`
Driver DriverInterface `json:"driver"`
}

type Device interface {
Expand Down
8 changes: 4 additions & 4 deletions driver.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package gobot

type Driver struct {
Interval string
Pin string
Name string
Commands []string
Interval string `json:"interval"`
Pin string `json:"pin"`
Name string `json:"name"`
Commands []string `json:"commands"`
Events map[string]chan interface{} `json:"-"`
}

Expand Down
8 changes: 4 additions & 4 deletions robot.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
)

type Robot struct {
Connections []Connection
Devices []Device
Name string
Connections []Connection `json:"connections"`
Devices []Device `json:"devices"`
Name string `json:"name"`
Commands map[string]interface{} `json:"-"`
RobotCommands []string `json:"Commands"`
RobotCommands []string `json:"commands"`
Work func() `json:"-"`
connections []*connection `json:"-"`
devices []*device `json:"-"`
Expand Down

0 comments on commit 396c9cf

Please sign in to comment.