Class: ScanBeacon::BLE112Advertiser

Inherits:
Object
  • Object
show all
Defined in:
lib/scan_beacon/ble112_advertiser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#adObject

Returns the value of attribute ad.



4
5
6
# File 'lib/scan_beacon/ble112_advertiser.rb', line 4

def ad
  @ad
end

#beaconObject

Returns the value of attribute beacon.



4
5
6
# File 'lib/scan_beacon/ble112_advertiser.rb', line 4

def beacon
  @beacon
end

#parserObject

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

#inspectObject



42
43
44
# File 'lib/scan_beacon/ble112_advertiser.rb', line 42

def inspect
  "<BLE112Advertiser ad=#{@ad.inspect}>"
end

#rotate_addrObject



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_adObject



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

#stopObject



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_adObject



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