mirror of
https://github.com/espressif/openthread.git
synced 2026-08-10 04:37:47 +00:00
[time] add constants for one sec, minute, hour, or day interval in msec (#7297)
This commit is contained in:
@@ -60,6 +60,11 @@ namespace ot {
|
||||
class Time : public Unequatable<Time>
|
||||
{
|
||||
public:
|
||||
static constexpr uint32_t kOneSecondInMsec = 1000u; ///< One second interval in msec.
|
||||
static constexpr uint32_t kOneMinuteInMsec = kOneSecondInMsec * 60; ///< One minute interval in msec.
|
||||
static constexpr uint32_t kOneHourInMsec = kOneMinuteInMsec * 60; ///< One hour interval in msec.
|
||||
static constexpr uint32_t kOneDayInMsec = kOneHourInMsec * 24; ///< One day interval in msec.
|
||||
|
||||
/**
|
||||
* This constant defines a maximum time duration ensured to be longer than any other duration.
|
||||
*
|
||||
|
||||
@@ -109,8 +109,8 @@ public:
|
||||
bool IsReceiverRegistered(Receiver aReceiver) const { return (mReceivers & Mask(aReceiver)) != 0; }
|
||||
|
||||
private:
|
||||
static constexpr uint32_t kTickInterval = 1000; // in msec.
|
||||
static constexpr uint32_t kRestartJitter = 4; // in msec, jitter added when restarting the timer [-4,+4] ms.
|
||||
static constexpr uint32_t kTickInterval = Time::kOneSecondInMsec;
|
||||
static constexpr uint32_t kRestartJitter = 4; // in msec, jitter added when restarting the timer [-4,+4] ms.
|
||||
|
||||
constexpr static uint32_t Mask(Receiver aReceiver) { return static_cast<uint32_t>(1U) << aReceiver; }
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ static uint32_t DivideAndGetRemainder(uint32_t &aDividend, uint32_t aDivisor)
|
||||
|
||||
void Uptime::UptimeToString(uint64_t aUptime, StringWriter &aWriter)
|
||||
{
|
||||
uint64_t days = aUptime / kOneDayInMsec;
|
||||
uint64_t days = aUptime / Time::kOneDayInMsec;
|
||||
uint32_t remainder;
|
||||
uint32_t hours;
|
||||
uint32_t minutes;
|
||||
@@ -126,13 +126,13 @@ void Uptime::UptimeToString(uint64_t aUptime, StringWriter &aWriter)
|
||||
if (days > 0)
|
||||
{
|
||||
aWriter.Append("%lud.", days);
|
||||
aUptime -= days * kOneDayInMsec;
|
||||
aUptime -= days * Time::kOneDayInMsec;
|
||||
}
|
||||
|
||||
remainder = static_cast<uint32_t>(aUptime);
|
||||
hours = DivideAndGetRemainder(remainder, kOneHourInMsec);
|
||||
minutes = DivideAndGetRemainder(remainder, kOneMinuteInMsec);
|
||||
seconds = DivideAndGetRemainder(remainder, kOneSecondInMsec);
|
||||
hours = DivideAndGetRemainder(remainder, Time::kOneHourInMsec);
|
||||
minutes = DivideAndGetRemainder(remainder, Time::kOneMinuteInMsec);
|
||||
seconds = DivideAndGetRemainder(remainder, Time::kOneSecondInMsec);
|
||||
|
||||
aWriter.Append("%02u:%02u:%02u.%03u", hours, minutes, seconds, remainder);
|
||||
}
|
||||
|
||||
@@ -99,11 +99,7 @@ public:
|
||||
static void UptimeToString(uint64_t aUptime, StringWriter &aWriter);
|
||||
|
||||
private:
|
||||
static constexpr uint32_t kTimerInterval = (1 << 30);
|
||||
static constexpr uint32_t kOneSecondInMsec = 1000;
|
||||
static constexpr uint32_t kOneMinuteInMsec = 60 * kOneSecondInMsec;
|
||||
static constexpr uint32_t kOneHourInMsec = 60 * kOneMinuteInMsec;
|
||||
static constexpr uint32_t kOneDayInMsec = 24 * kOneHourInMsec;
|
||||
static constexpr uint32_t kTimerInterval = (1 << 30);
|
||||
|
||||
static_assert(static_cast<uint32_t>(4 * kTimerInterval) == 0, "kTimerInterval is not correct");
|
||||
|
||||
|
||||
@@ -314,8 +314,6 @@ private:
|
||||
|
||||
static constexpr uint16_t kMinimalMtu = 1280;
|
||||
|
||||
static constexpr uint32_t kStateUpdatePeriod = 1000;
|
||||
|
||||
static void HandleSendQueue(Tasklet &aTasklet);
|
||||
void HandleSendQueue(void);
|
||||
|
||||
|
||||
@@ -323,21 +323,22 @@ void HistoryTracker::EntryAgeToString(uint32_t aEntryAge, char *aBuffer, uint16_
|
||||
|
||||
if (aEntryAge >= kMaxAge)
|
||||
{
|
||||
writer.Append("more than %u days", kMaxAge / kOneDayInMsec);
|
||||
writer.Append("more than %u days", kMaxAge / Time::kOneDayInMsec);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t days = aEntryAge / kOneDayInMsec;
|
||||
uint32_t days = aEntryAge / Time::kOneDayInMsec;
|
||||
|
||||
if (days > 0)
|
||||
{
|
||||
writer.Append("%u day%s ", days, (days == 1) ? "" : "s");
|
||||
aEntryAge -= days * kOneDayInMsec;
|
||||
aEntryAge -= days * Time::kOneDayInMsec;
|
||||
}
|
||||
|
||||
writer.Append("%02u:%02u:%02u.%03u", (aEntryAge / kOneHourInMsec),
|
||||
(aEntryAge % kOneHourInMsec) / kOneMinuteInMsec,
|
||||
(aEntryAge % kOneMinuteInMsec) / kOneSecondInMsec, (aEntryAge % kOneSecondInMsec));
|
||||
writer.Append("%02u:%02u:%02u.%03u", (aEntryAge / Time::kOneHourInMsec),
|
||||
(aEntryAge % Time::kOneHourInMsec) / Time::kOneMinuteInMsec,
|
||||
(aEntryAge % Time::kOneMinuteInMsec) / Time::kOneSecondInMsec,
|
||||
(aEntryAge % Time::kOneSecondInMsec));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -250,16 +250,11 @@ public:
|
||||
static void EntryAgeToString(uint32_t aEntryAge, char *aBuffer, uint16_t aSize);
|
||||
|
||||
private:
|
||||
static constexpr uint32_t kOneSecondInMsec = 1000;
|
||||
static constexpr uint32_t kOneMinuteInMsec = 60 * kOneSecondInMsec;
|
||||
static constexpr uint32_t kOneHourInMsec = 60 * kOneMinuteInMsec;
|
||||
static constexpr uint32_t kOneDayInMsec = 24 * kOneHourInMsec;
|
||||
|
||||
// `Timestamp` uses `uint32_t` value. `2^32` msec is 49 days, 17
|
||||
// hours, 2 minutes and 47 seconds and 296 msec. We use 49 days
|
||||
// as `kMaxAge` and check for aged entries every 16 hours.
|
||||
|
||||
static constexpr uint32_t kAgeCheckPeriod = 16 * kOneHourInMsec;
|
||||
static constexpr uint32_t kAgeCheckPeriod = 16 * Time::kOneHourInMsec;
|
||||
|
||||
static constexpr uint16_t kNetInfoListSize = OPENTHREAD_CONFIG_HISTORY_TRACKER_NET_INFO_LIST_SIZE;
|
||||
static constexpr uint16_t kUnicastAddrListSize = OPENTHREAD_CONFIG_HISTORY_TRACKER_UNICAST_ADDRESS_LIST_SIZE;
|
||||
|
||||
@@ -218,7 +218,7 @@ void JamDetector::UpdateHistory(bool aDidExceedThreshold)
|
||||
|
||||
// If we reached end of current one second interval, update the history bitmap
|
||||
|
||||
if (interval >= kOneSecondInterval)
|
||||
if (interval >= Time::kOneSecondInMsec)
|
||||
{
|
||||
mHistoryBitmap <<= 1;
|
||||
|
||||
@@ -229,7 +229,7 @@ void JamDetector::UpdateHistory(bool aDidExceedThreshold)
|
||||
|
||||
mAlwaysAboveThreshold = true;
|
||||
|
||||
mCurSecondStartTime += (interval / kOneSecondInterval) * kOneSecondInterval;
|
||||
mCurSecondStartTime += (interval / Time::kOneSecondInMsec) * Time::kOneSecondInMsec;
|
||||
|
||||
UpdateJamState();
|
||||
}
|
||||
|
||||
@@ -181,10 +181,9 @@ private:
|
||||
static constexpr uint8_t kMaxWindow = 63; // Max window size
|
||||
static constexpr int8_t kDefaultRssiThreshold = 0;
|
||||
|
||||
static constexpr uint16_t kMaxSampleInterval = 256; // in ms
|
||||
static constexpr uint16_t kMinSampleInterval = 2; // in ms
|
||||
static constexpr uint32_t kMaxRandomDelay = 4; // in ms
|
||||
static constexpr uint32_t kOneSecondInterval = 1000; // in ms
|
||||
static constexpr uint16_t kMaxSampleInterval = 256; // in ms
|
||||
static constexpr uint16_t kMinSampleInterval = 2; // in ms
|
||||
static constexpr uint32_t kMaxRandomDelay = 4; // in ms
|
||||
|
||||
void CheckState(void);
|
||||
void SetJamState(bool aNewState);
|
||||
|
||||
Reference in New Issue
Block a user