Rewrite device model auto-detection to use config memory magic#46
Conversation
Localising knowledge about the simulators for each device model in the respective model classes avoids the proliferation of simulator generation statements in enumerate().
- Allow device selection with --model by itself (without --tty given). This is very useful when you have two different models connected at the same time (like HX870 and GX1400) because the model names are easy to remember, but the tty names are not. - Allow --tty to specify an incomplete match (for example, `--tty usbserial` is now enough to select `/dev/cu.usbserial-17522`). An exact match is still preferred if there is one. - Bring back model auto-detection for GX1400, now using the config memory magic rather than the flash ID. If the GX1400 is the only connected device, it should work without --tty or --model. This change makes provisions for reading the config magic from other non-USB device models that might need several different baudrates, although in practice, all the GX and HX models that are implemented in hxtool at this time seem to work correctly at 38400 baud. - Auto-detecting the device model by USB meta data is now preferred whenever possible, even with --tty given. This should be fast and reliable, and it makes for a more unified approach to device selection. - Overriding auto-detection is still possible by specifying both --tty and --model.
|
Please let me know when it is rtl. |
|
From my perspective, it has been ready since I opened the PR last night (except for a typo that I fixed immediately). Did I miss something? |
|
I won't get to a full review. The tests with the sims pass fine? Anything more to add to the other tests, perhaps? |
|
Sure, tests are passing. This PR doesn’t touch any of the tests that already existed, they’re all fine as far as I can tell. As for a review – because the rewrite has left very little of the old For what it’s worth, I’m quite confident about the design overall. However, the new code surrounding This PR will merge into the |
I took a swing at the device model auto-detection, as we discussed in #42 (comment).
This proposed change largely replaces the
enumerate()function with new logic that’s better suited for adding new radio models, especially those lacking USB. It does so by removing hard-coded lists of model classes, and by reading config memory magic rather than the flash ID (#44).Reading data from the device memory for identification is potentially problematic: Some devices require different baud rates than others, which can cause delays due to timeouts, and some systems have extra serial ports that raise errors. To avoid these issues, the proposed logic trusts USB metadata whenever possible, which means reading the magic is rarely even necessary. It also adds an exclusion list of OS-specific serial ports known to cause errors or timeouts.
Additionally, this change streamlines the user experience by handling the
--ttyand--modelCLI options more consistently: Both options when given now simply restrict the auto-detection in accordance with the given values.For example,
hxtool --model HX890will now run the full auto-detection logic, but only consider devices identifying as HX890. This is a new feature, a rather useful one when you work with multiple device models connected at the same time. Previously,--modelsimply caused an error unless--ttywas given, too.As before, overriding auto-detection is possible by specifying both
--ttyand--model.