Class: BLE::CharDesc

Inherits:
Object
  • Object
show all
Defined in:
lib/ble/char_desc.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(desc) ⇒ CharDesc

Returns a new instance of CharDesc.

Parameters:

  • desc (Hash)

    Descriptors.


8
9
10
# File 'lib/ble/char_desc.rb', line 8

def initialize(desc)
  @desc= desc
end

Instance Attribute Details

#descObject (readonly)

Returns the value of attribute desc


6
7
8
# File 'lib/ble/char_desc.rb', line 6

def desc
  @desc
end

Instance Method Details

#configObject


14
15
16
# File 'lib/ble/char_desc.rb', line 14

def config
  @config||= Characteristic[@desc[:uuid]]
end

#flag?(flag_name) ⇒ Boolean

Returns:

  • (Boolean)

21
22
23
# File 'lib/ble/char_desc.rb', line 21

def flag?(flag_name)
  flags.include?(flag_name)
end

#flagsObject


11
12
13
# File 'lib/ble/char_desc.rb', line 11

def flags
  @flags||= @desc[:flags]
end

#post_process(val) ⇒ Object


58
59
60
# File 'lib/ble/char_desc.rb', line 58

def post_process(val)
  val = config[:in].call(val) if read_post_processor?
end

#pre_process(val) ⇒ Object


50
51
52
53
54
55
56
# File 'lib/ble/char_desc.rb', line 50

def pre_process(val)
  if verifier? && !verifies?(val)
    raise ArgumentError,
      "bad value for characteristic '#{uuid}'"
  end
  val = config[:out].call(val) if write_pre_processor?
end

#read_post_processor?Boolean

Returns:

  • (Boolean)

43
44
45
# File 'lib/ble/char_desc.rb', line 43

def read_post_processor?
  config[:in]
end

#read_processors?Boolean

Does incoming values have processors configured? If yes, the value needs to be post-processed after being received.

Returns:

  • (Boolean)

32
33
34
# File 'lib/ble/char_desc.rb', line 32

def read_processors?
  config && read_post_processor?
end

#uuidObject


18
19
20
# File 'lib/ble/char_desc.rb', line 18

def uuid
  @desc[:uuid]
end

#verifier?Boolean

It has been configured a verifier preprocessor to check outgoing data?

Returns:

  • (Boolean)

37
38
39
# File 'lib/ble/char_desc.rb', line 37

def verifier?
  config[:vrfy]
end

#verifies?(val) ⇒ Boolean

Is the received value verified by the verifier?

Returns:

  • (Boolean)

47
48
49
# File 'lib/ble/char_desc.rb', line 47

def verifies?(val)
  config[:vrfy].call(val)
end

#write_pre_processor?Boolean

Returns:

  • (Boolean)

40
41
42
# File 'lib/ble/char_desc.rb', line 40

def write_pre_processor?
  config[:out]
end

#write_processors?Boolean

Does outgoing values have processors configured? If yes, the value needs to be pre-processed before being send.

Returns:

  • (Boolean)

27
28
29
# File 'lib/ble/char_desc.rb', line 27

def write_processors?
  verifier? or write_pre_processor?
end