Re: alarm() - what am I doing wrong???
- From: Charles Sullivan <cwsulliv@xxxxxxxxxxxx>
- Date: Mon, 22 May 2006 20:41:16 GMT
On Mon, 22 May 2006 18:10:05 +0000, Jan Panteltje wrote:
On a sunny day (Mon, 22 May 2006 17:39:35 GMT) it happened Charles Sullivan
<cwsulliv@xxxxxxxxxxxx> wrote in
<pan.2006.05.22.17.39.34.902403@xxxxxxxxxxxx>:
On Mon, 22 May 2006 09:44:37 +0000, Jan Panteltje wrote:
Cannot you use alarm_isr() to increment a variable each second,
and set a flag for main if it reaches 5?
Then have main set a flag that resets the counter in alarm_isr()
before it reaches 5 if data comes in?
Then when mai nsees the flag that 5 is reached (in your main loop),
it should do something.
?
If I'm using alarm() to count seconds, then the read() would only
be able to check for incoming data every second, no? I think I'd
lose a lot of data that way.
Not sure, maybe I undestand you wrong.
You read loop (using poll() or select(), or whatever, would run continously.
But the alrm servuice routine would only be called once a second, and
retrigger *itself*.
Normal 'clock'
static elapsed_seconds;
main()
{
// init
while(1)
{
//read input status
// if something do whatever, reset elapsed_seconds.
// else
if elapsed_seconds > 5)
{
scream TIME!!!!!
elapsed_second = 0;
}
}
// add alarm signal handler one_second_tick
alarm(1);
}
void one_second_tick()
{
elapsed_seconds++;
// re-trigger self
alarm(1);
}
Jan.
The process just stays in that 'while' loop forever, waiting
for data.
The problem is that the data tends to come in bursts lasting
between 1 and perhaps 30 seconds each, maybe separated by
one or two seconds, then there are typically relatively long
periods of inactivity.
The data has to be processed immediately when it arrives
(there may or may not be some software handshaking with the
appliance I haven't shown, between the arrival of the first
byte and the reading of subsequent bytes.)
There are some housekeeping activities which need to be
attended to, but they can be deferred until it looks like
there's a quiet period as evidenced by about 5 seconds of no
activity.
The read() is blocking, so with your scheme I wouldn't know
the elapsed_seconds until some data actually arrives, but
even after processing the data I couldn't be sure it won't
be followed shortly thereafter by more data.
I've found a solution which works, however crudely. See
my response to Nils' comments.
Thanks for having taken the time to ponder my query and make
your suggestion.
Regards,
Charles Sullivan
.
- Follow-Ups:
- Re: alarm() - what am I doing wrong???
- From: Jan Panteltje
- Re: alarm() - what am I doing wrong???
- References:
- alarm() - what am I doing wrong???
- From: Charles Sullivan
- Re: alarm() - what am I doing wrong???
- From: Jan Panteltje
- Re: alarm() - what am I doing wrong???
- From: Charles Sullivan
- Re: alarm() - what am I doing wrong???
- From: Jan Panteltje
- alarm() - what am I doing wrong???
- Prev by Date: Re: GUI Development Options
- Next by Date: Re: alarm() - what am I doing wrong???
- Previous by thread: Re: alarm() - what am I doing wrong???
- Next by thread: Re: alarm() - what am I doing wrong???
- Index(es):
Relevant Pages
|
|