-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
53 lines (49 loc) · 1.46 KB
/
index.js
File metadata and controls
53 lines (49 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var async = require('async')
var bindings = require('./build/Release/bitscope')
function bitscope(options, callback) {
if ((typeof options) == 'function') {
callback = options
options = null
}
if (!options) {options = {}}
var device = options.device || 0
var rate = options.rate || 100000
var size = options.size || 1000
var channel = options.channel || 0
if ((typeof channel) == 'string') {
channel = channel.split(',').map(function(a){return parseInt(a)})
}
if (!Array.isArray(channel)) {channel = [channel]}
bindings.init(parseInt(device), function(error){
if (error) {return callback(error)}
async.map(channel, bindings.setup, function(error){
if (error) {return callback(error)}
bindings.trace(rate, size, function(error, data){
if (error) {return callback(error)}
async.map(
channel,
function(item, callback){
bindings.acquire(item, size, callback)
},
function(error, data){
if (error) {return callback(error)}
callback(
null,
channel.map(function(c, i){
return {
channel: c,
trace: data[i]
}
})
)
bindings.close(function(){})
}
)
})
})
})
}
['init', 'setup', 'trace', 'acquire', 'close'].forEach(function(name){
bitscope[name] = bindings[name]
})
module.exports = bitscope