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

Add functions to set Parent Endpoint and Composition Type for an Endpoint #28410

Merged
Merged
4 changes: 2 additions & 2 deletions src/app/clusters/descriptor/descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ CHIP_ERROR DescriptorAttrAccess::ReadPartsAttribute(EndpointId endpoint, Attribu
return CHIP_NO_ERROR;
});
}
else if (emberAfEndpointCompositionTypeForEndpoint(endpoint) == EMBER_AF_ENDPOINT_COMPOSITION_FLAT)
else if (IsFlatCompositionForEndpoint(endpoint))
{
err = aEncoder.EncodeList([endpoint](const auto & encoder) -> CHIP_ERROR {
for (uint16_t index = 0; index < emberAfEndpointCount(); index++)
Expand Down Expand Up @@ -104,7 +104,7 @@ CHIP_ERROR DescriptorAttrAccess::ReadPartsAttribute(EndpointId endpoint, Attribu
return CHIP_NO_ERROR;
});
}
else
else if (IsTreeCompositionForEndpoint(endpoint))
{
err = aEncoder.EncodeList([endpoint](const auto & encoder) -> CHIP_ERROR {
for (uint16_t index = 0; index < emberAfEndpointCount(); index++)
Expand Down
30 changes: 6 additions & 24 deletions src/app/util/af-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,24 +181,11 @@ typedef struct
uint16_t endpointSize;
} EmberAfEndpointType;

#ifdef DOXYGEN_SHOULD_SKIP_THIS
enum EmberAfEndpointBitmask;
#else
typedef uint8_t EmberAfEndpointBitmask;
enum
#endif
{ EMBER_AF_ENDPOINT_DISABLED = 0x00,
EMBER_AF_ENDPOINT_ENABLED = 0x01,
};

#ifdef DOXYGEN_SHOULD_SKIP_THIS
enum EmberAfEndpointCompositionType;
#else
typedef uint8_t EmberAfEndpointCompositionType;
enum
#endif
{ EMBER_AF_ENDPOINT_COMPOSITION_FLAT = 0x00,
EMBER_AF_ENDPOINT_COMPOSITION_TREE = 0x01,
enum class EmberAfEndpointOptions : uint8_t
{
isEnabled = 0x1,
isFlatComposition = 0x2,
isTreeComposition = 0x3,
};

/**
Expand All @@ -219,7 +206,7 @@ struct EmberAfDefinedEndpoint
/**
* Meta-data about the endpoint
*/
EmberAfEndpointBitmask bitmask = EMBER_AF_ENDPOINT_DISABLED;
chip::BitMask<EmberAfEndpointOptions> bitmask;
/**
* Endpoint type for this endpoint.
*/
Expand All @@ -234,11 +221,6 @@ struct EmberAfDefinedEndpoint
* Root endpoint id for composed device type.
*/
chip::EndpointId parentEndpointId = chip::kInvalidEndpointId;

/**
* Endpoint's composition type
*/
EmberAfEndpointCompositionType endpointCompositionType = EMBER_AF_ENDPOINT_COMPOSITION_FLAT;
};

// Cluster specific types
Expand Down
39 changes: 25 additions & 14 deletions src/app/util/af.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,6 @@ extern EmberAfDefinedEndpoint emAfEndpoints[];
*/
chip::EndpointId emberAfParentEndpointFromIndex(uint16_t index);

/**
* @brief Sets the parent endpoint for a given endpoint
*/
EmberAfStatus emberAfSetParentEndpointForEndpoint(chip::EndpointId childEndpoint, chip::EndpointId parentEndpoint);

/**
* @brief Sets the composition type for a given endpoint
*/
EmberAfStatus emberAfSetEndpointComposition(chip::EndpointId endpoint, EmberAfEndpointCompositionType aEndpointCompositionType);

/**
* @brief Returns the composition type for a given endpoint
*/
EmberAfEndpointCompositionType emberAfEndpointCompositionTypeForEndpoint(chip::EndpointId endpoint);
/**
* Returns the index of a given endpoint. Will return 0xFFFF if this is not a
* valid endpoint id or if the endpoint is disabled.
Expand Down Expand Up @@ -317,5 +303,30 @@ class EnabledEndpointsWithServerCluster
ClusterId mClusterId;
};

/**
* @brief Sets the parent endpoint for a given endpoint
*/
EmberAfStatus SetParentEndpointForEndpoint(EndpointId childEndpoint, EndpointId parentEndpoint);
mhazley marked this conversation as resolved.
Show resolved Hide resolved

/**
* @brief Sets an Endpoint to use Flat Composition
*/
EmberAfStatus SetFlatCompositionForEndpoint(EndpointId endpoint);

/**
* @brief Sets an Endpoint to use Tree Composition
*/
EmberAfStatus SetTreeCompositionForEndpoint(EndpointId endpoint);

/**
* @brief Returns true is an Endpoint has flat composition
*/
bool IsFlatCompositionForEndpoint(EndpointId endpoint);

/**
* @brief Returns true is an Endpoint has tree composition
*/
bool IsTreeCompositionForEndpoint(EndpointId endpoint);

} // namespace app
} // namespace chip
104 changes: 67 additions & 37 deletions src/app/util/attribute-storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ void emberAfEndpointConfigure()
emAfEndpoints[ep].deviceTypeList = endpointDeviceTypeList(ep);
emAfEndpoints[ep].endpointType = endpointTypeMacro(ep);
emAfEndpoints[ep].dataVersions = currentDataVersions;
emAfEndpoints[ep].bitmask = EMBER_AF_ENDPOINT_ENABLED;

emAfEndpoints[ep].bitmask.Set(EmberAfEndpointOptions::isEnabled);
emAfEndpoints[ep].bitmask.Set(EmberAfEndpointOptions::isFlatComposition);

// Increment currentDataVersions by 1 (slot) for every server cluster
// this endpoint has.
Expand Down Expand Up @@ -271,7 +273,7 @@ EmberAfStatus emberAfSetDynamicEndpoint(uint16_t index, EndpointId id, const Emb
emAfEndpoints[index].endpointType = ep;
emAfEndpoints[index].dataVersions = dataVersionStorage.data();
// Start the endpoint off as disabled.
emAfEndpoints[index].bitmask = EMBER_AF_ENDPOINT_DISABLED;
emAfEndpoints[index].bitmask.Clear(EmberAfEndpointOptions::isEnabled);
emAfEndpoints[index].parentEndpointId = parentEndpointId;

emberAfSetDynamicEndpointCount(MAX_ENDPOINT_COUNT - FIXED_ENDPOINT_COUNT);
Expand Down Expand Up @@ -322,7 +324,7 @@ uint16_t emberAfEndpointCount()

bool emberAfEndpointIndexIsEnabled(uint16_t index)
{
return (emAfEndpoints[index].bitmask & EMBER_AF_ENDPOINT_ENABLED);
return (emAfEndpoints[index].bitmask.Has(EmberAfEndpointOptions::isEnabled));
}

bool emberAfIsStringAttributeType(EmberAfAttributeType attributeType)
Expand Down Expand Up @@ -838,7 +840,7 @@ static uint16_t findIndexFromEndpoint(EndpointId endpoint, bool ignoreDisabledEn
for (epi = 0; epi < emberAfEndpointCount(); epi++)
{
if (emAfEndpoints[epi].endpoint == endpoint &&
(!ignoreDisabledEndpoints || emAfEndpoints[epi].bitmask & EMBER_AF_ENDPOINT_ENABLED))
(!ignoreDisabledEndpoints || emAfEndpoints[epi].bitmask.Has(EmberAfEndpointOptions::isEnabled)))
{
return epi;
}
Expand Down Expand Up @@ -919,11 +921,11 @@ bool emberAfEndpointEnableDisable(EndpointId endpoint, bool enable)
return false;
}

currentlyEnabled = emAfEndpoints[index].bitmask & EMBER_AF_ENDPOINT_ENABLED;
currentlyEnabled = emAfEndpoints[index].bitmask.Has(EmberAfEndpointOptions::isEnabled);

if (enable)
{
emAfEndpoints[index].bitmask |= EMBER_AF_ENDPOINT_ENABLED;
emAfEndpoints[index].bitmask.Set(EmberAfEndpointOptions::isEnabled);
}

#if defined(EZSP_HOST)
Expand Down Expand Up @@ -962,7 +964,7 @@ bool emberAfEndpointEnableDisable(EndpointId endpoint, bool enable)

if (!enable)
{
emAfEndpoints[index].bitmask &= EMBER_AF_ENDPOINT_DISABLED;
emAfEndpoints[index].bitmask.Clear(EmberAfEndpointOptions::isEnabled);
}

return true;
Expand Down Expand Up @@ -992,36 +994,6 @@ EndpointId emberAfParentEndpointFromIndex(uint16_t index)
return emAfEndpoints[index].parentEndpointId;
}

EmberAfStatus emberAfSetParentEndpointForEndpoint(chip::EndpointId childEndpoint, chip::EndpointId parentEndpoint)
{
uint16_t childIndex = emberAfIndexFromEndpoint(childEndpoint);
uint16_t parentIndex = emberAfIndexFromEndpoint(parentEndpoint);

if (childIndex == kEmberInvalidEndpointIndex || parentIndex == kEmberInvalidEndpointIndex)
{
return EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT;
}
emAfEndpoints[childIndex].parentEndpointId = parentEndpoint;
return EMBER_ZCL_STATUS_SUCCESS;
}

EmberAfStatus emberAfSetEndpointComposition(chip::EndpointId endpoint, EmberAfEndpointCompositionType aEndpointCompositionType)
{
uint16_t index = emberAfIndexFromEndpoint(endpoint);
if (index == kEmberInvalidEndpointIndex)
{
return EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT;
}
emAfEndpoints[index].endpointCompositionType = aEndpointCompositionType;
return EMBER_ZCL_STATUS_SUCCESS;
}

EmberAfEndpointCompositionType emberAfEndpointCompositionTypeForEndpoint(chip::EndpointId endpoint)
{
uint16_t index = emberAfIndexFromEndpoint(endpoint);
return emAfEndpoints[index].endpointCompositionType;
}

// If server == true, returns the number of server clusters,
// otherwise number of client clusters on this endpoint
uint8_t emberAfClusterCount(EndpointId endpoint, bool server)
Expand Down Expand Up @@ -1451,6 +1423,64 @@ app::AttributeAccessInterface * GetAttributeAccessOverride(EndpointId endpointId

return nullptr;
}

EmberAfStatus SetParentEndpointForEndpoint(EndpointId childEndpoint, EndpointId parentEndpoint)
{
uint16_t childIndex = emberAfIndexFromEndpoint(childEndpoint);
uint16_t parentIndex = emberAfIndexFromEndpoint(parentEndpoint);

if (childIndex == kEmberInvalidEndpointIndex || parentIndex == kEmberInvalidEndpointIndex)
{
return EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT;
}
emAfEndpoints[childIndex].parentEndpointId = parentEndpoint;
return EMBER_ZCL_STATUS_SUCCESS;
}

EmberAfStatus SetFlatCompositionForEndpoint(EndpointId endpoint)
{
uint16_t index = emberAfIndexFromEndpoint(endpoint);
if (index == kEmberInvalidEndpointIndex)
{
return EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT;
}
emAfEndpoints[index].bitmask.Clear(EmberAfEndpointOptions::isTreeComposition);
emAfEndpoints[index].bitmask.Set(EmberAfEndpointOptions::isFlatComposition);
return EMBER_ZCL_STATUS_SUCCESS;
}

EmberAfStatus SetTreeCompositionForEndpoint(EndpointId endpoint)
{
uint16_t index = emberAfIndexFromEndpoint(endpoint);
if (index == kEmberInvalidEndpointIndex)
{
return EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT;
}
emAfEndpoints[index].bitmask.Clear(EmberAfEndpointOptions::isFlatComposition);
emAfEndpoints[index].bitmask.Set(EmberAfEndpointOptions::isTreeComposition);
mhazley marked this conversation as resolved.
Show resolved Hide resolved
return EMBER_ZCL_STATUS_SUCCESS;
}

bool IsFlatCompositionForEndpoint(EndpointId endpoint)
{
uint16_t index = emberAfIndexFromEndpoint(endpoint);
if (index == kEmberInvalidEndpointIndex)
{
return false;
}
return emAfEndpoints[index].bitmask.Has(EmberAfEndpointOptions::isFlatComposition);
}

bool IsTreeCompositionForEndpoint(EndpointId endpoint)
{
uint16_t index = emberAfIndexFromEndpoint(endpoint);
if (index == kEmberInvalidEndpointIndex)
{
return false;
}
return emAfEndpoints[index].bitmask.Has(EmberAfEndpointOptions::isTreeComposition);
}

} // namespace app
} // namespace chip

Expand Down
Loading