10 #ifndef POSIXCLOCK_HPP 11 #define POSIXCLOCK_HPP 26 namespace duds {
namespace hardware {
namespace devices {
namespace clocks {
37 typedef boost::error_info<struct Info_posixclockid, clockid_t>
PosixClockId;
43 0x41, 0xba, 0xe3, 0x09,
47 0x5b, 0x24, 0xc3, 0x99, 0xc7, 0xeb
70 template<
class SVT,
class SQT,
class TVT,
class TQT>
122 int res = clock_gettime(clk, &ts);
136 template <
class Sample>
139 if (std::is_same<SQT, typename Sample::Quality>::value) {
140 dest.resolution = sampleResolution;
142 dest.resolution = timeResolution;
145 dest.accuracy = dest.estError = dest.precision =
146 duds::data::unspecified<typename Sample::Quality>();
169 GenericClock<SVT, SQT, TVT, TQT>(PosixClockDeviceId), clk(id), offset(os) {
172 int res = clock_getres(clk, &ts);
181 sampleResolution, rez);
183 timeResolution, rez);
197 static std::shared_ptr< GenericPosixClock <SVT, SQT, TVT, TQT> >
make(
198 clockid_t
id = CLOCK_REALTIME,
int os = 0
200 return std::make_shared< GenericPosixClock <SVT, SQT, TVT, TQT> >(
206 setSample(time, sum);
209 std::shared_ptr<Measurement> m =
210 std::make_shared<Measurement>();
212 setSample(m->measured, sum);
214 m->timestamp.clear();
219 std::shared_ptr<Measurement> m =
220 std::make_shared<Measurement>();
222 setSample(m->measured, sum);
224 if (
this == clock.get()) {
226 setSample(m->timestamp, sum);
229 clock->sampleTime(m->timestamp);
232 m->timestamp.clear();
257 #endif // #ifndef POSIXCLOCK_HPP boost::variant< std::string, duds::general::LanguageTaggedString, std::array< std::int32_t, 4 >, std::array< std::int64_t, 2 >, duds::data::int128_w, std::array< float, 4 >, std::array< double, 2 >, double, duds::data::Quantity, boost::recursive_wrapper< duds::data::QuantityNddArray >, duds::time::interstellar::Femtoseconds, duds::time::interstellar::Nanoseconds, duds::time::interstellar::FemtoTime, duds::time::interstellar::NanoTime, boost::uuids::uuid, boost::recursive_wrapper< duds::data::GenericValueTable >, std::shared_ptr< std::vector< char > >> GenericValue
A general value of a type can be serialized for transmission over a network and can be used with a re...
GenericPosixClock< duds::data::GenericValue, double, duds::time::interstellar::NanoTime, float > PosixClock
General use POSIX clock driver type.
An attempt was made to use a POSIX clock that is not supported by the system.
boost::multiprecision::int128_t int128_t
The type used for 128-bit integers.
boost::error_info< struct Info_posixclockid, clockid_t > PosixClockId
Indicates the POSIX clockid_t in an error involving a POSIX clock.
The base type for errors from clocks.
move_impl move(unsigned int c, unsigned int r)
Display stream manipulator that moves the display cursor to the given location.
A clock driver to use clocks through the POSIX interface.
virtual void sample(const ClockSptr &clock)
Samples the time from this clock and the given clock, then stores the measurement.
std::shared_ptr< PosixClock > PosixClockSptr
GenericPosixClock(clockid_t id, int os, Token)
Construct a clock device for the given POSIX clock.
clockid_t clk
The POSIX clock id.
Represents something with one or more sensors that are sampled through the same hardware.
TQT timeResolution
The clock's resolution for use with time stamps.
GenericSample< GenericValue, double > Sample
A sample type that is good for general purpose use.
static duds::data::int128_t sum(const timespec &ts)
Sums the second and nanosecond fields given by the POSIX functions into a large integer.
int offset
An offset in seconds that is applied to the time provided by the clock.
std::shared_ptr< GenericClock< SVT, SQT, TVT, TQT > > ClockSptr
virtual bool unambiguous() const noexcept
Returns true if the clock properly reports the time during a leap second.
duds::data::GenericMeasurement< SVT, SQT, TVT, TQT > Measurement
void setSample(Sample &dest, const duds::data::int128_t &time) const
Sets the sample values based on the time sample.
The foundation to a clock driver.
SQT sampleResolution
The clock's resolution for use with samples.
virtual void sampleTime(typename Measurement::TimeSample &time)
Samples the time from the clock device without storing the result in the clock's sensor object...
Stores a sample of something along with a timestamp stored as a sample from a clock.
duds::data::int128_t doSample() const
Samples the time and adds in an offset.
virtual void sample()
Samples the time from this clock stores it in the measured field of the Measurement object of the dev...
static std::shared_ptr< GenericPosixClock< SVT, SQT, TVT, TQT > > make(clockid_t id=CLOCK_REALTIME, int os=0)
Makes a new clock device for a POSIX clock.
constexpr boost::uuids::uuid PosixClockDeviceId
The UUID for the POSIX clock device.
#define DUDS_THROW_EXCEPTION(x)
Works like BOOST_THROW_EXCEPTION, but includes a stack trace if DUDS_ERRORS_VERBOSE is defined...
NanoClock::time_point NanoTime
A point in time in Interstellar Time stored in Nanoseconds.