Tidy up all console.log util.log from core nodes.

Try to make log,warn,error more consistent behaviour.

Especially make sure any existing catches produce errors
This commit is contained in:
dceejay
2015-02-25 19:10:44 +00:00
parent b6245bdef7
commit 71ff828947
13 changed files with 54 additions and 65 deletions

View File

@@ -16,7 +16,6 @@
module.exports = function(RED) {
"use strict";
var util = require("util");
var ArduinoFirmata = require('arduino-firmata');
var fs = require('fs');
var plat = require('os').platform();
@@ -33,14 +32,14 @@ module.exports = function(RED) {
var node = this;
node.board = new ArduinoFirmata();
if (portlist.indexOf(node.device) === -1) {
node.warn("Device "+node.device+" not found");
node.warn("device "+node.device+" not found");
}
else {
node.board.connect(node.device);
}
node.board.on('boardReady', function(){
node.log("version "+node.board.boardVersion);
if (RED.settings.verbose) { node.log("version "+node.board.boardVersion); }
});
node.on('close', function(done) {
@@ -48,7 +47,7 @@ module.exports = function(RED) {
try {
node.board.close(function() {
done();
node.log("port closed");
if (RED.settings.verbose) { node.log("port closed"); }
});
} catch(e) { done(); }
} else { done(); }
@@ -95,7 +94,7 @@ module.exports = function(RED) {
});
}
else {
util.log("[Firmata-arduino] port not configured");
this.warn("port not configured");
}
}
RED.nodes.registerType("arduino in",DuinoNodeIn);
@@ -145,7 +144,7 @@ module.exports = function(RED) {
});
}
else {
util.log("[Firmata-arduino] port not configured");
this.warn("port not configured");
}
}
RED.nodes.registerType("arduino out",DuinoNodeOut);

View File

@@ -16,7 +16,6 @@
module.exports = function(RED) {
"use strict";
var util = require("util");
var exec = require('child_process').exec;
var spawn = require('child_process').spawn;
var fs = require('fs');
@@ -24,17 +23,17 @@ module.exports = function(RED) {
var gpioCommand = __dirname+'/nrgpio';
if (!fs.existsSync("/dev/ttyAMA0")) { // unlikely if not on a Pi
//util.log("Info : Ignoring Raspberry Pi specific node.");
//RED.log.info("Ignoring Raspberry Pi specific node.");
throw "Info : Ignoring Raspberry Pi specific node.";
}
if (!fs.existsSync("/usr/share/doc/python-rpi.gpio")) {
util.log("[rpi-gpio] Info : Can't find Pi RPi.GPIO python library.");
RED.log.warn("Can't find Pi RPi.GPIO python library.");
throw "Warning : Can't find Pi RPi.GPIO python library.";
}
if ( !(1 & parseInt ((fs.statSync(gpioCommand).mode & parseInt ("777", 8)).toString (8)[0]) )) {
util.log("[rpi-gpio] Error : "+gpioCommand+" needs to be executable.");
RED.log.error(gpioCommand+" needs to be executable.");
throw "Error : nrgpio must to be executable.";
}
@@ -100,7 +99,7 @@ module.exports = function(RED) {
node.child.on('error', function (err) {
if (err.errno === "ENOENT") { node.error('nrgpio command not found'); }
else if (err.errno === "EACCES") { node.error('nrgpio command not executable'); }
else { node.log('error: ' + err); }
else { node.error('error: ' + err.errno); }
});
}
@@ -113,7 +112,7 @@ module.exports = function(RED) {
delete pinsInUse[node.pin];
if (node.child != null) {
node.done = done;
node.child.stdin.write(" close "+node.pin);
node.child.stdin.write("close "+node.pin);
node.child.kill('SIGKILL');
}
else { done(); }
@@ -191,7 +190,7 @@ module.exports = function(RED) {
node.child.on('error', function (err) {
if (err.errno === "ENOENT") { node.error('nrgpio command not found'); }
else if (err.errno === "EACCES") { node.error('nrgpio command not executable'); }
else { node.log('error: ' + err); }
else { node.error('error: ' + err.errno); }
});
}
@@ -204,7 +203,7 @@ module.exports = function(RED) {
delete pinsInUse[node.pin];
if (node.child != null) {
node.done = done;
node.child.stdin.write(" close "+node.pin);
node.child.stdin.write("close "+node.pin);
node.child.kill('SIGKILL');
}
else { done(); }
@@ -215,14 +214,14 @@ module.exports = function(RED) {
var pitype = { type:"" };
exec(gpioCommand+" rev 0", function(err,stdout,stderr) {
if (err) {
console.log('[rpi-gpio] Version command failed for some reason.');
RED.log.info('Version command failed for some reason.');
}
else {
if (stdout.trim() == "0") { pitype = { type:"Compute" }; }
else if (stdout.trim() == "1") { pitype = { type:"A/B v1" }; }
else if (stdout.trim() == "2") { pitype = { type:"A/B v2" }; }
else if (stdout.trim() == "3") { pitype = { type:"Model B+" }; }
else { console.log("SAW Pi TYPE",stdout.trim()); }
else { RED.log.info("Saw Pi Type",stdout.trim()); }
}
});
RED.nodes.registerType("rpi-gpio out",GPIOOutNode);
@@ -259,7 +258,7 @@ module.exports = function(RED) {
node.child.on('error', function (err) {
if (err.errno === "ENOENT") { node.error('nrgpio command not found'); }
else if (err.errno === "EACCES") { node.error('nrgpio ommand not executable'); }
else { node.log('error: ' + err); }
else { node.error('error: ' + err.errno); }
});
node.on("close", function(done) {

View File

@@ -38,11 +38,10 @@ if len(sys.argv) > 1:
while True:
try:
data = raw_input()
if data == "close":
GPIO.cleanup(pin)
if 'close' in data:
sys.exit(0)
p.ChangeDutyCycle(float(data))
except EOFError: # hopefully always caused by us sigint'ing the program
except (EOFError, SystemExit): # hopefully always caused by us sigint'ing the program
GPIO.cleanup(pin)
sys.exit(0)
except Exception as ex:
@@ -57,15 +56,14 @@ if len(sys.argv) > 1:
while True:
try:
data = raw_input()
if data == "close":
GPIO.cleanup(pin)
if 'close' in data:
sys.exit(0)
elif float(data) == 0:
p.stop()
else:
p.start(50)
p.ChangeFrequency(float(data))
except EOFError: # hopefully always caused by us sigint'ing the program
except (EOFError, SystemExit): # hopefully always caused by us sigint'ing the program
GPIO.cleanup(pin)
sys.exit(0)
except Exception as ex:
@@ -80,11 +78,10 @@ if len(sys.argv) > 1:
while True:
try:
data = raw_input()
if data == "close":
GPIO.cleanup(pin)
if 'close' in data:
sys.exit(0)
data = int(data)
except EOFError: # hopefully always caused by us sigint'ing the program
except (EOFError, SystemExit): # hopefully always caused by us sigint'ing the program
GPIO.cleanup(pin)
sys.exit(0)
except:
@@ -113,10 +110,9 @@ if len(sys.argv) > 1:
while True:
try:
data = raw_input()
if data == "close":
GPIO.cleanup(pin)
if 'close' in data:
sys.exit(0)
except EOFError: # hopefully always caused by us sigint'ing the program
except (EOFError, SystemExit): # hopefully always caused by us sigint'ing the program
GPIO.cleanup(pin)
sys.exit(0)
@@ -128,11 +124,10 @@ if len(sys.argv) > 1:
while True:
try:
data = raw_input()
if data == "close":
GPIO.cleanup()
if 'close' in data:
sys.exit(0)
data = int(data)
except EOFError: # hopefully always caused by us sigint'ing the program
except (EOFError, SystemExit): # hopefully always caused by us sigint'ing the program
GPIO.cleanup()
sys.exit(0)
except:
@@ -159,14 +154,13 @@ if len(sys.argv) > 1:
while True:
try:
data = raw_input()
if data == "close":
GPIO.cleanup()
if 'close' in data:
sys.exit(0)
c = data.split(",")
r.ChangeDutyCycle(float(c[0]))
g.ChangeDutyCycle(float(c[1]))
b.ChangeDutyCycle(float(c[2]))
except EOFError: # hopefully always caused by us sigint'ing the program
except (EOFError, SystemExit): # hopefully always caused by us sigint'ing the program
GPIO.cleanup()
sys.exit(0)
except: