Method: BLE.UUID

Defined in:
lib/ble/uuid.rb

.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