Class GattCharacteristic

java.lang.Object
com.codename1.bluetooth.gatt.GattCharacteristic

public class GattCharacteristic extends Object

A characteristic of a remote GattService -- the unit of data exchange with a BLE peripheral. Read, write and subscribe operations are routed through the owning peripheral's internal operation queue, so any number of calls may be issued concurrently; they execute in order.

Instances are constructed by the port during service discovery; application code never creates them.

  • Field Details

    • PROPERTY_BROADCAST

      public static final int PROPERTY_BROADCAST
      The characteristic supports broadcast (bit 0x01).
      See Also:
    • PROPERTY_READ

      public static final int PROPERTY_READ
      The characteristic can be read (bit 0x02).
      See Also:
    • PROPERTY_WRITE_WITHOUT_RESPONSE

      public static final int PROPERTY_WRITE_WITHOUT_RESPONSE
      The characteristic can be written without response (bit 0x04).
      See Also:
    • PROPERTY_WRITE

      public static final int PROPERTY_WRITE
      The characteristic can be written with response (bit 0x08).
      See Also:
    • PROPERTY_NOTIFY

      public static final int PROPERTY_NOTIFY
      The characteristic supports notifications (bit 0x10).
      See Also:
    • PROPERTY_INDICATE

      public static final int PROPERTY_INDICATE
      The characteristic supports indications (bit 0x20).
      See Also:
    • PROPERTY_SIGNED_WRITE

      public static final int PROPERTY_SIGNED_WRITE
      The characteristic supports signed writes (bit 0x40).
      See Also:
    • PROPERTY_EXTENDED_PROPS

      public static final int PROPERTY_EXTENDED_PROPS
      The characteristic has extended properties (bit 0x80).
      See Also:
  • Constructor Details

    • GattCharacteristic

      public GattCharacteristic(GattService service, BluetoothUuid uuid, int properties, int instanceId)
      Constructed by ports during service discovery; not application API.
  • Method Details

    • getUuid

      public BluetoothUuid getUuid()
      The UUID identifying this characteristic.
    • getService

      public GattService getService()
      The service this characteristic belongs to.
    • getProperties

      public int getProperties()
      The raw PROPERTY_* bitmask as advertised by the peripheral.
    • getInstanceId

      public int getInstanceId()
      Disambiguates multiple instances of the same characteristic UUID within one service.
    • canRead

      public boolean canRead()
      true when PROPERTY_READ is set.
    • canWrite

      public boolean canWrite()
      true when PROPERTY_WRITE is set.
    • canWriteWithoutResponse

      public boolean canWriteWithoutResponse()
    • canNotify

      public boolean canNotify()
      true when PROPERTY_NOTIFY is set.
    • canIndicate

      public boolean canIndicate()
      true when PROPERTY_INDICATE is set.
    • getDescriptors

      public List<GattDescriptor> getDescriptors()
      The descriptors of this characteristic, in discovery order.
    • getDescriptor

      public GattDescriptor getDescriptor(BluetoothUuid uuid)
      The first descriptor with the given UUID, or null.
    • addDescriptor

      public void addDescriptor(GattDescriptor descriptor)
      Called by ports while building the discovered GATT database; not application API.
    • read

      public AsyncResource<byte[]> read()
      Reads the current value. Resolves with the raw bytes on the EDT or fails with a BluetoothException.
    • write

      public AsyncResource<Boolean> write(byte[] value)
      Writes the value with response. Resolves true on the EDT once the peripheral acknowledged the write.
    • writeWithoutResponse

      public AsyncResource<Boolean> writeWithoutResponse(byte[] value)
      Writes the value without response. Resolves true once the value was queued to the controller -- there is no remote acknowledgement.
    • subscribe

      Subscribes to value changes. The first listener triggers the CCCD write that arms notifications (indications are used when the characteristic only supports PROPERTY_INDICATE); the returned resource resolves true once armed. Additional listeners resolve immediately. Values stream to the listener on the EDT until unsubscribe(GattNotificationListener) or disconnection.
    • unsubscribe

      Removes a listener added via subscribe(GattNotificationListener). When the last listener is removed the CCCD is written to disarm notifications; the returned resource resolves once done.
    • isSubscribed

      public boolean isSubscribed()
      true while notifications/indications are armed for this characteristic.
    • toString

      public String toString()
      Description copied from class: Object
      Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + '@' + Integer.toHexString(hashCode())
      Overrides:
      toString in class Object