Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libopendavinci/include/opendavinci/odcontext/base/Clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace odcontext {
* @param s Seconds.
* @param ps Partial microseconds.
*/
Clock(const uint32_t &s, const uint32_t &ps);
Clock(const uint32_t &s, const uint32_t &ps, const uint32_t &ns);

/**
* Copy constructor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace odcontext {
* @param s Seconds.
* @param ps Partial microseconds.
*/
ControlledTime(const uint32_t &s, const uint32_t &ps);
ControlledTime(const uint32_t &s, const uint32_t &ps, const uint32_t &ns);

/**
* Copy constructor.
Expand All @@ -62,6 +62,8 @@ namespace odcontext {

virtual int32_t getPartialMicroseconds() const;

virtual int32_t getPartialNanoseconds() const;

/**
* This method sets the seconds.
*
Expand All @@ -76,9 +78,17 @@ namespace odcontext {
*/
void setPartialMicroseconds(const int32_t &partialMS);

/**
* This method sets the partial nanoseconds.
*
* @param partialNS Partial nanoseconds.
*/
void setPartialNanoseconds(const int32_t &partialNS);

private:
int32_t m_seconds;
int32_t m_partialMicroseconds;
int32_t m_partialNanoseconds;
};

}
Expand Down
20 changes: 19 additions & 1 deletion libopendavinci/include/opendavinci/odcore/data/TimeStamp.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ namespace odcore {
*
* @param seconds Seconds.
* @param microseconds Microseconds.
* @param nanoseconds Nanoseconds.
*/
TimeStamp(const int32_t &seconds, const int32_t &microseconds);
TimeStamp(const int32_t &seconds, const int32_t &microseconds, const int32_t &nanoseconds);

virtual ~TimeStamp();

Expand Down Expand Up @@ -116,6 +117,14 @@ namespace odcore {
*/
long toMicroseconds() const;

/**
* This method converts the specified time into
* nanoseconds.
*
* @return This time converted into nanoseconds.
*/
long toNanoseconds() const;

/**
* This method returns the fractional microseconds
* to the next full second.
Expand All @@ -124,6 +133,14 @@ namespace odcore {
*/
int32_t getFractionalMicroseconds() const;

/**
* This method returns the fractional nanoseconds
* to the next full second.
*
* @return nanoseconds.
*/
int32_t getFractionalNanoseconds() const;

/**
* This method returns the seconds.
*
Expand Down Expand Up @@ -209,6 +226,7 @@ namespace odcore {
private:
int32_t m_seconds;
int32_t m_microseconds;
int32_t m_nanoseconds;

/**
* This method returns true if the given year is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,12 @@ namespace odcore {

virtual int32_t getPartialMicroseconds() const;

virtual int32_t getPartialNanoseconds() const;

private:
int32_t m_seconds;
int32_t m_partialMicroseconds;
int32_t m_partialNanoseconds;
};

}
Expand Down
8 changes: 8 additions & 0 deletions libopendavinci/include/opendavinci/odcore/wrapper/Time.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ namespace odcore {
*/
virtual int32_t getPartialMicroseconds() const = 0;

/**
* This method returns the partial nanoseconds from
* the next full second.
*
* @return Partial nanoseconds from the next full second.
*/
virtual int32_t getPartialNanoseconds() const = 0;

};

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,12 @@ namespace odcore {

virtual int32_t getPartialMicroseconds() const;

virtual int32_t getPartialNanoseconds() const;

private:
int32_t m_seconds;
int32_t m_partialMicroseconds;
int32_t m_partialNanoseconds;
};

}
Expand Down
4 changes: 2 additions & 2 deletions libopendavinci/src/odcontext/base/Clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ namespace odcontext {
Clock::Clock() :
m_theTime() {}

Clock::Clock(const uint32_t &s, const uint32_t &ps) :
m_theTime(s, ps) {}
Clock::Clock(const uint32_t &s, const uint32_t &ps, const uint32_t &ns) :
m_theTime(s, ps, ns) {}

Clock::Clock(const Clock &obj) :
m_theTime(obj.now()) {}
Expand Down
20 changes: 16 additions & 4 deletions libopendavinci/src/odcontext/base/ControlledTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,27 @@ namespace odcontext {
ControlledTime::ControlledTime() :
Time(),
m_seconds(0),
m_partialMicroseconds(0) {}
m_partialMicroseconds(0),
m_partialNanoseconds(0) {}

ControlledTime::ControlledTime(const uint32_t &s, const uint32_t &ps) :
ControlledTime::ControlledTime(const uint32_t &s, const uint32_t &ps, const uint32_t &ns) :
Time(),
m_seconds(s),
m_partialMicroseconds(ps) {}
m_partialMicroseconds(ps),
m_partialNanoseconds(ns) {}

ControlledTime::ControlledTime(const ControlledTime &ct) :
Time(ct),
m_seconds(ct.getSeconds()),
m_partialMicroseconds(ct.getPartialMicroseconds()) {}
m_partialMicroseconds(ct.getPartialMicroseconds()),
m_partialNanoseconds(ct.getPartialNanoseconds()) {}

ControlledTime::~ControlledTime() {}

ControlledTime& ControlledTime::operator=(const ControlledTime &ct) {
setSeconds(ct.getSeconds());
setPartialMicroseconds(ct.getPartialMicroseconds());
setPartialNanoseconds(ct.getPartialNanoseconds());

return (*this);
}
Expand All @@ -54,6 +58,10 @@ namespace odcontext {
return m_partialMicroseconds;
}

int32_t ControlledTime::getPartialNanoseconds() const {
return m_partialNanoseconds;
}

void ControlledTime::setSeconds(const int32_t &s) {
m_seconds = s;
}
Expand All @@ -62,5 +70,9 @@ namespace odcontext {
m_partialMicroseconds = partialMS;
}

void ControlledTime::setPartialNanoseconds(const int32_t &partialNS) {
m_partialNanoseconds = partialNS;
}

}
} // odcontext::base
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespace odcontext {
Lock l(m_timeMutex);
m_time.setSeconds(ct.getSeconds());
m_time.setPartialMicroseconds(ct.getPartialMicroseconds());
m_time.setPartialNanoseconds(ct.getPartialNanoseconds());
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ namespace odcore {
// Suspend this thread to the beginning of the secondsIncrement-th full second only
// if we are not executed with realtime flag because ManagedClientModule will do
// that for us.
Thread::usleepUntil(odcore::data::TimeStamp(odcore::data::TimeStamp().getSeconds() + secondsIncrement, 0));
Thread::usleepUntil(odcore::data::TimeStamp(odcore::data::TimeStamp().getSeconds() + secondsIncrement, 0, 0));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ namespace odcore {
// Check whether our clock was already initialized (i.e. getSeconds() > 0).
if (m_time.now().getSeconds() < 1) {
// Set seconds of our virtual clock to the clock from supercomponents.
m_time = odcontext::base::Clock(m_pulseMessage.getRealTimeFromSupercomponent().getSeconds(), 0);
m_time = odcontext::base::Clock(m_pulseMessage.getRealTimeFromSupercomponent().getSeconds(), 0, 0);
}

// Increment the virtual time by the nominal value of the time slice
Expand Down
12 changes: 6 additions & 6 deletions libopendavinci/src/odcore/data/Container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,23 @@ namespace odcore {
Container::Container() :
m_dataType(UNDEFINEDDATA),
m_serializedData(),
m_sent(TimeStamp(0, 0)),
m_received(TimeStamp(0, 0)) {}
m_sent(TimeStamp(0, 0, 0)),
m_received(TimeStamp(0, 0, 0)) {}

Container::Container(const SerializableData &serializableData) :
m_dataType(serializableData.getID()),
m_serializedData(),
m_sent(TimeStamp(0, 0)),
m_received(TimeStamp(0, 0)) {
m_sent(TimeStamp(0, 0, 0)),
m_received(TimeStamp(0, 0, 0)) {
// Get data for container.
m_serializedData << serializableData;
}

Container::Container(const SerializableData &serializableData, const int32_t &dataType) :
m_dataType(dataType),
m_serializedData(),
m_sent(TimeStamp(0, 0)),
m_received(TimeStamp(0, 0)) {
m_sent(TimeStamp(0, 0, 0)),
m_received(TimeStamp(0, 0, 0)) {
// Get data for container.
m_serializedData << serializableData;
}
Expand Down
53 changes: 45 additions & 8 deletions libopendavinci/src/odcore/data/TimeStamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,25 @@ namespace odcore {

TimeStamp::TimeStamp() :
m_seconds(0),
m_microseconds(0) {
m_microseconds(0),
m_nanoseconds(0) {
std::shared_ptr<odcore::wrapper::Time> time(odcore::wrapper::TimeFactory::getInstance().now());
if (time.get()) {
m_seconds = time->getSeconds();
m_microseconds = time->getPartialMicroseconds();
m_nanoseconds = time->getPartialNanoseconds();
}
}

TimeStamp::TimeStamp(const int32_t &seconds, const int32_t &microSeconds) :
TimeStamp::TimeStamp(const int32_t &seconds, const int32_t &microSeconds, const int32_t &nanoSeconds) :
m_seconds(seconds),
m_microseconds(microSeconds) {}
m_microseconds(microSeconds),
m_nanoseconds(nanoSeconds) {}

TimeStamp::TimeStamp(const string &ddmmyyyyhhmmss) :
m_seconds(0),
m_microseconds(0) {
m_microseconds(0),
m_nanoseconds(0) {
if (ddmmyyyyhhmmss.size() == 14) {
stringstream dataDD;
dataDD.str(ddmmyyyyhhmmss.substr(0, 2));
Expand Down Expand Up @@ -139,38 +143,53 @@ namespace odcore {
TimeStamp::TimeStamp(const TimeStamp &obj) :
SerializableData(),
m_seconds(obj.m_seconds),
m_microseconds(obj.m_microseconds) {}
m_microseconds(obj.m_microseconds),
m_nanoseconds(obj.m_nanoseconds) {}

TimeStamp::~TimeStamp() {}

TimeStamp& TimeStamp::operator=(const TimeStamp &obj) {
m_seconds = obj.m_seconds;
m_microseconds = obj.m_microseconds;
m_nanoseconds = obj.m_nanoseconds;
return (*this);
}

TimeStamp TimeStamp::operator+(const TimeStamp & t) const {
int32_t sumSeconds = m_seconds + t.getSeconds();
int32_t sumMicroseconds = m_microseconds + t.getFractionalMicroseconds();
int32_t sumNanoseconds = m_nanoseconds + t.getFractionalNanoseconds();

while (sumNanoseconds >= 1000L) {
sumMicroseconds++;
sumNanoseconds -= 1000L;
}

while (sumMicroseconds > 1000000L) {
sumSeconds++;
sumMicroseconds -= 1000000L;
}

return TimeStamp(sumSeconds, sumMicroseconds);
return TimeStamp(sumSeconds, sumMicroseconds, sumNanoseconds);
}

TimeStamp TimeStamp::operator-(const TimeStamp & t) const {
int32_t deltaSeconds = m_seconds - t.getSeconds();
int32_t deltaMicroseconds = m_microseconds - t.getFractionalMicroseconds();
int32_t deltaNanoseconds = m_nanoseconds - t.getFractionalNanoseconds();

while (deltaNanoseconds < 0) {
deltaMicroseconds--;
deltaNanoseconds += 1000L;
}

while (deltaMicroseconds < 0) {
deltaSeconds--;
deltaMicroseconds += 1000000L;
}

return TimeStamp(deltaSeconds, deltaMicroseconds);

return TimeStamp(deltaSeconds, deltaMicroseconds, deltaNanoseconds);
}

bool TimeStamp::operator==(const TimeStamp& t) const {
Expand Down Expand Up @@ -205,10 +224,18 @@ namespace odcore {
return getSeconds() * 1000000L + getFractionalMicroseconds();
}

long TimeStamp::toNanoseconds() const {
return getSeconds() * 1000000000L + (getFractionalMicroseconds() * 1000L + getFractionalNanoseconds());
}

int32_t TimeStamp::getFractionalMicroseconds() const {
return m_microseconds;
}

int32_t TimeStamp::getFractionalNanoseconds() const {
return m_nanoseconds;
}

int32_t TimeStamp::getSeconds() const {
return m_seconds;
}
Expand Down Expand Up @@ -420,7 +447,11 @@ namespace odcore {

const string TimeStamp::toString() const {
stringstream s;
s << m_seconds << "s/" << m_microseconds << "us.";
#ifdef HAVE_LINUX_RT
s << m_seconds << "s/" << m_microseconds << "us./" << m_nanoseconds << "ns.";
#else
s << m_seconds << "s/" << m_microseconds << "us.";
#endif
return s.str();
}

Expand All @@ -435,6 +466,9 @@ namespace odcore {
s->write(CRC32 < OPENDAVINCI_CORE_STRINGLITERAL3('m', 'i', 'c') >::RESULT,
m_microseconds);

s->write(CRC32 < OPENDAVINCI_CORE_STRINGLITERAL3('n', 'a', 'n') >::RESULT,
m_nanoseconds);

return out;
}

Expand All @@ -449,6 +483,9 @@ namespace odcore {
d->read(CRC32 < OPENDAVINCI_CORE_STRINGLITERAL3('m', 'i', 'c') >::RESULT,
m_microseconds);

d->read(CRC32 < OPENDAVINCI_CORE_STRINGLITERAL3('n', 'a', 'n') >::RESULT,
m_nanoseconds);

return in;
}

Expand Down
Loading