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

Sort Sources attribute in power source configuration cluster based on order of the power source cluster #17840

Merged
Changes from 1 commit
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
Prev Previous commit
changed scope of few variables
fessehaeve committed May 5, 2022
commit 92e51da865a7b0574b4a354e4778d50829405a8c
Original file line number Diff line number Diff line change
@@ -65,24 +65,24 @@ CHIP_ERROR PowerSourceConfigurationAttrAccess::Read(const ConcreteReadAttributeP
case Sources::Id:
err = aEncoder.EncodeList([](const auto & encoder) -> CHIP_ERROR {
std::pair<uint16_t, uint8_t> orderEpPair[kMaxPowerSources];
uint8_t idx = 0, order = 0;
uint8_t idx = 0;
for (auto endpoint : EnabledEndpointsWithServerCluster(PowerSource::Id))
{
uint8_t order = 0;
if (idx >= kMaxPowerSources)
break;
PowerSource::Attributes::Order::Get(endpoint, &order);
orderEpPair[idx] = std::make_pair(endpoint, order);
idx++;
}

int i, j, k;
for (i = 0; i < idx - 1; i++)
for (int i = 0; i < idx - 1; i++)
{
for (j = 0; j < idx - i - 1; j++)
for (int j = 0; j < idx - i - 1; j++)
if ((orderEpPair[j]).second > (orderEpPair[j + 1]).second)
swap(orderEpPair[j], orderEpPair[j + 1]);
}
for (k = 0; k < idx; k++)
for (int k = 0; k < idx; k++)
{
ReturnErrorOnFailure(encoder.Encode(orderEpPair[k].first));
}