Class: Netconf::Serial
Constant Summary
collapse
- DEFAULT_BAUD =
9600
- DEFAULT_DATABITS =
8
- DEFAULT_STOPBITS =
1
- DEFAULT_PARITY =
SerialPort::NONE
- DEFAULT_RDBLKSZ =
(1024*1024)
Instance Attribute Summary collapse
Attributes inherited from Transport
#capabilities, #rpc, #session_id, #state, #timeout, #waitio
Instance Method Summary
collapse
Methods inherited from Transport
#close, #closed?, #has_capability?, #open, #open?, #rpc_exec, #send_and_receive
Constructor Details
#initialize(args_h, &block) ⇒ Serial
Returns a new instance of Serial.
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/net/netconf/serial.rb', line 15
def initialize( args_h, &block )
os_type = args_h[:os_type] || Netconf::DEFAULT_OS_TYPE
raise Netconf::InitError, "Missing 'port' param" unless args_h[:port]
raise Netconf::InitError, "Missing 'username' param" unless args_h[:username]
@args = args_h.clone
@args[:prompt] ||= /([%>])\s+$/
extend Netconf::const_get( os_type )::TransSerial
@trans_timeout = @args[:timeout] || Netconf::DEFAULT_TIMEOUT
@trans_waitio = @args[:waitio] || Netconf::DEFAULT_WAITIO
super( &block )
end
|
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
13
14
15
|
# File 'lib/net/netconf/serial.rb', line 13
def args
@args
end
|
Instance Method Details
#login ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/net/netconf/serial.rb', line 37
def login
begin
puts
waitfor(/ogin:/)
rescue Timeout::Error
puts
waitfor(/ogin:/)
end
puts @args[:username]
waitfor(/assword:/)
puts @args[:password]
waitfor( @args[:prompt] )
end
|
#puts(str = nil) ⇒ Object
95
96
97
|
# File 'lib/net/netconf/serial.rb', line 95
def puts( str = nil )
@trans.puts str
end
|
#trans_close ⇒ Object
82
83
84
85
|
# File 'lib/net/netconf/serial.rb', line 82
def trans_close
@trans.write Netconf::RPC::MSG_CLOSE_SESSION
@trans.close
end
|
#trans_open {|_self| ... } ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/net/netconf/serial.rb', line 55
def trans_open
baud = @args[:speed] || DEFAULT_BAUD
data_bits = @args[:bits] || DEFAULT_DATABITS
stop_bits = @args[:stop] || DEFAULT_STOPBITS
parity = @args[:parity] || DEFAULT_PARITY
@trans = SerialPort.new( @args[:port], baud, data_bits, stop_bits, parity )
got = login()
yield self if block_given?
trans_start_netconf( got )
self
end
|
#trans_receive ⇒ Object
91
92
93
|
# File 'lib/net/netconf/serial.rb', line 91
def trans_receive
Netconf.trans_receive
end
|
#trans_receive_hello ⇒ Object
71
72
73
74
75
76
|
# File 'lib/net/netconf/serial.rb', line 71
def trans_receive_hello
hello_str = trans_receive()
so_xml = hello_str.index("\n") + 1
hello_str.slice!(0, so_xml)
hello_str
end
|
#trans_send(cmd_str) ⇒ Object
87
88
89
|
# File 'lib/net/netconf/serial.rb', line 87
def trans_send( cmd_str )
@trans.write( cmd_str )
end
|
#trans_send_hello ⇒ Object
78
79
80
|
# File 'lib/net/netconf/serial.rb', line 78
def trans_send_hello
nil
end
|
#waitfor(this_re = nil) ⇒ Object
99
100
101
|
# File 'lib/net/netconf/serial.rb', line 99
def waitfor( this_re = nil )
Netconf.waitfor(on_re)
end
|