Arendi.BleLibrary  4.5.1.999
Core-Library (PCL)
Arendi.BleLibrary.Extention.EnhancedPeripheral Class Reference

Abstract class representing an enhanced peripheral. More...

Inheritance diagram for Arendi.BleLibrary.Extention.EnhancedPeripheral:
Arendi.BleLibrary.Extention.ManagedPeripheral Arendi.BleLibrary.Extention.IEnhancedPeripheral Arendi.BleLibrary.Extention.IManagedPeripheral Arendi.BleLibrary.Extention.IManagedPeripheral

Public Member Functions

void Establish ()
 Initiate the establishment of a connection.
This is not allowed if peripheral mode is set to PeripheralMode.Inactive.
 
async Task EstablishAsync (int timeout=Constants.EnhancedPeripheralEstablishTimeout)
 Execute the establishment of a connection.
This is not allowed if peripheral mode is set to PeripheralMode.Inactive.
 
void Teardown ()
 Initiate the teardown of a connection.
This is not allowed if peripheral mode is set to PeripheralMode.Inactive.
 
async Task TeardownAsync (int timeout=Constants.EnhancedPeripheralTeardownTimeout)
 Execute the teardown of a connection.
This is not allowed if peripheral mode is set to PeripheralMode.Inactive.
 
void Update (UpdateSetup updateSetup)
 Start an update process
When the enhanced peripheral is in a stable state as PeripheralState.Idle or PeripheralState.Ready the update will be initiated immediately. In transition states the update will be initiated after completion of the state.
 
async Task UpdateAsync (UpdateSetup updateSetup, int timeout=Constants.EnhancedPeripheralUpdateTimeout)
 Execute an update process asynchronously.
When the enhanced peripheral is in a stable state as PeripheralState.Idle or PeripheralState.Ready the update will be initiated immediately. In transition states the update will be initiated after completion of the state.
 
override void Dispose ()
 Dispose the peripheral. A disposed enhanced peripheral is disconnected. More...
 
override string ToString ()
 Returns a string that represents the current object. More...
 
- Public Member Functions inherited from Arendi.BleLibrary.Extention.ManagedPeripheral
 ManagedPeripheral (Uuid uuid)
 Create a virtual managed peripheral with a specific UUID if the real peripheral is not known. A connection to this peripheral can not be established until the peripheral is found by the PeripheralManager<TPeripheral> More...
 
 ManagedPeripheral (IPeripheral peripheral)
 Create a managed peripheral with a peripheral object More...
 

Public Attributes

int ReconnectAfterFailedConnectTimeoutDefault => 5000
 
int ReconnectAfterDisconnectTimeoutDefault => 0
 
int RssiIntervalDefault => 1000
 
- Public Attributes inherited from Arendi.BleLibrary.Extention.ManagedPeripheral
const int RssiNotAvailable = int.MinValue
 RSSI value that indicates, that no value is known. More...
 

Protected Member Functions

 EnhancedPeripheral (Uuid uuid)
 Create enhanced peripheral based on an UUID and an optional name. The resulting object represents a virtual peripheral. More...
 
 EnhancedPeripheral (IPeripheral peripheral)
 Create enhanced peripheral based on an peripheral. More...
 
void CheckReady ()
 Check if state of the peripheral is ready. If not in Ready state an

Exceptions
PeripheralNotReadyException

is thrown. More...

 
virtual async Task< UpdateSetupInitializeAsync (CancellationToken cancellationToken=default(CancellationToken))
 Empty initialize method that can be overwritten in the derived class. This method is called in Initialize state after detection services of the peripheral. The method may be used to check the detected services and read/write some initial values. More...
 
virtual void Activate ()
 This method is called after the standard peripheral object for this peripheral is set. If a constructor with the standard peripheral object is called, that method will be called in the constructor. On virtual devices (no standard peripheral object on object creation) the method may be called later, when the virtual device is converted to a real peripheral. More...
 

Properties

PeripheralState State [get]
 
PeripheralMode Mode [get, set]
 
int ConnectTimeout [get, set]
 
int DiscoverServicesTimeout [get, set]
 
int DisconnectTimeout [get, set]
 
int ReconnectAfterDisconnectTimeout [get, set]
 
int ReconnectAfterFailedConnectTimeout [get, set]
 
int RssiInterval [get, set]
 
new bool IsDisposed [get]
 
- Properties inherited from Arendi.BleLibrary.Extention.ManagedPeripheral
IPeripheral Peripheral [get, set]
 
Uuid Uuid [get]
 
string Name [get, set]
 
int Rssi [get, set]
 
bool IsConnectable [get, set]
 
DateTime LastSeen [get, set]
 
bool IsDisposed [get]
 
- Properties inherited from Arendi.BleLibrary.Extention.IManagedPeripheral
IPeripheral Peripheral [get, set]
 Get/Set the used standard peripheral object. More...
 
Uuid Uuid [get]
 Get the UUID uniquely identifying an peripheral. More...
 
string Name [get, set]
 Get the name of the enhanced peripheral. More...
 
int Rssi [get, set]
 Get the last set RSSI value. The returned value was update when the peripheral was last seen (see Rssi). More...
 
bool IsConnectable [get, set]
 Is the device is connectable or not. More...
 
DateTime LastSeen [get, set]
 Time the peripheral was last seen. More...
 
bool IsDisposed [get]
 Check if the peripheral object is already disposed. More...
 
- Properties inherited from Arendi.BleLibrary.Extention.IEnhancedPeripheral
int ReconnectAfterFailedConnectTimeoutDefault [get]
 Default timeout after a failed connect [ms]. More...
 
int ReconnectAfterDisconnectTimeoutDefault [get]
 Default timeout after a disconnect [ms]. More...
 
int RssiIntervalDefault [get]
 Get the default interval for RSSI measurements [ms]. More...
 
PeripheralState State [get]
 Get the state of the peripheral. More...
 
PeripheralMode Mode [get, set]
 Get/Set the mode the peripheral is used. More...
 
int ConnectTimeout [get, set]
 Get/Set the connect timeout [ms]. By default the value is set to Constants.ConnectTimeout. It is allowed to set this value to Timeout.Infinite to keep trying to connect to a device. More...
 
int DiscoverServicesTimeout [get, set]
 Get/Set the discover services timeout [ms]. By default the value is set to Constants.DiscoverServicesTimeout. More...
 
int DisconnectTimeout [get, set]
 Get/Set the disconnect timeout [ms]. By default the value is set to Constants.DisconnectTimeout. More...
 
int ReconnectAfterDisconnectTimeout [get, set]
 Get/Set the reconnect timeout [ms] after a disconnect. This timeout is used after a peripheral has been disconnected. This value may be set to 0 to immediately retry to establish a connection. By default the value is set to ReconnectAfterDisconnectTimeoutDefault. More...
 
int ReconnectAfterFailedConnectTimeout [get, set]
 Get/Set the reconnect timeout [ms] after a failed connect. This timeout is used after a peripheral couldn't be connected to try next time. It is not recommended, to set this duration to a value of 0. By default the value is set to ReconnectAfterFailedConnectTimeoutDefault. More...
 
int RssiInterval [get, set]
 Get/Set the interval the RSSI is measured when the peripheral is connected [ms]. A value of 0 means, that no RSSI is measured. By default the value is set to RssiIntervalDefault. More...
 

Events

EventHandler< PeripheralStateChangedEventArgsStateChanged = delegate { }
 
EventHandler< EstablishStartedEventArgsEstablishStarted = delegate { }
 
EventHandler< EstablishSucceededEventArgsEstablishSucceeded = delegate { }
 
EventHandler< EstablishFailedEventArgsEstablishFailed = delegate { }
 
EventHandler< TeardownStartedEventArgsTeardownStarted = delegate { }
 
EventHandler< TeardownSucceededEventArgsTeardownSucceeded = delegate { }
 
EventHandler< TeardownFailedEventArgsTeardownFailed = delegate { }
 
EventHandler< UpdateStartedEventArgsUpdateStarted = delegate { }
 
EventHandler< UpdateSucceededEventArgsUpdateSucceeded = delegate { }
 
EventHandler< UpdateFailedEventArgsUpdateFailed = delegate { }
 
- Events inherited from Arendi.BleLibrary.Extention.ManagedPeripheral
EventHandler PeripheralUpdated = delegate { }
 Standard peripheral object of the peripheral has been set. More...
 
EventHandler< NameUpdatedEventArgsNameUpdated = delegate { }
 Name of the peripheral has changed. More...
 
EventHandler< RssiUpdatedEventArgsRssiUpdated = delegate { }
 RSSI level of the peripheral has changed. More...
 
EventHandler< IsConnectableUpdatedEventArgsIsConnectableUpdated = delegate { }
 Property if the peripheral may be connected has been updated. More...
 
- Events inherited from Arendi.BleLibrary.Extention.IEnhancedPeripheral
EventHandler< PeripheralStateChangedEventArgsStateChanged
 State of the peripheral changed. More...
 
EventHandler PeripheralUpdated
 Standard peripheral object of the peripheral has been set. More...
 
EventHandler< NameUpdatedEventArgsNameUpdated
 Name of the peripheral has changed. More...
 
EventHandler< RssiUpdatedEventArgsRssiUpdated
 RSSI level of the peripheral has changed. More...
 
EventHandler< IsConnectableUpdatedEventArgsIsConnectableUpdated
 Property if the peripheral may be connected has been updated. More...
 
EventHandler< EstablishStartedEventArgsEstablishStarted
 An establish operation has been started.
The establish operation may be initiated by enhanced peripheral mode PeripheralMode.Active or by the methods Establish and EstablishAsync. More...
 
EventHandler< EstablishSucceededEventArgsEstablishSucceeded
 An establish operation has succeeded.
The establish operation may be initiated by enhanced peripheral mode PeripheralMode.Active or by the methods Establish and EstablishAsync. More...
 
EventHandler< EstablishFailedEventArgsEstablishFailed
 An establish operation has failed.
The establish operation may be initiated by enhanced peripheral mode PeripheralMode.Active or by the methods Establish and EstablishAsync. More...
 
EventHandler< TeardownStartedEventArgsTeardownStarted
 A teardown operation has been started.
The teardown operation may have been initiated by enhanced peripheral mode PeripheralMode.Active or by the methods Teardown and TeardownAsync. More...
 
EventHandler< TeardownSucceededEventArgsTeardownSucceeded
 A teardown operation has succeeded.
The teardown operation may be initiated by enhanced peripheral mode PeripheralMode.Active or by the methods Teardown and TeardownAsync. More...
 
EventHandler< TeardownFailedEventArgsTeardownFailed
 A teardown operation has failed.
The tear down operation may be initiated by enhanced peripheral mode PeripheralMode.Active or by the methods Teardown and TeardownAsync. More...
 
EventHandler< UpdateStartedEventArgsUpdateStarted
 An update operation has been started.
The update operation may be initiated by the methods Update and UpdateAsync. Additionally the establish operation may include an update operation. More...
 
EventHandler< UpdateSucceededEventArgsUpdateSucceeded
 An update operation has succeeded.
The update operation may be initiated by the methods Update and UpdateAsync. More...
 
EventHandler< UpdateFailedEventArgsUpdateFailed
 An update operation has succeeded.
The update operation may be initiated by the methods Update and UpdateAsync. More...
 

Additional Inherited Members

- Protected Attributes inherited from Arendi.BleLibrary.Extention.ManagedPeripheral
const string PeripheralDisposedExceptionText = "The peripheral was already disposed by the peripheral manager. \nOverride the method \"bool CheckRemove()\" to prevent that a peripheral in use is removed by the peripheral manager"
 This text is used as object disposed exception message More...
 

Detailed Description

Abstract class representing an enhanced peripheral.

The enhanced peripheral class adds the ability to automatically connect disconnect a peripheral. The object will autonomously act according to the mode set for the peripheral.

Constructor & Destructor Documentation

§ EnhancedPeripheral() [1/2]

Arendi.BleLibrary.Extention.EnhancedPeripheral.EnhancedPeripheral ( Uuid  uuid)
protected

Create enhanced peripheral based on an UUID and an optional name. The resulting object represents a virtual peripheral.

Parameters
uuidUUID identifying the peripheral.

§ EnhancedPeripheral() [2/2]

Arendi.BleLibrary.Extention.EnhancedPeripheral.EnhancedPeripheral ( IPeripheral  peripheral)
protected

Create enhanced peripheral based on an peripheral.

Parameters
peripheralStandard peripheral object the enhanced peripheral should use.

Member Function Documentation

§ Activate()

virtual void Arendi.BleLibrary.Extention.EnhancedPeripheral.Activate ( )
protectedvirtual

This method is called after the standard peripheral object for this peripheral is set. If a constructor with the standard peripheral object is called, that method will be called in the constructor. On virtual devices (no standard peripheral object on object creation) the method may be called later, when the virtual device is converted to a real peripheral.

§ CheckReady()

void Arendi.BleLibrary.Extention.EnhancedPeripheral.CheckReady ( )
protected

Check if state of the peripheral is ready. If not in Ready state an

Exceptions
PeripheralNotReadyException

is thrown.

§ Dispose()

override void Arendi.BleLibrary.Extention.EnhancedPeripheral.Dispose ( )
virtual

Dispose the peripheral. A disposed enhanced peripheral is disconnected.

Reimplemented from Arendi.BleLibrary.Extention.ManagedPeripheral.

§ InitializeAsync()

virtual async Task<UpdateSetup> Arendi.BleLibrary.Extention.EnhancedPeripheral.InitializeAsync ( CancellationToken  cancellationToken = default(CancellationToken))
protectedvirtual

Empty initialize method that can be overwritten in the derived class. This method is called in Initialize state after detection services of the peripheral. The method may be used to check the detected services and read/write some initial values.

If an exception is thrown in this method the peripheral will be disconnected.

Parameters
cancellationTokenToken to cancel an ongoing async operation.
Returns
May return an UpdateSetup instance to force an update as part of the establish operation. The state of the peripheral will change into PeripheralState.Update after the return. If the update succeeds the system will continue with PeripheralState.EstablishLink and try again to establish. If it fails it will terminate the establish operation with a failure and force a teardown operation. If
null
is returned no update is required and the establish operation will be terminated after the return.

§ ToString()

override string Arendi.BleLibrary.Extention.EnhancedPeripheral.ToString ( )

Returns a string that represents the current object.

Returns
A string that represents the current object.