Class GattCharacteristic
java.lang.Object
com.codename1.bluetooth.gatt.GattCharacteristic
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe characteristic supports broadcast (bit0x01).static final intThe characteristic has extended properties (bit0x80).static final intThe characteristic supports indications (bit0x20).static final intThe characteristic supports notifications (bit0x10).static final intThe characteristic can be read (bit0x02).static final intThe characteristic supports signed writes (bit0x40).static final intThe characteristic can be written with response (bit0x08).static final intThe characteristic can be written without response (bit0x04). -
Constructor Summary
ConstructorsConstructorDescriptionGattCharacteristic(GattService service, BluetoothUuid uuid, int properties, int instanceId) Constructed by ports during service discovery; not application API. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDescriptor(GattDescriptor descriptor) Called by ports while building the discovered GATT database; not application API.booleantruewhenPROPERTY_INDICATEis set.booleantruewhenPROPERTY_NOTIFYis set.booleancanRead()truewhenPROPERTY_READis set.booleancanWrite()truewhenPROPERTY_WRITEis set.booleantruewhenPROPERTY_WRITE_WITHOUT_RESPONSEis set.getDescriptor(BluetoothUuid uuid) The first descriptor with the given UUID, ornull.The descriptors of this characteristic, in discovery order.intDisambiguates multiple instances of the same characteristic UUID within one service.intThe rawPROPERTY_*bitmask as advertised by the peripheral.The service this characteristic belongs to.getUuid()The UUID identifying this characteristic.booleantruewhile notifications/indications are armed for this characteristic.AsyncResource<byte[]> read()Reads the current value.Subscribes to value changes.toString()Returns a string representation of the object.Removes a listener added viasubscribe(GattNotificationListener).write(byte[] value) Writes the value with response.writeWithoutResponse(byte[] value) Writes the value without response.
-
Field Details
-
PROPERTY_BROADCAST
public static final int PROPERTY_BROADCASTThe characteristic supports broadcast (bit0x01).- See Also:
-
PROPERTY_READ
public static final int PROPERTY_READThe characteristic can be read (bit0x02).- See Also:
-
PROPERTY_WRITE_WITHOUT_RESPONSE
public static final int PROPERTY_WRITE_WITHOUT_RESPONSEThe characteristic can be written without response (bit0x04).- See Also:
-
PROPERTY_WRITE
public static final int PROPERTY_WRITEThe characteristic can be written with response (bit0x08).- See Also:
-
PROPERTY_NOTIFY
public static final int PROPERTY_NOTIFYThe characteristic supports notifications (bit0x10).- See Also:
-
PROPERTY_INDICATE
public static final int PROPERTY_INDICATEThe characteristic supports indications (bit0x20).- See Also:
-
PROPERTY_SIGNED_WRITE
public static final int PROPERTY_SIGNED_WRITEThe characteristic supports signed writes (bit0x40).- See Also:
-
PROPERTY_EXTENDED_PROPS
public static final int PROPERTY_EXTENDED_PROPSThe characteristic has extended properties (bit0x80).- See Also:
-
-
Constructor Details
-
GattCharacteristic
Constructed by ports during service discovery; not application API.
-
-
Method Details
-
getUuid
The UUID identifying this characteristic. -
getService
The service this characteristic belongs to. -
getProperties
public int getProperties()The rawPROPERTY_*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()truewhenPROPERTY_READis set. -
canWrite
public boolean canWrite()truewhenPROPERTY_WRITEis set. -
canWriteWithoutResponse
public boolean canWriteWithoutResponse()truewhenPROPERTY_WRITE_WITHOUT_RESPONSEis set. -
canNotify
public boolean canNotify()truewhenPROPERTY_NOTIFYis set. -
canIndicate
public boolean canIndicate()truewhenPROPERTY_INDICATEis set. -
getDescriptors
The descriptors of this characteristic, in discovery order. -
getDescriptor
The first descriptor with the given UUID, ornull. -
addDescriptor
Called by ports while building the discovered GATT database; not application API. -
read
Reads the current value. Resolves with the raw bytes on the EDT or fails with aBluetoothException. -
write
Writes the value with response. Resolvestrueon the EDT once the peripheral acknowledged the write. -
writeWithoutResponse
Writes the value without response. Resolvestrueonce 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 supportsPROPERTY_INDICATE); the returned resource resolvestrueonce armed. Additional listeners resolve immediately. Values stream to the listener on the EDT untilunsubscribe(GattNotificationListener)or disconnection. -
unsubscribe
Removes a listener added viasubscribe(GattNotificationListener). When the last listener is removed the CCCD is written to disarm notifications; the returned resource resolves once done. -
isSubscribed
public boolean isSubscribed()truewhile notifications/indications are armed for this characteristic. -
toString
Description copied from class:ObjectReturns 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())
-