Skip to content

Commit

Permalink
GattServer.getUUIDbyHandle added
Browse files Browse the repository at this point in the history
  • Loading branch information
seizu committed Sep 13, 2024
1 parent ece3d3e commit 062feb3
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/GattServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,38 @@ class GattServer {

throw new Error('Service not available')
}

/**
* Find the service UUID and characteristic UUID based on a characteristic handle
* @param {number} charHandle
* @returns {<Object|null>}
*/
async getUUIDbyHandle(charHandle) {
const handle = charHandle - 1;
const handleStr = 'char' + handle.toString(16).padStart(4, '0');

for (const key in this.dbus._matchRules) {
if (key.includes(handleStr)) {
const match = key.match(/service[0-9a-fA-F]+/);
if (match) {
const service = match[0];
const services = this._services;
for (const skey in services) {
if (services[skey].service === service) {
const characteristics = services[skey]._characteristics;
for (const ckey in characteristics) {
if (characteristics[ckey].characteristic === handleStr) {
return { 'service': skey, 'char': ckey };
}
}
return null;
}
}
}
}
}
return null;
}
}

module.exports = GattServer

0 comments on commit 062feb3

Please sign in to comment.