@@ -83,7 +83,8 @@ struct CopyAndAdjustDeltaTimeContext
83
83
84
84
void EventManagement::Init (Messaging::ExchangeManager * apExchangeManager, uint32_t aNumBuffers,
85
85
CircularEventBuffer * apCircularEventBuffer, const LogStorageResources * const apLogStorageResources,
86
- MonotonicallyIncreasingCounter<EventNumber> * apEventNumberCounter)
86
+ MonotonicallyIncreasingCounter<EventNumber> * apEventNumberCounter,
87
+ System::Clock::Milliseconds64 aMonotonicStartupTime)
87
88
{
88
89
CircularEventBuffer * current = nullptr ;
89
90
CircularEventBuffer * prev = nullptr ;
@@ -122,6 +123,8 @@ void EventManagement::Init(Messaging::ExchangeManager * apExchangeManager, uint3
122
123
mpEventBuffer = apCircularEventBuffer;
123
124
mState = EventManagementStates::Idle;
124
125
mBytesWritten = 0 ;
126
+
127
+ mMonotonicStartupTime = aMonotonicStartupTime;
125
128
}
126
129
127
130
CHIP_ERROR EventManagement::CopyToNextBuffer (CircularEventBuffer * apEventBuffer)
@@ -327,10 +330,12 @@ CHIP_ERROR EventManagement::ConstructEvent(EventLoadOutContext * apContext, Even
327
330
void EventManagement::CreateEventManagement (Messaging::ExchangeManager * apExchangeManager, uint32_t aNumBuffers,
328
331
CircularEventBuffer * apCircularEventBuffer,
329
332
const LogStorageResources * const apLogStorageResources,
330
- MonotonicallyIncreasingCounter<EventNumber> * apEventNumberCounter)
333
+ MonotonicallyIncreasingCounter<EventNumber> * apEventNumberCounter,
334
+ System::Clock::Milliseconds64 aMonotonicStartupTime)
331
335
{
332
336
333
- sInstance .Init (apExchangeManager, aNumBuffers, apCircularEventBuffer, apLogStorageResources, apEventNumberCounter);
337
+ sInstance .Init (apExchangeManager, aNumBuffers, apCircularEventBuffer, apLogStorageResources, apEventNumberCounter,
338
+ aMonotonicStartupTime);
334
339
}
335
340
336
341
/* *
@@ -365,12 +370,14 @@ CHIP_ERROR EventManagement::CopyAndAdjustDeltaTime(const TLVReader & aReader, si
365
370
// Does not go on the wire.
366
371
return CHIP_NO_ERROR;
367
372
}
368
- if ((aReader.GetTag () == TLV::ContextTag (to_underlying (EventDataIB::Tag::kSystemTimestamp ))) && !(ctx->mpContext ->mFirst ))
373
+ if ((aReader.GetTag () == TLV::ContextTag (to_underlying (EventDataIB::Tag::kSystemTimestamp ))) && !(ctx->mpContext ->mFirst ) &&
374
+ (ctx->mpContext ->mCurrentTime .mType == ctx->mpContext ->mPreviousTime .mType ))
369
375
{
370
376
return ctx->mpWriter ->Put (TLV::ContextTag (to_underlying (EventDataIB::Tag::kDeltaSystemTimestamp )),
371
377
ctx->mpContext ->mCurrentTime .mValue - ctx->mpContext ->mPreviousTime .mValue );
372
378
}
373
- if ((aReader.GetTag () == TLV::ContextTag (to_underlying (EventDataIB::Tag::kEpochTimestamp ))) && !(ctx->mpContext ->mFirst ))
379
+ if ((aReader.GetTag () == TLV::ContextTag (to_underlying (EventDataIB::Tag::kEpochTimestamp ))) && !(ctx->mpContext ->mFirst ) &&
380
+ (ctx->mpContext ->mCurrentTime .mType == ctx->mpContext ->mPreviousTime .mType ))
374
381
{
375
382
return ctx->mpWriter ->Put (TLV::ContextTag (to_underlying (EventDataIB::Tag::kDeltaEpochTimestamp )),
376
383
ctx->mpContext ->mCurrentTime .mValue - ctx->mpContext ->mPreviousTime .mValue );
@@ -411,16 +418,18 @@ CHIP_ERROR EventManagement::LogEventPrivate(EventLoggingDelegate * apDelegate, c
411
418
CircularEventBuffer * buffer = nullptr ;
412
419
EventLoadOutContext ctxt = EventLoadOutContext (writer, aEventOptions.mPriority , mLastEventNumber );
413
420
EventOptions opts;
414
- #if CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS & CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME
415
421
Timestamp timestamp;
416
- System::Clock::Timestamp utc_time;
417
-
422
+ System::Clock::Milliseconds64 utc_time;
418
423
err = System::SystemClock ().GetClock_RealTimeMS (utc_time);
419
- SuccessOrExit (err);
420
- timestamp = Timestamp::Epoch (utc_time);
421
- #else
422
- Timestamp timestamp (System::SystemClock ().GetMonotonicTimestamp ());
423
- #endif
424
+ if (err == CHIP_NO_ERROR)
425
+ {
426
+ timestamp = Timestamp::Epoch (utc_time);
427
+ }
428
+ else
429
+ {
430
+ auto systemTimeMs = System::SystemClock ().GetMonotonicMilliseconds64 () - mMonotonicStartupTime ;
431
+ timestamp = Timestamp::System (systemTimeMs);
432
+ }
424
433
425
434
opts = EventOptions (timestamp);
426
435
// Start the event container (anonymous structure) in the circular buffer
0 commit comments