-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Feature for a platform to add its discoverer to DiscoveryManager #7942
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
Comments
I started experimenting with parsing JSON as it arrives from a process's stdout stream. Using Jackson's ObjectMapper with the BoardPort class seems like the most straightforward way. The JSON would be expected to look like this when a board is connected:
If the board is removed, the JSON would look like this:
I didn't choose any of this... it's the natural result of using ObjectMapper and BoardPort. Hopefully that's ok? |
(I was just looking at this) The
but most of these fields are tied to a specific Discovery (for example IMHO we should leave only "label", "id" and "type/protocol", all the other values should be part of the |
Did you have already implemented a |
Sure, with the caveat this is early & unfinished, but it does work. I also added a copy constructor to BoardPort, which TeensyDiscovery uses to make a copy of its list for the rest of the IDE, so changes to the copies can't corrupt the original within the discovery. |
As you can see, the command line is hard-coded and I still have lots of debug printing left over in the code. Very much a work in progress... |
I created a simple Linux command line program for testing. https://github.com/PaulStoffregen/SerialDiscovery_JSON Just compile and run this in a terminal, and you'll see it print JSON as you plug and unplug USB serial devices. :) Hopefully this helps? |
Regarding the JSON fields and BoardPort variables, I believe we should add a "partially qualified board name" field. If the discoverer knows nothing about what board is actually connected, this would left out of the JSON data and the variable in BoardPort would be null. But if the discover can learn which board is connected, and if it can deduce any of the board's optional menu settings, it would construct as much of the "fully qualified board name" as possible. I believe the Serial discovery could populate the variable based on which board it found with a matching VID and PID numbers. In the future, we could make use of this variable to automatically set the correct Board and some of its optional settings when the user chooses a Port. Likewise, when a user make a selection from the Board menu, DiscoveryManager could be queried to find the best matching Port (if any) and automatically select it. While not every case can be resolved, this would go a long way towards easing one of the most common new user frustrations, at least when using genuine boards. |
@cmaglie - How can we move this process forward? Have you had a chance to look at the discovery code and try SerialDiscovery_JSON? Is there anything more I can do to work towards a pull request you'd merge? |
@cmaglie - Can you give me any guidance on how you'd like to see platform discoverers launched? I believe this is probably the main thing missing before I can submit a first pull request. Currently DiscoveryManager.java has a hard-coded list (of only 2, serialDiscoverer & networkDiscoverer) in its constructor. I'm pretty sure you want something more flexible and configurable to detect which platforms provide a JSON-based discoverer. I only need a little direction on how you want to see this done, and I'll try to come up with an initial implementation. @mastrolinux - Is this moving in a direction you'll be able to use with the CLI? If you can spend just a couple minutes, please compile SerialDiscovery_JSON on any Linux system and run it in a terminal, then plug and unplug some Arduino boards while it's running. You'll see the JSON printed to stdout. I'd imagine you'll need for CLI at least some way to know when the initial enumeration of boards has ended, right? I know you guys are probably crazy busy. Hopefully the dust has settled from 1.8.7 by now? I'd really like to move forward on this, to the point of a pull request for the IDE and at least a vision that it will also work for CLI. Really need a little input here. |
@PaulStoffregen I'm very sorry for the delay. Here some design notes: Discovery tool functionalityI've tried your JSON discovery, works great (do you have a similar tool also for Windows and MAC?). In my mind I the discovery tool should be interactive, something that the IDE starts when launched (more on this later) and send command via stdin/out, for example:
The rationale is that for some discovery the SYNC update may not be available or it could be expensive, so it will use the About how discoveries are launchedAll platforms that implement a custom discovery should declare in the
for example for Teensy I guess it will be something like:
The discovery should be a cross-platform tool, like the uploaders/compilers/etc. so the more natural way to deploy it is via package_index.json as any other tool.
The IDE at startup will search all custom discovery from all installed platforms and start them (with START_SYNC or, if not available, with START as fallback) to populate the board list. We need some more thoughts to understand how we can share discoveries (for example what happens if two platforms uses the same discovery tool? or, worse, if they use different versions of the same tool?) I've started to implement this on the Java IDE, it's in a very WIP state, I'll publish this in a PR for review and we can proceed from that. What kind of information the discovery giveThe discovery should give:
Example, for a serial port we will likely have: {
"label": "ttyACM0",
"protocol": "serial",
"properties": {
"port": "/dev/ttyACM0",
"isusb": true,
"vid": "1234",
"pid": "5678",
"serial": "889327498274982739842"
},
"identification": {
"vid": "1234",
"pid": "5678"
}
} note that the
so this method will be 100% compatible with the current platforms. Ok, for now I'll stop, waiting for your comments. |
Thanks! That really charts the path forward. :) On the new JSON format, how will device removal be reported? I don't see the "online" field. There's also no longer a unique identifier field. Removal can be tricky, because much less info may be available when the device is no longer present. A unique ID field gives the discovery tool a way to reliably refer to info it previously reported. In the "identification" section, I would hope to be able to optionally report custom menu settings. Or maybe that would be another section? On the SerialDiscovery tool, sadly there is no libudev for Macintosh and Windows. Macintosh does have CoreFoundation and IOKit, but they are very complex to use (at least from C/C++, I haven't tried Swift yet). Windows is the really difficult part, but Microsoft does have HID-specific APIs. Windows support for HID, and Apple's then-new HID Manager API in Leopard, were the main reason I chose to use HID instead of serial protocol when I started Teensy in 2008. In a strange full circle sort of way, back then Linux was the weakest system with only buggy libusb 0.1 that had been abandoned by libusb's developers. Around 2014 libudev became stable and universally deployed by default on pretty much all Linux distros, so Linux went from the worst to the easiest system. |
Would you like me to contribute any part of the Java code? Happy to do so. Otherwise, I'll just focus on updating the SerialDiscovery tool to the new format. Hopefully that'll help with testing? |
It seems not related to the discovery, but who knows, we could possibly add some more information later, I would not exclude it now.
I didn't thought on the specific format too much, maybe an "add" and "remove" reports, like:
I've just opened a PR for you! |
Sent a pull request. |
Closing since #8038 has been merged. |
The IDE should provide a configurable way for platforms to provide their own discoverers to the IDE's DiscoveryManager.
A recipe in platform.txt would allow a platform to specify a shell command to run for its discoverer.
Communication between the shell command and the IDE should use stdin/stdout with text in JSON format. Two fields would be mandatory, "id" for the unique port identifier to be used in the upload recipe, and "label" for the text to be shown in the Ports menu. Optional fields could provide information about the board, or FQBN, or partial QBN, depending on how much information about the hardware is known to the discoverer.
The text was updated successfully, but these errors were encountered: