Class LocalCharacteristic

implements Attribute

Class summary


constructor service/LocalService uuid/BleUuid properties/int permissions/int value/Data read-timeout-ms_/int

Constructors

constructor service/LocalService uuid/BleUuid properties/int permissions/int value/Data read-timeout-ms_/int

Methods

add-descriptor uuid/BleUuid properties/int permissions/int value/Data=null -> LocalDescriptor
Adds a descriptor to this characteristic.
uuid is the uuid of the descriptor
properties is one of the CHARACTERISTIC-PROPERTY-* values (see CHARACTERISTIC-PROPERTY-BROADCAST and similar).
permissions is one of the CHARACTERISTIC-PERMISSIONS-* values (see CHARACTERISTIC-PERMISSION-READ and similar).
if value is specified, it is used as the initial value for the characteristic.
The peripheral must not yet be deployed.

add-descriptor uuid/BleUuid --properties/int --permissions/int --value/Data=null -> LocalDescriptor
Adds a descriptor to this characteristic.
uuid is the uuid of the descriptor
properties is one of the CHARACTERISTIC-PROPERTY-* values (see CHARACTERISTIC-PROPERTY-BROADCAST and similar).
permissions is one of the CHARACTERISTIC-PERMISSIONS-* values (see CHARACTERISTIC-PERMISSION-READ and similar).
If value is specified, it is used as the initial value for the characteristic.
The peripheral must not yet be deployed.

add-descriptor uuid/BleUuid --value/Data --secure/bool=false -> LocalDescriptor
Adds a read-only descriptor to this characteristic with the given uuid.
If secure is specified, the descriptor requires encryption.
The peripheral must not yet be deployed.

The handle of the characteristic.
Typically, users do not need to access the handle directly. It may be useful for debugging purposes, but it is not required for normal operation.

handle-read-request --timeout-ms/int=read-timeout-ms_ [block] -> none
Handles read requests.
This blocking function waits for read requests on this characteristic and calls the given block for each request.
The block must return an io.Data which is then used as value of the characteristic.
If no request-handler is active, and the characteristic has a value, then the value is returned. In other words, this function takes precedence over the value that was given in the constructor or by set-value/write.

handle-write-request --timeout-ms/int=LocalService.DEFAULT-WRITE-TIMEOUT-MS [block] -> none
Handles write requests.
When new data is written to this characteristic, the given block is called with the value.
In many cases, the read function is sufficient and easier to use. See below for reasons to use this function instead.
This blocking function waits for write requests on this characteristic and calls the given block for each request with the written value.
If no request-handler is active, then the data is accumulated and can be read by calling read. In other words, this function takes precedence over the read function.
If data was accumulated before the handler or read was called, then the block is called with the accumulated data.
While read is easier to use, handle-write-request may be necessary for characteristics that respond. The BLE stack will send a response only once the called block has returned, thus ensuring that the data has been processed before the response is sent.

operator == other/any -> bool
Whether this object is equal to the other.
By default, identical is used for equality.
Inheritance
Classes overwrite this operator to get an equality specific to their needs. Equality operators often compare the type and field contents. For example:

class Pin:
  number/int

  constructor .number:

  operator == other:
    if other is not Pin: return false
    return number == other.number
A class doesn't have to follow the above format, but it must keep the operator in sync with any hash-code method. That is, if a class has a hash-code member, then the equality and hash-code must agree. If two instances are equal (a == b), then their hash codes must also be equal (a.hash-code == b.hash-code).

Reads a value that is written to this characteristic.
Waits until a client writes a value.

set-value value/Data -> none
Sets the value of the characteristic.
This value is returned when a client reads the characteristic. The handle-read-request function takes precedence over this value.
Clears the stored value if the given value is null.
In most cases write is sufficient and easier to use. The main reason to use this function is to set a value without sending out any notification.

Stringifies this object.
Inheritance
Objects that need a human-friendly string representation should overwrite this method. The default string is based on the internal class-ID.

write value/Data --set-value/bool=true -> none
Sets the value of this characteristic and sends a notification or indication if supported.
If the characteristic supports both indications and notifications, then a notification is sent.
If set-value is true (the default), sets the value of the characteristic to value. Any read requests will return this value until the value is changed again. See set-value for setting the value without sending out a notification.
If the characteristic doesn't support notifications or indications and set-value is set to false, then this function does nothing.