lib: Fix time-cast for dboard_iface::sleep()

The previous cast would take the number of nanoseconds, cast them to an
integer, and then add that to the previous command time. Now, we cast
the nanoseconds duration to a number of seconds, represented as a double,
first.
This commit is contained in:
Martin Braun 2023-07-11 12:35:45 +02:00 committed by michael-west
parent 9ddbe93fcb
commit a5ee66ade9

View file

@ -19,7 +19,10 @@ void dboard_iface::sleep(const std::chrono::nanoseconds& time)
// FIXME: Create a delay in the FPGA on the device.
auto cmd_time = get_command_time();
if (cmd_time.get_real_secs() != 0.0) {
set_command_time(cmd_time + uhd::time_spec_t(time.count()));
// Cast to double-represented duration so that time_spec_t() ctor knows
// which overloaded ctor to choose
const std::chrono::duration<double> time_s = time;
set_command_time(cmd_time + uhd::time_spec_t(time_s.count()));
} else {
// nanosleep is not really accurate in userland and it is also not very
// cross-platform. So just sleep for the minimum amount of time in us.