public static class ReadWriteListener.ReadWriteEvent extends Event implements UsesCustomNull
Modifier and Type | Field and Description |
---|---|
static java.util.UUID |
NON_APPLICABLE_UUID
Value used in place of
null , either indicating that descUuid() isn't used for the ReadWriteListener.ReadWriteEvent
because target() is ReadWriteListener.Target.CHARACTERISTIC , or that both descUuid() and charUuid() aren't applicable
because target() is ReadWriteListener.Target.RSSI . |
Modifier and Type | Method and Description |
---|---|
BleCharacteristic |
characteristic()
Forwards
BleNode.getNativeBleCharacteristic(UUID, UUID) , which will be nonnull
if target() is ReadWriteListener.Target.CHARACTERISTIC or ReadWriteListener.Target.DESCRIPTOR . |
java.util.UUID |
charUuid()
The
UUID of the characteristic associated with this ReadWriteListener.ReadWriteEvent . |
BleConnectionPriority |
connectionPriority()
This value gets set as a result of a
BleDevice.setConnectionPriority(BleConnectionPriority, ReadWriteListener) call. |
byte |
data_byte()
Returns the first byte from
data() , or 0x0 if not available. |
int |
data_int(boolean reverse)
Convenience method that attempts to parse
data() as an int. |
long |
data_long(boolean reverse)
Convenience method that attempts to parse
data() as a long. |
short |
data_short(boolean reverse)
Convenience method that attempts to parse
data() as a short. |
java.lang.String |
data_string()
Best effort parsing of
data() as a String . |
java.lang.String |
data_string(java.lang.String charset)
Convenience method that attempts to parse
data() as a String with the given charset, for example "UTF-8" . |
java.lang.String |
data_utf8()
Convenience method that attempts to parse the data as a UTF-8 string.
|
byte[] |
data()
The data sent to the peripheral if
type() ReadWriteListener.Type.isWrite() , otherwise the data received from the
peripheral if type() ReadWriteListener.Type.isRead() . |
BleDescriptor |
descriptor()
Forwards
BleNode.getNativeBleDescriptor_inChar(UUID, UUID) , which will be nonnull
if target() is ReadWriteListener.Target.DESCRIPTOR . |
DescriptorFilter |
descriptorFilter()
This is the
DescriptorFilter that was used for this read/write operation, if any. |
java.util.UUID |
descUuid()
The
UUID of the descriptor associated with this ReadWriteListener.ReadWriteEvent . |
BleDevice |
device()
The
BleDevice this ReadWriteListener.ReadWriteEvent is for. |
int |
gattStatus()
The native gatt status returned from the stack, if applicable.
|
boolean |
isNull()
Forwards
ReadWriteListener.Type.isNull() . |
boolean |
isRead()
Forwards
ReadWriteListener.Type.isRead() . |
boolean |
isWrite()
Forwards
ReadWriteListener.Type.isWrite() . |
java.lang.String |
macAddress()
Convience to return the mac address of
device() . |
int |
mtu()
This value gets set as a result of a
BleDevice.negotiateMtu(int, ReadWriteListener) call. |
Phy |
phy() |
int |
rssi()
This value gets updated as a result of a
BleDevice.readRssi(ReadWriteListener) call. |
BleService |
service()
Forwards
BleNode.getNativeBleService(UUID) , which will be nonnull
if target() is ReadWriteListener.Target.CHARACTERISTIC or ReadWriteListener.Target.DESCRIPTOR . |
java.util.UUID |
serviceUuid()
The
UUID of the service associated with this ReadWriteListener.ReadWriteEvent . |
boolean |
solicited()
This returns
true if this event was the result of an explicit call through SweetBlue, e.g. |
ReadWriteListener.Status |
status()
Indicates either success or the type of failure.
|
ReadWriteListener.Target |
target()
The type of GATT object this
ReadWriteListener.ReadWriteEvent is for, currently characteristic, descriptor, or rssi. |
Interval |
time_ota()
Time spent "over the air" - so in the native stack, processing in
the peripheral's embedded software, what have you.
|
Interval |
time_total()
Total time it took for the operation to complete, whether success
or failure.
|
java.lang.String |
toString() |
ReadWriteListener.Type |
type()
The type of operation, read, write, etc.
|
boolean |
wasCancelled()
Forwards
ReadWriteListener.Status.wasCancelled() . |
boolean |
wasSuccess()
Convenience method for checking if
status() equals ReadWriteListener.Status.SUCCESS . |
public static final java.util.UUID NON_APPLICABLE_UUID
null
, either indicating that descUuid()
isn't used for the ReadWriteListener.ReadWriteEvent
because target()
is ReadWriteListener.Target.CHARACTERISTIC
, or that both descUuid()
and charUuid()
aren't applicable
because target()
is ReadWriteListener.Target.RSSI
.public final BleDevice device()
BleDevice
this ReadWriteListener.ReadWriteEvent
is for.public final java.lang.String macAddress()
device()
.public final ReadWriteListener.Type type()
public final ReadWriteListener.Target target()
ReadWriteListener.ReadWriteEvent
is for, currently characteristic, descriptor, or rssi.public final java.util.UUID serviceUuid()
UUID
of the service associated with this ReadWriteListener.ReadWriteEvent
. This will always be a non-null UUID
,
even if target()
is ReadWriteListener.Target.DESCRIPTOR
. If target()
is ReadWriteListener.Target.RSSI
then this will be referentially equal
(i.e. you can use == to compare) to NON_APPLICABLE_UUID
.public final java.util.UUID charUuid()
UUID
of the characteristic associated with this ReadWriteListener.ReadWriteEvent
. This will always be a non-null UUID
,
even if target()
is ReadWriteListener.Target.DESCRIPTOR
. If target()
is ReadWriteListener.Target.RSSI
then this will be referentially equal
(i.e. you can use == to compare) to NON_APPLICABLE_UUID
.public final java.util.UUID descUuid()
UUID
of the descriptor associated with this ReadWriteListener.ReadWriteEvent
. If target()
is
ReadWriteListener.Target.CHARACTERISTIC
or ReadWriteListener.Target.RSSI
then this will be referentially equal
(i.e. you can use == to compare) to NON_APPLICABLE_UUID
.public final byte[] data()
type()
ReadWriteListener.Type.isWrite()
, otherwise the data received from the
peripheral if type()
ReadWriteListener.Type.isRead()
. This will never be null
. For error cases it will be a
zero-length array.public final Phy phy()
public final int rssi()
BleDevice.readRssi(ReadWriteListener)
call. It will
always be equivalent to BleDevice.getRssi()
but is included here for convenience.public final int mtu()
BleDevice.negotiateMtu(int, ReadWriteListener)
call. The value returned
will be the same as that given to BleDevice.negotiateMtu(int, ReadWriteListener)
, which means it will be the
same as BleDevice.getMtu()
if status()
equals ReadWriteListener.Status.SUCCESS
.BleDevice.getMtu()
public final ReadWriteListener.Status status()
ReadWriteListener.Status
are not used for certain values of ReadWriteListener.Type
.public final Interval time_ota()
time_total()
.public final Interval time_total()
time_ota()
. This will always be
longer than time_ota()
, though usually only slightly so.public final int gattStatus()
status()
returned is, for example,
ReadWriteListener.Status.NO_MATCHING_TARGET
, then the operation didn't even reach the point where a gatt status is
provided, in which case this member is set to BleStatuses.GATT_STATUS_NOT_APPLICABLE
(value of
-1). Otherwise it will be 0
for success or greater than
0
when there's an issue. Generally this value will only be meaningful when status()
is
ReadWriteListener.Status.SUCCESS
or ReadWriteListener.Status.REMOTE_GATT_FAILURE
. There are
also some cases where this will be 0 for success but status()
is for example
ReadWriteListener.Status.NULL_DATA
- in other words the underlying stack deemed the operation a success but SweetBlue
disagreed. For this reason it's recommended to treat this value as a debugging tool and use status()
for actual
application logic if possible.
BluetoothGatt
for its static GATT_*
status code members. Also see the source code of
BleStatuses
for SweetBlue's more comprehensive internal reference list of gatt status values. This list may not be
totally accurate or up-to-date, nor may it match GATT_ values used by the bluetooth stack on your phone.public final boolean solicited()
true
if this event was the result of an explicit call through SweetBlue, e.g. through
BleDevice.read(UUID)
, BleDevice.write(UUID, byte[])
, etc. It will return false
otherwise,
which can happen if for example you use BleDevice.getNativeGatt()
to bypass SweetBlue for whatever reason.
Another theoretical case is if you make an explicit call through SweetBlue, then you get ReadWriteListener.Status.TIMED_OUT
,
but then the native stack eventually *does* come back with something - this has never been observed, but it is possible.public final BleConnectionPriority connectionPriority()
BleDevice.setConnectionPriority(BleConnectionPriority, ReadWriteListener)
call. The value returned
will be the same as that given to BleDevice.setConnectionPriority(BleConnectionPriority, ReadWriteListener)
, which means it will be the
same as BleDevice.getConnectionPriority()
if status()
equals ReadWriteListener.Status.SUCCESS
.BleDevice.getConnectionPriority()
public final DescriptorFilter descriptorFilter()
DescriptorFilter
that was used for this read/write operation, if any.public final BleService service()
BleNode.getNativeBleService(UUID)
, which will be nonnull
if target()
is ReadWriteListener.Target.CHARACTERISTIC
or ReadWriteListener.Target.DESCRIPTOR
.public final BleCharacteristic characteristic()
BleNode.getNativeBleCharacteristic(UUID, UUID)
, which will be nonnull
if target()
is ReadWriteListener.Target.CHARACTERISTIC
or ReadWriteListener.Target.DESCRIPTOR
.public final BleDescriptor descriptor()
BleNode.getNativeBleDescriptor_inChar(UUID, UUID)
, which will be nonnull
if target()
is ReadWriteListener.Target.DESCRIPTOR
.public final boolean wasSuccess()
status()
equals ReadWriteListener.Status.SUCCESS
.public final boolean wasCancelled()
ReadWriteListener.Status.wasCancelled()
.public final boolean isRead()
ReadWriteListener.Type.isRead()
.public final boolean isWrite()
ReadWriteListener.Type.isWrite()
.public final byte data_byte()
data()
, or 0x0 if not available.public final java.lang.String data_utf8()
public final java.lang.String data_string()
data()
as a String
. For now simply forwards data_utf8()
.
In the future may try to autodetect encoding first.public final java.lang.String data_string(java.lang.String charset)
data()
as a String
with the given charset, for example "UTF-8"
.public final int data_int(boolean reverse)
data()
as an int.reverse
- - Set to true if you are connecting to a device with ByteOrder.BIG_ENDIAN
byte order, to automatically reverse the bytes before conversion.public final short data_short(boolean reverse)
data()
as a short.reverse
- - Set to true if you are connecting to a device with ByteOrder.BIG_ENDIAN
byte order, to automatically reverse the bytes before conversion.public final long data_long(boolean reverse)
data()
as a long.reverse
- - Set to true if you are connecting to a device with ByteOrder.BIG_ENDIAN
byte order, to automatically reverse the bytes before conversion.public final boolean isNull()
ReadWriteListener.Type.isNull()
.isNull
in interface UsesCustomNull
public final java.lang.String toString()
toString
in class java.lang.Object