Class: ScanBeacon::BLE112Device::BLE112Response
- Inherits:
-
Object
- Object
- ScanBeacon::BLE112Device::BLE112Response
- Defined in:
- lib/scan_beacon/ble112_device.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #advertisement? ⇒ Boolean
- #advertisement_data ⇒ Object
- #advertisement_type ⇒ Object
- #event? ⇒ Boolean
- #gap_scan? ⇒ Boolean
-
#initialize(data) ⇒ BLE112Response
constructor
A new instance of BLE112Response.
- #mac ⇒ Object
- #manufacturer_ad? ⇒ Boolean
- #rssi ⇒ Object
- #service_ad? ⇒ Boolean
- #size ⇒ Object
Constructor Details
#initialize(data) ⇒ BLE112Response
Returns a new instance of BLE112Response.
150 151 152 |
# File 'lib/scan_beacon/ble112_device.rb', line 150 def initialize(data) @data = (data || "").force_encoding("ASCII-8BIT") end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
148 149 150 |
# File 'lib/scan_beacon/ble112_device.rb', line 148 def data @data end |
Instance Method Details
#advertisement? ⇒ Boolean
174 175 176 |
# File 'lib/scan_beacon/ble112_device.rb', line 174 def advertisement? event? && gap_scan? && (manufacturer_ad? || service_ad?) end |
#advertisement_data ⇒ Object
182 183 184 |
# File 'lib/scan_beacon/ble112_device.rb', line 182 def advertisement_data @advertisement_data ||= data[20..-1] end |
#advertisement_type ⇒ Object
178 179 180 |
# File 'lib/scan_beacon/ble112_device.rb', line 178 def advertisement_type data[19].unpack('C')[0] end |
#event? ⇒ Boolean
158 159 160 |
# File 'lib/scan_beacon/ble112_device.rb', line 158 def event? data[0].unpack('C')[0] == BG_EVENT end |
#gap_scan? ⇒ Boolean
162 163 164 |
# File 'lib/scan_beacon/ble112_device.rb', line 162 def gap_scan? data[2..3].unpack('CC') == [BG_MSG_CLASS_GAP, 0] end |
#mac ⇒ Object
186 187 188 |
# File 'lib/scan_beacon/ble112_device.rb', line 186 def mac data[6..11].unpack('H2 H2 H2 H2 H2 H2').join(":") end |
#manufacturer_ad? ⇒ Boolean
166 167 168 |
# File 'lib/scan_beacon/ble112_device.rb', line 166 def manufacturer_ad? size > 20 && advertisement_type == 0xFF end |
#rssi ⇒ Object
190 191 192 |
# File 'lib/scan_beacon/ble112_device.rb', line 190 def rssi data[4].unpack('c')[0] end |
#service_ad? ⇒ Boolean
170 171 172 |
# File 'lib/scan_beacon/ble112_device.rb', line 170 def service_ad? size > 20 && advertisement_type ==0x03 end |
#size ⇒ Object
154 155 156 |
# File 'lib/scan_beacon/ble112_device.rb', line 154 def size data.size end |