scan_beacon 0.5.10 → 0.6.0
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/scan_beacon/ble112_advertiser.rb +2 -26
- data/lib/scan_beacon/bluez_advertiser.rb +17 -31
- data/lib/scan_beacon/generic_advertiser.rb +27 -0
- data/lib/scan_beacon/generic_individual_advertiser.rb +27 -0
- data/lib/scan_beacon/version.rb +1 -1
- data/lib/scan_beacon.rb +2 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9643cd20260fece814e2595cc27be91924bef9f3
|
4
|
+
data.tar.gz: f6348fcd26d8a6aeb6eedcb2ea7f7313c3aa6cba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6b8044679facdfdfb80de910fa26e0719f4fed52c38979c62f846604c1e2830a3f297281414ede5fc7d5e8fc84a53c299114a44ff2081dac5ce68a978309271
|
7
|
+
data.tar.gz: 3224871074669b94635c9e1395a3510ebdc68fa9c0245aa73a11992cb1554ddb47fc7363d4f72c1097166d555e1f6650e787a2b04a2310b3cbc38314bab6df3b
|
@@ -1,28 +1,9 @@
|
|
1
1
|
module ScanBeacon
|
2
|
-
class BLE112Advertiser
|
3
|
-
|
4
|
-
attr_accessor :beacon, :parser, :ad
|
2
|
+
class BLE112Advertiser < GenericIndividualAdvertiser
|
5
3
|
|
6
4
|
def initialize(opts = {})
|
7
5
|
@device = BLE112Device.new opts[:port]
|
8
|
-
|
9
|
-
self.parser = opts[:parser]
|
10
|
-
self.parser ||= BeaconParser.default_parsers.find {|parser| parser.beacon_type == beacon.beacon_types.first}
|
11
|
-
@advertising = false
|
12
|
-
end
|
13
|
-
|
14
|
-
def beacon=(value)
|
15
|
-
@beacon = value
|
16
|
-
update_ad
|
17
|
-
end
|
18
|
-
|
19
|
-
def parser=(value)
|
20
|
-
@parser = value
|
21
|
-
update_ad
|
22
|
-
end
|
23
|
-
|
24
|
-
def ad=(value)
|
25
|
-
@ad = value
|
6
|
+
super()
|
26
7
|
end
|
27
8
|
|
28
9
|
def start(with_rotation = false)
|
@@ -43,11 +24,6 @@ module ScanBeacon
|
|
43
24
|
"<BLE112Advertiser ad=#{@ad.inspect}>"
|
44
25
|
end
|
45
26
|
|
46
|
-
def update_ad
|
47
|
-
self.ad = @parser.generate_ad(@beacon) if @parser && @beacon
|
48
|
-
self.start if @advertising
|
49
|
-
end
|
50
|
-
|
51
27
|
def rotate_addr
|
52
28
|
@device.open do
|
53
29
|
@device.rotate_addr
|
@@ -1,54 +1,40 @@
|
|
1
1
|
module ScanBeacon
|
2
|
-
class BlueZAdvertiser
|
2
|
+
class BlueZAdvertiser < GenericIndividualAdvertiser
|
3
3
|
|
4
|
-
|
4
|
+
attr_reader :addr
|
5
5
|
|
6
6
|
def initialize(opts = {})
|
7
7
|
@device_id = opts[:device_id] || BlueZ.devices.map {|d| d[:device_id]}[0]
|
8
8
|
raise "No available devices" if @device_id.nil?
|
9
9
|
BlueZ.device_up @device_id
|
10
|
-
|
11
|
-
|
12
|
-
self.parser = opts[:parser]
|
13
|
-
self.parser ||= BeaconParser.default_parsers.find {|parser| parser.beacon_type == beacon.beacon_types.first}
|
10
|
+
addr = @initial_addr = BlueZ.devices.find {|d| d[:device_id] == @device_id}[:addr]
|
11
|
+
super(opts)
|
14
12
|
end
|
15
13
|
|
16
|
-
def
|
17
|
-
@beacon = value
|
18
|
-
update_ad
|
19
|
-
end
|
20
|
-
|
21
|
-
def parser=(value)
|
22
|
-
@parser = value
|
23
|
-
update_ad
|
24
|
-
end
|
25
|
-
|
26
|
-
def ad=(value)
|
27
|
-
@ad = value
|
14
|
+
def start(with_rotation = false)
|
28
15
|
BlueZ.set_advertisement_bytes @device_id, @ad
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
16
|
+
# You must call start advertising any time you change the advertisement bytes
|
17
|
+
# otherwise they won't take
|
18
|
+
if with_rotation
|
19
|
+
@addr = random_addr
|
20
|
+
BlueZ.start_advertising @device_id, addr
|
21
|
+
else
|
22
|
+
# have to pass nil for addr if we don't want to override it and use the internal
|
23
|
+
BlueZ.start_advertising @device_id, nil
|
24
|
+
end
|
25
|
+
|
26
|
+
@advertising=true
|
38
27
|
end
|
39
28
|
|
40
29
|
def stop
|
41
30
|
BlueZ.stop_advertising @device_id
|
31
|
+
@advertising=false
|
42
32
|
end
|
43
33
|
|
44
34
|
def inspect
|
45
35
|
"<BlueZAdvertiser ad=#{@ad.inspect}>"
|
46
36
|
end
|
47
37
|
|
48
|
-
def update_ad
|
49
|
-
self.ad = @parser.generate_ad(@beacon) if @parser && @beacon
|
50
|
-
end
|
51
|
-
|
52
38
|
def rotate_addr_and_update_ad
|
53
39
|
self.update_ad
|
54
40
|
self.stop
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module ScanBeacon
|
2
|
+
class GenericAdvertiser
|
3
|
+
attr_accessor :beacon, :parser, :ad
|
4
|
+
attr_reader :advertising
|
5
|
+
|
6
|
+
def initialize(opts = {})
|
7
|
+
self.beacon = opts[:beacon]
|
8
|
+
self.parser = opts[:parser]
|
9
|
+
if beacon
|
10
|
+
self.parser ||= BeaconParser.default_parsers.find {|parser| parser.beacon_type == beacon.beacon_types.first}
|
11
|
+
end
|
12
|
+
@advertising = false
|
13
|
+
end
|
14
|
+
|
15
|
+
def start(with_rotation = false)
|
16
|
+
raise NotImplementedError
|
17
|
+
end
|
18
|
+
|
19
|
+
def stop
|
20
|
+
raise NotImplementedError
|
21
|
+
end
|
22
|
+
|
23
|
+
def inspect
|
24
|
+
raise NotImplementedError
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module ScanBeacon
|
2
|
+
class GenericIndividualAdvertiser < GenericAdvertiser
|
3
|
+
def initialize(opts={})
|
4
|
+
@parser = nil
|
5
|
+
super(opts)
|
6
|
+
end
|
7
|
+
|
8
|
+
def beacon=(value)
|
9
|
+
@beacon = value
|
10
|
+
update_ad
|
11
|
+
end
|
12
|
+
|
13
|
+
def parser=(value)
|
14
|
+
@parser = value
|
15
|
+
update_ad
|
16
|
+
end
|
17
|
+
|
18
|
+
def update_ad
|
19
|
+
self.ad = @parser.generate_ad(@beacon) if @parser && @beacon
|
20
|
+
end
|
21
|
+
|
22
|
+
def ad=(value)
|
23
|
+
@ad = value
|
24
|
+
self.start if advertising
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/scan_beacon/version.rb
CHANGED
data/lib/scan_beacon.rb
CHANGED
@@ -5,6 +5,8 @@ require "scan_beacon/beacon_parser"
|
|
5
5
|
require "scan_beacon/generic_scanner"
|
6
6
|
require "scan_beacon/ble112_device"
|
7
7
|
require "scan_beacon/ble112_scanner"
|
8
|
+
require "scan_beacon/generic_advertiser"
|
9
|
+
require "scan_beacon/generic_individual_advertiser"
|
8
10
|
require "scan_beacon/ble112_advertiser"
|
9
11
|
case RUBY_PLATFORM
|
10
12
|
when /darwin/
|
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.
|
4
|
+
version: 0.6.0
|
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-10-
|
11
|
+
date: 2015-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -100,6 +100,8 @@ files:
|
|
100
100
|
- lib/scan_beacon/bluez_advertiser.rb
|
101
101
|
- lib/scan_beacon/bluez_scanner.rb
|
102
102
|
- lib/scan_beacon/core_bluetooth_scanner.rb
|
103
|
+
- lib/scan_beacon/generic_advertiser.rb
|
104
|
+
- lib/scan_beacon/generic_individual_advertiser.rb
|
103
105
|
- lib/scan_beacon/generic_scanner.rb
|
104
106
|
- lib/scan_beacon/version.rb
|
105
107
|
- scan_beacon.gemspec
|
@@ -123,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
125
|
version: '0'
|
124
126
|
requirements: []
|
125
127
|
rubyforge_project:
|
126
|
-
rubygems_version: 2.
|
128
|
+
rubygems_version: 2.4.6
|
127
129
|
signing_key:
|
128
130
|
specification_version: 4
|
129
131
|
summary: Provides Beacon scanning functionality
|