ffi-serial 1.0.0 → 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/ffi-serial/bsd.rb +1 -15
- data/lib/ffi-serial/darwin.rb +1 -15
- data/lib/ffi-serial/linux.rb +1 -14
- data/lib/ffi-serial/posix.rb +28 -13
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3202efbedc0fb5ee6984b9f2f338b2594e216788
|
4
|
+
data.tar.gz: 759504a859ecc078d47316b89eb19a5f25940d41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06650bbfcf4d148d086a475b2d13779a184f7c126f44363fe475c4e272e45e0266834f02d68b4afb78371e5f2109ea282ff27b2ab37e6932afa582caa1a2e37c
|
7
|
+
data.tar.gz: 0bebc5200e44b6fb342429a9f82f500d2fa5f5951edb1c653780544d05d30146eef3062474d6cbd388b38b254a7c8053220f2f09d7dee687fea35112b2a31a19
|
data/lib/ffi-serial/bsd.rb
CHANGED
@@ -28,21 +28,7 @@ module Serial #:nodoc:
|
|
28
28
|
:c_oflag, :ulong,
|
29
29
|
:c_cflag, :ulong,
|
30
30
|
:c_lflag, :ulong,
|
31
|
-
:cc_c, [:uchar,
|
32
|
-
:c_ispeed, :ulong,
|
33
|
-
:c_ospeed, :ulong
|
34
|
-
|
35
|
-
def baud #:nodoc:
|
36
|
-
CONSTANTS['BAUD_'].fetch(self[:c_ispeed])
|
37
|
-
end
|
38
|
-
|
39
|
-
def baud=(val) #:nodoc:
|
40
|
-
mask = CONSTANTS['BAUD'].fetch(val, nil)
|
41
|
-
if mask.nil?
|
42
|
-
raise ArgumentError.new "Invalid baud, supported values #{CONSTANTS['BAUD'].keys.inspect}"
|
43
|
-
end
|
44
|
-
self[:c_cflag] = self[:c_cflag] | mask; self[:c_ispeed] = mask; self[:c_ospeed] = mask; val
|
45
|
-
end
|
31
|
+
:cc_c, [:uchar, 64]
|
46
32
|
end
|
47
33
|
end
|
48
34
|
end
|
data/lib/ffi-serial/darwin.rb
CHANGED
@@ -27,21 +27,7 @@ module Serial #:nodoc:
|
|
27
27
|
:c_oflag, :ulong,
|
28
28
|
:c_cflag, :ulong,
|
29
29
|
:c_lflag, :ulong,
|
30
|
-
:cc_c, [:uchar,
|
31
|
-
:c_ispeed, :ulong,
|
32
|
-
:c_ospeed, :ulong
|
33
|
-
|
34
|
-
def baud #:nodoc:
|
35
|
-
CONSTANTS['BAUD_'].fetch(self[:c_ispeed])
|
36
|
-
end
|
37
|
-
|
38
|
-
def baud=(val) #:nodoc:
|
39
|
-
mask = CONSTANTS['BAUD'].fetch(val, nil)
|
40
|
-
if mask.nil?
|
41
|
-
raise ArgumentError.new "Invalid baud, supported values #{CONSTANTS['BAUD'].keys.inspect}"
|
42
|
-
end
|
43
|
-
self[:c_cflag] = self[:c_cflag] | mask; self[:c_ispeed] = mask; self[:c_ospeed] = mask; val
|
44
|
-
end
|
30
|
+
:cc_c, [:uchar, 64]
|
45
31
|
end
|
46
32
|
end
|
47
33
|
end
|
data/lib/ffi-serial/linux.rb
CHANGED
@@ -31,20 +31,7 @@ module Serial #:nodoc:
|
|
31
31
|
:c_cflag, :uint,
|
32
32
|
:c_lflag, :uint,
|
33
33
|
:c_line, :uchar,
|
34
|
-
:cc_c, [:uchar,
|
35
|
-
:ignored, [:uint8, 48] # ignored padding bytes
|
36
|
-
|
37
|
-
def baud #:nodoc:
|
38
|
-
CONSTANTS['BAUD_'].fetch(self[:c_cflag] & CONSTANTS['BAUD_BITMASK'])
|
39
|
-
end
|
40
|
-
|
41
|
-
def baud=(val) #:nodoc:
|
42
|
-
mask = CONSTANTS['BAUD'].fetch(val, nil)
|
43
|
-
if mask.nil?
|
44
|
-
raise ArgumentError.new "Invalid baud, supported values #{CONSTANTS['BAUD'].keys.inspect}"
|
45
|
-
end
|
46
|
-
self[:c_cflag] = self[:c_cflag] | mask; val
|
47
|
-
end
|
34
|
+
:cc_c, [:uchar, 64]
|
48
35
|
end
|
49
36
|
end
|
50
37
|
end
|
data/lib/ffi-serial/posix.rb
CHANGED
@@ -29,7 +29,12 @@ module Serial #:nodoc:
|
|
29
29
|
# Parse configuration first
|
30
30
|
termios = LIBC::Termios.new
|
31
31
|
|
32
|
-
|
32
|
+
baud = LIBC::CONSTANTS['BAUD'].fetch(baud, nil)
|
33
|
+
if baud.nil?
|
34
|
+
raise ArgumentError.new "Invalid baud, supported values #{CONSTANTS['BAUD'].keys.inspect}"
|
35
|
+
end
|
36
|
+
LIBC.cfsetispeed(termios, baud)
|
37
|
+
LIBC.cfsetospeed(termios, baud)
|
33
38
|
termios.data_bits = data_bits
|
34
39
|
termios.stop_bits = stop_bits
|
35
40
|
termios.parity = parity
|
@@ -43,8 +48,8 @@ module Serial #:nodoc:
|
|
43
48
|
termios[:c_iflag] = (termios[:c_iflag] | LIBC::CONSTANTS['IXON'] | LIBC::CONSTANTS['IXOFF'] | LIBC::CONSTANTS['IXANY'])
|
44
49
|
termios[:c_cflag] = (termios[:c_cflag] | LIBC::CONSTANTS['CLOCAL'] | LIBC::CONSTANTS['CREAD'] | LIBC::CONSTANTS['HUPCL'])
|
45
50
|
|
46
|
-
#
|
47
|
-
termios[:cc_c][LIBC::CONSTANTS['VMIN']] =
|
51
|
+
# non-blocking read
|
52
|
+
termios[:cc_c][LIBC::CONSTANTS['VMIN']] = 0
|
48
53
|
termios[:cc_c][LIBC::CONSTANTS['VTIME']] = 0
|
49
54
|
|
50
55
|
LIBC.tcsetattr(io, termios)
|
@@ -58,7 +63,7 @@ module Serial #:nodoc:
|
|
58
63
|
end
|
59
64
|
|
60
65
|
def baud #:nodoc:
|
61
|
-
LIBC.tcgetattr(self)
|
66
|
+
LIBC::CONSTANTS['BAUD_'].fetch(LIBC.cfgetispeed(LIBC.tcgetattr(self)))
|
62
67
|
end
|
63
68
|
|
64
69
|
def data_bits #:nodoc:
|
@@ -93,16 +98,23 @@ module Serial #:nodoc:
|
|
93
98
|
|
94
99
|
def self.tcgetattr(ruby_io) #:nodoc:
|
95
100
|
termios = Termios.new
|
96
|
-
if (0
|
97
|
-
|
98
|
-
end
|
99
|
-
termios
|
101
|
+
return termios if (0 == c_tcgetattr(ruby_io.fileno, termios))
|
102
|
+
raise ERRNO[FFI.errno].new
|
100
103
|
end
|
101
104
|
|
102
105
|
def self.tcsetattr(ruby_io, termios) #:nodoc:
|
103
|
-
if (0
|
104
|
-
|
105
|
-
|
106
|
+
return true if (0 == c_tcsetattr(ruby_io.fileno, CONSTANTS['TCSANOW'], termios))
|
107
|
+
raise ERRNO[FFI.errno].new
|
108
|
+
end
|
109
|
+
|
110
|
+
def self.cfsetispeed(termios, speed)
|
111
|
+
return true if (0 == c_cfsetispeed(termios, speed))
|
112
|
+
raise ERRNO[FFI.errno].new
|
113
|
+
end
|
114
|
+
|
115
|
+
def self.cfsetospeed(termios, speed)
|
116
|
+
return true if (0 == c_cfsetospeed(termios, speed))
|
117
|
+
raise ERRNO[FFI.errno].new
|
106
118
|
end
|
107
119
|
|
108
120
|
class Termios #:nodoc:
|
@@ -152,7 +164,6 @@ module Serial #:nodoc:
|
|
152
164
|
constants['DATA_BITS_'] = constants['DATA_BITS'].each_with_object({}) { |(k,v),r| r[v] = k }.freeze
|
153
165
|
constants['STOP_BITS_'] = constants['STOP_BITS'].each_with_object({}) { |(k,v),r| r[v] = k }.freeze
|
154
166
|
constants['PARITY_'] = constants['PARITY'].each_with_object({}) { |(k,v),r| r[v] = k }.freeze
|
155
|
-
constants['BAUD_BITMASK'] = constants['BAUD'].values.max
|
156
167
|
constants['DATA_BITS_BITMASK'] = constants['DATA_BITS'].values.max
|
157
168
|
constants['STOP_BITS_BITMASK'] = constants['STOP_BITS'].values.max
|
158
169
|
constants['PARITY_BITMASK'] = constants['PARITY'].values.max
|
@@ -164,7 +175,11 @@ module Serial #:nodoc:
|
|
164
175
|
attach_function :c_tcgetattr, :tcgetattr, [:int, :buffer_in], :int #:nodoc:
|
165
176
|
attach_function :c_tcsetattr, :tcsetattr, [:int, :int, :buffer_out], :int #:nodoc:
|
166
177
|
|
167
|
-
|
178
|
+
attach_function :c_cfsetispeed, :cfsetispeed, [:buffer_in, :uint32], :int #:nodoc:
|
179
|
+
attach_function :c_cfsetospeed, :cfsetospeed, [:buffer_in, :uint32], :int #:nodoc:
|
180
|
+
attach_function :cfgetispeed, [:buffer_in], :uint32 #:nodoc:
|
181
|
+
|
182
|
+
private_class_method :os_specific_constants, :c_tcgetattr, :c_tcsetattr, :c_cfsetispeed, :c_cfsetospeed #:nodoc:
|
168
183
|
private_constant :ERRNO #:nodoc:
|
169
184
|
end
|
170
185
|
|