Skip to content

Commit 30831ea

Browse files
author
Daisuke Baba
committed
Replace console.log with RED.log.info as console.log isn't redirect to stdout/stderr
1 parent 74f5b2f commit 30831ea

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

src/generic-ble.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ function getAddressOrUUID(peripheral) {
8080
return peripheral.address;
8181
}
8282

83-
function deleteBleDevice(addressOrUUID) {
83+
function deleteBleDevice(addressOrUUID, RED) {
8484
let value = bleDevices.del(addressOrUUID);
8585
if (value && TRACE) {
86-
console.log(`[GenericBLE:TRACE] Delete => ${addressOrUUID}`);
86+
RED.log.info(`[GenericBLE:TRACE] Delete => ${addressOrUUID}`);
8787
}
8888
}
8989

@@ -350,11 +350,11 @@ function characteristicsTask(services, bleDevice) {
350350
});
351351
}
352352

353-
function disconnectPeripheral(peripheral, done) {
353+
function disconnectPeripheral(peripheral, done, RED) {
354354
if (peripheral.state === 'disconnected' || peripheral.state === 'disconnecting') {
355355
delete peripheral._lock;
356356
if (TRACE) {
357-
console.log(`<disconnectPeripheral> <${peripheral.uuid}> Skipped to disconnect`);
357+
RED.log.info(`<disconnectPeripheral> <${peripheral.uuid}> Skipped to disconnect`);
358358
}
359359
if (done) {
360360
return done();
@@ -364,7 +364,7 @@ function disconnectPeripheral(peripheral, done) {
364364
if (peripheral._skipDisconnect) {
365365
delete peripheral._skipDisconnect;
366366
if (TRACE) {
367-
console.log(`<disconnectPeripheral> <${peripheral.uuid}> Skipped to disconnect <LOCKED>`);
367+
RED.log.info(`<disconnectPeripheral> <${peripheral.uuid}> Skipped to disconnect <LOCKED>`);
368368
}
369369
if (done) {
370370
return done();
@@ -375,7 +375,7 @@ function disconnectPeripheral(peripheral, done) {
375375
let timeout;
376376
let onDisconnected = () => {
377377
if (TRACE) {
378-
console.log(`<disconnectPeripheral> <${peripheral.uuid}> DISCONNECTED`);
378+
RED.log.info(`<disconnectPeripheral> <${peripheral.uuid}> DISCONNECTED`);
379379
}
380380
if (timeout) {
381381
deleteTimeout(timeout);
@@ -390,7 +390,7 @@ function disconnectPeripheral(peripheral, done) {
390390
};
391391
timeout = addTimeout(() => {
392392
if (TRACE) {
393-
console.log(`<disconnectPeripheral> <${peripheral.uuid}> DISCONNECT TIMEOUT`);
393+
RED.log.info(`<disconnectPeripheral> <${peripheral.uuid}> DISCONNECT TIMEOUT`);
394394
}
395395
deleteTimeout(timeout);
396396
timeout = null;
@@ -407,18 +407,18 @@ function disconnectPeripheral(peripheral, done) {
407407
delete peripheral._lock;
408408
}
409409

410-
function connectToPeripheral(peripheral) {
410+
function connectToPeripheral(peripheral, RED) {
411411
if (peripheral._lock) {
412412
if (TRACE) {
413-
console.log(`<connectToPeripheral> <${peripheral.uuid}> Gave up to connect`);
413+
RED.log.info(`<connectToPeripheral> <${peripheral.uuid}> Gave up to connect`);
414414
}
415415
peripheral._skipDisconnect = true;
416416
return Promise.reject(`<${peripheral.uuid}> Try again`);
417417
}
418418
let bleDevice = configBleDevices[getAddressOrUUID(peripheral)];
419419
if (!hasPendingOperations(bleDevice)) {
420420
if (TRACE) {
421-
console.log(`<connectToPeripheral> <${peripheral.uuid}> Skip to connect as there's nothing to do`);
421+
RED.log.info(`<connectToPeripheral> <${peripheral.uuid}> Skip to connect as there's nothing to do`);
422422
}
423423
return Promise.resolve();
424424
}
@@ -439,14 +439,14 @@ function connectToPeripheral(peripheral) {
439439
deleteTimeout(timeout);
440440
timeout = null;
441441
if (TRACE) {
442-
console.log(`<connectToPeripheral> <${peripheral.uuid}> discovering all services and characteristics...`);
442+
RED.log.info(`<connectToPeripheral> <${peripheral.uuid}> discovering all services and characteristics...`);
443443
}
444444
if (onDiscover) {
445445
onDiscover(peripheral);
446446
}
447447
if (peripheral.services) {
448448
if (TRACE) {
449-
console.log(`<connectToPeripheral> <${peripheral.uuid}> discovered 00`);
449+
RED.log.info(`<connectToPeripheral> <${peripheral.uuid}> discovered 00`);
450450
}
451451
return resolve([peripheral.services, bleDevice]);
452452
}
@@ -455,7 +455,7 @@ function connectToPeripheral(peripheral) {
455455
deleteTimeout(discoveryTimeout);
456456
if (peripheral.services) {
457457
if (TRACE) {
458-
console.log(`<connectToPeripheral> <${peripheral.uuid}> discovered 00`);
458+
RED.log.info(`<connectToPeripheral> <${peripheral.uuid}> discovered 00`);
459459
}
460460
return resolve([peripheral.services, bleDevice]);
461461
}
@@ -464,11 +464,11 @@ function connectToPeripheral(peripheral) {
464464
return;
465465
}
466466
if (TRACE) {
467-
console.log(`<connectToPeripheral> <${peripheral.uuid}> Setting up discoveryTimeout`);
467+
RED.log.info(`<connectToPeripheral> <${peripheral.uuid}> Setting up discoveryTimeout`);
468468
}
469469
let discoveryTimeout = addTimeout(() => {
470470
if (TRACE) {
471-
console.log(`<connectToPeripheral> <${peripheral.uuid}> discoveryTimeout fired`);
471+
RED.log.info(`<connectToPeripheral> <${peripheral.uuid}> discoveryTimeout fired`);
472472
}
473473
if (bleDevice) {
474474
bleDevice.emit('timeout');
@@ -485,18 +485,18 @@ function connectToPeripheral(peripheral) {
485485
(err, services) => {
486486
peripheral._discovering = false;
487487
if (TRACE) {
488-
console.log(`<connectToPeripheral> <${peripheral.uuid}> discoverAllServicesAndCharacteristics OK`);
488+
RED.log.info(`<connectToPeripheral> <${peripheral.uuid}> discoverAllServicesAndCharacteristics OK`);
489489
}
490490
deleteTimeout(discoveryTimeout);
491491
discoveryTimeout = null;
492492
if (err) {
493493
if (TRACE) {
494-
console.log(`<connectToPeripheral> <${peripheral.uuid}> err`, err);
494+
RED.log.info(`<connectToPeripheral> <${peripheral.uuid}> err`, err);
495495
}
496496
return reject(`<${peripheral.uuid}> ${err}\n=>${err.stack}`);
497497
}
498498
if (TRACE) {
499-
console.log(`<connectToPeripheral> <${peripheral.uuid}> discovered 01`);
499+
RED.log.info(`<connectToPeripheral> <${peripheral.uuid}> discovered 01`);
500500
}
501501
return resolve([services, bleDevice]);
502502
});
@@ -511,11 +511,11 @@ function connectToPeripheral(peripheral) {
511511
onConnected = null;
512512
reject(`<${peripheral.uuid}> Connection Timeout`);
513513
if (TRACE) {
514-
console.log(`<connectToPeripheral> <${peripheral.uuid}> Connection Timeout`);
514+
RED.log.info(`<connectToPeripheral> <${peripheral.uuid}> Connection Timeout`);
515515
}
516516
}, BLE_CONNECTION_TIMEOUT_MS);
517517
if (TRACE) {
518-
console.log(`<connectToPeripheral> <${peripheral.uuid}> peripheral.state=>${peripheral.state}`);
518+
RED.log.info(`<connectToPeripheral> <${peripheral.uuid}> peripheral.state=>${peripheral.state}`);
519519
}
520520
if (peripheral.state === 'connected') {
521521
return onConnected();
@@ -560,10 +560,10 @@ function peripheralTask(uuid, task, done, RED) {
560560
done(err);
561561
}
562562
next(err);
563-
});
563+
}, RED);
564564
}
565565

566-
connectToPeripheral(peripheral).then((result) => {
566+
connectToPeripheral(peripheral, RED).then((result) => {
567567
if (!result) {
568568
return new Promise((resolve) => {
569569
setTimeout(() => {
@@ -627,7 +627,7 @@ function onDiscoverFunc(RED) {
627627
schedulePeripheralTask(peripheral.uuid, characteristicsTask, null, RED);
628628
}
629629
} else {
630-
deleteBleDevice(addressOrUUID);
630+
deleteBleDevice(addressOrUUID, RED);
631631
}
632632
};
633633
}

0 commit comments

Comments
 (0)