10 #ifndef LINUXCLOCK_HPP 11 #define LINUXCLOCK_HPP 15 #include <sys/timex.h> 16 #include <boost/exception/errinfo_api_function.hpp> 17 #include <boost/exception/errinfo_errno.hpp> 20 namespace duds {
namespace hardware {
namespace devices {
namespace clocks {
26 0xbf, 0x2d, 0x4a, 0x68,
30 0x38, 0xd1, 0xd5, 0x5b, 0x20, 0x74
51 template<
class SVT,
class SQT,
class TVT,
class TQT>
69 template <
class Sample>
74 if (src.status & STA_UNSYNC) {
76 dest.accuracy = dest.estError =
77 duds::data::unspecified<typename Sample::Quality>();
81 dest.accuracy, src.maxerror);
83 dest.estError, src.esterror);
87 dest.precision, src.precision);
88 dest.resolution = duds::data::unspecified<typename Sample::Quality>();
90 if (src.status & STA_NANO) {
98 dest.origin =
sens[0]->uuid();
110 int res = adjtimex(&tx);
114 boost::errinfo_api_function(
"adjtimex") <<
115 boost::errinfo_errno(errno)
121 tx.time.tv_sec += tx.tai;
129 time = tx.time.tv_usec;
130 if (tx.status & STA_NANO) {
131 time += tx.time.tv_sec * std::nano::den;
133 time += tx.time.tv_sec * std::micro::den;
143 GenericClock<SVT, SQT, TVT, TQT>(LinuxClockDeviceId) { }
147 static std::shared_ptr< GenericLinuxClock <SVT, SQT, TVT, TQT> >
make() {
148 return std::make_shared< GenericLinuxClock <SVT, SQT, TVT, TQT> >(
Token());
159 std::shared_ptr<Measurement> m =
160 std::make_shared<Measurement>();
164 m->timestamp.clear();
171 std::shared_ptr<Measurement> m =
172 std::make_shared<Measurement>();
176 if (
this == clock.get()) {
181 clock->sampleTime(m->timestamp);
184 m->timestamp.clear();
209 #endif // #ifndef LINUXCLOCK_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...
void setSample(Sample &dest, const timex &src, const duds::data::int128_t &time)
Takes a partially converted time from adjtimex(), completes the conversion, and places it in the dest...
boost::multiprecision::int128_t int128_t
The type used for 128-bit integers.
GenericLinuxClock< duds::data::GenericValue, double, duds::time::interstellar::NanoTime, float > LinuxClock
General use Linux clock driver type.
std::chrono::duration< std::int64_t > Seconds
Stores a duration in seconds.
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.
std::vector< SensorSptr > sens
Contains Sensor objects to represent all the kinds of data this device can collect.
virtual void sample(const ClockSptr &clock)
Samples the time from this clock and the given clock, then stores the measurement.
Represents something with one or more sensors that are sampled through the same hardware.
GenericSample< GenericValue, double > Sample
A sample type that is good for general purpose use.
virtual void sampleTime(typename Measurement::TimeSample &time)
Samples the time from the clock device without storing the result in the clock's sensor object...
GenericLinuxClock(Token)
Constructs a new clock device with its UUID.
std::shared_ptr< GenericClock< SVT, SQT, TVT, TQT > > ClockSptr
std::shared_ptr< LinuxClock > LinuxClockSptr
Uses the Linux specific adjtimex() function to query for the time and the quailty of the time sample...
static void doSample(timex &tx, duds::data::int128_t &time)
Samples the time by calling adjtimex() and computes the time in either microseconds or nanoseconds (w...
static std::shared_ptr< GenericLinuxClock< SVT, SQT, TVT, TQT > > make()
Makes a new clock device object.
The foundation to a clock driver.
Stores a sample of something along with a timestamp stored as a sample from a clock.
virtual void sample()
Samples the time from this clock stores it in the measured field of the Measurement object of the dev...
constexpr boost::uuids::uuid LinuxClockDeviceId
The UUID for the Linux clock device.
unique_ptr< Earth > earth
#define DUDS_THROW_EXCEPTION(x)
Works like BOOST_THROW_EXCEPTION, but includes a stack trace if DUDS_ERRORS_VERBOSE is defined...
virtual bool unambiguous() const noexcept
Returns true if the clock properly reports the time during a leap second.
NanoClock::time_point NanoTime
A point in time in Interstellar Time stored in Nanoseconds.
duds::data::GenericMeasurement< SVT, SQT, TVT, TQT > Measurement
void setMeasurement(const ConstMeasurementSptr &store, int sIdx=0) const
Updates the current measurement of a member sensor.