Arendi.BleLibrary  6.2.1.1599
Core-Library (.NET Standard 1.0)
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 (CancellationToken token=default(CancellationToken))
 Initiate the establishment of a connection.
This is not allowed if peripheral mode is set to PeripheralMode.Inactive. This call is blocking.
 
Task EstablishAsync (CancellationToken token=default(CancellationToken))
 Execute the establishment of a connection.
This is not allowed if peripheral mode is set to PeripheralMode.Inactive.
 
void Teardown (CancellationToken token=default(CancellationToken))
 Initiate the teardown of a connection.
This is not allowed if peripheral mode is set to PeripheralMode.Inactive. This call is blocking.
 
Task TeardownAsync (CancellationToken token=default(CancellationToken))
 Execute the teardown of a connection.
This is not allowed if peripheral mode is set to PeripheralMode.Inactive.
 
void Update (UpdateSetup updateSetup, CancellationToken token=default(CancellationToken))
 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. This call is blocking.
 
Task UpdateAsync (UpdateSetup updateSetup, CancellationToken token=default(CancellationToken))
 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...
 
void OnAdvertisingReport (IPeripheral p, int newRssi, AdvertiseInfoList infoList, bool connectable)
 Method called when an advertising has been received for this peripheral.
 

Public Attributes

int ReconnectAfterFailedConnectTimeoutDefault => 5000
 
int ReconnectAfterDisconnectTimeoutDefault => 0
 
int RssiIntervalDefault => ConnectionRssiIntervalDefault
 
int ConnectionRssiIntervalDefault => 0
 
- Public Attributes inherited from Arendi.BleLibrary.Extention.ManagedPeripheral
const int RssiNotAvailable = Constants.RssiNotAvailable
 RSSI value that indicates, that no value is known. This is deprecated and the value from the Constants should be used instead. 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 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 UpdateSetup Initialize (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...
 
- Protected Member Functions inherited from Arendi.BleLibrary.Extention.ManagedPeripheral
virtual void HandleAdvertisingReport (IPeripheral p, int newRssi, AdvertiseInfoList infoList, bool connectable)
 Virtual method called when an advertising has been received for this peripheral by a call of OnAdvertisingReport. It may be overwritten to add more advertisement handling. More...
 

Properties

PeripheralState State [get]
 
PeripheralMode Mode [get, set]
 
int ConnectionRssi [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]
 
int ConnectionRssiInterval [get, set]
 
bool EstablishServiceDiscovery [get, set]
 
ParameterSet EstablishParameter [get, set]
 
DataLengthSet EstablishDataLength [get, set]
 
PhySet EstablishPhy [get, set]
 
int EstablishAttMtu [get, set]
 
new bool IsDisposed [get]
 
- Properties inherited from Arendi.BleLibrary.Extention.ManagedPeripheral
IPeripheral Peripheral [get, set]
 
Uuid Uuid [get]
 
string Name [get]
 Get the name of the enhanced peripheral. More...
 
int AdvertisementRssi [get]
 Get the RSSI value of the last received advertisement. More...
 
DateTime AdvertisementTime [get]
 Get the time the last advertisement was received. More...
 
bool IsConnectable [get]
 Is the device is connectable or not. More...
 
DateTime LastSeen [get, set]
 
ILog Log [get]
 
bool IsDisposed [get]
 
- Properties inherited from Arendi.BleLibrary.Extention.IManagedPeripheral
IPeripheral Peripheral [get]
 Get/Set the used standard peripheral object. More...
 
Uuid Uuid [get]
 Get the UUID uniquely identifying an peripheral. More...
 
DateTime LastSeen [get, set]
 Time the peripheral was last seen in an advertisement or connection. More...
 
ILog Log [get]
 Logger instance. 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...
 
int ConnectionRssiIntervalDefault [get]
 Get the default interval for connection 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 ConnectionRssi [get, set]
 Get the connection RSSI for this peripheral. If the peripheral is not connected Constants.RssiNotAvailable is returned. 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...
 
int ConnectionRssiInterval [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 ConnectionRssiIntervalDefault. More...
 
bool EstablishServiceDiscovery [get, set]
 Execute a service discovery in the establish process (Default:true). More...
 
ParameterSet EstablishParameter [get, set]
 Set the connection parameter that should be set in establish process (if supported by the adapter). If set to null (=> default) no connection parameter update is initiated in establish process. More...
 
DataLengthSet EstablishDataLength [get, set]
 Set the data length that should be set in establish process (if supported by the adapter). If set to null (=> default) no data length update is initiated in establish process. More...
 
PhySet EstablishPhy [get, set]
 Set the phy that should be set in establish process (if supported by the adapter). If set to null (=> default) no phy update is initiated in establish process. More...
 
int EstablishAttMtu [get, set]
 Set the ATT MTU value that should be exchanged in establish process (if supported by the adapter). If set to 0 (=> default) or equal or less to 23 no ATT MTU is initiated in establish process. More...
 

Events

EventHandler< PeripheralStateChangedEventArgsStateChanged = delegate { }
 
EventHandler< RssiUpdatedEventArgsConnectionRssiUpdated = 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< RssiUpdatedEventArgsAdvertisementRssiUpdated = delegate { }
 Advertisement RSSI level of the peripheral has changed. More...
 
EventHandler< AdvertisementTimeUpdatedEventArgsAdvertisementTimeUpdated = delegate { }
 Advertisement time 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< RssiUpdatedEventArgsConnectionRssiUpdated
 RSSI level of the peripheral connection has changed. More...
 
EventHandler< IsConnectableUpdatedEventArgsIsConnectableUpdated
 Property if the peripheral may be connected has been updated. 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.

◆ Initialize()

virtual UpdateSetup Arendi.BleLibrary.Extention.EnhancedPeripheral.Initialize ( 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.

◆ InitializeAsync()

virtual 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.