-
Notifications
You must be signed in to change notification settings - Fork 92
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
Get network configuration of a device #733
Conversation
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.
Looks good overall. I'd like to see unit tests for the formatting logic.
src/cmd/usb.js
Outdated
const platform = platformForId(usbDevice.platformId); | ||
if (platform.generation <= 2) { | ||
output = output.concat(`Device ID: ${chalk.cyan(usbDevice.id)} (${chalk.cyan(platform.displayName)})`); | ||
output = output.concat('\tCannot get network interfaces for Gen 2 devices'); | ||
output = output.concat('\n'); | ||
return; | ||
} | ||
return this.getNetworkIface(usbDevice) | ||
.then((outputData) => { | ||
output = output.concat(outputData); | ||
}); |
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.
Always prefer feature detection over version checks if possible. What does a Gen 2 device or maybe even a Gen 3 device without support for the NetworkIface control request do? If it errors out quickly with a predictable error code (NOT_SUPPORTED or something), then it's best to catch the error and say "Getting network interfaces is not supported for this device". If the error takes a while or it does something else weird, it's ok to fall back to checking the version.
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.
Done.
const ifaceList = await usbDevice.getNetworkInterfaceList(); | ||
for (const iface of ifaceList) { | ||
const ifaceInfo = await usbDevice.getNetworkInterface({ index: iface.index, timeout: 10000 }); |
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.
I suggest separating the code that does the control requests from the code that formats the data. Then write one or a couple of unit tests passing data the data structure that you get from the control request to the formatting function to check that all the output logic works as expected.
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.
Done also!
2a7ee0e
to
345224a
Compare
@monkbroc updated the new output format when there is an error. |
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.
Nice work!
src/cmd/usb.test.js
Outdated
access_token: '1234' | ||
}, | ||
}); | ||
const res = await usbCommands._formatNetworkIfaceOutput(nwInfo, 'p2', '0123456789abcdef'); |
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.
Nice test! The test doesn't need to be async and this line doesn't need await since _formatNetworkIfaceOutput is not async.
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.
yessss
c585f60
to
b919cf5
Compare
Description
Implements a command which resembles the linux
ifconfig
command that shows information about the network interfaces and their statesThis is only possible on Gen2 because the USB control requests to request this information are guarded by
HAL_PLATFORM_IFAPI
which is enabled only for Gen3 and above.How to Test
Check out this branch and from the particle-cli root directory, run
npm start -- usb network-interfaces
Expected Outcome
Related Issues / Discussions
particle-iot/particle-usb#102
Completeness