-
Notifications
You must be signed in to change notification settings - Fork 6
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
"tockloader listen" proof of concept #2
Conversation
Can you convert this to draft if it is still WIP? Or do you want this to be merged in its current state and then keep working from there? |
Oops! Yep, I wanted to make it a draft, but I forgot :D |
ad7b4f6
to
cc43e00
Compare
Here's a small update: In my last commit I added the ability for async read/write to the serial port with the help of a new crate "console_rs" . This crate helps with reading from console without echo-ing output to the user. As things stand now, when a letter is received by the board, it automatically re-sends it back to the host PC. Currently, there is one issue: on WSL and under an Ubuntu Virtual Machine, when waiting for input, if the board sends output the final output is a bit wonky. The error seems to be coming from the "console" crate. An issue and a PR are already opened, so as things stand there are good chances this will be fixed in the near future. CTRL+C is captured by the "console" crate, but it decides to still send the signal rather then passing the key-press. I'll try in my next commit to capture the interrupt signal to exit gracefully. |
I think the output problem might be due to the way the console interprets |
Oh, that might be it! I'll try to experiment with it. |
I think you should always display |
I've implemented your suggestion and now it seems to work as expected. Thank you! |
In this last commit I've implemented port auto-detection with the help of tokio-serial, and I've played around a bit more with how I send data to the board. Previously, I was using the In this commit I've switched over to the After starting to type I wouldn't receive any more data from the board. The program keeps sending key presses over, but the program wouldn't receive anything back. (I printed to screen a debug message saying what it was sending over, and it kept sending the correct characters. So it was not a printing-to-screen issue.) I'll try to investigate this strange behavior some more, but I have to say I'm not quite sure why this is happening. |
I have figured out why on my Ubuntu VM the board wasn't working as expected. The Unexpected BehaviourAfter starting to put input into the console, there was a non-zero chance the program would go into a state where the console could still read input but no output from console would be displayed. This usually happens after 2 or 3 key presses. The Actual ProblemAfter some deliberation, I had started to suspect that tokio couldn't start the read task because the key task would nearly never yield. The issue is also compounded by the fact that the key press is thread-blocking. After some digging around my hunch might be correct. In this stack overflow post a user reports that Console.ReadKey() in C# blocks the console. I suspect that something similar is happening here. The SolutionThe solution that seems to work on all three of the platforms i can test on (Windows 10 Native, WSL, Linux VM) is to put the "read_key" call under a blocking task (thread?). This seems to solve the issue. |
I've cleaned up the code a bit, and I think it's time I made this PR open for review. While it still doesn't implement all of the functionalities the original "listen" had, I think it's in a good shape for a prototype, something to work off of. So far, I've tested this code on Windows 10, WSL running under Windows 10 and an Ubuntu 22.04 Virtual Machine with a BBC Microbit v2. |
Hello, I have found that your implementation works, but has problems when typing the "backspace" after a uncompleted word. It starts removing the caracters from the promt, such as |
I can't replicate your issue, could you tell me what OS you used, the terminal ( |
Before, if an invalid UTF-8 sequence was decoded, the program would error out. Now, it will decode as much as it and can keep the remaining uninterpreted bytes in its buffer.
Don't be like me, add the checks to a git hook
I have tested the latest version of your branch (8930527) on a native Debian 12 machine for a user whose shell is Bash. Two terminal emulators (Konsole and WezTerm) yielded the same results for two boards: |
Hmm, I have running both Konsole and WezTerm on my Ubuntu 22 virtual machine and on a Debian 12 virtual machine I have am still not experiencing what you describe. I am using a
If you are using the same kernel version? If yes, I fear that this might actually happen only on native linux machines. I can try to work on a fix, but I'll be doing it blindly. I'm not 100% sure how Tock is handling user-input behind the scenes, but it seems to just echo it back on the serial interface, which makes the issue even stranger. I don't remember if I encountered this at some point also whilst figuring out the Possibly a related issue is when pressing tab. For me, when I press tab and then backspace, only 1 space is deleted. After pressing backspace again, no more characters are deleted. I'll try to investigate this issue some more... EditI've dug a bit in the tock source code, and the two issues might be very well connected. |
Hopefully that bug should be solved by this newest commit. The issue appears only in newer versions of the kernel, specifically after the code that handled "backspace" was updated in the kernel. Instead of the usual
to delete the last character, an additional
was snuck in. The reason python tockloader worked was because In my testing another issue has raised up: I can't pipe input or output from tockloader-rs because of the way the To note, I'd like to also refactor this code once a code structure is established ( see #8 ) |
Actually, arguably, we shouldn't do that -- Tock usually takes care of always using a full CRLF for newlines, as just a CR or LF alone are very useful control characters when drawing to a terminal emulator over a serial port. It's unfortunate that we still have places in Tock where we don't do this, and we should fix this upstream instead, even just for the sake of working with more full-featured serial monitors in their default configuration. I'm personally not invested in |
I agree with you here. If the issue is a simple one, I might tackle it myself. Edit: The Yet another issueI've found yet another issue: holding down the arrow keys. This one seems to originate from the
After the cursor ends up at the end, the terminal outputs "^[[D", which is weird, as it isn't being sent by the board. That is what leads me to believe it is a At this point, I think it would be worthwhile to investigate other crates for direct input. EDIT: This seems to only happen in my Ubuntu VM, on the VSCode terminal 😵 |
I think we can close this PR in favour of #9, thoughts? |
This pull request is a WIP proof of concept for the "tockloader listen" subcommand.
Currently, I am able to listen on a given port for output (tested on a micro:bit v2). It works both on Windows and under WSL.
Notes regarding implementation
This PR adds the following libraries:
tokio
- for creating async codetokio-serial
- for reading and writing to serialtokio-util
bytes
Notes regarding the python version
The python version of 'tockloader listen' has a lot of functionalities and I'd like note down some of them here.
While creating the proof of concept I'll attempt to implement as many of these functionalities as it is reasonable.