[PATCH] shell: Add rtems_shell_wait_for_explicit_input()

Gedare Bloom gedare at rtems.org
Fri Jun 3 13:10:26 UTC 2016


On Fri, Jun 3, 2016 at 4:05 AM, Sebastian Huber
<sebastian.huber at embedded-brains.de> wrote:
> From: Alexander Krutwig <alexander.krutwig at embedded-brains.de>
>
> ---
>  cpukit/libmisc/shell/shell-wait-for-input.c | 26 ++++++++++++++++++++++----
>  cpukit/libmisc/shell/shell.h                | 18 ++++++++++++++++++
>  2 files changed, 40 insertions(+), 4 deletions(-)
>
> diff --git a/cpukit/libmisc/shell/shell-wait-for-input.c b/cpukit/libmisc/shell/shell-wait-for-input.c
> index a4bfc21..69ab883 100644
> --- a/cpukit/libmisc/shell/shell-wait-for-input.c
> +++ b/cpukit/libmisc/shell/shell-wait-for-input.c
> @@ -53,11 +53,12 @@ static rtems_status_code restore_serial_settings(int fd, struct termios *term)
>    return rv == 0 ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
>  }
>
> -rtems_status_code rtems_shell_wait_for_input(
> +rtems_status_code rtems_shell_wait_for_explicit_input(
>    int fd,
>    int timeout_in_seconds,
>    rtems_shell_wait_for_input_notification notification,
> -  void *notification_arg
> +  void *notification_arg,
> +  int desired_input
>  )
>  {
>    struct termios term;
> @@ -68,11 +69,12 @@ rtems_status_code rtems_shell_wait_for_input(
>      int i = 0;
>
>      for (i = 0; i < timeout_in_seconds && !input_detected; ++i) {
> -      char c;
> +      unsigned char c;
>
>        (*notification)(fd, timeout_in_seconds - i, notification_arg);
>
> -      input_detected = read(fd, &c, sizeof(c)) > 0;
> +      input_detected = read(fd, &c, sizeof(c)) > 0
> +        && (desired_input == -1 || desired_input == c);
I'd suggest desired_input < 0. Also, desired_input of 0 might make
sense, and be more logical to understand? Can one send a '\0' to the
shell without any other character?

>      }
>
>      sc = restore_serial_settings(fd, &term);
> @@ -83,3 +85,19 @@ rtems_status_code rtems_shell_wait_for_input(
>
>    return sc;
>  }
> +
> +rtems_status_code rtems_shell_wait_for_input(
> +  int fd,
> +  int timeout_in_seconds,
> +  rtems_shell_wait_for_input_notification notification,
> +  void *notification_arg
> +)
> +{
> +  return rtems_shell_wait_for_explicit_input(
> +    fd,
> +    timeout_in_seconds,
> +    notification,
> +    notification_arg,
> +    -1
> +  );
> +}
> diff --git a/cpukit/libmisc/shell/shell.h b/cpukit/libmisc/shell/shell.h
> index ea8532d..4d545d6 100644
> --- a/cpukit/libmisc/shell/shell.h
> +++ b/cpukit/libmisc/shell/shell.h
> @@ -322,6 +322,24 @@ extern rtems_status_code rtems_shell_wait_for_input(
>    void *notification_arg
>  );
>
> +/**
> + * @brief Waits for explicit input.
> + *
> + * @param desired_input An explicit unsigned character to wait for or -1 to
> + *   accept any input.
> + *
> + * @retval RTEMS_SUCCESSFUL Input detected.
> + * @retval RTEMS_TIMEOUT Timeout expired.
> + * @retval RTEMS_UNSATISFIED Cannot change or restore termios attributes.
> + */
> +extern rtems_status_code rtems_shell_wait_for_explicit_input(
> +  int fd,
> +  int timeout_in_seconds,
> +  rtems_shell_wait_for_input_notification notification,
> +  void *notification_arg,
> +  int desired_input
> +);
> +
>  extern int rtems_shell_main_monitor(int argc, char **argv);
>
>  /*
> --
> 1.8.4.5
>
> _______________________________________________
> devel mailing list
> devel at rtems.org
> http://lists.rtems.org/mailman/listinfo/devel



More information about the devel mailing list