Skip to content

Commit 6c6b980

Browse files
authored
feat(zigbee_ep): use static heap memory allocation
1 parent bf3e5c1 commit 6c6b980

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

libraries/Zigbee/src/ZigbeeEP.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ void ZigbeeEP::setVersion(uint8_t version) {
3535
}
3636

3737
bool ZigbeeEP::setManufacturerAndModel(const char *name, const char *model) {
38+
// Allocate a new array of size length + 2 (1 for the length, 1 for null terminator)
39+
// This memory space can't be deleted or overwritten, therefore using static
40+
static char zb_name[ZB_MAX_NAME_LENGTH + 2];
41+
static char zb_model[ZB_MAX_NAME_LENGTH + 2];
42+
3843
// Convert manufacturer to ZCL string
3944
size_t name_length = strlen(name);
4045
size_t model_length = strlen(model);
@@ -48,9 +53,6 @@ bool ZigbeeEP::setManufacturerAndModel(const char *name, const char *model) {
4853
log_e("Failed to get basic cluster");
4954
return false;
5055
}
51-
// Allocate a new array of size length + 2 (1 for the length, 1 for null terminator)
52-
char zb_name[ZB_MAX_NAME_LENGTH + 2];
53-
char zb_model[ZB_MAX_NAME_LENGTH + 2];
5456
// Store the length as the first element
5557
zb_name[0] = static_cast<char>(name_length); // Cast size_t to char
5658
zb_model[0] = static_cast<char>(model_length);
@@ -245,14 +247,14 @@ void ZigbeeEP::zbReadBasicCluster(const esp_zb_zcl_attribute_t *attribute) {
245247
zbstring_t *zbstr = (zbstring_t *)attribute->data.value;
246248
memcpy(_read_manufacturer, zbstr->data, zbstr->len);
247249
_read_manufacturer[zbstr->len] = '\0';
248-
log_i("Peer Manufacturer is \"%s\"", zb_manufacturer);
250+
log_i("Peer Manufacturer is \"%s\"", _read_manufacturer);
249251
xSemaphoreGive(lock);
250252
}
251253
if (attribute->id == ESP_ZB_ZCL_ATTR_BASIC_MODEL_IDENTIFIER_ID && attribute->data.type == ESP_ZB_ZCL_ATTR_TYPE_CHAR_STRING && attribute->data.value) {
252254
zbstring_t *zbstr = (zbstring_t *)attribute->data.value;
253255
memcpy(_read_model, zbstr->data, zbstr->len);
254256
_read_model[zbstr->len] = '\0';
255-
log_i("Peer Model is \"%s\"", zb_model);
257+
log_i("Peer Model is \"%s\"", _read_model);
256258
xSemaphoreGive(lock);
257259
}
258260
}

0 commit comments

Comments
 (0)