diff --git a/node-red-contrib-ble-rw.zip b/node-red-contrib-ble-rw.zip new file mode 100644 index 0000000..b923e68 Binary files /dev/null and b/node-red-contrib-ble-rw.zip differ diff --git a/src/GattServer.js b/src/GattServer.js index 47dc160..e940812 100644 --- a/src/GattServer.js +++ b/src/GattServer.js @@ -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