1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-29 13:49:14 +08:00
hybridgroup.gobot/src/gobot/connection.go

42 lines
880 B
Go
Raw Normal View History

2013-10-22 16:45:31 -07:00
package gobot
2013-10-23 22:00:03 -07:00
import (
"fmt"
2013-10-24 22:04:58 -07:00
"reflect"
2013-10-23 22:00:03 -07:00
)
2013-10-22 16:45:31 -07:00
type Connection struct {
Name string
2013-10-24 22:04:58 -07:00
Adaptor *Adaptor
2013-10-23 22:00:03 -07:00
Port Port
2013-10-24 22:04:58 -07:00
Robot *Robot
2013-10-23 22:00:03 -07:00
Params map[string]string
}
2013-10-24 22:04:58 -07:00
func NewConnection(a reflect.Value, r *Robot) *Connection {
c := new(Connection)
c.Name = reflect.ValueOf(a).FieldByName("Name").String()
c.Robot = r
c.Adaptor = new(Adaptor)
c.Adaptor.Name = reflect.ValueOf(a).FieldByName("Name").String()
return c
2013-10-23 22:00:03 -07:00
}
2013-10-22 16:45:31 -07:00
2013-10-24 22:04:58 -07:00
func (c *Connection) Connect() {
fmt.Println("Connecting to "+ c.Adaptor.Name + " on port " + c.Port.ToString() + "...")
c.Adaptor.Connect()
2013-10-22 16:45:31 -07:00
}
2013-10-24 22:04:58 -07:00
func (c *Connection) Disconnect() {
fmt.Println("Diconnecting from "+ c.Adaptor.Name + " on port " + c.Port.ToString() + "...")
c.Adaptor.Disconnect()
2013-10-22 16:45:31 -07:00
}
2013-10-23 22:00:03 -07:00
2013-10-24 22:04:58 -07:00
func (c *Connection) IsConnected() bool {
return c.Adaptor.IsConnected()
2013-10-23 22:00:03 -07:00
}
2013-10-24 22:04:58 -07:00
func (c *Connection) AdaptorName() string {
return c.Adaptor.Name
2013-10-23 22:00:03 -07:00
}