Skip to content

Commit

Permalink
added pulseCount to processed data output, fixed error handling for r…
Browse files Browse the repository at this point in the history
…epl handler
  • Loading branch information
mwittig committed Mar 30, 2019
1 parent 49c82a3 commit 0097f38
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ board.on("data", (function(_this) {
board.on("rfReceive", (function(_this) {
return function(event) {
var data;
if ('pulses' in event && (event.pulses != null)) {
event.pulseCount = event.pulses.length;
}
data = JSON.stringify(event);
data = data.substring(1, data.length - 1);
return console.log("processed: ".grey + ("" + data).blue + "".grey);
Expand All @@ -49,4 +52,6 @@ board.connect().then((function(_this) {
output: process.stdout
}).context.board = board;
};
})(this)).done();
})(this))["catch"](function(error) {
return console.log(error.message);
});
7 changes: 6 additions & 1 deletion src/client.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ baudrate = parseInt(process.argv[3]) or 115200
board = new Board("serialport", {serialDevice, baudrate})
console.log "connecting to #{serialDevice} with #{baudrate}".green


board.on "data", (data) =>
console.log "raw data: \"".grey + "#{data}".blue + "\"".grey

board.on "rfReceive", (event) =>
if 'pulses' of event and event.pulses?
event.pulseCount = event.pulses.length
data = JSON.stringify(event)
data = data.substring(1, data.length-1)
console.log "processed: ".grey + "#{data}".blue + "".grey
Expand All @@ -27,4 +30,6 @@ board.connect().then( =>
input: process.stdin,
output: process.stdout
}).context.board = board
).done()
).catch( (error) ->
console.log error.message
)

0 comments on commit 0097f38

Please sign in to comment.