public static class NotificationListener.NotificationEvent extends Event implements UsesCustomNull
Modifier and Type | Field and Description |
---|---|
static java.util.UUID |
NON_APPLICABLE_UUID
Value used in place of
null . |
Modifier and Type | Method and Description |
---|---|
BleCharacteristic |
characteristic()
|
java.util.UUID |
charUuid()
The
UUID of the characteristic associated with this NotificationListener.NotificationEvent . |
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 received from the peripheral.
|
BleDevice |
device()
The
BleDevice this NotificationListener.NotificationEvent is for. |
static NotificationListener.NotificationEvent |
fromReadWriteEvent(BleDevice device,
ReadWriteListener.ReadWriteEvent event) |
int |
gattStatus()
The native gatt status returned from the stack, if applicable.
|
boolean |
isNull()
Forwards
NotificationListener.Type.isNull() . |
java.lang.String |
macAddress()
Convience to return the mac address of
device() . |
BleService |
service()
Forwards
BleNode.getNativeBleService(UUID) . |
java.util.UUID |
serviceUuid()
The
UUID of the service associated with this NotificationListener.NotificationEvent . |
boolean |
solicited()
This returns
true if this event was the result of an explicit call through SweetBlue, e.g. |
NotificationListener.Status |
status()
Indicates either success or the type of failure.
|
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() |
NotificationListener.Type |
type()
The type of operation, read, write, etc.
|
boolean |
wasSuccess()
Convenience method for checking if
status() equals NotificationListener.Status.SUCCESS . |
public static final java.util.UUID NON_APPLICABLE_UUID
null
.public BleDevice device()
BleDevice
this NotificationListener.NotificationEvent
is for.public java.lang.String macAddress()
device()
.public NotificationListener.Type type()
public java.util.UUID serviceUuid()
UUID
of the service associated with this NotificationListener.NotificationEvent
. This will always be a non-null UUID
.public java.util.UUID charUuid()
UUID
of the characteristic associated with this NotificationListener.NotificationEvent
. This will always be a non-null UUID
.public byte[] data()
null
. For error cases it will be a
zero-length array.public NotificationListener.Status status()
public Interval time_ota()
time_total()
.public Interval time_total()
ReadWriteListener.ReadWriteEvent.time_ota()
. This will always be
longer than time_ota()
, though usually only slightly so.public 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 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 BleService service()
BleNode.getNativeBleService(UUID)
.public BleCharacteristic characteristic()
public boolean wasSuccess()
status()
equals NotificationListener.Status.SUCCESS
.public byte data_byte()
data()
, or 0x0 if not available.public java.lang.String data_utf8()
public 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 java.lang.String data_string(java.lang.String charset)
data()
as a String
with the given charset, for example "UTF-8"
.public 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 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 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 boolean isNull()
NotificationListener.Type.isNull()
.isNull
in interface UsesCustomNull
public java.lang.String toString()
toString
in class java.lang.Object
public static NotificationListener.NotificationEvent fromReadWriteEvent(BleDevice device, ReadWriteListener.ReadWriteEvent event)