-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli.js
40 lines (35 loc) · 822 Bytes
/
cli.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
var argv = require("optimist").argv,
fs = require("fs"),
BluetoothScanner = require("./index.js");
function help() {
fs.createReadStream("usage.txt")
.on("end", function() {
process.exit();
})
.pipe(process.stdout);
}
var hcidev = argv.interface || argv.i || "hci0";
var scanner = new BluetoothScanner(hcidev);
if (argv.help || argv.h) {
help();
}
if (argv.info) {
scanner.getHciconfig(function(err, result) {
if (!err) {
console.log(JSON.stringify(result, null, 2) /* pretty format - 2 spaces */);
}
else {
console.error("[Error]".red, err.message);
}
});
}
if (argv.scan) {
scanner.scan(function(err, result) {
if (!err) {
console.log(JSON.stringify(result, null, 2));
}
else {
console.error("[Error]".red, err.message);
}
});
}