module BLE

Encapsulates Characteristic descriptors and offers easy access to characteristic related information.

To add a new characteristic description:

BLE::Characteristic.add 'c4935338-4307-47cf-ae1f-feac9e2b3ae7',
    name: 'Controlled mind',
    type: 'net.cortex-minus.characteristic.controlled_mind'
    vrfy: ->(x) { x >= 0 },
      in: ->(s) { s.unpack('s<').first },
     out: ->(v) { [ v ].pack('s<') }

Returned characteristic description will be a hash:

{
   name: "Bluetooth characteristic name",
   type: "org.bluetooth.characteristic.name",
   uuid: "128bit-uuid-string",
   vrfy: ->(x) { verify_value(x) },
     in: ->(s) { s.unpack(....) ... },
    out: ->(v) { [ v ].pack(....) ... }
}

Constants

BLUEZ
DBUS

Bus

E_ALREADY_CONNECTED
E_ALREADY_EXISTS
E_AUTH_ATTEMPT_FAILED
E_AUTH_CANCELED
E_AUTH_FAILED
E_AUTH_REJECTED
E_AUTH_TIMEOUT
E_DOES_NOT_EXIST
E_FAILED
E_INVALID_ARGS
E_INVALID_ARGUMENTS
E_INVALID_SIGNATURE
E_IN_PROGRESS

Errors

E_NOT_AUTHORIZED
E_NOT_CONNECTED
E_NOT_READY
E_NOT_SUPPORTED
E_UNKNOWN_OBJECT
GATT_BASE_UUID

Base UUID for GATT services defined with 16bit or 32bit UUID

I_ADAPTER

Interfaces

I_AGENT
I_AGENT_MANAGER
I_DEVICE
I_GATT_CHARACTERISTIC
I_GATT_SERVICE
I_INTROSPECTABLE
I_PROPERTIES
I_PROXIMITY_REPORTER
VERSION

0.0.3 PATCH

Public Class Methods

UUID(val) click to toggle source

Cast value to a well-formatted 128bit UUID string @param [String, Integer] val uuid @return [String] well formated 128bit UUID

# File lib/ble/uuid.rb, line 5
def self.UUID(val)
    case val
    when Integer
        if !(0..4294967295).include?(val)  # 2**32-1
            raise ArgumentError, "not a 16-bit or 32-bit UUID"
        end
        ([val].pack("L>").unpack('H*').first + GATT_BASE_UUID[8..-1])
    when String
        if val !~ UUID::REGEX
            raise ArgumentError, "not a 128bit uuid string"
        end
        val.downcase
    else raise ArgumentError, "invalid uuid type"
    end
end
ok?() click to toggle source

Check if Bluetooth underlying API is accessible

# File lib/ble.rb, line 90
def self.ok?
    BLUEZ.exists?
end
registerAgent(agent, service, path) click to toggle source

“DisplayOnly”, “DisplayYesNo”, “KeyboardOnly”,

"NoInputNoOutput" and "KeyboardDisplay" which
# File lib/ble.rb, line 74
def self.registerAgent(agent, service, path)
    raise NotYetImplemented
    bus = DBus.session_bus
    service = bus.request_service("org.ruby.service")

    service.export(BLE::Agent.new(agent_path))

    o_bluez = BLUEZ.object('/org/bluez')
    o_bluez.introspect
    o_bluez[I_AGENT_MANAGER].RegisterAgent(agent_path, "NoInputNoOutput")
end