Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ICD] Stay in active mode when a reliable message context is awaiting an ack #28380

Merged
Merged
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
13 changes: 13 additions & 0 deletions src/app/icd/ICDEventManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace chip {
namespace app {

uint8_t ICDEventManager::expectedMsgCount = 0;
uint8_t ICDEventManager::awaitingAckCount = 0;
static_assert(UINT8_MAX >= CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS,
"ICDEventManager::expectedMsgCount cannot hold count for the max exchange count");

Expand Down Expand Up @@ -97,7 +98,19 @@ void ICDEventManager::ICDEventHandler(const ChipDeviceEvent * event, intptr_t ar
{
icdManager->UpdateOperationState(ICDManager::OperationalState::ActiveMode);
}
break;
case DeviceEventType::kICDMsgAckSyncEvent:
jmartinez-silabs marked this conversation as resolved.
Show resolved Hide resolved
// When a Reliable Message Context is awaiting an ack, we keep the ICD in its active mode
if (event->AckSync.awaitingAck)
{
awaitingAckCount++;
}
else if (awaitingAckCount > 0)
{
awaitingAckCount--;
}

icdManager->SetKeepActiveModeRequirements(ICDManager::KeepActiveFlags::kAwaitingMsgAck, (awaitingAckCount != 0));
break;
case DeviceEventType::kAppWakeUpEvent:
icdManager->UpdateOperationState(ICDManager::OperationalState::ActiveMode);
Expand Down
1 change: 1 addition & 0 deletions src/app/icd/ICDEventManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class ICDEventManager
*/
static void ICDEventHandler(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg);
static uint8_t expectedMsgCount;
static uint8_t awaitingAckCount;
ICDManager * mICDManager;
};

Expand Down
1 change: 1 addition & 0 deletions src/app/icd/ICDManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class ICDManager
kCommissioningWindowOpen = 0x01,
kFailSafeArmed = 0x02,
kExpectingMsgResponse = 0x03,
kAwaitingMsgAck = 0x04,
};

ICDManager() {}
Expand Down
19 changes: 19 additions & 0 deletions src/include/platform/CHIPDeviceEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,16 @@ enum PublicEventTypes
*/
kChipMsgRxEventHandled,

/**
* This event is used to sync the ICD with any Reliable Message exchange
* expecting an ack. The ICD shall stay in active Mode
* until the Reliable Message exchange post this event again
* informing the ICD that it is no longer awaiting the ack.
*
* This event contains an AckSync structure.
*/
kICDMsgAckSyncEvent,

/**
* An application event occured that should wake up the system/device
*/
Expand Down Expand Up @@ -580,6 +590,15 @@ struct ChipDeviceEvent final
bool wasReceived;
bool clearsExpectedResponse;
} RxEventContext;

struct
{
/*
* Set to true when a Reliable Message Context is awaiting for a ack to a message sent
* Set to false when the Reliable Message Context is no longer awaiting for a ack
*/
bool awaitingAck;
} AckSync;
};

void Clear() { memset(this, 0, sizeof(*this)); }
Expand Down
19 changes: 19 additions & 0 deletions src/messaging/ReliableMessageContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@
#include <messaging/ErrorCategory.h>
#include <messaging/Flags.h>
#include <messaging/ReliableMessageMgr.h>
#include <platform/PlatformManager.h>
#include <protocols/Protocols.h>
#include <protocols/secure_channel/Constants.h>

using namespace chip::DeviceLayer;

namespace chip {
namespace Messaging {

Expand All @@ -51,6 +54,22 @@ ReliableMessageMgr * ReliableMessageContext::GetReliableMessageMgr()
return static_cast<ExchangeContext *>(this)->GetExchangeMgr()->GetReliableMessageMgr();
}

void ReliableMessageContext::SetMessageNotAcked(bool messageNotAcked)
jmartinez-silabs marked this conversation as resolved.
Show resolved Hide resolved
{
mFlags.Set(Flags::kFlagMessageNotAcked, messageNotAcked);

#if CONFIG_DEVICE_LAYER
DeviceLayer::ChipDeviceEvent event;
event.Type = DeviceLayer::DeviceEventType::kICDMsgAckSyncEvent;
event.AckSync.awaitingAck = messageNotAcked;
CHIP_ERROR status = DeviceLayer::PlatformMgr().PostEvent(&event);
if (status != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "Failed to post AckSync event %" CHIP_ERROR_FORMAT, status.Format());
}
#endif
}

CHIP_ERROR ReliableMessageContext::FlushAcks()
{
CHIP_ERROR err = CHIP_NO_ERROR;
Expand Down
5 changes: 0 additions & 5 deletions src/messaging/ReliableMessageContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,6 @@ inline void ReliableMessageContext::SetAckPending(bool inAckPending)
mFlags.Set(Flags::kFlagAckPending, inAckPending);
}

inline void ReliableMessageContext::SetMessageNotAcked(bool messageNotAcked)
{
mFlags.Set(Flags::kFlagMessageNotAcked, messageNotAcked);
}

inline void ReliableMessageContext::SetRequestingActiveMode(bool activeMode)
{
mFlags.Set(Flags::kFlagActiveMode, activeMode);
Expand Down
Loading