2013-12-30 16:51:21 -08:00
|
|
|
package gobot
|
|
|
|
|
2014-04-29 13:20:32 -07:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
2014-04-15 17:59:44 -07:00
|
|
|
|
2014-04-15 21:10:32 -07:00
|
|
|
type testStruct struct {
|
|
|
|
i int
|
|
|
|
f float64
|
|
|
|
}
|
|
|
|
|
2014-06-10 15:16:11 -07:00
|
|
|
func (t *testStruct) Hello(name string, message string) string {
|
2014-04-15 21:10:32 -07:00
|
|
|
return fmt.Sprintf("Hello %v! %v", name, message)
|
|
|
|
}
|
|
|
|
|
2014-04-11 06:02:21 -07:00
|
|
|
type null struct{}
|
|
|
|
|
|
|
|
func (null) Write(p []byte) (int, error) {
|
|
|
|
return len(p), nil
|
|
|
|
}
|
|
|
|
|
2013-12-30 16:51:21 -08:00
|
|
|
type testDriver struct {
|
|
|
|
Driver
|
2014-04-15 17:59:44 -07:00
|
|
|
Adaptor *testAdaptor
|
2013-12-30 16:51:21 -08:00
|
|
|
}
|
|
|
|
|
2014-06-10 15:16:11 -07:00
|
|
|
func (t *testDriver) Init() bool { return true }
|
|
|
|
func (t *testDriver) Start() bool { return true }
|
|
|
|
func (t *testDriver) Halt() bool { return true }
|
|
|
|
func (t *testDriver) TestDriverCommand(params map[string]interface{}) string {
|
2014-04-15 17:59:44 -07:00
|
|
|
name := params["name"].(string)
|
|
|
|
return fmt.Sprintf("hello %v", name)
|
|
|
|
}
|
2013-12-30 16:51:21 -08:00
|
|
|
|
|
|
|
type testAdaptor struct {
|
|
|
|
Adaptor
|
|
|
|
}
|
|
|
|
|
2014-06-10 15:16:11 -07:00
|
|
|
func (t *testAdaptor) Finalize() bool { return true }
|
|
|
|
func (t *testAdaptor) Connect() bool { return true }
|
2013-12-30 16:51:21 -08:00
|
|
|
|
2014-04-15 17:59:44 -07:00
|
|
|
func newTestDriver(name string, adaptor *testAdaptor) *testDriver {
|
2014-06-10 15:16:11 -07:00
|
|
|
return &testDriver{
|
|
|
|
Driver: Driver{
|
|
|
|
Commands: []string{
|
|
|
|
"TestDriverCommand",
|
|
|
|
"DriverCommand",
|
|
|
|
},
|
|
|
|
Name: name,
|
|
|
|
},
|
|
|
|
Adaptor: adaptor,
|
2013-12-30 17:22:16 -08:00
|
|
|
}
|
2013-12-30 16:51:21 -08:00
|
|
|
}
|
2014-04-14 23:16:35 -07:00
|
|
|
|
2013-12-30 16:51:21 -08:00
|
|
|
func newTestAdaptor(name string) *testAdaptor {
|
2014-06-10 15:16:11 -07:00
|
|
|
return &testAdaptor{
|
|
|
|
Adaptor: Adaptor{
|
|
|
|
Name: name,
|
|
|
|
Params: map[string]interface{}{
|
|
|
|
"param1": "1",
|
|
|
|
"param2": 2,
|
|
|
|
},
|
|
|
|
},
|
2014-04-14 23:16:35 -07:00
|
|
|
}
|
2013-12-30 16:51:21 -08:00
|
|
|
}
|
2013-12-31 13:16:25 -08:00
|
|
|
|
2014-04-15 19:19:14 -07:00
|
|
|
func robotTestFunction(params map[string]interface{}) string {
|
|
|
|
message := params["message"].(string)
|
|
|
|
robotname := params["robotname"].(string)
|
|
|
|
return fmt.Sprintf("hey %v, %v", robotname, message)
|
|
|
|
}
|
|
|
|
|
2014-05-15 11:50:45 -07:00
|
|
|
func NewTestRobot(name string) *Robot {
|
|
|
|
return newTestRobot(name)
|
|
|
|
}
|
2014-04-14 23:16:35 -07:00
|
|
|
func newTestRobot(name string) *Robot {
|
2014-04-15 17:59:44 -07:00
|
|
|
adaptor1 := newTestAdaptor("Connection 1")
|
|
|
|
adaptor2 := newTestAdaptor("Connection 2")
|
|
|
|
adaptor3 := newTestAdaptor("Connection 3")
|
|
|
|
driver1 := newTestDriver("Device 1", adaptor1)
|
|
|
|
driver2 := newTestDriver("Device 2", adaptor2)
|
|
|
|
driver3 := newTestDriver("Device 3", adaptor3)
|
2014-05-03 03:22:22 -07:00
|
|
|
work := func() {}
|
|
|
|
//Commands := map[string]interface{}{
|
|
|
|
// "robotTestFunction": robotTestFunction,
|
|
|
|
//}
|
|
|
|
return NewRobot(name, []Connection{adaptor1, adaptor2, adaptor3}, []Device{driver1, driver2, driver3}, work)
|
2013-12-31 13:16:25 -08:00
|
|
|
}
|
2014-04-15 21:10:32 -07:00
|
|
|
|
|
|
|
func newTestStruct() *testStruct {
|
|
|
|
s := new(testStruct)
|
|
|
|
s.i = 10
|
|
|
|
s.f = 0.2
|
|
|
|
return s
|
|
|
|
}
|