scan_beacon 0.6.4 → 0.6.5

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: 06d7b866b545422618dc14fc1229e8dc28fed321
4
- data.tar.gz: b1989dea9025dec91ef228c1b3ef2bdcdb648eee
3
+ metadata.gz: 2854fb487434f83d2e24c5d9928d38f1da8c5159
4
+ data.tar.gz: 6e731cc3982883356caa1c8b87d94d8e7440c40b
5
5
  SHA512:
6
- metadata.gz: 46609a18cce5083333cec616b6b6f24fcc2b92338c2360d09f8a31fef3da11e8eaeff152e63562c38b3013b69849132ad42796398334bee47f424b7569e6fd56
7
- data.tar.gz: 22b231911ea22001e93a8cd6e70c0263c7fe3599ecf723677db1c31e952fe965f6b24a1ec97f3533083f504505b2963bf9d626c4f2d71f447359163bc5796703
6
+ metadata.gz: 74f7cb551de59d34214f478a6af5308b442910894360ce3abfd4a997c2b71f34a5d7009fce3b8c9dc3bd3979f1dc3b13166365852debf15960af43bb3bdb07b1
7
+ data.tar.gz: 6d5ddf2c696194f18daff43b165e3658995e4591c01859984a6cd8b16b01a5736098e60ecdf96e84c88fe520d9b2c7d7c93573dc9a172a16fd42a00bf5afb0e1
@@ -28,14 +28,8 @@ module ScanBeacon
28
28
  BG_GAP_CONNECTABLE = 2
29
29
 
30
30
  def self.find_all
31
- # try to reset all the possible devices
32
- devices = Dir.glob("/dev/{cu.usbmodem,ttyACM}*")
33
- devices.map {|device_path|
34
- Thread.new { self.new(device_path).reset }
35
- }.each(&:join)
36
- # reset causes devices to reattach, possibly at different path
37
- devices = Dir.glob("/dev/{cu.usbmodem,ttyACM}*")
38
- devices.select {|device_path|
31
+ self.reset_all
32
+ possible_devices.select {|device_path|
39
33
  device = self.new(device_path)
40
34
  device.open{ device.get_addr } != nil
41
35
  }
@@ -134,6 +128,38 @@ module ScanBeacon
134
128
  sleep 1
135
129
  end
136
130
 
131
+ def self.possible_devices
132
+ Dir.glob("/dev/{cu.usbmodem,ttyACM}*")
133
+ end
134
+
135
+ def self.reset_all
136
+ # try to reset all the devices
137
+ device_count = possible_devices.count
138
+ possible_devices.each do |device_path|
139
+ File.open(device_path, 'r+b') do |file|
140
+ file.write([BG_COMMAND, 1, BG_MSG_CLASS_SYSTEM, BG_RESET, 0].pack('C*'))
141
+ end
142
+ end
143
+
144
+ # wait for them to show up again, but only wait for up to 5 secs
145
+ sleep 0.1
146
+ wait_count = 0
147
+ while possible_devices.count < device_count && wait_count < 50
148
+ sleep 0.1
149
+ wait_count += 1
150
+ end
151
+
152
+ # try to open them - if we get a busy, wait and try again
153
+ possible_devices.each do |device_path|
154
+ begin
155
+ File.open(device_path, 'r+b') {|f| f.close }
156
+ rescue Errno::EBUSY
157
+ sleep 0.1
158
+ retry
159
+ end
160
+ end
161
+ end
162
+
137
163
  class BLE112Response
138
164
  def initialize(data)
139
165
  data ||= ""
@@ -1,3 +1,3 @@
1
1
  module ScanBeacon
2
- VERSION = "0.6.4"
2
+ VERSION = "0.6.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scan_beacon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Radius Networks
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-24 00:00:00.000000000 Z
11
+ date: 2015-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler