Skip to content

Instantly share code, notes, and snippets.

@mjohnsullivan
Created May 13, 2013 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjohnsullivan/5566896 to your computer and use it in GitHub Desktop.
Save mjohnsullivan/5566896 to your computer and use it in GitHub Desktop.
AxisCam motion detection with new Node streams Transform without prototypes
/**
* 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