Module: BLE

Defined in:
lib/ble/char_desc.rb,
lib/ble.rb,
lib/ble/uuid.rb,
lib/ble/agent.rb,
lib/ble/device.rb,
lib/ble/adapter.rb,
lib/ble/service.rb,
lib/ble/version.rb,
lib/ble/db_ollie.rb,
lib/ble/db_nordic.rb,
lib/ble/db_nordic.rb,
lib/ble/db_eddystone.rb,
lib/ble/db_eddystone.rb,
lib/ble/char_registry.rb,
lib/ble/notifications.rb,
lib/ble/characteristic.rb,
lib/ble/db_sig_service.rb,
lib/ble/db_sig_characteristic.rb

Overview

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(....) ... }
}

Defined Under Namespace

Modules: CharRegistry, Notifications, Service Classes: AccessUnavailable, Adapter, Agent, CharDesc, Characteristic, Device, Error, NotAuthorized, NotFound, NotReady, NotSupported, NotYetImplemented, StalledObject, UUID

Constant Summary collapse

GATT_BASE_UUID =

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

"00000000-0000-1000-8000-00805f9b34fb"
VERSION =

0.0.3 PATCH

  • FIX

    NotSupported exeption was not declared.

'1.0.0'

Class Method Summary collapse

Class Method Details

.ok?Boolean

Check if Bluetooth underlying API is accessible

Returns:

  • (Boolean)

90
91
92
# File 'lib/ble.rb', line 90

def self.ok?
    BLUEZ.exists?
end

.registerAgent(agent, service, path) ⇒ Object

Raises:


74
75
76
77
78
79
80
81
82
83
84
# 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

.UUID(val) ⇒ String

Cast value to a well-formatted 128bit UUID string

Parameters:

  • val (String, Integer)

    uuid

Returns:

  • (String)

    well formated 128bit UUID


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 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