Skip to content

Commit

Permalink
Merge branch 'pr_863' into 'main'
Browse files Browse the repository at this point in the history
[GH_PR] support r/w floating(single) value type (CON-1077)

See merge request app-frameworks/esp-matter!674
  • Loading branch information
dhrishi committed Apr 2, 2024
2 parents dda2d77 + f913c85 commit 434aa0b
Show file tree
Hide file tree
Showing 7 changed files with 741 additions and 628 deletions.
438 changes: 219 additions & 219 deletions components/esp_matter/esp_matter_attribute.cpp

Large diffs are not rendered by default.

120 changes: 60 additions & 60 deletions components/esp_matter/esp_matter_attribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -479,14 +479,14 @@ attribute_t *create_replacement_product_list(cluster_t *cluster, uint8_t *value,

namespace carbon_monoxide_concentration_measurement {
namespace attribute {
attribute_t *create_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_min_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_max_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_peak_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_min_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_max_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_peak_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_peak_measured_value_window(cluster_t *cluster, uint32_t value);
attribute_t *create_average_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_average_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_average_measured_value_window(cluster_t *cluster, uint32_t value);
attribute_t *create_uncertainty(cluster_t *cluster, uint16_t value);
attribute_t *create_uncertainty(cluster_t *cluster, float value);
attribute_t *create_measurement_unit(cluster_t *cluster, uint8_t value);
attribute_t *create_measurement_medium(cluster_t *cluster, uint8_t value);
attribute_t *create_level_value(cluster_t *cluster, uint8_t value);
Expand All @@ -495,14 +495,14 @@ attribute_t *create_level_value(cluster_t *cluster, uint8_t value);

namespace carbon_dioxide_concentration_measurement {
namespace attribute {
attribute_t *create_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_min_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_max_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_peak_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_min_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_max_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_peak_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_peak_measured_value_window(cluster_t *cluster, uint32_t value);
attribute_t *create_average_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_average_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_average_measured_value_window(cluster_t *cluster, uint32_t value);
attribute_t *create_uncertainty(cluster_t *cluster, uint16_t value);
attribute_t *create_uncertainty(cluster_t *cluster, float value);
attribute_t *create_measurement_unit(cluster_t *cluster, uint8_t value);
attribute_t *create_measurement_medium(cluster_t *cluster, uint8_t value);
attribute_t *create_level_value(cluster_t *cluster, uint8_t value);
Expand All @@ -511,14 +511,14 @@ attribute_t *create_level_value(cluster_t *cluster, uint8_t value);

namespace nitrogen_dioxide_concentration_measurement {
namespace attribute {
attribute_t *create_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_min_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_max_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_peak_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_min_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_max_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_peak_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_peak_measured_value_window(cluster_t *cluster, uint32_t value);
attribute_t *create_average_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_average_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_average_measured_value_window(cluster_t *cluster, uint32_t value);
attribute_t *create_uncertainty(cluster_t *cluster, uint16_t value);
attribute_t *create_uncertainty(cluster_t *cluster, float value);
attribute_t *create_measurement_unit(cluster_t *cluster, uint8_t value);
attribute_t *create_measurement_medium(cluster_t *cluster, uint8_t value);
attribute_t *create_level_value(cluster_t *cluster, uint8_t value);
Expand All @@ -527,14 +527,14 @@ attribute_t *create_level_value(cluster_t *cluster, uint8_t value);

namespace ozone_concentration_measurement {
namespace attribute {
attribute_t *create_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_min_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_max_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_peak_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_min_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_max_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_peak_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_peak_measured_value_window(cluster_t *cluster, uint32_t value);
attribute_t *create_average_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_average_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_average_measured_value_window(cluster_t *cluster, uint32_t value);
attribute_t *create_uncertainty(cluster_t *cluster, uint16_t value);
attribute_t *create_uncertainty(cluster_t *cluster, float value);
attribute_t *create_measurement_unit(cluster_t *cluster, uint8_t value);
attribute_t *create_measurement_medium(cluster_t *cluster, uint8_t value);
attribute_t *create_level_value(cluster_t *cluster, uint8_t value);
Expand All @@ -543,14 +543,14 @@ attribute_t *create_level_value(cluster_t *cluster, uint8_t value);

namespace formaldehyde_concentration_measurement {
namespace attribute {
attribute_t *create_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_min_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_max_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_peak_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_min_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_max_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_peak_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_peak_measured_value_window(cluster_t *cluster, uint32_t value);
attribute_t *create_average_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_average_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_average_measured_value_window(cluster_t *cluster, uint32_t value);
attribute_t *create_uncertainty(cluster_t *cluster, uint16_t value);
attribute_t *create_uncertainty(cluster_t *cluster, float value);
attribute_t *create_measurement_unit(cluster_t *cluster, uint8_t value);
attribute_t *create_measurement_medium(cluster_t *cluster, uint8_t value);
attribute_t *create_level_value(cluster_t *cluster, uint8_t value);
Expand All @@ -559,14 +559,14 @@ attribute_t *create_level_value(cluster_t *cluster, uint8_t value);

namespace pm1_concentration_measurement {
namespace attribute {
attribute_t *create_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_min_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_max_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_peak_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_min_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_max_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_peak_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_peak_measured_value_window(cluster_t *cluster, uint32_t value);
attribute_t *create_average_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_average_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_average_measured_value_window(cluster_t *cluster, uint32_t value);
attribute_t *create_uncertainty(cluster_t *cluster, uint16_t value);
attribute_t *create_uncertainty(cluster_t *cluster, float value);
attribute_t *create_measurement_unit(cluster_t *cluster, uint8_t value);
attribute_t *create_measurement_medium(cluster_t *cluster, uint8_t value);
attribute_t *create_level_value(cluster_t *cluster, uint8_t value);
Expand All @@ -575,14 +575,14 @@ attribute_t *create_level_value(cluster_t *cluster, uint8_t value);

namespace pm25_concentration_measurement {
namespace attribute {
attribute_t *create_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_min_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_max_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_peak_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_min_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_max_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_peak_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_peak_measured_value_window(cluster_t *cluster, uint32_t value);
attribute_t *create_average_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_average_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_average_measured_value_window(cluster_t *cluster, uint32_t value);
attribute_t *create_uncertainty(cluster_t *cluster, uint16_t value);
attribute_t *create_uncertainty(cluster_t *cluster, float value);
attribute_t *create_measurement_unit(cluster_t *cluster, uint8_t value);
attribute_t *create_measurement_medium(cluster_t *cluster, uint8_t value);
attribute_t *create_level_value(cluster_t *cluster, uint8_t value);
Expand All @@ -591,14 +591,14 @@ attribute_t *create_level_value(cluster_t *cluster, uint8_t value);

namespace pm10_concentration_measurement {
namespace attribute {
attribute_t *create_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_min_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_max_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_peak_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_min_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_max_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_peak_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_peak_measured_value_window(cluster_t *cluster, uint32_t value);
attribute_t *create_average_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_average_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_average_measured_value_window(cluster_t *cluster, uint32_t value);
attribute_t *create_uncertainty(cluster_t *cluster, uint16_t value);
attribute_t *create_uncertainty(cluster_t *cluster, float value);
attribute_t *create_measurement_unit(cluster_t *cluster, uint8_t value);
attribute_t *create_measurement_medium(cluster_t *cluster, uint8_t value);
attribute_t *create_level_value(cluster_t *cluster, uint8_t value);
Expand All @@ -607,14 +607,14 @@ attribute_t *create_level_value(cluster_t *cluster, uint8_t value);

namespace radon_concentration_measurement {
namespace attribute {
attribute_t *create_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_min_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_max_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_peak_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_min_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_max_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_peak_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_peak_measured_value_window(cluster_t *cluster, uint32_t value);
attribute_t *create_average_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_average_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_average_measured_value_window(cluster_t *cluster, uint32_t value);
attribute_t *create_uncertainty(cluster_t *cluster, uint16_t value);
attribute_t *create_uncertainty(cluster_t *cluster, float value);
attribute_t *create_measurement_unit(cluster_t *cluster, uint8_t value);
attribute_t *create_measurement_medium(cluster_t *cluster, uint8_t value);
attribute_t *create_level_value(cluster_t *cluster, uint8_t value);
Expand All @@ -623,14 +623,14 @@ attribute_t *create_level_value(cluster_t *cluster, uint8_t value);

namespace total_volatile_organic_compounds_concentration_measurement {
namespace attribute {
attribute_t *create_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_min_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_max_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_peak_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_min_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_max_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_peak_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_peak_measured_value_window(cluster_t *cluster, uint32_t value);
attribute_t *create_average_measured_value(cluster_t *cluster, nullable<uint16_t> value);
attribute_t *create_average_measured_value(cluster_t *cluster, nullable<float> value);
attribute_t *create_average_measured_value_window(cluster_t *cluster, uint32_t value);
attribute_t *create_uncertainty(cluster_t *cluster, uint16_t value);
attribute_t *create_uncertainty(cluster_t *cluster, float value);
attribute_t *create_measurement_unit(cluster_t *cluster, uint8_t value);
attribute_t *create_measurement_medium(cluster_t *cluster, uint8_t value);
attribute_t *create_level_value(cluster_t *cluster, uint8_t value);
Expand Down
42 changes: 42 additions & 0 deletions components/esp_matter/esp_matter_attribute_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,18 @@ static esp_err_t console_set_handler(int argc, char **argv)
uint16_t value = atoi(argv[3]);
val = esp_matter_enum16(value);
}
} else if (type == ESP_MATTER_VAL_TYPE_FLOAT) {
if (matter_attribute->IsNullable()) {
if (strncmp(argv[3], "null", sizeof("null")) == 0) {
val = esp_matter_nullable_float(nullable<float>());
} else {
float value = (float)atof(argv[3]);
val = esp_matter_nullable_float(value);
}
} else {
float value = (float)atof(argv[3]);
val = esp_matter_float(value);
}
} else {
ESP_LOGE(TAG, "Type not handled: %d", type);
return ESP_ERR_INVALID_ARG;
Expand Down Expand Up @@ -935,6 +947,20 @@ static esp_err_t console_get_handler(int argc, char **argv)
} else {
val = esp_matter_enum16(Traits::StorageToWorking(value));
}
} else if (type == ESP_MATTER_VAL_TYPE_FLOAT) {
using Traits = chip::app::NumericAttributeTraits<float>;
Traits::StorageType value;
uint8_t *read_able = Traits::ToAttributeStoreRepresentation(value);
get_val_raw(endpoint_id, cluster_id, attribute_id, read_able, sizeof(value));
if (matter_attribute->IsNullable()) {
if (Traits::IsNullValue(value)) {
val = esp_matter_nullable_float(nullable<float>());
} else {
val = esp_matter_nullable_float(Traits::StorageToWorking(value));
}
} else {
val = esp_matter_float(Traits::StorageToWorking(value));
}
} else {
ESP_LOGE(TAG, "Type not handled: %d", type);
return ESP_ERR_INVALID_ARG;
Expand Down Expand Up @@ -1828,6 +1854,22 @@ static esp_err_t get_attr_val_from_data(esp_matter_attr_val_t *val, EmberAfAttri
break;
}

case ZCL_SINGLE_ATTRIBUTE_TYPE: {
using Traits = chip::app::NumericAttributeTraits<float>;
Traits::StorageType attribute_value;
memcpy((float *)&attribute_value, value, sizeof(Traits::StorageType));
if (attribute_metadata->IsNullable()) {
if (Traits::IsNullValue(attribute_value)) {
*val = esp_matter_nullable_float(nullable<float>());
} else {
*val = esp_matter_nullable_float(attribute_value);
}
} else {
*val = esp_matter_float(attribute_value);
}
break;
}

default:
*val = esp_matter_invalid(NULL);
break;
Expand Down
Loading

0 comments on commit 434aa0b

Please sign in to comment.