scan with timeout
Joel Sherrill
joel.sherrill at OARcorp.com
Wed Mar 27 14:09:22 UTC 2002
Stan wrote:
>
> Hi,
>
> I should like all input operation (read...scan...) return on timeout.
> What are best way for that ?
>
> This code you seem good ?
> In fact, the first call to the function scan return on timeout, but not the
> following.
> An idea?
Read up on termios :) It includes POSIX's way of specifying a timeout
or
minimum number of bytes to read.
http://www.opengroup.org/cgi-bin/dbcgix?TPL=sd_formframes&TOKEN=BWBNB&override=sd_search
> /**********************************************************************/
> /* transfer character from the buffer */
> char inbyte(int minor, int* timeout) {
> register char a;
> register int length;
>
> while ((char *)(((int)rcv[minor].in+1) & ((int)BUFFER_LENGTH-1))==
> rcv[minor].out){
> if(*timeout) (*timeout)--; else return '\0';
> rtems_task_wake_after(1);
> }
> a=*(char *)((int)rcv[minor].offset+(int)rcv[minor].out);
> rcv[minor].out= (char *)(((int)rcv[minor].out+1) &
> ((int)BUFFER_LENGTH-1));
> length = (BUFFER_LENGTH -1) & (
> ( ((int)rcv[minor].out <= (int)rcv[minor].in) ? 0 : BUFFER_LENGTH) -
> (int)rcv[minor].out
> + (int)rcv[minor].in + 1);
>
> if ((params[minor].mode & MODE_RTSCTS) && length < RTS_START_SIZE)
> StartRemoteTx(minor);
>
> return (a);
> }
>
> rtems_device_driver console_read(
> rtems_device_major_number major,
> rtems_device_minor_number minor,
> void *arg
> )
> {
>
> rtems_libio_rw_args_t *rw_args;
> char *buffer;
> int maximum;
> int count = 0;
> volatile int timeout;
>
> rw_args = (rtems_libio_rw_args_t *) arg;
>
> buffer = rw_args->buffer;
> maximum = rw_args->count;
>
> for (count = 0; count < maximum; count++) {
> timeout = 100*60; /* 100*60*5 = 5 minutes */
> buffer[ count ] = (char) inbyte(minor, &timeout);
> if(timeout==0) break;
> if ( params[minor].mode & MODE_CANON && (buffer[ count ] == '\n' ||
> buffer[ count ] == '\r')){
> if ( params[minor].mode & MODE_ADD_LF ) buffer[ count] = '\n';
> count++;
> break;
> }
> }
>
> rw_args->bytes_moved = count;
> return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
>
> }
> /***************************************************************************
> */
>
> thanks.
>
> Stan .
--
Joel Sherrill, Ph.D. Director of Research & Development
joel at OARcorp.com On-Line Applications Research
Ask me about RTEMS: a free RTOS Huntsville AL 35805
Support Available (256) 722-9985
More information about the users
mailing list