Skip to content
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

sys/shell: ensure character is flushed when echoing. #10630

Merged
merged 1 commit into from
Feb 12, 2019

Conversation

jcarrano
Copy link
Contributor

@jcarrano jcarrano commented Dec 18, 2018

Contribution description

When using a serial terminal without local echo, the current line would not get updated as the user typed because the shell module's readline() was not flushing each character.

This commit fixes that behavior. For additional clarity, fflush is turned into a macro (flush_if_needed) which expands to either a call to fflush() or empty, according to the standard library used.

This also fixes the erase/line editing behavior (the delete characters were not being flushed either.)

Testing procedure

Test that the shell is not broken by running

make -C tests/shell all flash
make -C tests/shell test

To test echo, I used miniterm.py (from pyserial) but any terminal with raw mode and no local echo should do:

$ miniterm.py --raw --eol CRLF /dev/ttyACM0 115200

Type a command. I used the 'test/shell' application.

Without this patch: you won't see anything on the screen until you type enter.

With this patch: you will see characters show up as you type. If you press backspace you will see the characters disappear too.

References

Mentioned by @neiljay in the mailing list some months ago: https://lists.riot-os.org/pipermail/devel/2018-July/005823.html

@jcarrano jcarrano added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Dec 18, 2018
Copy link
Contributor

@leandrolanzieri leandrolanzieri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and now the echo works, also erasing characters.

@@ -44,6 +44,12 @@ static void _putchar(int c) {
#endif
#endif

#ifdef MODULE_NEWLIB
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not defining this in the _putchar function if it is only needed with newlib?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we don't need to flush after every character. I do think, however, that it would be better if stdio was in unbuffered mode: it fits better with the HW.

Copy link
Contributor

@kaspar030 kaspar030 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix was long overdue. thx!

Please remove the macro though.

sys/shell/shell.c Outdated Show resolved Hide resolved
When using a serial terminal without local echo, the current line
would not get updated as the user typed because the shell module's
readline() was not flushing each character.

This commit fixes that behavior. For additional clarity, fflush is
turned into a macro (flush_if_needed) which expands to either a call
to fflush() or empty, according to the standard library used.

This also fixes the erase/line editing behavior (the delete characters
were not being flushed either.)
@jcarrano
Copy link
Contributor Author

I force pushed the fix (no point in a fixup commit)

@MrKevinWeiss
Copy link
Contributor

@kaspar030 Is it good to go?

@MrKevinWeiss MrKevinWeiss added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Feb 12, 2019
@kaspar030
Copy link
Contributor

Let me do some tests

@MrKevinWeiss
Copy link
Contributor

Tested with pyterm on nucleo-l476rg and it seems good.

@MrKevinWeiss
Copy link
Contributor

MrKevinWeiss commented Feb 12, 2019

miniterm is a bit funky though, let's wait a bit.
copy paste error, it echos until 128 chars then freezes and requires a reset. Expected behaviour I guess...

@kaspar030
Copy link
Contributor

I tested on nrf52dk using pyterm and picocom. I was curious if any tests might break when there's a possible double echo, but it seems fine. Let's also run the CI tests on samr21.
When those also pass, I'm happy here.

@kaspar030 kaspar030 added CI: run tests If set, CI server will run tests on hardware for the labeled PR CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Feb 12, 2019
@kaspar030
Copy link
Contributor

miniterm is a bit funky though, let's wait a bit.

maybe quickly add a change request, so noone gets trigger happy?

@kaspar030
Copy link
Contributor

At least on the samr21-xpro all tests succeeded.

@jcarrano
Copy link
Contributor Author

jcarrano commented Feb 12, 2019

copy paste error, it echos until 128 chars then freezes and requires a reset. Expected behaviour I guess...

mmm, weird. In any case, it should not be affected by this change. Is it a thing with the terminal or with RIOT? To be sure the terminal is not messing things up, I always test with:

  • raw encoding
  • CRLF line endings (because that's what riot uses)
  • No local echo, no local buffering

@MrKevinWeiss
Copy link
Contributor

I used your miniterm setup

miniterm.py --raw --eol CRLF /dev/ttyACM0 115200
> main(): This is RIOT! (Version: 2018.10-RC1-597-gb34dc-tstxxx/10630)
test_shell.
> 00000000111111112222222233333333444444445555555566666666777777778888888899999999aaaaaaaabbbbbbbbccccccccddddddddeeeeeeeefffffff

sorry 127 bytes, I guess it gets full, I can't delete or press enter. It doesn't crash... Ideally it would discard the last byte and evaluate the new one.

I don't think it is part of this PR though.

@jcarrano
Copy link
Contributor Author

@MrKevinWeiss see #10639 .

@MrKevinWeiss
Copy link
Contributor

I am not sending at once, these are just typed characters (at the speed of me).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: run tests If set, CI server will run tests on hardware for the labeled PR Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants