File tree Expand file tree Collapse file tree 2 files changed +44
-3
lines changed
Expand file tree Collapse file tree 2 files changed +44
-3
lines changed Original file line number Diff line number Diff line change @@ -48,7 +48,8 @@ class BluezBindings extends EventEmitter {
4848 if ( ! uuid || typeof uuid !== 'string' ) {
4949 return uuid ;
5050 }
51- if ( uuid && uuid . length === 32 ) {
51+ uuid = this . _to128bitUuid ( uuid ) ;
52+ if ( uuid . length === 32 ) {
5253 uuid = `${ uuid . substring ( 0 , 8 ) } -${ uuid . substring ( 8 , 12 ) } -${ uuid . substring (
5354 12 ,
5455 16
@@ -59,7 +60,28 @@ class BluezBindings extends EventEmitter {
5960
6061 _stripDashes ( uuid ) {
6162 if ( typeof uuid === 'string' ) {
62- uuid = uuid . split ( '-' ) . join ( '' ) ;
63+ uuid = uuid . split ( '-' ) . join ( '' ) . toLowerCase ( ) ;
64+ }
65+ return this . _to16bitUuid ( uuid ) ;
66+ }
67+
68+ _to128bitUuid ( uuid ) {
69+ // Bluetooth Base UUID(00000000-0000-1000-8000-00805F9B34FB)
70+ // Device Name (w/o dashes) : 2a00 => 00002a0000001000800000805f9b34fb
71+ if ( uuid . length === 4 ) {
72+ uuid = `0000${ uuid } -0000-1000-8000-00805f9b34fb` ;
73+ }
74+ return uuid ;
75+ }
76+
77+ _to16bitUuid ( uuid ) {
78+ // Bluetooth Base UUID(00000000-0000-1000-8000-00805F9B34FB)
79+ // Device Name (w/o dashes) : 00002a0000001000800000805f9b34fb => 2a00
80+ if (
81+ uuid . indexOf ( '0000' ) === 0 &&
82+ uuid . indexOf ( '00001000800000805f9b34fb' ) === 8
83+ ) {
84+ return uuid . substring ( 4 , 8 ) ;
6385 }
6486 return uuid ;
6587 }
Original file line number Diff line number Diff line change 1616 */
1717
1818describe ( 'bindings' , ( ) => {
19+ const bindings = require ( 'noble/lib/bluez/bindings' ) . default ;
1920 test ( 'object is an instance of NobleBindings class' , ( ) => {
20- const bindings = require ( 'noble/lib/bluez/bindings' ) . default ;
2121 expect ( bindings ) . not . toBeNull ( ) ;
2222 expect ( bindings . bluez ) . toBeTruthy ( ) ;
2323 } ) ;
24+ test ( '#_addDashes adds - to 128bit/16bit UUID' , ( ) => {
25+ expect ( bindings . _addDashes ( '00002a0000001000800000805f9b34fb' ) ) . toBe (
26+ '00002a00-0000-1000-8000-00805f9b34fb'
27+ ) ;
28+ expect ( bindings . _addDashes ( '2a00' ) ) . toBe (
29+ '00002a00-0000-1000-8000-00805f9b34fb'
30+ ) ;
31+ } ) ;
32+ test ( '#_stripDashes strips - from 128bit/16bit UUID' , ( ) => {
33+ expect ( bindings . _stripDashes ( '00002a00-0000-1000-8000-00805f9b34fb' ) ) . toBe (
34+ '2a00'
35+ ) ;
36+ expect ( bindings . _stripDashes ( '00000000-0000-1000-8000-00805F9B34FB' ) ) . toBe (
37+ '0000'
38+ ) ;
39+ expect ( bindings . _stripDashes ( 'f000aa44-0451-4000-b000-000000000000' ) ) . toBe (
40+ 'f000aa4404514000b000000000000000'
41+ ) ;
42+ } ) ;
2443} ) ;
You can’t perform that action at this time.
0 commit comments