-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathbin.js
executable file
·76 lines (66 loc) · 1.9 KB
/
bin.js
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env node
var minimist = require('minimist')
var argv = minimist(process.argv.slice(2))
var hackrf = require('./')
var devices = hackrf()
console.log('Found %d HackRF devices', devices.length)
if (devices.length === 0) throw new Error('No devices connected')
var d = devices.open(0)
var pulse = 0
var low = Infinity
var high = 0
console.log('HackRF version is %s', d.getVersion())
function parse (f) {
if (typeof f === 'number') return f
f = f.replace(/M/i, '* 1000000')
f = f.replace(/k/i, '* 1000')
f = f.replace(/hz/, '')
return eval('(' + f + ')') // yolo
}
if (argv.frequency) d.setFrequency(parse(argv.frequency))
if (argv.bandwidth) d.setBandwidth(parse(argv.bandwidth))
if (argv['sample-rate']) d.setSampleRate(parse(argv['sample-rate']))
if (argv.lnaGain) d.setLNAGain(argv.lnaGain)
if (argv.vgaGain) d.setVGAGain(argv.vgaGain)
if (argv.txGain) d.setTxGain(argv.txGain)
if (argv.rxgraph) {
d.startRx(function (data, cb) {
var total = 0
for(var i = 0; i < data.length; i++) total += data[i]
if (total <= low) low = total
if (total >= high) high = total
var a = (total - low) / (high - low)
if (a) a = Math.pow(a, 2)
a = Math.max(0, a)
console.log(new Array(Math.floor((a || 0) * 80)).join('#'))
cb()
})
}
if (argv.startrx) {
d.startRx(function (data, cb) {
process.stdout.write(data)
cb()
})
}
if (argv.starttx) {
d.startTx(function (b, cb) {
for (var i = 0; i < b.length; i++) b[i] = pulse
pulse = 0
cb()
})
if (argv.interactive) {
console.log('(`killall node` in another terminal to kill me)')
process.stdin.setRawMode(true)
process.stdin.on('data', function () {
pulse = 127
console.log('Sending....')
})
} else {
setInterval(function () {
if (pulse === 0) pulse = 127
else pulse = 0
if (pulse) console.log('Sending pulse!')
else console.log('Idling...')
}, 200)
}
}