Skip to content

Commit

Permalink
Winston: use logging levels
Browse files Browse the repository at this point in the history
  • Loading branch information
derTobsch committed Nov 25, 2018
1 parent 46e82b2 commit 1dc9510
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 36 deletions.
4 changes: 2 additions & 2 deletions fluffd/fluffaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ commands["flashdlc"] = {
fluff.addGeneralPlusCallback(function(data) {
if (!(data[0] == 0x24 && data[1] == 0x02))
return;
winston.log("info", "FlashDLC: Got Ready to Receive");
winston.info( "FlashDLC: Got Ready to Receive");

fs.readFile(params.dlcfile, function(error, dlc) {
if (error)
Expand Down Expand Up @@ -235,7 +235,7 @@ commands["other"] = {
module.exports = {
execute : function(fluff, cmd, params, callback) {
if (!commands[cmd])
winston.log("error", "Command not found: " + cmd);
winston.error( "Command not found: " + cmd);
else
commands[cmd].run(fluff, params, callback);
},
Expand Down
56 changes: 28 additions & 28 deletions fluffd/fluffcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ const FURBY = {
// Otherwise, Furby will remain in a state where it doesn't accept any connection attempts.
function exitHandler(furby) {
process.on("SIGINT", function() {
winston.log("info", "\nClosing connection...");
winston.info( "\nClosing connection...");
furby.disconnect(function(error) {
if (error)
winston.log("error", "Error while disconnecting: " + error);
winston.error( "Error while disconnecting: " + error);
else
winston.log("info", "Disconnected, exiting.");
winston.info( "Disconnected, exiting.");

// TODO: This does not work with multiple furbies connect
process.exit();
Expand All @@ -43,13 +43,13 @@ function exitHandler(furby) {
function getFurbyCharacteristics(furby, serviceUUID, characteristicUUIDs, callback) {
furby.discoverServices([serviceUUID], function(error, services) {
if (error) {
winston.log("error", "Error in discoverServices: " + error);
winston.error( "Error in discoverServices: " + error);
return;
}

services[0].discoverCharacteristics(characteristicUUIDs, function(error, characteristics) {
if (error) {
winston.log("error", "Error in discoverCharacteristics: " + error);
winston.error( "Error in discoverCharacteristics: " + error);
return;
}

Expand Down Expand Up @@ -93,10 +93,10 @@ class Fluff {
generalPlusWrite(data, callback) {
this.gpWrite.write(data, true, function(error) {
if (error) {
winston.log("warn", "Error in generalPlusWrite: " + error);
winston.warn( "Error in generalPlusWrite: " + error);
if (callback) callback("generalPlusWrite: " + error);
} else {
winston.log("verbose", "generalPlusWrite: " + data.toString("hex"));
winston.verbose( "generalPlusWrite: " + data.toString("hex"));
if (callback) callback(false);
}
});
Expand All @@ -110,7 +110,7 @@ class Fluff {
if (i < sequence.length) {
this.gpWrite.write(sequence[i], true, function(error) {
if (error) {
winston.log("warn", "Error in generalPlusWriteSequence: " + error);
winston.warn( "Error in generalPlusWriteSequence: " + error);
if (callback) callback("generalPlusWriteSequence: " + error);
return;
}
Expand All @@ -130,10 +130,10 @@ class Fluff {
nordicWrite(data, callback) {
this.nWrite.write(data, true, function(error) {
if (error) {
winston.log("warn", "Error in nordicWrite: " + error);
winston.warn( "Error in nordicWrite: " + error);
if (callback) callback("nordicWrite: " + error);
} else {
winston.log("verbose", "nordicWrite: " + data.toString("hex"));
winston.verbose( "nordicWrite: " + data.toString("hex"));
if (callback) callback(false);
}
});
Expand All @@ -143,10 +143,10 @@ class Fluff {
writeToSlot(data, callback) {
this.fileWrite.write(data, true, function(error) {
if (error) {
winston.log("warn", "Error in writeToSlot: " + error);
winston.warn( "Error in writeToSlot: " + error);
if (callback) callback("writeToSlot: " + error);
} else {
winston.log("verbose", "writeToSlot: " + data.toString("hex"));
winston.verbose( "writeToSlot: " + data.toString("hex"));
if (callback) callback(false);
}
});
Expand All @@ -155,34 +155,34 @@ class Fluff {
// Subscribe to GeneralPlusListen, RSSIListen and NordicListen characteristics
subscribeNotifications() {
this.nListen.on("data", (data, isNotification) => {
winston.log("verbose", "Nordic notification: " + data.toString("hex"));
winston.verbose( "Nordic notification: " + data.toString("hex"));
for (let c of this.nCallbacks)
c(data);
});

this.gpListen.on("data", (data, isNotification) => {
winston.log("verbose", "GP notification: " + data.toString("hex"));
winston.verbose( "GP notification: " + data.toString("hex"));
for (let c of this.gpCallbacks)
c(data);
});

this.rssiListen.on("data", (data, isNotification) => {
winston.log("verbose", "RSSI notification: " + data.toString("hex"));
winston.verbose( "RSSI notification: " + data.toString("hex"));
});

this.nListen.subscribe((error) => {
if (error)
winston.log("error", "Error while subscribing to NordicListen: " + error);
winston.error( "Error while subscribing to NordicListen: " + error);
});

this.gpListen.subscribe((error) => {
if (error)
winston.log("error", "Error while subscribing to GeneralPlusListen: " + error);
winston.error( "Error while subscribing to GeneralPlusListen: " + error);
});

this.rssiListen.subscribe((error) => {
if (error)
winston.log("error", "Error while subscribing to RSSIListen: " + error);
winston.error( "Error while subscribing to RSSIListen: " + error);
});
}

Expand Down Expand Up @@ -225,7 +225,7 @@ module.exports = {}
module.exports.connect = function(furby, callback) {
furby.connect(function(error) {
if (error) {
winston.log("error", "Error while connecting: " + error);
winston.error( "Error while connecting: " + error);
return;
}

Expand All @@ -239,11 +239,11 @@ module.exports.connect = function(furby, callback) {
let nListen = characteristics[FURBY.CHARACTERISTIC.NORDIC_LISTEN];
let rssiListen = characteristics[FURBY.CHARACTERISTIC.RSSI_LISTEN];
let fileWrite = characteristics[FURBY.CHARACTERISTIC.FILEWRITE];
winston.log("debug", "Read all fluff characteristics");
winston.debug("Read all fluff characteristics");
callback(new Fluff(gpWrite, gpListen, nWrite, nListen, rssiListen, fileWrite));
});

winston.log("info", "Connected to Furby");
winston.info( "Connected to Furby");
});
};

Expand All @@ -252,30 +252,30 @@ module.exports.introspect = function(furby) {

furby.connect(function(error) {
if (error) {
winston.log("error", "Error while connecting for introspection: " + error);
winston.error( "Error while connecting for introspection: " + error);
return;
}

winston.log("info","GATT data structure of furby with UUID " + furby.uuid);
winston.info("GATT data structure of furby with UUID " + furby.uuid);
furby.discoverServices(null, function(error, services) {
winston.log("info","Furby exposes the following services: ");
winston.info("Furby exposes the following services: ");

let count = 0;

// Scan all characteristics
services.forEach(function(ser, idx) {
ser.discoverCharacteristics(null, function(error, characteristics) {
winston.log("info"," " + idx + ") uuid: " + ser.uuid + ", with characteristics: ");
winston.info(" " + idx + ") uuid: " + ser.uuid + ", with characteristics: ");
for (let i in characteristics)
winston.log("info"," > uuid: " + characteristics[i]);
winston.info(" > uuid: " + characteristics[i]);

count++;
if (count >= services.length) {
furby.disconnect(function(error) {
if (error)
winston.log("error", "Error while disconnecting: " + error);
winston.error( "Error while disconnecting: " + error);
else
winston.log("info", "Disconnected, exiting")
winston.info( "Disconnected, exiting")

process.exit();
});
Expand Down
12 changes: 6 additions & 6 deletions fluffd/fluffd.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* fluffd: Furby Bluetooth Low Energy / Bluetooth Smart Communication Server:
* Connect to Furby, start fluff server:
* node fluffd.js
*
*
* Connect to Furby, show all BLE services and characteristics and exit:
* node main.js introspect
*
Expand Down Expand Up @@ -55,18 +55,18 @@ function startCommand(name, post_data, res) {
respond(multiple_errstring === "" ? false : multiple_errstring);
}

winston.log("verbose", "Sending " + name + " command to all Furbies, params:", post_data.params);
winston.verbose( "Sending " + name + " command to all Furbies, params:", post_data.params);
for (let uuid in furbies)
fluffaction.execute(furbies[uuid], name, post_data.params, respond_single);

// Send command to a single one of the connected furbies
} else {
winston.log("verbose", "Sending " + name + " command to single Furby " + post_data.target + ", params: " + post_data.params);
winston.verbose( "Sending " + name + " command to single Furby " + post_data.target + ", params: " + post_data.params);

if (post_data.target in furbies) {
fluffaction.execute(furbies[post_data.target], name, post_data.params, respond);
} else {
winston.log("warn", "could not find target");
winston.warn( "could not find target");
res.end("error: could not find target");
}
}
Expand All @@ -82,7 +82,7 @@ function parseCommand(name, req, res) {
post_data = JSON.parse(POST);
startCommand(name, post_data, res);
} catch(e) {
winston.log("warn", "Could not parse HTTP command: " + e);
winston.warn( "Could not parse HTTP command: " + e);
res.end("error: " + e);
return;
}
Expand Down Expand Up @@ -127,7 +127,7 @@ noble.on("stateChange", function(state) {

noble.on("discover", function(peripheral) {
if(peripheral.advertisement.localName === "Furby") {
winston.log("info", "Discovered Furby: " + peripheral.uuid);
winston.info( "Discovered Furby: " + peripheral.uuid);

// Introspection mode
if (process.argv[2] === "introspect") {
Expand Down

0 comments on commit 1dc9510

Please sign in to comment.