Class: ScanBeacon::BLE112Device::BLE112Response

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

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ BLE112Response

Returns a new instance of BLE112Response.



112
113
114
# File 'lib/scan_beacon/ble112_device.rb', line 112

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

Instance Method Details

#advertisement?Boolean

Returns:

  • (Boolean)


136
137
138
# File 'lib/scan_beacon/ble112_device.rb', line 136

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


144
145
146
# File 'lib/scan_beacon/ble112_device.rb', line 144

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


140
141
142
# File 'lib/scan_beacon/ble112_device.rb', line 140

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

#event?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'lib/scan_beacon/ble112_device.rb', line 120

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

#gap_scan?Boolean

Returns:

  • (Boolean)


124
125
126
# File 'lib/scan_beacon/ble112_device.rb', line 124

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

#macObject



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

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

#manufacturer_ad?Boolean

Returns:

  • (Boolean)


128
129
130
# File 'lib/scan_beacon/ble112_device.rb', line 128

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

#rssiObject



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

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

#service_ad?Boolean

Returns:

  • (Boolean)


132
133
134
# File 'lib/scan_beacon/ble112_device.rb', line 132

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

#sizeObject



116
117
118
# File 'lib/scan_beacon/ble112_device.rb', line 116

def size
  @data.size
end