trikRuntime
timeVal.h
Go to the documentation of this file.
1 /* Copyright 2015 - 2016 Anastasiia Kornilova.
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License. */
14 
15 #pragma once
16 #include <QtCore/qmetatype.h>
17 namespace trikKernel {
18 
20 class TimeVal
21 {
22 public:
23 
30  TimeVal(int sec, int mcsec);
31 
33  uint32_t packedUInt32() const;
34 
37  static TimeVal fromPackedUInt32(uint32_t packedTime);
38 
40  static int timeInterval(int packedTimeLeft, int packedTimeRight);
41 #if QT_VERSION < 0x050000
42  friend void *qMetaTypeConstructHelper<TimeVal>(const TimeVal *t);
45 #else
46  friend struct QtMetaTypePrivate::QMetaTypeFunctionHelper<TimeVal>;
47 #endif
48 
52  friend int operator-(const TimeVal &left, const TimeVal &right);
53 
54 private:
55  TimeVal() = default;
56 
57  explicit TimeVal(int packedTime);
58 
59  uint32_t mTime = 0;
60 
61  static const uint32_t mSecConst = 15625;
62  static const uint32_t mShift = 8;
63 };
64 
65 inline int operator-(const TimeVal &left, const TimeVal &right)
66 {
67  return (left.mTime - right.mTime) << TimeVal::mShift;
68 }
69 
70 }
71 
72 Q_DECLARE_METATYPE(trikKernel::TimeVal)
Definition: analogSensor.h:23
Structure of a time value in a convenient format.
Definition: timeVal.h:20
static TimeVal fromPackedUInt32(uint32_t packedTime)
Creates TimeVal using packed data.
Definition: timeVal.cpp:29
uint32_t packedUInt32() const
Returns packed data that shifted to the left on mShift bits.
Definition: timeVal.cpp:24
static int timeInterval(int packedTimeLeft, int packedTimeRight)
Counts time interval between two packed data of time.
Definition: timeVal.cpp:34
friend int operator-(const TimeVal &left, const TimeVal &right)
"Minus" operator is for computing time interval between two timestamps, returns value in microsends...
Definition: timeVal.h:65