Class: ScanBeacon::BLE112Device::BLE112Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ BLE112Response

Returns a new instance of BLE112Response.



151
152
153
# File 'lib/scan_beacon/ble112_device.rb', line 151

def initialize(data)
  @data = (data || "").force_encoding("ASCII-8BIT")
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



149
150
151
# File 'lib/scan_beacon/ble112_device.rb', line 149

def data
  @data
end

Instance Method Details

#advertisement?Boolean

Returns:

  • (Boolean)


175
176
177
# File 'lib/scan_beacon/ble112_device.rb', line 175

def advertisement?
  event? && gap_scan? && (manufacturer_ad? || service_ad?)
end


183
184
185
# File 'lib/scan_beacon/ble112_device.rb', line 183

def advertisement_data
  @advertisement_data ||= data[20..-1]
end


179
180
181
# File 'lib/scan_beacon/ble112_device.rb', line 179

def advertisement_type
  data[19].unpack('C')[0]
end

#event?Boolean

Returns:

  • (Boolean)


159
160
161
# File 'lib/scan_beacon/ble112_device.rb', line 159

def event?
  data[0].unpack('C')[0] == BG_EVENT
end

#gap_scan?Boolean

Returns:

  • (Boolean)


163
164
165
# File 'lib/scan_beacon/ble112_device.rb', line 163

def gap_scan?
  data[2..3].unpack('CC') == [BG_MSG_CLASS_GAP, 0]
end

#macObject



187
188
189
# File 'lib/scan_beacon/ble112_device.rb', line 187

def mac
  data[6..11].unpack('H2 H2 H2 H2 H2 H2').join(":")
end

#manufacturer_ad?Boolean

Returns:

  • (Boolean)


167
168
169
# File 'lib/scan_beacon/ble112_device.rb', line 167

def manufacturer_ad?
  size > 20 && advertisement_type == 0xFF
end

#rssiObject



191
192
193
# File 'lib/scan_beacon/ble112_device.rb', line 191

def rssi
  data[4].unpack('c')[0]
end

#service_ad?Boolean

Returns:

  • (Boolean)


171
172
173
# File 'lib/scan_beacon/ble112_device.rb', line 171

def service_ad?
  size > 20 && advertisement_type ==0x03
end

#sizeObject



155
156
157
# File 'lib/scan_beacon/ble112_device.rb', line 155

def size
  data.size
end