net-telnet-rfc2217 0.0.3 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/net/telnet/rfc2217/version.rb +1 -1
- data/lib/net/telnet/rfc2217.rb +67 -68
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c39563771f3856b4bc00958b23c0dfd9fbc1dddc74f1296576450ecba9c63d1
|
4
|
+
data.tar.gz: 5ac03d21506442c8b686ae9d5f1d9d452a40f7a2404eaf6cc941c7ebdd703bf0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e6c931590c7d2cca1127f3291fa2596b338ab10fe3fe2f128860b405cd02e59c6d49876c37c821cb4c3da3e91e079a0ec34b3aa553dca3359e5b6e702e0a5f3
|
7
|
+
data.tar.gz: 6c589b90e212849f27283d9ff71eb44a674ed3831e23d695900991716e977f0f7f3bdfbd613a7c15845b836a6f3a0b6fb696b32452388f4254b6172546e828f8
|
data/lib/net/telnet/rfc2217.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'net/telnet'
|
2
|
-
require 'byebug'
|
3
2
|
|
4
3
|
# have to patch Telnet to allow us to read control sequences
|
5
4
|
require 'net/telnet/rfc2217/telnet'
|
@@ -14,43 +13,9 @@ module Net
|
|
14
13
|
|
15
14
|
attr_reader :telnet
|
16
15
|
|
17
|
-
COM_PORT_OPTION = 44.chr
|
18
|
-
|
19
|
-
SET_BAUDRATE = 1.chr
|
20
|
-
SET_DATASIZE = 2.chr
|
21
|
-
SET_PARITY = 3.chr
|
22
|
-
SET_STOPSIZE = 4.chr
|
23
|
-
SET_CONTROL = 5.chr
|
24
|
-
NOTIFY_LINESTATE = 6.chr
|
25
|
-
NOTIFY_MODEMSTATE = 7.chr
|
26
|
-
FLOWCONTROL_SUSPEND = 8.chr
|
27
|
-
SET_LINESTATE_MASK = 10.chr
|
28
|
-
SET_MODEMSTATE_MASK = 11.chr
|
29
|
-
PURGE_DATA = 12.chr
|
30
|
-
|
31
|
-
SET_BAUDRATE_RESPONSE = 101.chr
|
32
|
-
SET_DATASIZE_RESPONSE = 102.chr
|
33
|
-
SET_PARITY_RESPONSE = 103.chr
|
34
|
-
SET_STOPSIZE_RESPONSE = 104.chr
|
35
|
-
SET_CONTROL_RESPONSE = 105.chr
|
36
|
-
NOTIFY_LINESTATE_RESPONSE = 106.chr
|
37
|
-
NOTIFY_MODEMSTATE_RESPONSE = 107.chr
|
38
|
-
FLOWCONTROL_SUSPEND_RESPONSE = 108.chr
|
39
|
-
SET_LINESTATE_MASK_RESPONSE = 110.chr
|
40
|
-
SET_MODEMSTATE_MASK_RESPONSE = 111.chr
|
41
|
-
PURGE_DATA_RESPONSE = 112.chr
|
42
|
-
|
43
|
-
NONE = 1
|
44
|
-
ODD = 2
|
45
|
-
EVEN = 3
|
46
|
-
MARK = 4
|
47
|
-
SPACE = 5
|
48
|
-
|
49
|
-
SERIAL_PORT_PARAMS = %w{baud data_bits stop_bits parity}.freeze
|
50
|
-
|
51
16
|
class << self
|
52
|
-
def open(
|
53
|
-
sp = new(
|
17
|
+
def open(**kwargs)
|
18
|
+
sp = new(opt**kwargs)
|
54
19
|
if block_given?
|
55
20
|
begin
|
56
21
|
yield sp
|
@@ -64,9 +29,15 @@ module Net
|
|
64
29
|
end
|
65
30
|
end
|
66
31
|
|
67
|
-
|
68
|
-
set_modem_params(options.slice(*SERIAL_PORT_PARAMS))
|
32
|
+
attr_reader :baud, :data_bits, :parity, :stop_bits
|
69
33
|
|
34
|
+
def initialize(host, port: 23, baud: 115200, data_bits: 8, parity: :none, stop_bits: 1, &block)
|
35
|
+
set_modem_params(baud: baud, data_bits: data_bits, parity: parity, stop_bits: stop_bits)
|
36
|
+
|
37
|
+
options = {
|
38
|
+
'Host' => host,
|
39
|
+
'Port' => port,
|
40
|
+
}
|
70
41
|
options['Binmode'] = true
|
71
42
|
options['Telnetmode'] = false
|
72
43
|
@telnet = Telnet.new(options, &block)
|
@@ -81,35 +52,15 @@ module Net
|
|
81
52
|
end
|
82
53
|
end
|
83
54
|
|
84
|
-
def
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
def set_modem_params(modem_params)
|
89
|
-
@modem_params = modem_params.dup
|
90
|
-
@modem_params['baud'] = 115200 unless @modem_params.key?('baud')
|
91
|
-
@modem_params['data_bits'] = 8 unless @modem_params.key?('data_bits')
|
92
|
-
@modem_params['stop_bits'] = 1 unless @modem_params.key?('stop_bits')
|
93
|
-
unless @modem_params.key?('parity')
|
94
|
-
@modem_params['parity'] = (data_bits == 8 ? NONE : EVEN)
|
95
|
-
end
|
96
|
-
write_modem_params if telnet
|
97
|
-
end
|
98
|
-
|
99
|
-
def baud
|
100
|
-
get_modem_params['baud']
|
101
|
-
end
|
55
|
+
def set_modem_params(baud: nil, data_bits: nil, parity: nil, stop_bits: nil)
|
56
|
+
raise ArgumentError, "Parity must be :none, :even, :odd, :mark, or :space" unless parity.nil? || %i{none even odd mark space}.include?(parity)
|
102
57
|
|
103
|
-
|
104
|
-
|
105
|
-
|
58
|
+
@baud ||= baud || 115200
|
59
|
+
@data_bits ||= data_bits || 8
|
60
|
+
@parity ||= parity || :none
|
61
|
+
@stop_bits ||= stop_bits || 1
|
106
62
|
|
107
|
-
|
108
|
-
get_modem_params['stop_bits']
|
109
|
-
end
|
110
|
-
|
111
|
-
def parity
|
112
|
-
get_modem_params['parity']
|
63
|
+
write_modem_params if telnet
|
113
64
|
end
|
114
65
|
|
115
66
|
def sock
|
@@ -119,11 +70,16 @@ module Net
|
|
119
70
|
def read(length, outbuf = '')
|
120
71
|
readpartial(length, outbuf)
|
121
72
|
while outbuf.length < length
|
122
|
-
outbuf.concat(length - outbuf.length)
|
73
|
+
outbuf.concat(readpartial(length - outbuf.length))
|
123
74
|
end
|
124
75
|
outbuf
|
125
76
|
end
|
126
77
|
|
78
|
+
def readbyte
|
79
|
+
read(1)&.[](0)
|
80
|
+
end
|
81
|
+
alias getbyte readbyte
|
82
|
+
|
127
83
|
def readpartial(length, outbuf = '')
|
128
84
|
loop do
|
129
85
|
# 0 is special and means "just see if there's data to read"
|
@@ -189,6 +145,15 @@ module Net
|
|
189
145
|
result
|
190
146
|
end
|
191
147
|
|
148
|
+
def ready?
|
149
|
+
loop do
|
150
|
+
return true unless @buffer.empty?
|
151
|
+
return false if sock.wait_readable(0).nil?
|
152
|
+
# consume control characters first
|
153
|
+
readpartial(0)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
192
157
|
def ungetbyte(b)
|
193
158
|
@buffer.insert(0, b.chr)
|
194
159
|
end
|
@@ -212,12 +177,46 @@ module Net
|
|
212
177
|
|
213
178
|
private
|
214
179
|
|
180
|
+
COM_PORT_OPTION = 44.chr
|
181
|
+
|
182
|
+
SET_BAUDRATE = 1.chr
|
183
|
+
SET_DATASIZE = 2.chr
|
184
|
+
SET_PARITY = 3.chr
|
185
|
+
SET_STOPSIZE = 4.chr
|
186
|
+
SET_CONTROL = 5.chr
|
187
|
+
NOTIFY_LINESTATE = 6.chr
|
188
|
+
NOTIFY_MODEMSTATE = 7.chr
|
189
|
+
FLOWCONTROL_SUSPEND = 8.chr
|
190
|
+
SET_LINESTATE_MASK = 10.chr
|
191
|
+
SET_MODEMSTATE_MASK = 11.chr
|
192
|
+
PURGE_DATA = 12.chr
|
193
|
+
|
194
|
+
SET_BAUDRATE_RESPONSE = 101.chr
|
195
|
+
SET_DATASIZE_RESPONSE = 102.chr
|
196
|
+
SET_PARITY_RESPONSE = 103.chr
|
197
|
+
SET_STOPSIZE_RESPONSE = 104.chr
|
198
|
+
SET_CONTROL_RESPONSE = 105.chr
|
199
|
+
NOTIFY_LINESTATE_RESPONSE = 106.chr
|
200
|
+
NOTIFY_MODEMSTATE_RESPONSE = 107.chr
|
201
|
+
FLOWCONTROL_SUSPEND_RESPONSE = 108.chr
|
202
|
+
SET_LINESTATE_MASK_RESPONSE = 110.chr
|
203
|
+
SET_MODEMSTATE_MASK_RESPONSE = 111.chr
|
204
|
+
PURGE_DATA_RESPONSE = 112.chr
|
205
|
+
|
206
|
+
NONE = 1
|
207
|
+
ODD = 2
|
208
|
+
EVEN = 3
|
209
|
+
MARK = 4
|
210
|
+
SPACE = 5
|
211
|
+
|
212
|
+
private_constant *(constants - [:WaitReadable])
|
213
|
+
|
215
214
|
def write_modem_params
|
216
215
|
telnet.write(
|
217
216
|
IAC + SB + COM_PORT_OPTION + SET_BAUDRATE + [baud].pack("N") + IAC + SE +
|
218
217
|
IAC + SB + COM_PORT_OPTION + SET_DATASIZE + data_bits.chr + IAC + SE +
|
219
218
|
IAC + SB + COM_PORT_OPTION + SET_STOPSIZE + stop_bits.chr + IAC + SE +
|
220
|
-
IAC + SB + COM_PORT_OPTION + SET_PARITY + parity.chr + IAC + SE)
|
219
|
+
IAC + SB + COM_PORT_OPTION + SET_PARITY + const_get(parity.upcase, false).chr + IAC + SE)
|
221
220
|
sock.flush
|
222
221
|
end
|
223
222
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: net-telnet-rfc2217
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cody Cutrer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-telnet
|
@@ -81,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
requirements: []
|
84
|
-
rubygems_version: 3.
|
84
|
+
rubygems_version: 3.1.2
|
85
85
|
signing_key:
|
86
86
|
specification_version: 4
|
87
87
|
summary: Library for getting an IO-like object for a remote serial port
|