-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hubinfo tool #51
base: master
Are you sure you want to change the base?
hubinfo tool #51
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/usr/bin/env node | ||
require("../dist/node/hubinfo").main(process.argv.slice(2)); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import * as Consts from "./consts"; | ||
import { Hub } from "./hub"; | ||
import { LPF2Hub } from "./lpf2hub"; | ||
import { PoweredUP } from "./poweredup-node"; | ||
import { toBin, toHex } from "./utils"; | ||
|
||
function sanitizeString(s: string) { | ||
return s.replace(/\0/g, " ").replace(/ +$/, ""); | ||
} | ||
|
||
export function main(argv: string[]) { | ||
let portInfo = false; | ||
let quiet = false; | ||
for (const arg of argv) { | ||
switch (arg) { | ||
case "-p": | ||
case "--portinfo": | ||
portInfo = true; | ||
break; | ||
case "-q": | ||
case "--quiet": | ||
quiet = true; | ||
break; | ||
default: | ||
console.log("Usage: lpf2-hubinfo [-p|--portinfo] [-q|--quiet]"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The process never quits, likely as Noble is still running in the background. Can you add something like |
||
return; | ||
} | ||
} | ||
if (portInfo) { | ||
LPF2Hub.requestPortModeInfo = true; | ||
} | ||
const pup = new PoweredUP(); | ||
pup.on("discover", async (hub: Hub) => { | ||
const hubName = sanitizeString(hub.name); | ||
if (!quiet) { | ||
console.log(`Discovered ${hub.uuid} (${hubName})`); | ||
} | ||
await hub.connect(); | ||
hub.on("portInfo", ({ port, type, hardwareVersion, softwareVersion }) => { | ||
const typeName = Consts.DeviceTypeNames[type] || "unknown"; | ||
console.log(`${hub.uuid} Port ${toHex(port)}, type ${toHex(type, 4)} (${typeName})`); | ||
console.log(`${hub.uuid} Port ${toHex(port)}, hardware v${hardwareVersion}, software v${softwareVersion}`); | ||
}); | ||
hub.on("portModes", ({ port, count, input, output }) => { | ||
console.log(`${hub.uuid} Port ${toHex(port)}, total modes ${count}, input modes ${toBin(input, count)}, output modes ${toBin(output, count)}`); | ||
}); | ||
hub.on("portModeCombinations", ({ port, modeCombinationMasks }) => { | ||
console.log(`${hub.uuid} Port ${toHex(port)}, mode combinations [${modeCombinationMasks.map((c: number) => toBin(c, 0)).join(", ")}]`); | ||
}); | ||
hub.on("portModeInfo", (info) => { | ||
const { port, mode, type } = info; | ||
const prefix = `${hub.uuid} Port ${toHex(port)}, mode ${mode}`; | ||
switch (type) { | ||
case 0x00: // Mode Name | ||
console.log(`${prefix}, name ${sanitizeString(info.name)}`); | ||
break; | ||
case 0x01: // RAW Range | ||
console.log(`${prefix}, RAW min ${info.min}, max ${info.max}`); | ||
break; | ||
case 0x02: // PCT Range | ||
console.log(`${prefix}, PCT min ${info.min}, max ${info.max}`); | ||
break; | ||
case 0x03: // SI Range | ||
console.log(`${prefix}, SI min ${info.min}, max ${info.max}`); | ||
break; | ||
case 0x04: // SI Symbol | ||
console.log(`${prefix}, SI symbol ${sanitizeString(info.name)}`); | ||
break; | ||
case 0x80: // Value Format | ||
console.log(`${prefix}, Value ${info.numValues} x ${info.dataType}, Decimal format ${info.decimalFormat}`); | ||
break; | ||
} | ||
}); | ||
await hub.sleep(2000); | ||
const typeName = Consts.HubTypeNames[hub.type] || `unknown (${toHex(hub.type)})`; | ||
console.log(`${hub.uuid} firmware v${hub.firmwareVersion} hardware v${hub.hardwareVersion} ${typeName} (${hubName})`); | ||
if (hub instanceof LPF2Hub && !portInfo) { | ||
await hub.shutdown(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we add another |
||
} | ||
}); | ||
pup.scan(); | ||
if (!quiet) { | ||
console.log("Waiting for hubs..."); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency with this library name, could we call it
poweredup-hubinfo
? I'm not sure LPF2 is the right name to use given that its Lego internal only, and most people know the technology as Powered UP.