DUDS
Distributed Update of Data from Something
CppClock.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of the DUDS project. It is subject to the BSD-style
3  * license terms in the LICENSE file found in the top-level directory of this
4  * distribution and at https://github.com/jjackowski/duds/blob/master/LICENSE.
5  * No part of DUDS, including this file, may be copied, modified, propagated,
6  * or distributed except according to the terms contained in the LICENSE file.
7  *
8  * Copyright (C) 2017 Jeff Jackowski
9  */
10 #ifndef CPPCLOCK_HPP
11 #define CPPCLOCK_HPP
12 
14 
15 namespace duds { namespace hardware { namespace devices { namespace clocks {
16 
20 constexpr boost::uuids::uuid CppClockDeviceId = {
21  0x7f, 0x3a, 0x9f, 0x9a,
22  0x82, 0x59,
23  0x43, 0xde,
24  0x97, 0xac,
25  0xd2, 0xea, 0x2a, 0x48, 0x51, 0xb2
26 };
27 
44 template<class CLK, class SVT, class SQT, class TVT, class TQT>
46 public duds::hardware::devices::clocks::GenericClock<SVT, SQT, TVT, TQT> {
47 public:
52  typedef CLK Clock;
53 protected:
56  struct Token { };
57 public:
63  GenericClock<SVT, SQT, TVT, TQT>(CppClockDeviceId) { }
67  static std::shared_ptr< GenericCppClock <CLK, SVT, SQT, TVT, TQT> > make() {
68  return std::make_shared< GenericCppClock <CLK, SVT, SQT, TVT, TQT> >(
69  Token()
70  );
71  }
72  virtual void sampleTime(typename Measurement::TimeSample &time) {
73  time.accuracy = time.precision = time.estError =
74  duds::data::unspecified<TQT>();
75  time.resolution = (TQT)Clock::period::num / (TQT)Clock::period::den;
76  time.value = Clock::now();
77  }
78  virtual void sample() {
79  std::shared_ptr<Measurement> m =
80  std::make_shared<Measurement>();
81  m->measured.accuracy = m->measured.precision = m->measured.estError =
82  duds::data::unspecified<SQT>();
83  m->measured.resolution = (SQT)Clock::period::num / (SQT)Clock::period::den;
84  typename Clock::time_point ctp = Clock::now();
85  m->measured.value = ctp;
86  // no timestamp
87  m->timestamp.clear();
88  // store the measurement
90  }
91  virtual void sample(const ClockSptr &clock) {
92  std::shared_ptr<Measurement> m =
93  std::make_shared<Measurement>();
94  m->measured.accuracy = m->measured.precision = m->measured.estError =
95  duds::data::unspecified<SQT>();
96  m->measured.resolution = (SQT)Clock::period::num / (SQT)Clock::period::den;
97  typename Clock::time_point ctp = Clock::now();
98  m->measured.value = ctp;
99  // if the supplied clock driver is this clock driver . . .
100  if (this == clock.get()) {
101  // sample the clock just once
102  m->timestamp.value = ctp;
103  //std::chrono::time_point_cast
104  //<typename TVT::duration>(ctp);
105  m->timestamp.accuracy = m->timestamp.precision =
106  m->timestamp.estError = duds::data::unspecified<TQT>();
107  m->timestamp.resolution = (TQT)Clock::period::num /
108  (TQT)Clock::period::den;
109  } else if (clock) {
110  // sample the other clock
111  clock->sampleTime(m->timestamp);
112  } else {
113  // no timestamp
114  m->timestamp.clear();
115  }
116  // store the measurement
118  }
119  virtual bool unambiguous() const noexcept {
120  return false;
121  }
122 };
123 
127 typedef GenericCppClock<
128  duds::time::interstellar::NanoClock, // could be FemtoClock
130  double,
132  float
134 
135 typedef std::shared_ptr<CppClock> CppClockSptr;
136 
137 } } } }
138 
139 
140 #endif // #ifndef CPPCLOCK_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...
The clock driver for C++ clocks that meet the requirements of the TrivialClock concept.
Definition: CppClock.hpp:45
Provides Interstellar Time in Nanoseconds.
virtual void sampleTime(typename Measurement::TimeSample &time)
Samples the time from the clock device without storing the result in the clock&#39;s sensor object...
Definition: CppClock.hpp:72
virtual bool unambiguous() const noexcept
Returns true if the clock properly reports the time during a leap second.
Definition: CppClock.hpp:119
std::shared_ptr< CppClock > CppClockSptr
Definition: CppClock.hpp:135
QT estError
The estimated error of the observation.
Definition: Sample.hpp:120
GenericCppClock< duds::time::interstellar::NanoClock, duds::data::GenericValue, double, duds::time::interstellar::NanoTime, float > CppClock
General use C++ clock driver type.
Definition: CppClock.hpp:133
static std::shared_ptr< GenericCppClock< CLK, SVT, SQT, TVT, TQT > > make()
Makes a new clock device object.
Definition: CppClock.hpp:67
GenericCppClock(Token)
Constructs a new clock device with its UUID.
Definition: CppClock.hpp:62
move_impl move(unsigned int c, unsigned int r)
Display stream manipulator that moves the display cursor to the given location.
constexpr boost::uuids::uuid CppClockDeviceId
The UUID for the C++ clock device.
Definition: CppClock.hpp:20
QT resolution
The expected resolution of the instrument under the conditions in which the sample was taken...
Definition: Sample.hpp:128
VT value
The value sampled from the insturment.
Definition: Sample.hpp:102
Represents something with one or more sensors that are sampled through the same hardware.
Definition: Device.hpp:34
std::shared_ptr< GenericClock< SVT, SQT, TVT, TQT > > ClockSptr
Definition: Clock.hpp:84
The foundation to a clock driver.
Definition: Clock.hpp:78
QT accuracy
The expected accuracy of the instrument under the conditions in which the sample was taken...
Definition: Sample.hpp:107
Stores a sample of something along with a timestamp stored as a sample from a clock.
Definition: Measurement.hpp:24
virtual void sample()
Samples the time from this clock stores it in the measured field of the Measurement object of the dev...
Definition: CppClock.hpp:78
duds::data::GenericMeasurement< SVT, SQT, TVT, TQT > Measurement
Definition: CppClock.hpp:48
virtual void sample(const ClockSptr &clock)
Samples the time from this clock and the given clock, then stores the measurement.
Definition: CppClock.hpp:91
QT precision
The expected precision of the instrument under the conditions in which the sample was taken...
Definition: Sample.hpp:114
NanoClock::time_point NanoTime
A point in time in Interstellar Time stored in Nanoseconds.
void setMeasurement(const ConstMeasurementSptr &store, int sIdx=0) const
Updates the current measurement of a member sensor.
Definition: Device.hpp:105