27#include <condition_variable>
39#ifndef BT_GATT_CMD_HPP_
40#define BT_GATT_CMD_HPP_
81 std::mutex mtxCommand;
82 std::mutex mtxRspReceived;
83 std::condition_variable cvRspReceived;
100 : source(source_), rsp_data(rsp_data_)
104 const jau::TROOctets& char_value,
const uint64_t timestamp)
override;
108 const bool confirmationSent)
override;
110 std::shared_ptr<ResponseCharListener> rspCharListener;
113 std::string rspCharStr() const noexcept {
114 return nullptr != rspCharRef ? rspCharRef->toString() :
"n/a";
116 std::string srvUUIDStr() const noexcept {
117 return nullptr != service_uuid ? service_uuid->
toString() :
"n/a";
119 std::string rspUUIDStr() const noexcept {
120 return nullptr != rsp_uuid ? rsp_uuid->
toString() :
"n/a";
122 bool isConnected() const noexcept;
124 bool isResolvedEq() const noexcept {
125 return nullptr != cmdCharRef && cmdCharRef->isValidInstance();
145 const
jau::uuid_t& service_uuid_,
146 const
jau::uuid_t& cmd_uuid_,
147 const
jau::uuid_t& rsp_uuid_,
149 : name(
std::move(name_)),
150 service_uuid(&service_uuid_),
151 cmd_uuid(&cmd_uuid_),
152 rsp_uuid(&rsp_uuid_),
158 dataCallback(
nullptr),
160 rspCharListener(
std::make_shared<ResponseCharListener>( *this, rsp_data) ),
161 verbose(
jau::environment::
get().debug)
179 : name(std::move(name_)),
180 service_uuid(
nullptr),
181 cmd_uuid(&cmd_uuid_),
182 rsp_uuid(&rsp_uuid_),
188 dataCallback(
nullptr),
190 rspCharListener( std::make_shared<ResponseCharListener>( *
this, rsp_data ) ),
205 : name(std::move(name_)),
206 service_uuid(&service_uuid_),
207 cmd_uuid(&cmd_uuid_),
214 dataCallback(
nullptr),
216 rspCharListener(
nullptr ),
231 : name(std::move(name_)),
232 service_uuid(
nullptr),
233 cmd_uuid(&cmd_uuid_),
240 dataCallback(
nullptr),
242 rspCharListener(
nullptr ),
259 const std::string&
getName() const noexcept {
return name; }
BTDevice represents one remote Bluetooth device.
BTGattChar event listener for notification and indication events.
Class maps a GATT command and optionally its asynchronous response to a synchronous atomic operation.
void setVerbose(const bool v) noexcept
Set verbosity for UUID resolution.
const std::string & getName() const noexcept
Return name, representing the command.
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.
bool hasResponseSet() const noexcept
Return true if a notification or indication response has been set via constructor,...
jau::function< void(BTGattCharRef charDecl, const jau::TROOctets &char_value, const uint64_t timestamp)> DataCallback
const jau::uuid_t * getServiceUUID() const noexcept
Return command's BTGattService jau::uuid_t, may be nullptr.
HCIStatusCode close() noexcept
Close this command instance, usually called at destruction.
HCIStatusCode send(const bool prefNoAck, const jau::TROOctets &cmd_data, const jau::fraction_i64 &timeout) noexcept
Send the command to the remote BTDevice.
BTGattCmd(BTDevice &dev_, std::string name_, const jau::uuid_t &cmd_uuid_) noexcept
Constructor for commands without response.
HCIStatusCode sendOnly(const bool prefNoAck, const jau::TROOctets &cmd_data) noexcept
Send the command to the remote BTDevice, only.
BTGattCmd(BTDevice &dev_, std::string name_, const jau::uuid_t &service_uuid_, const jau::uuid_t &cmd_uuid_) noexcept
Constructor for commands without response.
const jau::uuid_t * getCommandUUID() const noexcept
Return command's BTGattChar value jau::uuid_t to write command, never nullptr.
const jau::uuid_t * getResponseUUID() const noexcept
Return command's optional BTGattChar value jau::uuid_t for the notification or indication response,...
bool isResolved() noexcept
Query whether all UUIDs of this commands have been resolved.
const jau::TROOctets & getResponse() const noexcept
Returns the read-only response data object for configured commands with response notification or indi...
void setResponseMinSize(jau::nsize_t v) noexcept
void setDataCallback(const DataCallback &dcb) noexcept
std::string toString() const noexcept
Persistent endian aware octet data, i.e.
Transient read only and endian aware octet data, i.e.
static environment & get(const std::string &root_prefix_domain="jau") noexcept
Static singleton initialization of this project's environment with the given global root prefix_domai...
Class template jau::function is a general-purpose static-polymorphic function wrapper.
virtual std::string toString() const noexcept=0
Returns the string representation in BE network order, i.e.
lb_endian_t
Simplified reduced endian type only covering little- and big-endian.
@ little
Identifier for little endian, equivalent to endian::little.
Entry * get(const EUI48 &addr, const std::string &name, AddressNameEntryMatchFunc m) noexcept
Returns a matching BTSecurityRegistry::Entry with the given addr and/or name.
HCIStatusCode
BT Core Spec v5.2: Vol 1, Part F Controller Error Codes: 1.3 List of Error Codes.
std::shared_ptr< BTGattChar > BTGattCharRef
fraction< int64_t > fraction_i64
fraction using int64_t as integral type
uint_fast32_t nsize_t
Natural 'size_t' alternative using uint_fast32_t as its natural sized type.
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.