getc using shell?

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
ljfischer
Posts: 19
Joined: Sat Jan 04, 2014 5:03 am

getc using shell?

Post by ljfischer »

I want to create a monitor that constantly updates my terminal - vt100 style. It should parse individual keystrokes and react to them. Is there any *standard* way to do that using the shell? (Ive got lots of background activity doing ADC, etc)
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: getc using shell?

Post by Giovanni »

Hi,

It is not clear for me, if you use the shell, it is the shell getting keystrokes and updating the terminal. Shell commands can interact with the I/O stream using the interface passed as parameter. What do you need to do exactly?

Giovanni
mobyfab
Posts: 484
Joined: Sat Nov 19, 2011 6:47 pm
Has thanked: 21 times
Been thanked: 31 times

Re: getc using shell?

Post by mobyfab »

Have a look at this:

viewtopic.php?f=4&t=1530
ljfischer
Posts: 19
Joined: Sat Jan 04, 2014 5:03 am

Re: getc using shell?

Post by ljfischer »

Two things Im looking for:
- Im looking for greater understanding of the shell *context*. I know how to output data to the terminal, when I get a shell command callback. I would like to output data, using chprintf, outside of those callbacks. For instance, in my main thread or in a sub thread. Or at least have a shell thread that can process data and output it.
- While using the shell, Im looking for a 'single character typed' notifier - fgetc like. So that when I have a monitor being displayed, single characters, without return, can cause things to happen.

Can these things be done via the "shell?"
Thanks,
larry

- And thank you for the fast reply!!!
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: getc using shell?

Post by Giovanni »

Hi,

Look at the following example:

Code: Select all

static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) {
  static uint8_t buf[] =
      "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
      "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
      "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
      "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
      "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
      "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
      "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
      "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
      "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
      "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
      "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
      "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
      "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
      "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
      "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
      "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";

  (void)argv;
  if (argc > 0) {
    chprintf(chp, "Usage: write\r\n");
    return;
  }

  while (chnGetTimeout((BaseChannel *)chp, TIME_IMMEDIATE) == Q_TIMEOUT) {
    chSequentialStreamWrite(&SDU2, buf, sizeof buf - 1);
  }
  chprintf(chp, "\r\n\nstopped\r\n");
}


It is a shell command that runs until a key is pressed (any key). "chp" is the console channel where you can read and write using the channels API.

Giovanni
ljfischer
Posts: 19
Joined: Sat Jan 04, 2014 5:03 am

Re: getc using shell?

Post by ljfischer »

Perfect!

Thank you!
Larry
skute
Posts: 64
Joined: Wed Aug 29, 2012 10:17 pm

Re: getc using shell?

Post by skute »

There is a nice, minimal readline-like console @ https://github.com/Helius/microrl. You provide characters to it and a printing function and it will process the escape characters and command completions and such. This would provide you with the vt100 type of interface you are looking for.
ljfischer
Posts: 19
Joined: Sat Jan 04, 2014 5:03 am

Re: getc using shell?

Post by ljfischer »

No worries on the vt100 - thats easy enough.

One more question: Using the mechanism that we described, is it still valid to use chprintf, or do I need to manage my printing via chSequentialStreamWrite?
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: getc using shell?

Post by Giovanni »

You can use both, chprintf() internally uses chSequentialStreamWrite().

Giovanni
Post Reply