Skip to content

Commit

Permalink
Remove unused ZCL message-manipulation bits. (#26964)
Browse files Browse the repository at this point in the history
These were being used by the old scenes implementation, which is now gone.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Jun 15, 2023
1 parent f918c2b commit 1532424
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 193 deletions.
18 changes: 0 additions & 18 deletions src/app/util/af.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,24 +241,6 @@ uint16_t emberAfFixedEndpointCount(void);
*/
bool emberAfIsTypeSigned(EmberAfAttributeType dataType);

/**
* @brief Function that extracts a 16-bit integer from the message buffer
*/
uint16_t emberAfGetInt16u(const uint8_t * message, uint16_t currentIndex, uint16_t msgLen);

/**
* @brief Macro for consistency, that extracts single byte out of the message
*/
#define emberAfGetInt8u(message, currentIndex, msgLen) message[currentIndex]

/**
* @brief Macro for consistency that copies a uint8_t from variable into buffer.
*/
#define emberAfCopyInt8u(data, index, x) (data[index] = (x))
/**
* @brief function that copies a uint16_t value into a buffer
*/
void emberAfCopyInt16u(uint8_t * data, uint16_t index, uint16_t x);
/*
* @brief Function that copies a ZCL string type into a buffer. The size
* parameter should indicate the maximum number of characters to copy to the
Expand Down
4 changes: 0 additions & 4 deletions src/app/util/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,3 @@
#include <app/util/attribute-storage.h>
#include <app/util/attribute-table.h>
#include <app/util/util.h>

// the variables used to setup and send responses to cluster messages
extern uint8_t appResponseData[EMBER_AF_RESPONSE_BUFFER_LEN];
extern uint16_t appResponseLength;
4 changes: 0 additions & 4 deletions src/app/util/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@
#define EMBER_BINDING_TABLE_SIZE 10
#endif // EMBER_BINDING_TABLE_SIZE

// Legacy definition that we can remove once Scenes is no longer using the
// Zigbee message-writing bits.
#define EMBER_AF_MAXIMUM_SEND_PAYLOAD_LENGTH 1024

/**
* @brief CHIP uses millisecond ticks
*/
Expand Down
101 changes: 2 additions & 99 deletions src/app/util/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,108 +16,11 @@
*/

#include <app/util/af.h>
#include <app/util/config.h>
#include <app/util/util.h>
#include <lib/support/TypeTraits.h>
#include <lib/core/CHIPEncoding.h>

using namespace chip;

//------------------------------------------------------------------------------

// these variables are for storing responses that are created by zcl-utils
// in functions called from emberIncomingMsgHandler. The response is sent
// from emberAfTick (meant to be called immediately after emberTick).
// There is only space for one response as each call to emberTick will
// only result in a single call to emberIncomingMsgHandler. If the device
// receives multiple ZCL messages, the stack will queue these and hand
// these to the application via emberIncomingMsgHandler one at a time.
uint8_t appResponseData[EMBER_AF_RESPONSE_BUFFER_LEN];
uint16_t appResponseLength;

//------------------------------------------------------------------------------
// Utilities for adding bytes to the response buffer: appResponseData. These
// functions take care of incrementing appResponseLength.

uint8_t * emberAfPutInt8uInResp(uint8_t value)
{
// emberAfDebugPrint("try %x max %x\r\n", appResponseLength, EMBER_AF_RESPONSE_BUFFER_LEN);
if (appResponseLength < EMBER_AF_RESPONSE_BUFFER_LEN)
{
// emberAfDebugPrint("put %x at spot %x\r\n", value, appResponseLength);
appResponseData[appResponseLength] = value;
appResponseLength++;
return &appResponseData[appResponseLength - 1];
}

return nullptr;
}

uint16_t * emberAfPutInt16uInResp(uint16_t value)
{
uint8_t * low = emberAfPutInt8uInResp(EMBER_LOW_BYTE(value));
uint8_t * high = emberAfPutInt8uInResp(EMBER_HIGH_BYTE(value));

if (low && high)
{
return (uint16_t *) low;
}

return nullptr;
}

uint8_t * emberAfPutBlockInResp(const uint8_t * data, uint16_t length)
{
if ((appResponseLength + length) < EMBER_AF_RESPONSE_BUFFER_LEN)
{
memmove(appResponseData + appResponseLength, data, length);
appResponseLength = static_cast<uint16_t>(appResponseLength + length);
return &appResponseData[appResponseLength - length];
}

return nullptr;
}

uint8_t * emberAfPutStringInResp(const uint8_t * buffer)
{
uint8_t length = emberAfStringLength(buffer);
return emberAfPutBlockInResp(buffer, static_cast<uint16_t>(length + 1));
}

void emberAfPutInt16sInResp(int16_t value)
{
emberAfPutInt16uInResp(static_cast<uint16_t>(value));
}

// ------------------------------------
// Utilities for reading from RAM buffers (reading from incoming message
// buffer)
// ------------------------------------

// retrieves an uint64_t which contains between 1 and 8 bytes of relevant data
// depending on number of bytes requested.
uint64_t emberAfGetInt(const uint8_t * message, uint16_t currentIndex, uint16_t msgLen, uint8_t bytes)
{
uint64_t result = 0;
uint8_t i = bytes;
if ((currentIndex + bytes) > msgLen)
{
emberAfDebugPrintln("GetInt, %x bytes short", bytes);
emberAfDebugFlush();
return 0;
}
while (i > 0)
{
result = (result << 8) + message[(currentIndex + i) - 1];
i--;
}
return result;
}

uint16_t emberAfGetInt16u(const uint8_t * message, uint16_t currentIndex, uint16_t msgLen)
{
return static_cast<uint16_t>(emberAfGetInt(message, currentIndex, msgLen, 2));
}

uint8_t emberAfStringLength(const uint8_t * buffer)
{
// The first byte specifies the length of the string. A length of 0xFF means
Expand All @@ -129,6 +32,6 @@ uint16_t emberAfLongStringLength(const uint8_t * buffer)
{
// The first two bytes specify the length of the long string. A length of
// 0xFFFF means the string is invalid and there is no character data.
uint16_t length = emberAfGetInt16u(buffer, 0, 2);
uint16_t length = Encoding::LittleEndian::Get16(buffer);
return (length == 0xFFFF ? 0 : length);
}
6 changes: 0 additions & 6 deletions src/app/util/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,6 @@ uint16_t emberAfFindClusterNameIndex(ClusterId cluster)
return 0xFFFF;
}

void emberAfCopyInt16u(uint8_t * data, uint16_t index, uint16_t x)
{
data[index] = (uint8_t)(((x)) & 0xFF);
data[index + 1] = (uint8_t)(((x) >> 8) & 0xFF);
}

void emberAfCopyString(uint8_t * dest, const uint8_t * src, size_t size)
{
if (src == nullptr)
Expand Down
26 changes: 2 additions & 24 deletions src/app/util/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#include <inttypes.h>

#include <app/util/af-types.h>

// Cluster name structure
typedef struct
{
Expand All @@ -28,11 +30,6 @@ typedef struct

extern const EmberAfClusterName zclClusterNames[];

#include <app/util/af.h>

// EMBER_AF_MAXIMUM_SEND_PAYLOAD_LENGTH is defined in config.h
#define EMBER_AF_RESPONSE_BUFFER_LEN EMBER_AF_MAXIMUM_SEND_PAYLOAD_LENGTH

void emberAfInit();
uint16_t emberAfFindClusterNameIndex(chip::ClusterId cluster);

Expand All @@ -45,25 +42,6 @@ uint16_t emberAfFindClusterNameIndex(chip::ClusterId cluster);
*/
EmberAfDifferenceType emberAfGetDifference(uint8_t * pData, EmberAfDifferenceType value, uint8_t dataSize);

/**
* Retrieves an uint64_t from the given Zigbee payload. The integer retrieved
* may be cast into an integer of the appropriate size depending on the
* number of bytes requested from the message. In Zigbee, all integers are
* passed over the air in LSB form. LSB to MSB conversion is
* done within this function automatically before the integer is returned.
*
* Obviously (due to return value) this function can only handle
* the retrieval of integers between 1 and 8 bytes in length.
*
*/
uint64_t emberAfGetInt(const uint8_t * message, uint16_t currentIndex, uint16_t msgLen, uint8_t bytes);

uint8_t * emberAfPutInt8uInResp(uint8_t value);
uint16_t * emberAfPutInt16uInResp(uint16_t value);
uint8_t * emberAfPutBlockInResp(const uint8_t * data, uint16_t length);
uint8_t * emberAfPutStringInResp(const uint8_t * buffer);
void emberAfPutInt16sInResp(int16_t value);

bool emberAfContainsAttribute(chip::EndpointId endpoint, chip::ClusterId clusterId, chip::AttributeId attributeId);

/* @brief returns true if the attribute is known to be volatile (i.e. RAM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <app/util/af.h>
#include <app/util/attribute-storage-null-handling.h>
#include <app/util/odd-sized-integers.h>
#include <lib/core/CHIPEncoding.h>

namespace chip {
namespace app {
Expand Down Expand Up @@ -92,7 +93,12 @@ EmberAfStatus Set(chip::EndpointId endpoint, {{zapTypeToEncodableClusterObjectTy
"value.size() might be too big");
VerifyOrReturnError(value.size() <= {{maxLength}}, EMBER_ZCL_STATUS_CONSTRAINT_ERROR);
uint8_t zclString[{{maxLength}} + {{>sizingBytes}}];
emberAfCopyInt{{#if (isShortString type)}}8{{else}}16{{/if}}u(zclString, 0, static_cast<{{>lengthType}}>(value.size()));
auto length = static_cast<{{>lengthType}}>(value.size());
{{#if (isShortString type)}}
Encoding::Put8(zclString, length);
{{else}}
Encoding::LittleEndian::Put16(zclString, length);
{{/if}}
memcpy(&zclString[{{>sizingBytes}}], value.data(), value.size());
return emberAfWriteAttribute(endpoint, {{>clusterId}}, Id, zclString, ZCL_{{typeAsDelimitedMacro type}}_ATTRIBUTE_TYPE);
{{else}}
Expand Down
Loading

0 comments on commit 1532424

Please sign in to comment.