From 7bb841027fee1e87785d52683ea1822e63b33d3c Mon Sep 17 00:00:00 2001 From: Adrian Zankich Date: Sat, 26 Oct 2013 15:00:41 -0700 Subject: [PATCH] Add port to adaptor --- adaptor.go | 1 + connection.go | 7 ++--- port.go | 71 --------------------------------------------------- 3 files changed, 5 insertions(+), 74 deletions(-) diff --git a/adaptor.go b/adaptor.go index 2d93e96b..cdf4c6ff 100644 --- a/adaptor.go +++ b/adaptor.go @@ -2,6 +2,7 @@ package gobot type Adaptor struct { Name string + Port string Connected bool Params map[string]string } diff --git a/connection.go b/connection.go index df4c891e..e5b101ea 100644 --- a/connection.go +++ b/connection.go @@ -8,7 +8,7 @@ import ( type Connection struct { Name string Adaptor interface{} - Port Port + Port string Robot *Robot Params map[string]string @@ -17,13 +17,14 @@ type Connection struct { func NewConnection(a interface{}, r *Robot) *Connection { c := new(Connection) c.Name = reflect.ValueOf(a).Elem().FieldByName("Name").String() + c.Port = reflect.ValueOf(a).Elem().FieldByName("Port").String() c.Robot = r c.Adaptor = a return c } func (c *Connection) Connect() { - fmt.Println("Connecting to " + reflect.ValueOf(c).Elem().FieldByName("Name").String() + " on port " + c.Port.ToString() + "...") + fmt.Println("Connecting to " + c.Name + " on port " + c.Port + "...") reflect.ValueOf(c.Adaptor).MethodByName("Connect").Call([]reflect.Value{}) } @@ -32,7 +33,7 @@ func (c *Connection) Disconnect() { } func (c *Connection) IsConnected() bool { - return reflect.ValueOf(c.Adaptor).MethodByName("IsConnect").Call([]reflect.Value{})[0].Bool() + return reflect.ValueOf(c.Adaptor).MethodByName("IsConnected").Call([]reflect.Value{})[0].Bool() } func (c *Connection) AdaptorName() string { diff --git a/port.go b/port.go index 956e3e51..ba48380e 100644 --- a/port.go +++ b/port.go @@ -11,74 +11,3 @@ func (Port) NewPort(p string) *Port{ func (p *Port) ToString() string { return p.Name } -/* -module Artoo - # The Artoo::Port class represents port and/or host to be used to connect - # tp a specific individual hardware device. - class Port - attr_reader :port, :host - - # Create new port - # @param [Object] data - def initialize(data=nil) - @is_tcp, @is_serial, @is_portless = false - parse(data) - end - - # @return [Boolean] True if serial port - def is_serial? - @is_serial == true - end - - # @return [Boolean] True if tcp port - def is_tcp? - @is_tcp == true - end - - # @return [Boolean] True if does not have real port - def is_portless? - @is_portless == true - end - - # @return [String] port - def to_s - if is_portless? - "none" - elsif is_serial? - port - else - "#{host}:#{port}" - end - end - - private - - def parse(data) - case - # portless - when data.nil? - @port = nil - @is_portless = true - - # is TCP host/port? - when m = /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):(\d{1,5})/.match(data) - @port = m[2] - @host = m[1] - @is_tcp = true - - # is it a numeric port for localhost tcp? - when /^[0-9]{1,5}$/.match(data) - @port = data - @host = "localhost" - @is_tcp = true - - # must be a serial port - else - @port = data - @host = nil - @is_serial = true - end - end - end -end -*/ \ No newline at end of file