Skip to content

Commit 062feb3

Browse files
committed
GattServer.getUUIDbyHandle added
1 parent ece3d3e commit 062feb3

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

src/GattServer.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,38 @@ class GattServer {
5454

5555
throw new Error('Service not available')
5656
}
57+
58+
/**
59+
* Find the service UUID and characteristic UUID based on a characteristic handle
60+
* @param {number} charHandle
61+
* @returns {<Object|null>}
62+
*/
63+
async getUUIDbyHandle(charHandle) {
64+
const handle = charHandle - 1;
65+
const handleStr = 'char' + handle.toString(16).padStart(4, '0');
66+
67+
for (const key in this.dbus._matchRules) {
68+
if (key.includes(handleStr)) {
69+
const match = key.match(/service[0-9a-fA-F]+/);
70+
if (match) {
71+
const service = match[0];
72+
const services = this._services;
73+
for (const skey in services) {
74+
if (services[skey].service === service) {
75+
const characteristics = services[skey]._characteristics;
76+
for (const ckey in characteristics) {
77+
if (characteristics[ckey].characteristic === handleStr) {
78+
return { 'service': skey, 'char': ckey };
79+
}
80+
}
81+
return null;
82+
}
83+
}
84+
}
85+
}
86+
}
87+
return null;
88+
}
5789
}
5890

5991
module.exports = GattServer

0 commit comments

Comments
 (0)