-
Notifications
You must be signed in to change notification settings - Fork 2
/
ping.js
executable file
·67 lines (63 loc) · 1.61 KB
/
ping.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
#!/usr/bin/env node
"use strict";
const Jvc = require("./jvc");
const { exit } = require("node:process");
const { parseArgs: _parseArgs } = require("node:util");
function usage() {
console.log("usage: ping.js [options...] <host>");
console.log(" -p, --password Specify password (default: no password)");
console.log(" -P, --port Specify port (default: 20554)");
console.log(" -d, --debug Enable debug output");
console.log(" --help Show this message and quit");
exit(1);
}
function parseArgs() {
const options = {
port: {
type: "string",
short: "P",
},
password: {
type: "string",
short: "p",
},
debug: {
type: "boolean",
short: "d",
},
help: {
type: "boolean",
},
};
let args;
try {
args = _parseArgs({ options, allowPositionals: true, strict: true });
} catch (e) {
console.log(`ping.js: ${e.message}`);
usage();
}
if (args.values.help || args.positionals.length !== 1) {
usage();
}
return {
host: args.positionals[0],
port: args.values.port,
password: args.values.password,
debug: args.values.debug ? console.log : undefined,
};
}
async function ping() {
const jvc = new Jvc(parseArgs());
const power = await jvc.getPower();
console.log(`Power ${power}`);
console.log(`Model ${await jvc.getModelCode()}`);
console.log(`Mac ${await jvc.getMacAddress()}`);
if (power.isOn) {
console.log(`Lens ${await jvc.getLensMemory()}`);
console.log(`Ver ${await jvc.getSoftwareVersion()}`);
}
jvc.disconnect();
}
ping()
.then()
.catch((error) => console.error(error));