@@ -743,12 +743,14 @@ function initBluetoothGattCallback() {
743743 * @param newState [number] - Returns the new connection state. Can be one of STATE_DISCONNECTED or STATE_CONNECTED
744744 */
745745 onConnectionStateChange ( gatt : android . bluetooth . BluetoothGatt , status : number , newState : number ) {
746- CLog (
747- CLogTypes . info ,
748- `TNS_BluetoothGattCallback.onConnectionStateChange ---- gatt: ${ gatt } , device:${
749- gatt . getDevice ( ) && gatt . getDevice ( ) . getAddress ( )
750- } status: ${ status } , newState: ${ newState } , subdelegates:${ this . subDelegates . length } `
751- ) ;
746+ if ( Trace . isEnabled ( ) ) {
747+ CLog (
748+ CLogTypes . info ,
749+ `TNS_BluetoothGattCallback.onConnectionStateChange ---- gatt: ${ gatt } , device:${
750+ gatt . getDevice ( ) && gatt . getDevice ( ) . getAddress ( )
751+ } status: ${ status } , newState: ${ newState } , subdelegates:${ this . subDelegates . length } `
752+ ) ;
753+ }
752754 this . subDelegates . forEach ( ( d ) => {
753755 if ( d . onConnectionStateChange ) {
754756 d . onConnectionStateChange ( gatt , status , newState ) ;
@@ -818,7 +820,7 @@ function initBluetoothGattCallback() {
818820 address = device . getAddress ( ) ;
819821 }
820822 if ( Trace . isEnabled ( ) ) {
821- CLog ( CLogTypes . info , `TNS_BluetoothGattCallback.onCharacteristicChanged ---- gatt: ${ gatt } , characteristic: ${ characteristic } , device: ${ address } ` ) ;
823+ CLog ( CLogTypes . info , `TNS_BluetoothGattCallback.onCharacteristicChanged ---- gatt: ${ gatt } , characteristic: ${ characteristic } , device: ${ address } ` , this . subDelegates . length ) ;
822824 }
823825
824826 this . subDelegates . forEach ( ( d ) => {
@@ -1811,10 +1813,12 @@ export class Bluetooth extends BluetoothCommon {
18111813 }
18121814 const cUUID = uuidToString ( characteristic . getUuid ( ) ) ;
18131815 const sUUID = uuidToString ( characteristic . getService ( ) . getUuid ( ) ) ;
1814- CLog (
1815- CLogTypes . info ,
1816- `${ methodName } ---- got result peripheralUUID:${ args . peripheralUUID } serviceUUID:${ args . serviceUUID } characteristicUUID:${ args . characteristicUUID } status:${ status } `
1817- ) ;
1816+ if ( Trace . isEnabled ( ) ) {
1817+ CLog (
1818+ CLogTypes . info ,
1819+ `${ methodName } ---- got result peripheralUUID:${ args . peripheralUUID } serviceUUID:${ args . serviceUUID } characteristicUUID:${ args . characteristicUUID } status:${ status } `
1820+ ) ;
1821+ }
18181822 if ( UUID === pUUID && cUUID === args . characteristicUUID && sUUID === args . serviceUUID ) {
18191823 if ( status === GATT_SUCCESS ) {
18201824 const value = characteristic . getValue ( ) ;
@@ -1840,10 +1844,12 @@ export class Bluetooth extends BluetoothCommon {
18401844 this . addDisconnectListener ( onDisconnect ) ;
18411845 try {
18421846 if ( ! wrapper . gatt . readCharacteristic ( characteristic ) ) {
1843- CLog (
1844- CLogTypes . error ,
1845- `${ methodName } ---- error: readCharacteristic returned false peripheralUUID:${ args . peripheralUUID } serviceUUID:${ args . serviceUUID } characteristicUUID:${ args . characteristicUUID } `
1846- ) ;
1847+ if ( Trace . isEnabled ( ) ) {
1848+ CLog (
1849+ CLogTypes . error ,
1850+ `${ methodName } ---- error: readCharacteristic returned false peripheralUUID:${ args . peripheralUUID } serviceUUID:${ args . serviceUUID } characteristicUUID:${ args . characteristicUUID } `
1851+ ) ;
1852+ }
18471853 onError (
18481854 new BluetoothError ( BluetoothCommon . msg_error_function_call , {
18491855 method : 'readCharacteristic' ,
@@ -2049,7 +2055,14 @@ export class Bluetooth extends BluetoothCommon {
20492055 }
20502056 const cUUID = uuidToString ( characteristic . getUuid ( ) ) ;
20512057 const sUUID = uuidToString ( characteristic . getService ( ) . getUuid ( ) ) ;
2058+
2059+ if ( Trace . isEnabled ( ) ) {
2060+ CLog ( CLogTypes . info , methodName , '---- writeCharacteristic onCharacteristicWrite:' , UUID , cUUID , sUUID , status ) ;
2061+ }
20522062 if ( UUID === pUUID && cUUID === args . characteristicUUID && sUUID === args . serviceUUID ) {
2063+ if ( Trace . isEnabled ( ) ) {
2064+ CLog ( CLogTypes . info , methodName , '---- write got result:' , status === GATT_SUCCESS ) ;
2065+ }
20532066 if ( status === GATT_SUCCESS ) {
20542067 resolve ( ) ;
20552068 clearListeners ( ) ;
@@ -2060,7 +2073,7 @@ export class Bluetooth extends BluetoothCommon {
20602073 } ,
20612074 } ;
20622075 this . bluetoothGattCallback . addSubDelegate ( subD ) ;
2063- this . addDisconnectListener ( reject ) ;
2076+ this . addDisconnectListener ( onDisconnect ) ;
20642077
20652078 try {
20662079 characteristic . setValue ( val ) ;
@@ -2168,10 +2181,12 @@ export class Bluetooth extends BluetoothCommon {
21682181
21692182 const cUUID = uuidToString ( characteristic . getUuid ( ) ) ;
21702183 const sUUID = uuidToString ( characteristic . getService ( ) . getUuid ( ) ) ;
2171- CLog (
2172- CLogTypes . info ,
2173- `${ methodName } ---- onCharacteristicWrite peripheralUUID:${ args . peripheralUUID } serviceUUID:${ args . serviceUUID } characteristicUUID:${ args . characteristicUUID } UUID:${ UUID } pUUID:${ pUUID } cUUID:${ cUUID } sUUID:${ sUUID } status:${ status } `
2174- ) ;
2184+ if ( Trace . isEnabled ( ) ) {
2185+ CLog (
2186+ CLogTypes . info ,
2187+ `${ methodName } ---- onCharacteristicWrite peripheralUUID:${ args . peripheralUUID } serviceUUID:${ args . serviceUUID } characteristicUUID:${ args . characteristicUUID } UUID:${ UUID } pUUID:${ pUUID } cUUID:${ cUUID } sUUID:${ sUUID } status:${ status } `
2188+ ) ;
2189+ }
21752190 if ( UUID === pUUID && cUUID === args . characteristicUUID && sUUID === args . serviceUUID ) {
21762191 if ( status === GATT_SUCCESS ) {
21772192 // sometimes the callback is received too fast and somehow it blocks the promise.
0 commit comments