Created
May 13, 2013 08:21
-
-
Save mjohnsullivan/5566896 to your computer and use it in GitHub Desktop.
AxisCam motion detection with new Node streams Transform without prototypes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Parses out motion data from the Axis camera motion stream | |
* Implemented with the new Node streams | |
*/ | |
var stream = require('stream'), | |
util = require('util') | |
var MotionLevelStream = function() { | |
stream.Transform.call(this, {objectMode: true}) | |
this._transform = function(data, encoding, cb) { | |
var that = this | |
// Important bit of the stream is: group=0;level=0;threshold=11; | |
var match = data.toString().match(/group=\d+;level=\d+;threshold=\d+/g) | |
if (match) | |
match.forEach(function(motion) { | |
var motionMatch = motion.match(/group=(\d+);level=(\d+);threshold=(\d+)/) | |
that.push({ group: Number(motionMatch[1]), | |
level: Number(motionMatch[2]), | |
threshold: Number(motionMatch[3]), | |
ts: new Date }) | |
}) | |
cb() | |
} | |
} | |
util.inherits(MotionLevelStream, stream.Transform) | |
exports.createStream = function() { | |
return new MotionLevelStream() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment