[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-09-15 12:08:59 -07:00
committed by Jonathan Hui
parent 43be2b821f
commit 4feadec950
51 changed files with 629 additions and 339 deletions
+3 -3
View File
@@ -1966,7 +1966,7 @@ void Interpreter::HandleIcmpReceive(Message & aMessage,
if (aMessage.Read(aMessage.GetOffset(), sizeof(uint32_t), &timestamp) >= static_cast<int>(sizeof(uint32_t)))
{
mServer->OutputFormat(" time=%dms", TimerMilli::Elapsed(HostSwap32(timestamp)));
mServer->OutputFormat(" time=%dms", TimerMilli::GetNow().GetValue() - HostSwap32(timestamp));
}
mServer->OutputFormat("\r\n");
@@ -2022,7 +2022,7 @@ void Interpreter::ProcessPing(int argc, char *argv[])
case 3:
SuccessOrExit(error = ParsePingInterval(argv[index], interval));
VerifyOrExit(0 < interval && interval <= Timer::kMaxDt, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(0 < interval && interval <= Timer::kMaxDelay, error = OT_ERROR_INVALID_ARGS);
mInterval = interval;
break;
@@ -2049,7 +2049,7 @@ void Interpreter::HandlePingTimer(Timer &aTimer)
void Interpreter::HandlePingTimer()
{
otError error = OT_ERROR_NONE;
uint32_t timestamp = HostSwap32(TimerMilli::GetNow());
uint32_t timestamp = HostSwap32(TimerMilli::GetNow().GetValue());
otMessage * message;
const otMessageInfo *messageInfo = static_cast<const otMessageInfo *>(&mMessageInfo);