digital-transport 0.8.2 → 0.8.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/digital-transport.gemspec +1 -1
- data/lib/digital/transport/adapters/serial.rb +13 -38
- data/lib/digital/transport/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7210be7b3f3b38e00cd8e5bf1e9f45a4c641d506
|
4
|
+
data.tar.gz: 8cfdac45b4518b7cad332922ffe4d34d6f4853a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa7617898078749f5951ecccce2e8dcd945a177ad060081c8c4e3c4964e29298eda61b3bb4a0d8260a83883a65f8be7bcd065834cc6bee2a19e5b13c9134160a
|
7
|
+
data.tar.gz: 0b7d162b828715896ad015fc15df1d341f927c3597f143962f53926187aa985d987d564fae26d31118247eaf54c7bf8c2d74a74dfb99472a0d2064d7b1193a33
|
data/digital-transport.gemspec
CHANGED
@@ -27,5 +27,5 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_development_dependency 'rspec', '~> 3.4'
|
28
28
|
|
29
29
|
spec.add_dependency 'functional-ruby'
|
30
|
-
spec.add_dependency 'rs_232', '~>3.0.0.
|
30
|
+
spec.add_dependency 'rs_232', '~>3.0.0.pre3' unless RUBY_PLATFORM === /java/
|
31
31
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rs_232'
|
2
|
+
require 'timeout'
|
2
3
|
|
3
4
|
module Digital
|
4
5
|
module Transport
|
@@ -54,20 +55,8 @@ module Digital
|
|
54
55
|
|
55
56
|
def read(count, blocking = false)
|
56
57
|
raise NotConnected unless open?
|
57
|
-
|
58
|
-
|
59
|
-
bytes_count = (count == -1) ? @io.available? : count
|
60
|
-
|
61
|
-
if blocking
|
62
|
-
bytes = read_io_until(count, count)
|
63
|
-
array.push bytes if bytes
|
64
|
-
else
|
65
|
-
bytes_count.times do
|
66
|
-
byte = @io.read(1)
|
67
|
-
array.push byte if byte
|
68
|
-
end
|
69
|
-
end
|
70
|
-
Either.right(array.empty? ? nil : array.join)
|
58
|
+
f = blocking ? method(:read_blocking) : method(:read_non_blocking)
|
59
|
+
Either.right f.(count)
|
71
60
|
rescue => ex
|
72
61
|
@io.close
|
73
62
|
Either.left(ex)
|
@@ -75,32 +64,18 @@ module Digital
|
|
75
64
|
|
76
65
|
private
|
77
66
|
|
78
|
-
|
79
|
-
|
80
|
-
# simulate blocking function
|
81
|
-
#
|
82
|
-
# @param [Fixnum] count
|
83
|
-
# @param [Fixnum] up_to
|
84
|
-
#
|
85
|
-
# no direct ruby usage
|
86
|
-
#
|
87
|
-
def block_io_until(count, up_to)
|
88
|
-
up_to -= 1 while @io.available? < count && up_to > 0
|
89
|
-
up_to > 0
|
67
|
+
def read_non_blocking(count)
|
68
|
+
@io.read(count)
|
90
69
|
end
|
91
70
|
|
92
|
-
#
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
#
|
101
|
-
def read_io_until(count, up_to)
|
102
|
-
sleep 0.001 until block_io_until(count, up_to)
|
103
|
-
read(count)
|
71
|
+
# todo: shouldn't block forever.
|
72
|
+
def read_blocking(count)
|
73
|
+
bytes = ''
|
74
|
+
while bytes.length < count
|
75
|
+
bytes += read_non_blocking(count).to_s
|
76
|
+
sleep 0.001
|
77
|
+
end
|
78
|
+
bytes
|
104
79
|
end
|
105
80
|
end
|
106
81
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: digital-transport
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roman Lishtaba
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -128,14 +128,14 @@ dependencies:
|
|
128
128
|
requirements:
|
129
129
|
- - "~>"
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: 3.0.0.
|
131
|
+
version: 3.0.0.pre3
|
132
132
|
type: :runtime
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: 3.0.0.
|
138
|
+
version: 3.0.0.pre3
|
139
139
|
description: Library intended to unify interface between multiple transport adapters
|
140
140
|
email:
|
141
141
|
- roman@lishtaba.com
|
@@ -187,3 +187,4 @@ signing_key:
|
|
187
187
|
specification_version: 4
|
188
188
|
summary: interface between multiple transport adapters
|
189
189
|
test_files: []
|
190
|
+
has_rdoc:
|