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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 44fd8d0003d2e47f4722d3db91858c0ef47895ae
4
- data.tar.gz: ad008840aa913c6f549173132911f9e4675cba98
3
+ metadata.gz: 3202efbedc0fb5ee6984b9f2f338b2594e216788
4
+ data.tar.gz: 759504a859ecc078d47316b89eb19a5f25940d41
5
5
  SHA512:
6
- metadata.gz: aa8df84c7b52849bc7e51dc3f1c30ea2c1566f8de0c9dbe2082ab931816daa8e949a1444a04dea90e7b8a7ae7d61f2eba97e8f261876ef3684188414eaf64104
7
- data.tar.gz: 0ced23dda4e32e280b99473331bc8d55d7f871a5b72fe4cec3fa8b1790a95bcbe549718a7c7ed755a4e54f4046f5902c8c3f77918d1368a1aef962d3d290ce5f
6
+ metadata.gz: 06650bbfcf4d148d086a475b2d13779a184f7c126f44363fe475c4e272e45e0266834f02d68b4afb78371e5f2109ea282ff27b2ab37e6932afa582caa1a2e37c
7
+ data.tar.gz: 0bebc5200e44b6fb342429a9f82f500d2fa5f5951edb1c653780544d05d30146eef3062474d6cbd388b38b254a7c8053220f2f09d7dee687fea35112b2a31a19
@@ -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, 20],
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
@@ -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, 20],
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
@@ -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, 19],
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
@@ -29,7 +29,12 @@ module Serial #:nodoc:
29
29
  # Parse configuration first
30
30
  termios = LIBC::Termios.new
31
31
 
32
- termios.baud = baud
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
- # Blocking read
47
- termios[:cc_c][LIBC::CONSTANTS['VMIN']] = 1
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).baud
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 != c_tcgetattr(ruby_io.fileno, termios))
97
- raise ERRNO[FFI.errno].new
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 != c_tcsetattr(ruby_io.fileno, CONSTANTS['TCSANOW'], termios))
104
- raise ERRNO[FFI.errno].new
105
- end
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
- private_class_method :os_specific_constants, :c_tcgetattr, :c_tcsetattr #:nodoc:
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-serial
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johan van der Vyver