aboutsummaryrefslogtreecommitdiffstats
path: root/src/direct_bt/GATTHandler.cpp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-06-25 00:30:09 +0200
committerSven Gothel <[email protected]>2020-06-25 00:30:09 +0200
commita1a31f0b59b9896a04973846bfad2aa0bc9e8d1f (patch)
tree782d40db1b54693d32d07d841a8cca4a3bb08573 /src/direct_bt/GATTHandler.cpp
parent8693aa160c4c4f7b72c34c99e7550a224a856644 (diff)
GATTHandler/DBTDevice (incl Java): Add ping[GATT](), testing device availability via retrieval of GATT info
Issues a ping to the device, validating whether it is still reachable. This method could be periodically utilized to shorten the underlying OS disconnect period after turning the device off, which lies within 7-13s. In case the device is no more reachable, disconnect will be initiated due to the occurring IO error. +++ Implementation attempts to read the mandatory APPEARANCE CharacteristicValue of the mandatory GENERIC_ACCESS service.
Diffstat (limited to 'src/direct_bt/GATTHandler.cpp')
-rw-r--r--src/direct_bt/GATTHandler.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/direct_bt/GATTHandler.cpp b/src/direct_bt/GATTHandler.cpp
index e744f936..0a5ee71b 100644
--- a/src/direct_bt/GATTHandler.cpp
+++ b/src/direct_bt/GATTHandler.cpp
@@ -899,6 +899,27 @@ std::shared_ptr<GenericAccess> GATTHandler::getGenericAccess(std::vector<GATTSer
return res;
}
+bool GATTHandler::ping() {
+ std::shared_ptr<GenericAccess> res = nullptr;
+ for(size_t i=0; i<services.size() && nullptr == res; i++) {
+ std::vector<GATTCharacteristicRef> & genericAccessCharDeclList = services.at(i)->characteristicList;
+ POctets value(32, 0);
+
+ for(size_t i=0; i<genericAccessCharDeclList.size(); i++) {
+ const GATTCharacteristic & charDecl = *genericAccessCharDeclList.at(i);
+ if( _GENERIC_ACCESS != *charDecl.service->type ) {
+ continue;
+ }
+ if( _APPEARANCE == *charDecl.value_type ) {
+ if( readCharacteristicValue(charDecl, value.resize(0)) ) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+}
+
std::shared_ptr<DeviceInformation> GATTHandler::getDeviceInformation(std::vector<GATTCharacteristicRef> & characteristicDeclList) {
std::shared_ptr<DeviceInformation> res = nullptr;
POctets value(number(Defaults::MAX_ATT_MTU), 0);