File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ( / s e r v i c e [ 0 - 9 a - f A - 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
5991module . exports = GattServer
You can’t perform that action at this time.
0 commit comments