Commit 4c1e43e2 authored by Claes Sjofors's avatar Claes Sjofors

Time function for plc without exceptions at invalid times added, and fix in...

Time function for plc without exceptions at invalid times added, and fix in time_Aadd for negative deltatimes
parent cdeacae0
...@@ -581,6 +581,8 @@ static const pwr_tNid pwr_cNNid = 0; //!< Zero node identity constan ...@@ -581,6 +581,8 @@ static const pwr_tNid pwr_cNNid = 0; //!< Zero node identity constan
static const pwr_tStatus pwr_cNStatus = 0; //!< Zero status constant. static const pwr_tStatus pwr_cNStatus = 0; //!< Zero status constant.
static const pwr_tTime pwr_cNTime = {0, 0}; //!< Zero time constant. static const pwr_tTime pwr_cNTime = {0, 0}; //!< Zero time constant.
static const pwr_tDeltaTime pwr_cNDeltaTime = {0, 0}; //!< Zero deltatime constant. static const pwr_tDeltaTime pwr_cNDeltaTime = {0, 0}; //!< Zero deltatime constant.
static const pwr_tTime pwr_cNotATime = {0, 1000000000}; //!< Illegal time.
static const pwr_tDeltaTime pwr_cNotADeltaTime = {0, 1000000000}; //!< Illegal delta time.
/* Gereral macro definitions */ /* Gereral macro definitions */
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* published by the Free Software Foundation, either version 2 of * published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version. * the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful * This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
# include <string.h> # include <string.h>
# include <ctype.h> # include <ctype.h>
# include <stdlib.h> # include <stdlib.h>
# include <math.h>
#endif #endif
#if defined OS_LYNX #if defined OS_LYNX
...@@ -68,16 +69,23 @@ ...@@ -68,16 +69,23 @@
# define assertAbs(p) do {\ # define assertAbs(p) do {\
pwr_Assert(p->tv_sec >= 0 && p->tv_nsec >= 0 && p->tv_nsec < 1000000000);\ pwr_Assert(p->tv_sec >= 0 && p->tv_nsec >= 0 && p->tv_nsec < 1000000000);\
} while (0) } while (0)
# define notATime(p) (p->tv_sec < 0 || p->tv_nsec < 0 || p->tv_nsec >= 1000000000)
#else #else
# define assertAbs(p) do {\ # define assertAbs(p) do {\
pwr_Assert(p->tv_nsec >= 0 && p->tv_nsec < 1000000000);\ pwr_Assert(p->tv_nsec >= 0 && p->tv_nsec < 1000000000);\
} while (0) } while (0)
# define notATime(p) (p->tv_nsec < 0 || p->tv_nsec >= 1000000000)
#endif #endif
#define assertDelta(p) do {\ #define assertDelta(p) do {\
pwr_Assert((p->tv_sec > 0) ? (p->tv_nsec >= 0 && p->tv_nsec < 1000000000) : TRUE);\ pwr_Assert((p->tv_sec > 0) ? (p->tv_nsec >= 0 && p->tv_nsec < 1000000000) : TRUE);\
pwr_Assert((p->tv_sec < 0) ? (p->tv_nsec <= 0 && p->tv_nsec > -1000000000) : TRUE);\ pwr_Assert((p->tv_sec < 0) ? (p->tv_nsec <= 0 && p->tv_nsec > -1000000000) : TRUE);\
} while (0) } while (0)
#define notADeltaTime(p) \
(((p->tv_sec >= 0) && (p->tv_nsec < 0 || p->tv_nsec >= 1000000000)) || \
((p->tv_sec < 0) && (p->tv_nsec > 0 || p->tv_nsec <= -1000000000)))
#define ONEDAY 86400 #define ONEDAY 86400
...@@ -168,7 +176,7 @@ time_IsNull ( ...@@ -168,7 +176,7 @@ time_IsNull (
return (t1->tv_sec == pwr_cNTime.tv_sec) && (t1->tv_nsec == pwr_cNTime.tv_nsec); return (t1->tv_sec == pwr_cNTime.tv_sec) && (t1->tv_nsec == pwr_cNTime.tv_nsec);
} }
//! Add an absolute time and a delta time. //! Add an absolute time and a delta time.
/*! Add two timespecs, result = t + d, where: /*! Add two timespecs, result = t + d, where:
...@@ -178,6 +186,9 @@ time_IsNull ( ...@@ -178,6 +186,9 @@ time_IsNull (
If 'result' argument is NULL If 'result' argument is NULL
then 't' will be used as resultant. then 't' will be used as resultant.
Returns the address to the resulting time. Returns the address to the resulting time.
Input arguments containing invalid times will
cause an exception.
*/ */
pwr_tTime * pwr_tTime *
...@@ -187,18 +198,74 @@ time_Aadd ( ...@@ -187,18 +198,74 @@ time_Aadd (
pwr_tDeltaTime *a pwr_tDeltaTime *a
) )
{ {
pwr_tInt64 tv_nsec = t->tv_nsec + a->tv_nsec;
pwr_tInt64 tv_sec = t->tv_sec + a->tv_sec;
pwr_tTime *r = result; pwr_tTime *r = result;
pwr_tInt64 tv_nsec;
assertAbs(t); assertAbs(t);
assertDelta(a); assertDelta(a);
if (result == NULL) r = t; if (result == NULL) r = t;
tv_nsec = t->tv_nsec + a->tv_nsec; tv_sec += tv_nsec / 1000000000;
r->tv_sec = t->tv_sec + a->tv_sec + (tv_nsec / 1000000000); tv_nsec %= 1000000000;
r->tv_nsec = tv_nsec % 1000000000; if (tv_nsec < 0 && tv_sec > 0) {
tv_sec--;
tv_nsec += 1000000000;
} else if (tv_sec < 0 && tv_nsec > 0) {
tv_sec++;
tv_nsec -= 1000000000;
}
r->tv_sec = tv_sec;
r->tv_nsec = tv_nsec;
return r;
}
//! Add an absolute time and a delta time.
/*! Add two timespecs, result = t + d, where:
- 'result' and 't' is an absolute time, and
- 'd' is a delta time.
If 'result' argument is NULL
then 't' will be used as resultant.
Returns the address to the resulting time.
If any input argument contains an invalid time
an invalid time, pwr_cNotATime, is returned.
*/
pwr_tTime *
time_Aadd_NE (
pwr_tTime *result,
pwr_tTime *t,
pwr_tDeltaTime *a
)
{
pwr_tInt64 tv_nsec = t->tv_nsec + a->tv_nsec;
pwr_tInt64 tv_sec = t->tv_sec + a->tv_sec;
pwr_tTime *r = result;
if (result == NULL) r = t;
if ( notATime(t) || notADeltaTime(a)) {
*r = pwr_cNotATime;
return r;
}
tv_sec += tv_nsec / 1000000000;
tv_nsec %= 1000000000;
if (tv_nsec < 0 && tv_sec > 0) {
tv_sec--;
tv_nsec += 1000000000;
} else if (tv_sec < 0 && tv_nsec > 0) {
tv_sec++;
tv_nsec -= 1000000000;
}
r->tv_sec = tv_sec;
r->tv_nsec = tv_nsec;
return r; return r;
} }
...@@ -210,6 +277,9 @@ time_Aadd ( ...@@ -210,6 +277,9 @@ time_Aadd (
If argument 't2' is NULL the comparison will If argument 't2' is NULL the comparison will
be done as if t2 == 0. be done as if t2 == 0.
Input arguments containing invalid times will
cause an exception.
*/ */
int int
...@@ -234,11 +304,49 @@ time_Acomp ( ...@@ -234,11 +304,49 @@ time_Acomp (
else else
return ((t1->tv_sec > t2->tv_sec) ? 1 : -1); return ((t1->tv_sec > t2->tv_sec) ? 1 : -1);
} }
//! Compare two timespecs.
/*! Returns \n
1 if t1 > t2 \n
0 if t1 == t2 \n
-1 if t1 < t2 \n
If argument 't2' is NULL the comparison will
be done as if t2 == 0.
If any input argument contains an invalid time
-2 is returned.
*/
int
time_Acomp_NE (
pwr_tTime *t1,
pwr_tTime *t2
)
{
static pwr_tTime null = {0, 0};
if (t2 == NULL) t2 = &null;
if ( notATime(t1) || notATime(t2))
return -2;
if (t1->tv_sec == t2->tv_sec)
{
if ( t1->tv_nsec == t2->tv_nsec)
return 0;
return ((t1->tv_nsec > t2->tv_nsec) ? 1 : -1);
}
else
return ((t1->tv_sec > t2->tv_sec) ? 1 : -1);
}
//! Subtract a time from a time, //! Subtract a time from a time,
/*! r = t - s /*! r = t - s
Result is always a delta time. Result is always a delta time.
Input arguments containing invalid times will
cause an exception.
*/ */
pwr_tDeltaTime * pwr_tDeltaTime *
...@@ -270,11 +378,54 @@ time_Adiff ( ...@@ -270,11 +378,54 @@ time_Adiff (
return r; return r;
} }
//! Subtract a time from a time,
/*! r = t - s
Result is always a delta time.
If any input argument contains an invalid time
an invalid time, pwr_cNotADeltaTime, is returned.
*/
pwr_tDeltaTime *
time_Adiff_NE (
pwr_tDeltaTime *r,
pwr_tTime *t,
pwr_tTime *s
)
{
pwr_tInt64 tv_nsec = t->tv_nsec - s->tv_nsec;
pwr_tInt64 tv_sec = t->tv_sec - s->tv_sec;
if ( r == NULL || notATime(t) || notATime(s)) {
*r = pwr_cNotADeltaTime;
return r;
}
tv_sec = tv_sec + tv_nsec / 1000000000;
tv_nsec = tv_nsec % 1000000000;
if (tv_nsec < 0 && tv_sec > 0) {
tv_sec--;
tv_nsec += 1000000000;
} else if (tv_sec < 0 && tv_nsec > 0) {
tv_sec++;
tv_nsec -= 1000000000;
}
r->tv_sec = tv_sec;
r->tv_nsec = tv_nsec;
return r;
}
//! Subtract a delta time from a time, //! Subtract a delta time from a time,
/*! r = t - s /*! r = t - s
Result is always an abstime. Result is always an abstime.
Input arguments containing invalid times will
cause an exception.
*/ */
pwr_tTime * pwr_tTime *
...@@ -308,13 +459,59 @@ time_Asub ( ...@@ -308,13 +459,59 @@ time_Asub (
return r; return r;
} }
//! Subtract a delta time from a time,
/*! r = t - s
Result is always an abstime.
If any input argument contains an invalid time
an invalid time, pwr_cNotATime, is returned.
*/
pwr_tTime *
time_Asub_NE (
pwr_tTime *result,
pwr_tTime *t,
pwr_tDeltaTime *s
)
{
pwr_tInt64 tv_nsec = t->tv_nsec - s->tv_nsec;
pwr_tInt64 tv_sec = t->tv_sec - s->tv_sec;
pwr_tTime *r = result;
if (r == NULL) r = t;
if ( notATime(t) || notADeltaTime(s)) {
*r = pwr_cNotATime;
return r;
}
tv_sec += tv_nsec / 1000000000;
tv_nsec %= 1000000000;
if (tv_nsec < 0 && tv_sec > 0) {
tv_sec--;
tv_nsec += 1000000000;
} else if (tv_sec < 0 && tv_nsec > 0) {
tv_sec++;
tv_nsec -= 1000000000;
}
r->tv_sec = tv_sec;
r->tv_nsec = tv_nsec;
return r;
}
//! Take the absolute walue of a delta time. //! Take the absolute walue of a delta time.
/*! /*!
'result' = |'t'| 'result' = |'t'|
A NULL address => abs value is written to 't'. A NULL address => abs value is written to 't'.
Returns the address to the resulting time. Returns the address to the resulting time.
Input arguments containing invalid times will
cause an exception.
*/ */
pwr_tDeltaTime * pwr_tDeltaTime *
...@@ -334,9 +531,45 @@ time_Dabs ( ...@@ -334,9 +531,45 @@ time_Dabs (
return r; return r;
} }
//! Take the absolute walue of a delta time.
/*!
'result' = |'t'|
A NULL address => abs value is written to 't'.
Returns the address to the resulting time.
If any input argument contains an invalid time
an invalid time, pwr_cNotADeltaTime, is returned.
*/
pwr_tDeltaTime *
time_Dabs_NE (
pwr_tDeltaTime *result,
pwr_tDeltaTime *t
)
{
pwr_tDeltaTime *r = result;
if (r == NULL) r = t;
if ( notADeltaTime(t)) {
*r = pwr_cNotADeltaTime;
return r;
}
if (r->tv_sec < 0) r->tv_sec = -r->tv_sec;
if (r->tv_nsec < 0) r->tv_nsec = -r->tv_nsec;
return r;
}
//! Add two delta times, the result is also delta. //! Add two delta times, the result is also delta.
/*! If 'result' is NULL then 'a' will be added to 't'. */ /*! If 'result' is NULL then 'a' will be added to 't'.
Input arguments containing invalid times will
cause an exception.
*/
pwr_tDeltaTime * pwr_tDeltaTime *
time_Dadd ( time_Dadd (
...@@ -370,7 +603,49 @@ time_Dadd ( ...@@ -370,7 +603,49 @@ time_Dadd (
return r; return r;
} }
//! Add two delta times, the result is also delta.
/*! If 'result' is NULL then 'a' will be added to 't'.
If any input argument contains an invalid time
an invalid time, pwr_cNotADeltaTime, is returned.
*/
pwr_tDeltaTime *
time_Dadd_NE (
pwr_tDeltaTime *result,
pwr_tDeltaTime *t,
pwr_tDeltaTime *a
)
{
pwr_tDeltaTime *r = result;
pwr_tInt64 tv_nsec, tv_sec;
if (result == NULL) r = t;
if ( notADeltaTime(t) || notADeltaTime(a)) {
*r = pwr_cNotADeltaTime;
return r;
}
tv_nsec = t->tv_nsec + a->tv_nsec;
tv_sec = t->tv_sec + a->tv_sec + (tv_nsec / 1000000000);
tv_nsec = tv_nsec % 1000000000;
if (tv_nsec < 0 && tv_sec > 0) {
tv_sec--;
tv_nsec += 1000000000;
} else if (tv_sec < 0 && tv_nsec > 0) {
tv_sec++;
tv_nsec -= 1000000000;
}
r->tv_sec = tv_sec;
r->tv_nsec = tv_nsec;
return r;
}
//! Compare two delta times. //! Compare two delta times.
/*! Returns \n /*! Returns \n
1 if t1 > t2 \n 1 if t1 > t2 \n
...@@ -379,6 +654,9 @@ time_Dadd ( ...@@ -379,6 +654,9 @@ time_Dadd (
If argument 't2' is NULL the comparison will If argument 't2' is NULL the comparison will
be done as if t2 == 0. be done as if t2 == 0.
Input arguments containing invalid times will
cause an exception.
*/ */
int int
...@@ -402,7 +680,42 @@ time_Dcomp ( ...@@ -402,7 +680,42 @@ time_Dcomp (
} }
return ((t1->tv_sec > t2->tv_sec) ? 1 : -1); return ((t1->tv_sec > t2->tv_sec) ? 1 : -1);
} }
//! Compare two delta times.
/*! Returns \n
1 if t1 > t2 \n
0 if t1 == t2 \n
-1 if t1 < t2 \n
If argument 't2' is NULL the comparison will
be done as if t2 == 0.
If any input argument contains an invalid time
-2 is returned.
*/
int
time_Dcomp_NE (
pwr_tDeltaTime *t1,
pwr_tDeltaTime *t2
)
{
static pwr_tDeltaTime null = {0, 0};
if (t2 == NULL)
t2 = &null;
if ( notADeltaTime(t1) || notADeltaTime(t2))
return -2;
if (t1->tv_sec == t2->tv_sec) {
if (t1->tv_nsec == t2->tv_nsec)
return 0;
return ((t1->tv_nsec > t2->tv_nsec) ? 1 : -1);
}
return ((t1->tv_sec > t2->tv_sec) ? 1 : -1);
}
//! Negate a delta time, //! Negate a delta time,
/*! /*!
result = -d result = -d
...@@ -410,6 +723,9 @@ time_Dcomp ( ...@@ -410,6 +723,9 @@ time_Dcomp (
If 'result' argument is NULL If 'result' argument is NULL
then 'd' will be used as resultant. then 'd' will be used as resultant.
Returns the address to the resulting time. Returns the address to the resulting time.
Input arguments containing invalid times will
cause an exception.
*/ */
pwr_tDeltaTime * pwr_tDeltaTime *
...@@ -429,9 +745,46 @@ time_Dneg ( ...@@ -429,9 +745,46 @@ time_Dneg (
return r; return r;
} }
//! Negate a delta time,
/*!
result = -d
If 'result' argument is NULL
then 'd' will be used as resultant.
Returns the address to the resulting time.
If any input argument contains an invalid time
an invalid time, pwr_cNotADeltaTime, is returned.
*/
pwr_tDeltaTime *
time_Dneg_NE (
pwr_tDeltaTime *result,
pwr_tDeltaTime *t
)
{
pwr_tDeltaTime *r = result;
if (r == NULL) r = t;
if ( notADeltaTime(t)) {
*r = pwr_cNotADeltaTime;
return r;
}
r->tv_sec = -r->tv_sec;
r->tv_nsec = -r->tv_nsec;
return r;
}
//! Subtract two delta times. //! Subtract two delta times.
/*! The result is also delta. */ /*! The result is also delta.
Input arguments containing invalid times will
cause an exception.
*/
pwr_tDeltaTime * pwr_tDeltaTime *
time_Dsub ( time_Dsub (
...@@ -464,6 +817,47 @@ time_Dsub ( ...@@ -464,6 +817,47 @@ time_Dsub (
return r; return r;
} }
//! Subtract two delta times.
/*! The result is also delta.
If any input argument contains an invalid time
an invalid time, pwr_cNotADeltaTime, is returned.
*/
pwr_tDeltaTime *
time_Dsub_NE (
pwr_tDeltaTime *result,
pwr_tDeltaTime *t,
pwr_tDeltaTime *s
)
{
pwr_tInt64 tv_nsec = t->tv_nsec - s->tv_nsec;
pwr_tInt64 tv_sec = t->tv_sec - s->tv_sec;
pwr_tDeltaTime *r = result;
if (r == NULL) r = t;
if ( notADeltaTime(t) || notADeltaTime(s)) {
*r = pwr_cNotADeltaTime;
return r;
}
tv_sec = tv_sec + tv_nsec / 1000000000;
tv_nsec = tv_nsec % 1000000000;
if (tv_nsec < 0 && tv_sec > 0) {
tv_sec--;
tv_nsec += 1000000000;
} else if (tv_sec < 0 && tv_nsec > 0) {
tv_sec++;
tv_nsec -= 1000000000;
}
r->tv_sec = tv_sec;
r->tv_nsec = tv_nsec;
return r;
}
//! Convert a delta time to ascii string. //! Convert a delta time to ascii string.
...@@ -481,6 +875,12 @@ time_DtoAscii ( ...@@ -481,6 +875,12 @@ time_DtoAscii (
if (dt == NULL) if (dt == NULL)
return TIME__IVDTIME; return TIME__IVDTIME;
if ( notADeltaTime(dt)) {
strncpy(buf, "NotADeltaTime", bufsize);
buf[bufsize-1] = '\0';
return TIME__NADT;
}
day = div(dt->tv_sec, 24 * 3600); day = div(dt->tv_sec, 24 * 3600);
hour = div(day.rem, 3600); hour = div(day.rem, 3600);
min = div(hour.rem, 60); min = div(hour.rem, 60);
...@@ -526,9 +926,13 @@ time_AtoAscii ( ...@@ -526,9 +926,13 @@ time_AtoAscii (
pwr_tTime time; pwr_tTime time;
pwr_tTime *tp; pwr_tTime *tp;
if ( ts && notATime(ts)) {
strncpy(buf, "NotATime", bufsize);
buf[bufsize-1] = '\0';
return TIME__NAT;
}
if (ts == NULL) if (ts == NULL) {
{
time_GetTime(&time); time_GetTime(&time);
tp = &time; tp = &time;
} }
...@@ -908,6 +1312,8 @@ time_AtoFormAscii ( ...@@ -908,6 +1312,8 @@ time_AtoFormAscii (
} }
//! Convert millisec to timespec. //! Convert millisec to timespec.
/*!
Not thread safe if dt is NULL. */
pwr_tDeltaTime * pwr_tDeltaTime *
time_MsToD ( time_MsToD (
...@@ -916,7 +1322,7 @@ time_MsToD ( ...@@ -916,7 +1322,7 @@ time_MsToD (
) )
{ {
static pwr_tDeltaTime time; static pwr_tDeltaTime time;
static pwr_tDeltaTime *t = &time; pwr_tDeltaTime *t = &time;
if (dt != NULL) t = dt; if (dt != NULL) t = dt;
...@@ -927,6 +1333,8 @@ time_MsToD ( ...@@ -927,6 +1333,8 @@ time_MsToD (
} }
//! Convert float to time. //! Convert float to time.
/*!
Not thread safe if dt is NULL. */
pwr_tDeltaTime * pwr_tDeltaTime *
time_FloatToD ( time_FloatToD (
...@@ -935,16 +1343,25 @@ time_FloatToD ( ...@@ -935,16 +1343,25 @@ time_FloatToD (
) )
{ {
static pwr_tDeltaTime time; static pwr_tDeltaTime time;
static pwr_tDeltaTime *t = &time; pwr_tDeltaTime *t = &time;
if (dt != NULL) t = dt; if (dt != NULL) t = dt;
if ( isnan(f)) {
*t = pwr_cNotADeltaTime;
return t;
}
t->tv_sec = f; t->tv_sec = f;
t->tv_nsec = (f - t->tv_sec) * 1e9; t->tv_nsec = (f - t->tv_sec) * 1e9;
return t; return t;
} }
//! Convert double to time.
/*!
Not thread safe if dt is NULL. */
pwr_tDeltaTime * pwr_tDeltaTime *
time_Float64ToD ( time_Float64ToD (
pwr_tDeltaTime *dt, pwr_tDeltaTime *dt,
...@@ -952,10 +1369,15 @@ time_Float64ToD ( ...@@ -952,10 +1369,15 @@ time_Float64ToD (
) )
{ {
static pwr_tDeltaTime time; static pwr_tDeltaTime time;
static pwr_tDeltaTime *t = &time; pwr_tDeltaTime *t = &time;
if (dt != NULL) t = dt; if (dt != NULL) t = dt;
if ( isnan(f)) {
*t = pwr_cNotADeltaTime;
return t;
}
t->tv_sec = f; t->tv_sec = f;
t->tv_nsec = (f - t->tv_sec) * 1e9; t->tv_nsec = (f - t->tv_sec) * 1e9;
...@@ -964,6 +1386,9 @@ time_Float64ToD ( ...@@ -964,6 +1386,9 @@ time_Float64ToD (
//! Convert time to Float32. //! Convert time to Float32.
/*!
Not thread safe if f is NULL.
*/
pwr_tFloat32 pwr_tFloat32
time_DToFloat ( time_DToFloat (
...@@ -972,12 +1397,18 @@ time_DToFloat ( ...@@ -972,12 +1397,18 @@ time_DToFloat (
) )
{ {
static pwr_tFloat32 flt; static pwr_tFloat32 flt;
pwr_tFloat32 *fp = &flt;
if (f != NULL) fp = f;
flt = 1e-9 * dt->tv_nsec + dt->tv_sec; if ( notADeltaTime(dt)) {
*fp = NAN;
return *fp;
}
if (f != NULL) *f = flt; *fp = 1e-9 * dt->tv_nsec + dt->tv_sec;
return flt; return *fp;
} }
//! Convert time to Float64. //! Convert time to Float64.
...@@ -989,12 +1420,18 @@ time_DToFloat64 ( ...@@ -989,12 +1420,18 @@ time_DToFloat64 (
) )
{ {
static pwr_tFloat64 flt; static pwr_tFloat64 flt;
pwr_tFloat64 *fp = &flt;
flt = 1e-9 * dt->tv_nsec + dt->tv_sec; if (f != NULL) fp = f;
if ( notADeltaTime(dt)) {
*fp = NAN;
return *fp;
}
if (f != NULL) *f = flt; *fp = 1e-9 * dt->tv_nsec + dt->tv_sec;
return flt; return *fp;
} }
time_tClock time_tClock
......
...@@ -160,20 +160,29 @@ typedef enum { ...@@ -160,20 +160,29 @@ typedef enum {
int time_IsNull (pwr_tTime *t1); int time_IsNull (pwr_tTime *t1);
pwr_tTime * time_Aabs (pwr_tTime*, pwr_tTime*); pwr_tTime * time_Aabs (pwr_tTime*, pwr_tTime*);
pwr_tTime * time_Aadd (pwr_tTime*, pwr_tTime*, pwr_tDeltaTime*); pwr_tTime * time_Aadd (pwr_tTime*, pwr_tTime*, pwr_tDeltaTime*);
pwr_tTime * time_Aadd_NE (pwr_tTime*, pwr_tTime*, pwr_tDeltaTime*);
int time_Acomp (pwr_tTime*, pwr_tTime*); int time_Acomp (pwr_tTime*, pwr_tTime*);
int time_Acomp_NE (pwr_tTime*, pwr_tTime*);
pwr_tDeltaTime * time_Adiff (pwr_tDeltaTime*, pwr_tTime*, pwr_tTime*); pwr_tDeltaTime * time_Adiff (pwr_tDeltaTime*, pwr_tTime*, pwr_tTime*);
pwr_tDeltaTime * time_Adiff_NE (pwr_tDeltaTime*, pwr_tTime*, pwr_tTime*);
pwr_tTime * time_Aneg (pwr_tTime*, pwr_tTime*); pwr_tTime * time_Aneg (pwr_tTime*, pwr_tTime*);
pwr_tTime * time_Asub (pwr_tTime*, pwr_tTime*, pwr_tDeltaTime*); pwr_tTime * time_Asub (pwr_tTime*, pwr_tTime*, pwr_tDeltaTime*);
pwr_tTime * time_Asub_NE (pwr_tTime*, pwr_tTime*, pwr_tDeltaTime*);
pwr_tDeltaTime * time_Dabs (pwr_tDeltaTime*, pwr_tDeltaTime*); pwr_tDeltaTime * time_Dabs (pwr_tDeltaTime*, pwr_tDeltaTime*);
pwr_tDeltaTime * time_Dabs_NE (pwr_tDeltaTime*, pwr_tDeltaTime*);
pwr_tDeltaTime * time_Dadd (pwr_tDeltaTime*, pwr_tDeltaTime*, pwr_tDeltaTime*); pwr_tDeltaTime * time_Dadd (pwr_tDeltaTime*, pwr_tDeltaTime*, pwr_tDeltaTime*);
pwr_tDeltaTime * time_Dadd_NE (pwr_tDeltaTime*, pwr_tDeltaTime*, pwr_tDeltaTime*);
pwr_tDeltaTime * time_Dneg (pwr_tDeltaTime*, pwr_tDeltaTime*); pwr_tDeltaTime * time_Dneg (pwr_tDeltaTime*, pwr_tDeltaTime*);
pwr_tDeltaTime * time_Dneg_NE (pwr_tDeltaTime*, pwr_tDeltaTime*);
pwr_tDeltaTime * time_Dsub (pwr_tDeltaTime*, pwr_tDeltaTime*, pwr_tDeltaTime*); pwr_tDeltaTime * time_Dsub (pwr_tDeltaTime*, pwr_tDeltaTime*, pwr_tDeltaTime*);
pwr_tDeltaTime * time_Dsub_NE (pwr_tDeltaTime*, pwr_tDeltaTime*, pwr_tDeltaTime*);
#if defined (OS_VMS) || defined(OS_ELN) #if defined (OS_VMS) || defined(OS_ELN)
pwr_tStatus time_Dmul (pwr_tDeltaTime*, pwr_tDeltaTime*, pwr_tInt32); pwr_tStatus time_Dmul (pwr_tDeltaTime*, pwr_tDeltaTime*, pwr_tInt32);
#endif #endif
int time_Dcomp (pwr_tDeltaTime*, pwr_tDeltaTime*); int time_Dcomp (pwr_tDeltaTime*, pwr_tDeltaTime*);
int time_Dcomp_NE (pwr_tDeltaTime*, pwr_tDeltaTime*);
pwr_tStatus time_DtoAscii (pwr_tDeltaTime*, int, char*, int); pwr_tStatus time_DtoAscii (pwr_tDeltaTime*, int, char*, int);
pwr_tStatus time_AtoAscii (pwr_tTime*, time_eFormat, char*, int); pwr_tStatus time_AtoAscii (pwr_tTime*, time_eFormat, char*, int);
pwr_tStatus time_AsciiToD (const char*, pwr_tDeltaTime*); pwr_tStatus time_AsciiToD (const char*, pwr_tDeltaTime*);
......
...@@ -109,35 +109,35 @@ ...@@ -109,35 +109,35 @@
@aref atadd AtAdd @aref atadd AtAdd
*/ */
#define AtAdd_exec(obj,t1,t2) \ #define AtAdd_exec(obj,t1,t2) \
time_Aadd( &obj->ActVal, &t1, &t2); time_Aadd_NE( &obj->ActVal, &t1, &t2);
/*_* /*_*
DTADD DTADD
@aref dtadd DtAdd @aref dtadd DtAdd
*/ */
#define DtAdd_exec(obj,t1,t2) \ #define DtAdd_exec(obj,t1,t2) \
time_Dadd( &obj->ActVal, &t1, &t2); time_Dadd_NE( &obj->ActVal, &t1, &t2);
/*_* /*_*
ATSUB ATSUB
@aref atsub AtSub @aref atsub AtSub
*/ */
#define AtSub_exec(obj,t1,t2) \ #define AtSub_exec(obj,t1,t2) \
time_Adiff( &obj->ActVal, &t1, &t2); time_Adiff_NE( &obj->ActVal, &t1, &t2);
/*_* /*_*
ATDTSUB ATDTSUB
@aref atdtsub AtDtSub @aref atdtsub AtDtSub
*/ */
#define AtDtSub_exec(obj,t1,t2) \ #define AtDtSub_exec(obj,t1,t2) \
time_Asub( &obj->ActVal, &t1, &t2); time_Asub_NE( &obj->ActVal, &t1, &t2);
/*_* /*_*
DTSUB DTSUB
@aref dtsub DtSub @aref dtsub DtSub
*/ */
#define DtSub_exec(obj,t1,t2) \ #define DtSub_exec(obj,t1,t2) \
time_Dsub( &obj->ActVal, &t1, &t2); time_Dsub_NE( &obj->ActVal, &t1, &t2);
/*_* /*_*
DTTOA DTTOA
...@@ -165,42 +165,42 @@ ...@@ -165,42 +165,42 @@
@aref atgreaterthan AtGreaterThan @aref atgreaterthan AtGreaterThan
*/ */
#define AtGreaterThan_exec(obj,t1,t2) \ #define AtGreaterThan_exec(obj,t1,t2) \
obj->Status = (time_Acomp( &t1, &t2) == 1); obj->Status = (time_Acomp_NE( &t1, &t2) == 1);
/*_* /*_*
ATLESSTHAN ATLESSTHAN
@aref atlessthan AtLessThan @aref atlessthan AtLessThan
*/ */
#define AtLessThan_exec(obj,t1,t2) \ #define AtLessThan_exec(obj,t1,t2) \
obj->Status = (time_Acomp( &t1, &t2) == -1); obj->Status = (time_Acomp_NE( &t1, &t2) == -1);
/*_* /*_*
ATEQUAL ATEQUAL
@aref atequal AtEqual @aref atequal AtEqual
*/ */
#define AtEqual_exec(obj,t1,t2) \ #define AtEqual_exec(obj,t1,t2) \
obj->Status = (time_Acomp( &t1, &t2) == 0); obj->Status = (time_Acomp_NE( &t1, &t2) == 0);
/*_* /*_*
DTGREATERTHAN DTGREATERTHAN
@aref dtgreaterthan DtGreaterThan @aref dtgreaterthan DtGreaterThan
*/ */
#define DtGreaterThan_exec(obj,t1,t2) \ #define DtGreaterThan_exec(obj,t1,t2) \
obj->Status = (time_Dcomp( &t1, &t2) == 1); obj->Status = (time_Dcomp_NE( &t1, &t2) == 1);
/*_* /*_*
DTLESSTHAN DTLESSTHAN
@aref dtlessthan DtLessThan @aref dtlessthan DtLessThan
*/ */
#define DtLessThan_exec(obj,t1,t2) \ #define DtLessThan_exec(obj,t1,t2) \
obj->Status = (time_Dcomp( &t1, &t2) == -1); obj->Status = (time_Dcomp_NE( &t1, &t2) == -1);
/*_* /*_*
DTEQUAL DTEQUAL
@aref dtequalthan DtEqual @aref dtequalthan DtEqual
*/ */
#define DtEqual_exec(obj,t1,t2) \ #define DtEqual_exec(obj,t1,t2) \
obj->Status = (time_Dcomp( &t1, &t2) == 0); obj->Status = (time_Dcomp_NE( &t1, &t2) == 0);
/*_* /*_*
LOCALTIME LOCALTIME
......
...@@ -47,3 +47,5 @@ ivtime <invalid time> /error ...@@ -47,3 +47,5 @@ ivtime <invalid time> /error
ivdtime <invalid delta time> /error ivdtime <invalid delta time> /error
negtime <negative time> /info negtime <negative time> /info
clkchange <clock has changed> /info clkchange <clock has changed> /info
nadt <Not a deltatime> /error
nat <Not a time> /error
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
#include "co_api_user.h" #include "co_api_user.h"
#include "co_msg.h" #include "co_msg.h"
#include "co_syi.h" #include "co_syi.h"
#include "co_time_msg.h"
#include "pwr_baseclasses.h" #include "pwr_baseclasses.h"
#include "rt_xnav_msg.h" #include "rt_xnav_msg.h"
#include "flow.h" #include "flow.h"
...@@ -869,7 +870,7 @@ void XNav::attrvalue_to_string( int type_id, pwr_tTid tid, void *value_ptr, ...@@ -869,7 +870,7 @@ void XNav::attrvalue_to_string( int type_id, pwr_tTid tid, void *value_ptr,
default: default:
sts = time_AtoAscii( (pwr_tTime *) value_ptr, time_eFormat_DateAndTime, sts = time_AtoAscii( (pwr_tTime *) value_ptr, time_eFormat_DateAndTime,
timstr, sizeof(timstr)); timstr, sizeof(timstr));
if ( EVEN(sts)) if ( EVEN(sts) && sts != TIME__NAT)
strcpy( timstr, "-"); strcpy( timstr, "-");
*len = snprintf( str, size, "%s", timstr); *len = snprintf( str, size, "%s", timstr);
} }
...@@ -884,7 +885,7 @@ void XNav::attrvalue_to_string( int type_id, pwr_tTid tid, void *value_ptr, ...@@ -884,7 +885,7 @@ void XNav::attrvalue_to_string( int type_id, pwr_tTid tid, void *value_ptr,
default: default:
sts = time_DtoAscii( (pwr_tDeltaTime *) value_ptr, 1, sts = time_DtoAscii( (pwr_tDeltaTime *) value_ptr, 1,
timstr, sizeof(timstr)); timstr, sizeof(timstr));
if ( EVEN(sts)) if ( EVEN(sts) && sts != TIME__NADT)
strcpy( timstr, "Undefined time"); strcpy( timstr, "Undefined time");
*len = snprintf( str, size, "%s", timstr); *len = snprintf( str, size, "%s", timstr);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment