Class: ScanBeacon::BLE112Advertiser
- Inherits:
-
Object
- Object
- ScanBeacon::BLE112Advertiser
- Defined in:
- lib/scan_beacon/ble112_advertiser.rb
Instance Attribute Summary collapse
-
#ad ⇒ Object
Returns the value of attribute ad.
-
#beacon ⇒ Object
Returns the value of attribute beacon.
-
#parser ⇒ Object
Returns the value of attribute parser.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ BLE112Advertiser
constructor
A new instance of BLE112Advertiser.
- #inspect ⇒ Object
- #rotate_addr ⇒ Object
- #rotate_addr_and_update_ad ⇒ Object
- #start(with_rotation = false) ⇒ Object
- #stop ⇒ Object
- #update_ad ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ BLE112Advertiser
Returns a new instance of BLE112Advertiser.
6 7 8 9 10 11 12 |
# File 'lib/scan_beacon/ble112_advertiser.rb', line 6 def initialize(opts = {}) @device = BLE112Device.new opts[:port] self.beacon = opts[:beacon] self.parser = opts[:parser] self.parser ||= BeaconParser.default_parsers.find {|parser| parser.beacon_type == beacon.beacon_types.first} @advertising = false end |
Instance Attribute Details
#ad ⇒ Object
Returns the value of attribute ad.
4 5 6 |
# File 'lib/scan_beacon/ble112_advertiser.rb', line 4 def ad @ad end |
#beacon ⇒ Object
Returns the value of attribute beacon.
4 5 6 |
# File 'lib/scan_beacon/ble112_advertiser.rb', line 4 def beacon @beacon end |
#parser ⇒ Object
Returns the value of attribute parser.
4 5 6 |
# File 'lib/scan_beacon/ble112_advertiser.rb', line 4 def parser @parser end |
Instance Method Details
#inspect ⇒ Object
42 43 44 |
# File 'lib/scan_beacon/ble112_advertiser.rb', line 42 def inspect "<BLE112Advertiser ad=#{@ad.inspect}>" end |
#rotate_addr ⇒ Object
51 52 53 54 55 |
# File 'lib/scan_beacon/ble112_advertiser.rb', line 51 def rotate_addr @device.open do @device.rotate_addr end end |
#rotate_addr_and_update_ad ⇒ Object
57 58 59 60 |
# File 'lib/scan_beacon/ble112_advertiser.rb', line 57 def rotate_addr_and_update_ad self.update_ad self.start(true) end |
#start(with_rotation = false) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/scan_beacon/ble112_advertiser.rb', line 28 def start(with_rotation = false) @device.open do @device.start_advertising(@ad, with_rotation) @advertising = true end end |
#stop ⇒ Object
35 36 37 38 39 40 |
# File 'lib/scan_beacon/ble112_advertiser.rb', line 35 def stop @device.open do @device.stop_advertising @advertising = false end end |
#update_ad ⇒ Object
46 47 48 49 |
# File 'lib/scan_beacon/ble112_advertiser.rb', line 46 def update_ad self.ad = @parser.generate_ad(@beacon) if @parser && @beacon self.start if @advertising end |