[time] adding Time class (#4195)

This commit adds `Time` class which represents an instance of time
(it is a simple wrapper over a `uint32_t` corresponding to a
numerical time value). The `Time` class provides helpful operator
overloads:
- Operators `+` and `-` with a `Time` instance and a `Duration` to
  get a `Time` instance after or before.
- Operator `-` with two `Time` instances to calculate the `Duration`
  duration between two time instances.
- Operators `<`, `<=`, `>`,'>=', '==' and `!=` to compare two `Time`
  instances. They correctly handle the wrapping of numeric time value.

The core modules are updated to use the new `Time` and `Duration`
types which help make the code simpler. This commit also updates the
 unit test `test_timer` to add test cases for newly added types.
This commit is contained in:
Abtin Keshavarzian
2019-10-04 15:35:53 -07:00
committed by Jonathan Hui
parent 43be2b821f
commit 4feadec950
51 changed files with 629 additions and 339 deletions
+2 -2
View File
@@ -320,8 +320,8 @@ otError otThreadGetParentInfo(otInstance *aInstance, otRouterInfo *aParentInfo)
aParentInfo->mPathCost = parent->GetCost();
aParentInfo->mLinkQualityIn = parent->GetLinkInfo().GetLinkQuality();
aParentInfo->mLinkQualityOut = parent->GetLinkQualityOut();
aParentInfo->mAge = static_cast<uint8_t>(TimerMilli::MsecToSec(TimerMilli::Elapsed(parent->GetLastHeard())));
aParentInfo->mAllocated = true;
aParentInfo->mAge = static_cast<uint8_t>(Time::MsecToSec(TimerMilli::GetNow() - parent->GetLastHeard()));
aParentInfo->mAllocated = true;
aParentInfo->mLinkEstablished = parent->GetState() == Neighbor::kStateValid;
#if !OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE