demo/insn: report start and end time as unsigned values
Report the seconds and microseconds values from the INSN_GTOD instructions as unsigned values to postpone the Y2038 problem to a Y2106 problem. Be a bit more careful with the conversion to a signed difference. We wouldn't normally expect time to go backwards, but it is possible if the system time is set to to an older time between the instructions. Also, in the description of INSN_GTOD in the Comedilib manual, explicitly mention that the seconds and microseconds values are unsigned.
This commit is contained in:
parent
e0ee6039eb
commit
a4dd004076
2 changed files with 16 additions and 5 deletions
19
demo/insn.c
19
demo/insn.c
|
@ -52,6 +52,7 @@ int main(int argc, char *argv[])
|
|||
comedi_insnlist il;
|
||||
lsampl_t t1[2], t2[2];
|
||||
lsampl_t data[MAX_SAMPLES];
|
||||
long diffus;
|
||||
struct parsed_options options;
|
||||
|
||||
init_parsed_options(&options);
|
||||
|
@ -102,14 +103,24 @@ int main(int argc, char *argv[])
|
|||
exit(-1);
|
||||
}
|
||||
|
||||
printf("initial time: %d.%06d\n", t1[0], t1[1]);
|
||||
printf("initial time: %u.%06u\n", t1[0], t1[1]);
|
||||
for(i = 0; i < options.n_scan; i++){
|
||||
printf("%d\n", data[i]);
|
||||
}
|
||||
printf("final time: %d.%06d\n", t2[0], t2[1]);
|
||||
printf("final time: %u.%06u\n", t2[0], t2[1]);
|
||||
|
||||
printf("difference (us): %ld\n",(long)(t2[0]-t1[0]) * 1000000 +
|
||||
(t2[1] - t1[1]));
|
||||
if (t2[0] >= t1[0]) {
|
||||
diffus = (long)(t2[0] - t1[0]);
|
||||
} else {
|
||||
diffus = -(long)(t1[0] - t2[0]);
|
||||
}
|
||||
diffus *= 1000000;
|
||||
if (t2[1] >= t1[1]) {
|
||||
diffus += (long)(t2[1] - t1[1]);
|
||||
} else {
|
||||
diffus -= (long)(t1[1] - t2[1]);
|
||||
}
|
||||
printf("difference (us): %ld\n", diffus);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -604,7 +604,7 @@ configure a subdevice
|
|||
<listitem>
|
||||
<para>
|
||||
read a timestamp, identical to <function>gettimeofday</function> except the seconds
|
||||
and microseconds values are of type <type><link linkend="ref-type-lsampl-t">lsampl_t</link></type>.
|
||||
and microseconds values are unsigned values of type <type><link linkend="ref-type-lsampl-t">lsampl_t</link></type>.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
|
Loading…
Add table
Reference in a new issue