public abstract class BleTransaction extends java.lang.Object implements P_ITransaction
BleDevice
. Transactions provide a convenient way
to encapsulate a series of reads and writes for things like authentication handshakes, firmware updates, etc. You optionally
provide subclass instances to the various overloads of BleDevice.connect()
. Normally in your start()
method you then do some reads/writes and call succeed()
or fail()
depending on the ReadWriteListener.Status
returned.
Modifier and Type | Class and Description |
---|---|
static class |
BleTransaction.Atomicity |
static class |
BleTransaction.Auth
Tagging subclass to force type-discrepancy for various
BleDevice.connect() overloads. |
static class |
BleTransaction.EndReason
Values are passed to
onEnd(EndReason) . |
static class |
BleTransaction.Init
Tagging subclass to force type-discrepancy for various
BleDevice.connect() overloads. |
static class |
BleTransaction.Ota
Tagging subclass to force type-correctness for
BleDevice.performOta(BleTransaction.Ota) . |
P_ITransaction.Type
Constructor and Description |
---|
BleTransaction() |
public P_ITransaction.Type getTransactionType()
getTransactionType
in interface P_ITransaction
protected abstract void start()
protected void update(double timeStep)
protected void onEnd(BleTransaction.EndReason reason)
fail()
or succeed()
, or from the library implicitly ending
the transaction, for example if getDevice()
becomes BleDeviceState.BLE_DISCONNECTED
.
Override this method to wrap up any loose ends or notify UI or what have you.protected BleTransaction.Atomicity getAtomicity()
Boolean.FALSE
. Optionally override if you want your transaction's reads/writes to execute "atomically".
This means that if you're connected to multiple devices only the reads/writes of this transaction's device
will be executed until this transaction is finished.public BleDevice getDevice()
public boolean isRunning()
public void cancel()
public boolean fail()
GenericListener_Void.onEvent(Event)
when ReadWriteListener.Status
is something other than ReadWriteListener.Status.SUCCESS
. If you do so,
DeviceReconnectFilter.ConnectFailEvent.txnFailReason()
will be set.false
if the transaction wasn't running to begin with.public boolean succeed()
Boolean.FALSE
if the transaction wasn't running to begin with.public double getTime()
update(double)
for example to fail()
or succeed()
a transaction that has taken longer than a certain
amount of time.update(double)
public final ReadWriteListener.ReadWriteEvent read(BleRead read)
BleDevice.read(BleRead)
public final java.lang.Void readMany(BleRead[] bleReads)
BleDevice.readMany(BleRead[])
public final java.lang.Void readMany(java.lang.Iterable<BleRead> bleReads)
BleDevice.readMany(Iterable)
public final ReadWriteListener.ReadWriteEvent readBatteryLevel(ReadWriteListener listener)
BleDevice.readBatteryLevel(ReadWriteListener)
public final java.lang.Void enableNotifies(BleNotify[] notifies)
BleDevice.enableNotifies(BleNotify[])
public final java.lang.Void enableNotifies(java.lang.Iterable<BleNotify> notifies)
BleDevice.enableNotifies(Iterable)
public final ReadWriteListener.ReadWriteEvent enableNotify(BleNotify notify)
BleDevice.enableNotify(BleNotify)
public final ReadWriteListener.ReadWriteEvent disableNotify(BleNotify notify)
BleDevice.disableNotify(BleNotify)
public final java.lang.Void disableNotifies(BleNotify[] notifies)
BleDevice.disableNotifies(BleNotify[])
public final java.lang.Void disableNotifies(java.lang.Iterable<BleNotify> notifies)
BleDevice.disableNotifies(Iterable)
public final ReadWriteListener.ReadWriteEvent write(BleWrite write)
BleDevice.write(BleWrite)
public final ReadWriteListener.ReadWriteEvent write(BleWrite bleWrite, ReadWriteListener listener)
BleDevice.write(BleWrite, ReadWriteListener)
public final ReadWriteListener.ReadWriteEvent write(BleDescriptorWrite write)
BleDevice.write(BleDescriptorWrite)
public final ReadWriteListener.ReadWriteEvent write(BleDescriptorWrite write, ReadWriteListener listener)
BleDevice.write(BleWrite, ReadWriteListener)
public final ReadWriteListener.ReadWriteEvent read(BleDescriptorRead read)
BleDevice.read(BleDescriptorRead)
public final ReadWriteListener.ReadWriteEvent readRssi()
BleDevice.readRssi()
public final ReadWriteListener.ReadWriteEvent readRssi(ReadWriteListener listener)
BleDevice.readRssi(ReadWriteListener)
public final ReadWriteListener.ReadWriteEvent setConnectionPriority(BleConnectionPriority connectionPriority)
public final ReadWriteListener.ReadWriteEvent setConnectionPriority(BleConnectionPriority connectionPriority, ReadWriteListener listener)
public final ReadWriteListener.ReadWriteEvent negotiateMtuToDefault()
BleDevice.negotiateMtuToDefault()
public final ReadWriteListener.ReadWriteEvent negotiateMtuToDefault(ReadWriteListener listener)
public final ReadWriteListener.ReadWriteEvent negotiateMtu(int mtu)
BleDevice.negotiateMtu(int)
public final ReadWriteListener.ReadWriteEvent negotiateMtu(int mtu, ReadWriteListener listener)
BleDevice.negotiateMtu(int, ReadWriteListener)
public final ReadWriteListener.ReadWriteEvent setPhyOptions(Phy phyOptions)
BleDevice.setPhyOptions(Phy)
public final ReadWriteListener.ReadWriteEvent setPhyOptions(Phy phyOptions, ReadWriteListener listener)
BleDevice.setPhyOptions(Phy, ReadWriteListener)
public final ReadWriteListener.ReadWriteEvent readPhyOptions()
BleDevice.readPhyOptions()
public final ReadWriteListener.ReadWriteEvent readPhyOptions(ReadWriteListener listener)
BleDevice.readPhyOptions(ReadWriteListener)