> In order to solve my problem (rather than the problem you actually
solved), > you will have to come up with code that:
> 1) Runs by polling (i.e. it doesn't get its own thread).
Sorry copied you a quick example, and must have left too large a gap when
assuming parallel conclusions for your code. See another example directly in
your code below.
> 2) Only uses doubles for storage of state between calls (in my case I
> only use psub->l which holds the time we last chimed).
I presume that one uses psub->dpvt if he needs some context that can't be
stored in a double (see below)?
> 3) If I start the program at 7 minutes past the hour with the period set
> to 15, it only chimes at 0, 15, 30 and 45 minutes past the hour.
See moving to struct tm, zeroing the minutes and seconds and then moving the
struct tm back to the epics time stamp below.
> 4) Allows me at runtime to change the chime period to 60, and from then
> on it will only chime on the hour.
See below.
The bottom line is that its better to avoid touching the time stamp's
internal fields directly and choose instead to use the higher level
functions for manipulating time stamps. IMHO that will result in less
maintenance both from portability and from longevity perspectives.
struct myStruct {
epicsTimeStamp begin;
};
void initBegTS ( struct subRecord * psub )
{
struct myStruct *pms = (struct myStruct *) psub->dpvt;
struct tm tmpTM;
unsigned long nSec;
epicsTimeGetCurrent ( & pms->begin );
epicsTimeToTM ( & tmpTM, & nSec, & pms->begin );
tmpTM.tm_sec = 0;
tmpTM.tm_min = 0;
epicsTimeFromTM ( & pms->begin, & tmpTM, 0);
}
long consoleChimeInit ( struct subRecord * psub )
{
psub->dpvt = (void *)
calloc( 1, sizeof ( struct myStruct ) );
initBegTS ( psub );
return(0);
}
long consoleChime (psub)
struct subRecord *psub;
{
struct myStruct *pms = (struct myStruct *) psub->dpvt;
epicsTimeStamp current;
double diff;
epicsTimeGetCurrent ( & current );
diff = epicsTimeDiffInSeconds ( & current, & pms->begin );
if ( diff > psub->a ) {
const char *prompt = envGetConfigParamPtr ( &IOCSH_PS1 );
char out[21];
epicsTimeToStrftime ( out, 20, "%Y-%m-%d %H:%M", ¤t );
printf("\n%s %s", out, prompt);
fflush(stdout);
initBegTS ( psub );
}
}
HTH,
Jeff
> -----Original Message-----
> From: Andrew Johnson [mailto:[email protected]]
> Sent: Thursday, September 14, 2006 4:22 PM
> To: Jeff Hill
> Cc: 'Tech Talk'
> Subject: Re: alternative approach to measuring a time delay
>
> Jeff Hill wrote:
> >
> > From my perspective, the following is a somewhat cleaner way to
> implement a
> > timeout (in contrast to the OSI version of the chime program)
>
> Please note that my code is called by a subroutine record that is
> processed every 10 seconds, and the only context storage it has
> available to it are the available fields of that subroutine record,
> which are all doubles. It does not contain any 'wait with timeout'
> calls of any kind, since these are illegal in the context of a
> subroutine record routine.
>
> While it might be possible to re-use one of the record fields as an
> epicsTimeStamp this is an ugly solution that I suspect you yourself
> would reject - we can't guarantee that the double field would be big
> enough to hold a future epicsTimeStamp object, and this solution would
> also open up the possibility that someone might try and read the value
> of that field remotely, when it would be interpreted as a double and
> might cause a Floting Point Exception.
>
> In order to solve my problem (rather than the problem you actually
> solved), you will have to come up with code that:
>
> 1) Runs by polling (i.e. it doesn't get its own thread).
> 2) Only uses doubles for storage of state between calls (in my case I
> only use psub->l which holds the time we last chimed).
> 3) If I start the program at 7 minutes past the hour with the period set
> to 15, it only chimes at 0, 15, 30 and 45 minutes past the hour.
> 4) Allows me at runtime to change the chime period to 60, and from then
> on it will only chime on the hour.
>
> I'll be happy to change my code if you can come up with a short, simple
> and portable solution that meets those requirements as well as your
> constraints.
>
> - Andrew
> --
> There is considerable overlap between the intelligence of the smartest
> bears and the dumbest tourists -- Yosemite National Park Ranger
- Navigate by Date:
- Prev:
RE:Spiricon Laser Beam Analyzer Elder Matias
- Next:
Epics 3.14.8.2 for Windows still has problems Liyu, Andrei
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
<2006>
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
- Navigate by Thread:
- Prev:
Re: RE: Channel archiver r_ani
- Next:
Epics 3.14.8.2 for Windows still has problems Liyu, Andrei
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
<2006>
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
|