Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
Classes | Public Types | Public Member Functions | List of all members
direct_bt::BTGattCmd Class Reference

Class maps a GATT command and optionally its asynchronous response to a synchronous atomic operation. More...

#include <BTGattCmd.hpp>

Collaboration diagram for direct_bt::BTGattCmd:

Public Types

typedef jau::function< void(BTGattCharRef charDecl, const jau::TROOctets &char_value, const uint64_t timestamp)> DataCallback
 

Public Member Functions

 BTGattCmd (BTDevice &dev_, std::string name_, const jau::uuid_t &cmd_uuid_) noexcept
 Constructor for commands without response. More...
 
 BTGattCmd (BTDevice &dev_, std::string name_, const jau::uuid_t &cmd_uuid_, const jau::uuid_t &rsp_uuid_, const jau::nsize_t rsp_capacity) noexcept
 Constructor for commands with notification or indication response. More...
 
 BTGattCmd (BTDevice &dev_, std::string name_, const jau::uuid_t &service_uuid_, const jau::uuid_t &cmd_uuid_) noexcept
 Constructor for commands without response. More...
 
 BTGattCmd (BTDevice &dev_, std::string name_, const jau::uuid_t &service_uuid_, const jau::uuid_t &cmd_uuid_, const jau::uuid_t &rsp_uuid_, const jau::nsize_t rsp_capacity) noexcept
 Constructor for commands with notification or indication response. More...
 
 ~BTGattCmd () noexcept
 
HCIStatusCode close () noexcept
 Close this command instance, usually called at destruction. More...
 
const jau::uuid_tgetCommandUUID () const noexcept
 Return command's BTGattChar value jau::uuid_t to write command, never nullptr. More...
 
const std::string & getName () const noexcept
 Return name, representing the command. More...
 
const jau::TROOctetsgetResponse () const noexcept
 Returns the read-only response data object for configured commands with response notification or indication. More...
 
const jau::uuid_tgetResponseUUID () const noexcept
 Return command's optional BTGattChar value jau::uuid_t for the notification or indication response, may be nullptr. More...
 
const jau::uuid_tgetServiceUUID () const noexcept
 Return command's BTGattService jau::uuid_t, may be nullptr. More...
 
bool hasResponseSet () const noexcept
 Return true if a notification or indication response has been set via constructor, otherwise false. More...
 
bool isResolved () noexcept
 Query whether all UUIDs of this commands have been resolved. More...
 
HCIStatusCode send (const bool prefNoAck, const jau::TROOctets &cmd_data, const jau::fraction_i64 &timeout) noexcept
 Send the command to the remote BTDevice. More...
 
HCIStatusCode sendOnly (const bool prefNoAck, const jau::TROOctets &cmd_data) noexcept
 Send the command to the remote BTDevice, only. More...
 
void setDataCallback (const DataCallback &dcb) noexcept
 
void setResponseMinSize (jau::nsize_t v) noexcept
 
void setVerbose (const bool v) noexcept
 Set verbosity for UUID resolution. More...
 
std::string toString () const noexcept
 

Detailed Description

Class maps a GATT command and optionally its asynchronous response to a synchronous atomic operation.

The GATT command is issued by writing the associated GATT characteristic value via BTGattChar::writeValueNoResp() or BTGattChar::writeValue().

Its optional asynchronous characteristic value notification or indication response is awaited and collected after command issuance.

If a response jau::uuid_t is given, notification or indication will be enabled at first send() command and disabled at close() or destruction.

See also
BTGattChar::writeValueNoResp()
BTGattChar::writeValue()
Since
2.4.0
Examples
dbt_scanner10.cpp.

Definition at line 66 of file BTGattCmd.hpp.

Member Typedef Documentation

◆ DataCallback

typedef jau::function<void(BTGattCharRef charDecl, const jau::TROOctets& char_value, const uint64_t timestamp)> direct_bt::BTGattCmd::DataCallback

Definition at line 69 of file BTGattCmd.hpp.

Constructor & Destructor Documentation

◆ BTGattCmd() [1/4]

direct_bt::BTGattCmd::BTGattCmd ( BTDevice dev_,
std::string  name_,
const jau::uuid_t service_uuid_,
const jau::uuid_t cmd_uuid_,
const jau::uuid_t rsp_uuid_,
const jau::nsize_t  rsp_capacity 
)
inlinenoexcept

Constructor for commands with notification or indication response.

Parameters
dev_the remote BTDevice
name_user given name, representing the command
service_uuid_command's BTGattService jau::uuid_t
cmd_uuid_command's BTGattChar value jau::uuid_t to write the command
rsp_uuid_command's BTGattChar value jau::uuid_t for the notification or indication response.
rsp_capacityinitial capacity of response sink, see getResponse()

Definition at line 144 of file BTGattCmd.hpp.

◆ BTGattCmd() [2/4]

direct_bt::BTGattCmd::BTGattCmd ( BTDevice dev_,
std::string  name_,
const jau::uuid_t cmd_uuid_,
const jau::uuid_t rsp_uuid_,
const jau::nsize_t  rsp_capacity 
)
inlinenoexcept

Constructor for commands with notification or indication response.

Since no service UUID is given, the BTGattChar lookup is less efficient.

Parameters
dev_the remote BTDevice
name_user given name, representing the command
cmd_uuid_command's BTGattChar value jau::uuid_t to write the command
rsp_uuid_command's BTGattChar value jau::uuid_t for the notification or indication response.
rsp_capacityinitial capacity of response sink, see getResponse()

Definition at line 175 of file BTGattCmd.hpp.

◆ BTGattCmd() [3/4]

direct_bt::BTGattCmd::BTGattCmd ( BTDevice dev_,
std::string  name_,
const jau::uuid_t service_uuid_,
const jau::uuid_t cmd_uuid_ 
)
inlinenoexcept

Constructor for commands without response.

Parameters
dev_the remote BTDevice
name_user given name, representing the command
service_uuid_command's BTGattService jau::uuid_t
cmd_uuid_command's BTGattChar value jau::uuid_t to write the command

Definition at line 202 of file BTGattCmd.hpp.

◆ BTGattCmd() [4/4]

direct_bt::BTGattCmd::BTGattCmd ( BTDevice dev_,
std::string  name_,
const jau::uuid_t cmd_uuid_ 
)
inlinenoexcept

Constructor for commands without response.

Since no service UUID is given, the BTGattChar lookup is less efficient.

Parameters
dev_the remote BTDevice
name_user given name, representing the command
cmd_uuid_command's BTGattChar value jau::uuid_t to write the command

Definition at line 229 of file BTGattCmd.hpp.

◆ ~BTGattCmd()

direct_bt::BTGattCmd::~BTGattCmd ( )
inlinenoexcept

Definition at line 253 of file BTGattCmd.hpp.

Member Function Documentation

◆ close()

HCIStatusCode BTGattCmd::close ( )
noexcept

Close this command instance, usually called at destruction.

If a response jau::uuid_t has been given, notification or indication will be disabled.

Definition at line 133 of file BTGattCmd.cpp.

Here is the caller graph for this function:

◆ setResponseMinSize()

void direct_bt::BTGattCmd::setResponseMinSize ( jau::nsize_t  v)
inlinenoexcept

Definition at line 255 of file BTGattCmd.hpp.

Here is the caller graph for this function:

◆ setDataCallback()

void direct_bt::BTGattCmd::setDataCallback ( const DataCallback dcb)
inlinenoexcept

Definition at line 256 of file BTGattCmd.hpp.

Here is the caller graph for this function:

◆ getName()

const std::string & direct_bt::BTGattCmd::getName ( ) const
inlinenoexcept

Return name, representing the command.

Definition at line 259 of file BTGattCmd.hpp.

◆ getServiceUUID()

const jau::uuid_t * direct_bt::BTGattCmd::getServiceUUID ( ) const
inlinenoexcept

Return command's BTGattService jau::uuid_t, may be nullptr.

Definition at line 262 of file BTGattCmd.hpp.

◆ getCommandUUID()

const jau::uuid_t * direct_bt::BTGattCmd::getCommandUUID ( ) const
inlinenoexcept

Return command's BTGattChar value jau::uuid_t to write command, never nullptr.

Definition at line 265 of file BTGattCmd.hpp.

◆ hasResponseSet()

bool direct_bt::BTGattCmd::hasResponseSet ( ) const
inlinenoexcept

Return true if a notification or indication response has been set via constructor, otherwise false.

Examples
dbt_scanner10.cpp.

Definition at line 268 of file BTGattCmd.hpp.

Here is the caller graph for this function:

◆ getResponseUUID()

const jau::uuid_t * direct_bt::BTGattCmd::getResponseUUID ( ) const
inlinenoexcept

Return command's optional BTGattChar value jau::uuid_t for the notification or indication response, may be nullptr.

Definition at line 271 of file BTGattCmd.hpp.

◆ setVerbose()

void direct_bt::BTGattCmd::setVerbose ( const bool  v)
inlinenoexcept

Set verbosity for UUID resolution.

Examples
dbt_scanner10.cpp.

Definition at line 274 of file BTGattCmd.hpp.

Here is the caller graph for this function:

◆ getResponse()

const jau::TROOctets & direct_bt::BTGattCmd::getResponse ( ) const
inlinenoexcept

Returns the read-only response data object for configured commands with response notification or indication.

jau::TROOctets::size() matches the size of last received command response or zero.

See also
send()
Examples
dbt_scanner10.cpp.

Definition at line 283 of file BTGattCmd.hpp.

Here is the caller graph for this function:

◆ isResolved()

bool BTGattCmd::isResolved ( )
noexcept

Query whether all UUIDs of this commands have been resolved.

In case no command has been issued via send() yet, the UUIDs will be resolved with this call.

Returns
true if all UUIDs have been resolved, otherwise false
Examples
dbt_scanner10.cpp.

Definition at line 167 of file BTGattCmd.cpp.

Here is the caller graph for this function:

◆ send()

HCIStatusCode BTGattCmd::send ( const bool  prefNoAck,
const jau::TROOctets cmd_data,
const jau::fraction_i64 timeout 
)
noexcept

Send the command to the remote BTDevice.

If a notification or indication result jau::uuid_t has been set via constructor, it will be awaited and can be retrieved via getResponse() after command returns.

Parameters
prefNoAckpass true to prefer command write without acknowledge, otherwise use with-ack if available
cmd_dataraw command octets
timeoutmaximum duration in fractions of seconds to wait for the response to become available, if any.
Returns
See also
getResponse()
Examples
dbt_scanner10.cpp.

Definition at line 176 of file BTGattCmd.cpp.

Here is the caller graph for this function:

◆ sendOnly()

HCIStatusCode BTGattCmd::sendOnly ( const bool  prefNoAck,
const jau::TROOctets cmd_data 
)
noexcept

Send the command to the remote BTDevice, only.

Regardless whether a notification or indication result jau::uuid_t has been set via constructor, this command will not wait for the response.

Parameters
prefNoAckpass true to prefer command write without acknowledge, otherwise use with-ack if available
cmd_dataraw command octets
Returns
See also
getResponse()

Definition at line 179 of file BTGattCmd.cpp.

Here is the caller graph for this function:

◆ toString()

std::string BTGattCmd::toString ( ) const
noexcept
Examples
dbt_scanner10.cpp.

Definition at line 262 of file BTGattCmd.cpp.

Here is the caller graph for this function:

The documentation for this class was generated from the following files: