Class: BLE::Adapter
- Inherits:
-
Object
- Object
- BLE::Adapter
- Defined in:
- lib/ble/adapter.rb
Overview
a.devices
Class Method Summary collapse
-
.list ⇒ Array<String>
Return a list of available unix device name for the adapter installed on the system.
Instance Method Summary collapse
-
#[](address) ⇒ Device
Return the device corresponding to the given address.
-
#address ⇒ String
The Bluetooth device address.
-
#alias ⇒ String
The Bluetooth friendly name.
-
#alias=(val) ⇒ void
Set the alias name.
-
#devices ⇒ Array<String>
List of devices MAC address that have been discovered.
-
#filter(uuids, rssi: nil, pathloss: nil, transport: :le) ⇒ self
This method sets the device discovery filter for the caller.
-
#iface ⇒ String
The Bluetooth interface name.
-
#initialize(iface) ⇒ Adapter
constructor
Create a new Adapter.
-
#name ⇒ String
The Bluetooth system name (pretty hostname).
-
#start_discovery ⇒ Boolean
Starts the device discovery session.
-
#stop_discovery ⇒ Boolean
This method will cancel any previous #start_discovery transaction.
Constructor Details
#initialize(iface) ⇒ Adapter
Create a new Adapter
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ble/adapter.rb', line 21 def initialize(iface) @iface = iface.dup.freeze @o_adapter = BLUEZ.object("/org/bluez/#{@iface}") @o_adapter.introspect # @o_adapter[I_PROPERTIES] # .on_signal('PropertiesChanged') do |intf, props| # end # end end |
Class Method Details
.list ⇒ Array<String>
Return a list of available unix device name for the adapter installed on the system.
12 13 14 15 16 |
# File 'lib/ble/adapter.rb', line 12 def self.list o_bluez = BLUEZ.object('/org/bluez') o_bluez.introspect o_bluez.subnodes.reject {|adapter| ['test'].include?(adapter) } end |
Instance Method Details
#[](address) ⇒ Device
The device object returned has a dependency on the adapter.
Return the device corresponding to the given address.
74 75 76 |
# File 'lib/ble/adapter.rb', line 74 def [](address) Device.new(@iface, address) end |
#address ⇒ String
The Bluetooth device address.
40 41 42 |
# File 'lib/ble/adapter.rb', line 40 def address @o_adapter[I_ADAPTER]['Address'] end |
#alias ⇒ String
The Bluetooth friendly name. In case no alias is set, it will return the system provided name.
53 54 55 |
# File 'lib/ble/adapter.rb', line 53 def alias @o_adapter[I_ADAPTER]['Alias'] end |
#alias=(val) ⇒ void
This method returns an undefined value.
Set the alias name.
When resetting the alias with an empty string, the property will default back to system name
64 65 66 67 |
# File 'lib/ble/adapter.rb', line 64 def alias=(val) @o_adapter[I_ADAPTER]['Alias'] = val.nil? ? '' : val.to_str nil end |
#devices ⇒ Array<String>
List of devices MAC address that have been discovered.
156 157 158 159 160 |
# File 'lib/ble/adapter.rb', line 156 def devices @o_adapter.introspect # Force refresh @o_adapter.subnodes.map {|dev| # Format: dev_aa_bb_cc_dd_ee_ff dev[4..-1].tr('_', ':') } end |
#filter(uuids, rssi: nil, pathloss: nil, transport: :le) ⇒ self
Need to sync with the adapter-api.txt
This method sets the device discovery filter for the caller. When this method is called with nil or an empty list of UUIDs, filter is removed.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/ble/adapter.rb', line 90 def filter(uuids, rssi: nil, pathloss: nil, transport: :le) unless [:auto, :bredr, :le].include?(transport) raise ArgumentError, "transport must be one of :auto, :bredr, :le" end filter = { } unless uuids.nil? || uuids.empty? filter['UUIDs' ] = DBus.variant('as', uuids) end unless rssi.nil? filter['RSSI' ] = DBus.variant('n', rssi) end unless pathloss.nil? filter['Pathloss' ] = DBus.variant('q', pathloss) end unless transport.nil? filter['Transport'] = DBus.variant('s', transport.to_s) end @o_adapter[I_ADAPTER].SetDiscoveryFilter(filter) self end |
#iface ⇒ String
The Bluetooth interface name
34 35 36 |
# File 'lib/ble/adapter.rb', line 34 def iface @iface end |
#name ⇒ String
The Bluetooth system name (pretty hostname).
46 47 48 |
# File 'lib/ble/adapter.rb', line 46 def name @o_adapter[I_ADAPTER]['Name'] end |
#start_discovery ⇒ Boolean
Starts the device discovery session. This includes an inquiry procedure and remote device name resolving. Use #stop_discovery to release the sessions acquired. This process will start creating device in the underlying api as new devices are discovered.
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/ble/adapter.rb', line 122 def start_discovery @o_adapter[I_ADAPTER].StartDiscovery true rescue DBus::Error => e case e.name when E_IN_PROGRESS then true when E_FAILED then false else raise ScriptError end end |
#stop_discovery ⇒ Boolean
The discovery procedure is shared
This method will cancel any previous #start_discovery transaction. between all discovery sessions thus calling #stop_discovery will only release a single session.
140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/ble/adapter.rb', line 140 def stop_discovery @o_adapter[I_ADAPTER].StopDiscovery true rescue DBus::Error => e case e.name when E_FAILED then false when E_NOT_READY then false when E_NOT_AUTHORIZED then raise NotAuthorized else raise ScriptError end end |