diff --git a/components/esp_matter_controller/esp_matter_controller_cluster_command.cpp b/components/esp_matter_controller/esp_matter_controller_cluster_command.cpp index 688666abb..a485a19f6 100644 --- a/components/esp_matter_controller/esp_matter_controller_cluster_command.cpp +++ b/components/esp_matter_controller/esp_matter_controller_cluster_command.cpp @@ -19,6 +19,7 @@ #include #endif #include +#include using namespace chip::app::Clusters; static const char *TAG = "cluster_command"; @@ -62,10 +63,10 @@ static esp_err_t send_command(command_data_t *command_data, peer_device_t *remot } return esp_matter::cluster::level_control::command::send_move( remote_device, remote_endpoint_id, - /* move_mode */ (uint8_t)strtol(command_data->command_data_str[0], NULL, 10), - /* rate*/ (uint8_t)strtol(command_data->command_data_str[1], NULL, 10), - /* option_mask */ (uint8_t)strtol(command_data->command_data_str[2], NULL, 10), - /* option_override*/ (uint8_t)strtol(command_data->command_data_str[3], NULL, 10)); + /* move_mode */ string_to_uint8(command_data->command_data_str[0]), + /* rate*/ string_to_uint8(command_data->command_data_str[1]), + /* option_mask */ string_to_uint8(command_data->command_data_str[2]), + /* option_override*/ string_to_uint8(command_data->command_data_str[3])); break; case LevelControl::Commands::MoveToLevel::Id: if (command_data->command_data_count != 4) { @@ -76,10 +77,10 @@ static esp_err_t send_command(command_data_t *command_data, peer_device_t *remot } return esp_matter::cluster::level_control::command::send_move_to_level( remote_device, remote_endpoint_id, - /* level */ (uint8_t)strtol(command_data->command_data_str[0], NULL, 10), - /* transition_time */ (uint16_t)strtol(command_data->command_data_str[1], NULL, 10), - /* option_mask */ (uint8_t)strtol(command_data->command_data_str[2], NULL, 10), - /* option_override */ (uint8_t)strtol(command_data->command_data_str[3], NULL, 10)); + /* level */ string_to_uint8(command_data->command_data_str[0]), + /* transition_time */ string_to_uint16(command_data->command_data_str[1]), + /* option_mask */ string_to_uint8(command_data->command_data_str[2]), + /* option_override */string_to_uint8(command_data->command_data_str[3]) ); break; case LevelControl::Commands::Step::Id: if (command_data->command_data_count != 5) { @@ -90,11 +91,11 @@ static esp_err_t send_command(command_data_t *command_data, peer_device_t *remot } return esp_matter::cluster::level_control::command::send_step( remote_device, remote_endpoint_id, - /* step_mode */ (uint8_t)strtol(command_data->command_data_str[0], NULL, 10), - /* step_size */ (uint8_t)strtol(command_data->command_data_str[1], NULL, 10), - /* transition_time */ (uint16_t)strtol(command_data->command_data_str[2], NULL, 10), - /* option_mask */ (uint8_t)strtol(command_data->command_data_str[3], NULL, 10), - /* option_override */ (uint8_t)strtol(command_data->command_data_str[4], NULL, 10)); + /* step_mode */ string_to_uint8(command_data->command_data_str[0]), + /* step_size */ string_to_uint8(command_data->command_data_str[1]), + /* transition_time */ string_to_uint16(command_data->command_data_str[2]), + /* option_mask */ string_to_uint8(command_data->command_data_str[3]), + /* option_override */ string_to_uint8(command_data->command_data_str[4])); break; case LevelControl::Commands::Stop::Id: if (command_data->command_data_count != 2) { @@ -103,8 +104,8 @@ static esp_err_t send_command(command_data_t *command_data, peer_device_t *remot } return esp_matter::cluster::level_control::command::send_stop( remote_device, remote_endpoint_id, - /* option_mask */ (uint8_t)strtol(command_data->command_data_str[0], NULL, 10), - /* option_override */ (uint8_t)strtol(command_data->command_data_str[1], NULL, 10)); + /* option_mask */ string_to_uint8(command_data->command_data_str[0]), + /* option_override */ string_to_uint8(command_data->command_data_str[1])); break; default: return ESP_ERR_NOT_SUPPORTED; @@ -129,11 +130,11 @@ static esp_err_t send_command(command_data_t *command_data, peer_device_t *remot } return esp_matter::cluster::color_control::command::send_move_to_hue( remote_device, remote_endpoint_id, - /* hue */ (uint8_t)strtol(command_data->command_data_str[0], NULL, 10), - /* direction */ (uint8_t)strtol(command_data->command_data_str[1], NULL, 10), - /* transition_time */ (uint16_t)strtol(command_data->command_data_str[2], NULL, 10), - /* option_mask */ (uint8_t)strtol(command_data->command_data_str[3], NULL, 10), - /* option_override */ (uint8_t)strtol(command_data->command_data_str[4], NULL, 10)); + /* hue */ string_to_uint8(command_data->command_data_str[0]), + /* direction */ string_to_uint8(command_data->command_data_str[1]), + /* transition_time */ string_to_uint16(command_data->command_data_str[2]), + /* option_mask */ string_to_uint8(command_data->command_data_str[3]), + /* option_override */ string_to_uint8(command_data->command_data_str[4])); break; case ColorControl::Commands::MoveToSaturation::Id: if (command_data->command_data_count != 4) { @@ -144,10 +145,10 @@ static esp_err_t send_command(command_data_t *command_data, peer_device_t *remot } return esp_matter::cluster::color_control::command::send_move_to_saturation( remote_device, remote_endpoint_id, - /* saturation */ (uint8_t)strtol(command_data->command_data_str[0], NULL, 10), - /* transition_time */ (uint16_t)strtol(command_data->command_data_str[1], NULL, 10), - /* option_mask */ (uint8_t)strtol(command_data->command_data_str[2], NULL, 10), - /* option_override */ (uint8_t)strtol(command_data->command_data_str[3], NULL, 10)); + /* saturation */ string_to_uint8(command_data->command_data_str[0]), + /* transition_time */ string_to_uint16(command_data->command_data_str[1]), + /* option_mask */ string_to_uint8(command_data->command_data_str[2]), + /* option_override */ string_to_uint8(command_data->command_data_str[3])); break; case ColorControl::Commands::MoveToHueAndSaturation::Id: if (command_data->command_data_count != 5) { @@ -158,11 +159,11 @@ static esp_err_t send_command(command_data_t *command_data, peer_device_t *remot } return esp_matter::cluster::color_control::command::send_move_to_hue_and_saturation( remote_device, remote_endpoint_id, - /* hue */ (uint8_t)strtol(command_data->command_data_str[0], NULL, 10), - /* saturation */ (uint8_t)strtol(command_data->command_data_str[1], NULL, 10), - /* transition_time */ (uint16_t)strtol(command_data->command_data_str[2], NULL, 10), - /* option_mask */ (uint8_t)strtol(command_data->command_data_str[3], NULL, 10), - /* option_override */ (uint8_t)strtol(command_data->command_data_str[4], NULL, 10)); + /* hue */ string_to_uint8(command_data->command_data_str[0]), + /* saturation */ string_to_uint8(command_data->command_data_str[1]), + /* transition_time */ string_to_uint16(command_data->command_data_str[2]), + /* option_mask */ string_to_uint8(command_data->command_data_str[3]), + /* option_override */ string_to_uint8(command_data->command_data_str[4])); break; default: return ESP_ERR_NOT_SUPPORTED; @@ -228,8 +229,8 @@ esp_err_t send_invoke_cluster_command(uint64_t node_id, uint16_t endpoint_id, in ESP_LOGE(TAG, "Failed to alloc memory for command data"); return ESP_ERR_NO_MEM; } - command_data->cluster_id = (uint32_t)strtol(cmd_data_argv[0], NULL, 10); - command_data->command_id = (uint32_t)strtol(cmd_data_argv[1], NULL, 10); + command_data->cluster_id = string_to_uint32(cmd_data_argv[0]); + command_data->command_id = string_to_uint32(cmd_data_argv[1]); command_data->command_data_count = cmd_data_argc - 2; for (size_t idx = 0; idx < command_data->command_data_count; idx++) { diff --git a/components/esp_matter_controller/esp_matter_controller_console.cpp b/components/esp_matter_controller/esp_matter_controller_console.cpp index aaa8b8815..2b9971619 100644 --- a/components/esp_matter_controller/esp_matter_controller_console.cpp +++ b/components/esp_matter_controller/esp_matter_controller_console.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -60,8 +61,8 @@ static esp_err_t controller_pairing_handler(int argc, char **argv) return ESP_ERR_INVALID_ARG; } - uint64_t nodeId = (uint64_t)strtoull(argv[1], NULL, 10); - uint32_t pincode = (uint32_t)strtoul(argv[2], NULL, 10); + uint64_t nodeId = string_to_uint64(argv[1]); + uint32_t pincode = string_to_uint32(argv[2]); return controller::pairing_on_network(nodeId, pincode); } else if (strncmp(argv[0], "ble-wifi", sizeof("ble-wifi")) == 0) { return ESP_ERR_NOT_SUPPORTED; @@ -77,8 +78,8 @@ static esp_err_t controller_invoke_command_handler(int argc, char **argv) return ESP_ERR_INVALID_ARG; } - uint64_t node_id = (uint64_t)strtoull(argv[0], NULL, 10); - uint16_t endpoint_id = (uint16_t)strtoul(argv[1], NULL, 10); + uint64_t node_id = string_to_uint64(argv[0]); + uint16_t endpoint_id = string_to_uint16(argv[1]); return controller::send_invoke_cluster_command(node_id, endpoint_id, argc - 2, argv + 2); } @@ -89,10 +90,10 @@ static esp_err_t controller_read_attr_handler(int argc, char **argv) return ESP_ERR_INVALID_ARG; } - uint64_t node_id = (uint64_t)strtoull(argv[0], NULL, 10); - uint16_t endpoint_id = (uint16_t)strtoul(argv[1], NULL, 10); - uint32_t cluster_id = (uint32_t)strtoul(argv[2], NULL, 10); - uint32_t attribute_id = (uint32_t)strtoul(argv[3], NULL, 10); + uint64_t node_id = string_to_uint64(argv[0]); + uint16_t endpoint_id = string_to_uint16(argv[1]); + uint32_t cluster_id = string_to_uint32(argv[2]); + uint32_t attribute_id = string_to_uint32(argv[3]); return controller::send_read_attr_command(node_id, endpoint_id, cluster_id, attribute_id); } @@ -103,10 +104,10 @@ static esp_err_t controller_write_attr_handler(int argc, char **argv) return ESP_ERR_INVALID_ARG; } - uint64_t node_id = (uint64_t)strtoull(argv[0], NULL, 10); - uint16_t endpoint_id = (uint16_t)strtoul(argv[1], NULL, 10); - uint32_t cluster_id = (uint32_t)strtoul(argv[2], NULL, 10); - uint32_t attribute_id = (uint32_t)strtoul(argv[3], NULL, 10); + uint64_t node_id = string_to_uint64(argv[0]); + uint16_t endpoint_id = string_to_uint16(argv[1]); + uint32_t cluster_id = string_to_uint32(argv[2]); + uint32_t attribute_id = string_to_uint32(argv[3]); char *attribute_val_str = argv[4]; return controller::send_write_attr_command(node_id, endpoint_id, cluster_id, attribute_id, attribute_val_str); @@ -118,10 +119,10 @@ static esp_err_t controller_read_event_handler(int argc, char **argv) return ESP_ERR_INVALID_ARG; } - uint64_t node_id = (uint64_t)strtoull(argv[0], NULL, 10); - uint16_t endpoint_id = (uint16_t)strtoul(argv[1], NULL, 10); - uint32_t cluster_id = (uint32_t)strtoul(argv[2], NULL, 10); - uint32_t event_id = (uint32_t)strtoul(argv[3], NULL, 10); + uint64_t node_id = string_to_uint64(argv[0]); + uint16_t endpoint_id = string_to_uint16(argv[1]); + uint32_t cluster_id = string_to_uint32(argv[2]); + uint32_t event_id = string_to_uint32(argv[3]); return controller::send_read_event_command(node_id, endpoint_id, cluster_id, event_id); } @@ -132,12 +133,12 @@ static esp_err_t controller_subscribe_attr_handler(int argc, char **argv) return ESP_ERR_INVALID_ARG; } - uint64_t node_id = (uint64_t)strtoull(argv[0], NULL, 10); - uint16_t endpoint_id = (uint16_t)strtoul(argv[1], NULL, 10); - uint32_t cluster_id = (uint32_t)strtoul(argv[2], NULL, 10); - uint32_t attribute_id = (uint32_t)strtoul(argv[3], NULL, 10); - uint16_t min_interval = (uint16_t)strtoul(argv[4], NULL, 10); - uint16_t max_interval = (uint16_t)strtoul(argv[5], NULL, 10); + uint64_t node_id = string_to_uint64(argv[0]); + uint16_t endpoint_id = string_to_uint16(argv[1]); + uint32_t cluster_id = string_to_uint32(argv[2]); + uint32_t attribute_id = string_to_uint32(argv[3]); + uint16_t min_interval = string_to_uint16(argv[4]); + uint16_t max_interval = string_to_uint16(argv[5]); return controller::send_subscribe_attr_command(node_id, endpoint_id, cluster_id, attribute_id, min_interval, max_interval); } @@ -148,12 +149,12 @@ static esp_err_t controller_subscribe_event_handler(int argc, char **argv) return ESP_ERR_INVALID_ARG; } - uint64_t node_id = (uint64_t)strtoull(argv[0], NULL, 10); - uint16_t endpoint_id = (uint16_t)strtoul(argv[1], NULL, 10); - uint32_t cluster_id = (uint32_t)strtoul(argv[2], NULL, 10); - uint32_t event_id = (uint32_t)strtoul(argv[3], NULL, 10); - uint16_t min_interval = (uint16_t)strtoul(argv[4], NULL, 10); - uint16_t max_interval = (uint16_t)strtoul(argv[5], NULL, 10); + uint64_t node_id = string_to_uint64(argv[0]); + uint16_t endpoint_id = string_to_uint16(argv[1]); + uint32_t cluster_id = string_to_uint32(argv[2]); + uint32_t event_id = string_to_uint32(argv[3]); + uint16_t min_interval = string_to_uint16(argv[4]); + uint16_t max_interval = string_to_uint16(argv[5]); return controller::send_subscribe_event_command(node_id, endpoint_id, cluster_id, event_id, min_interval, max_interval); } @@ -163,8 +164,8 @@ static esp_err_t controller_shutdown_subscription_handler(int argc, char **argv) if (argc != 2) { return ESP_ERR_INVALID_ARG; } - uint64_t node_id = (uint64_t)strtoull(argv[0], NULL, 10); - uint32_t subscription_id = (uint32_t) strtoul(argv[1], NULL, 10); + uint64_t node_id = string_to_uint64(argv[0]); + uint32_t subscription_id = string_to_uint32(argv[1]); return controller::send_shutdown_subscription(node_id, subscription_id); } diff --git a/components/esp_matter_controller/esp_matter_controller_read_command.cpp b/components/esp_matter_controller/esp_matter_controller_read_command.cpp index 2b604e94a..bcaf40026 100644 --- a/components/esp_matter_controller/esp_matter_controller_read_command.cpp +++ b/components/esp_matter_controller/esp_matter_controller_read_command.cpp @@ -139,12 +139,12 @@ void read_command::OnEventData(const chip::app::EventHeader &event_header, chip: void read_command::OnError(CHIP_ERROR error) { - ChipLogError(chipTool, "Read Error: %s", chip::ErrorStr(error)); + ESP_LOGE(TAG, "Read Error: %s", chip::ErrorStr(error)); } void read_command::OnDeallocatePaths(chip::app::ReadPrepareParams &&aReadPrepareParams) { - // Intentionally eempty because the AttributePathParamsList or EventPathParamsList will be deleted with the + // Intentionally empty because the AttributePathParamsList or EventPathParamsList will be deleted with the // read_command. } diff --git a/components/esp_matter_controller/esp_matter_controller_subscribe_command.cpp b/components/esp_matter_controller/esp_matter_controller_subscribe_command.cpp index 87668df1b..d5450e724 100644 --- a/components/esp_matter_controller/esp_matter_controller_subscribe_command.cpp +++ b/components/esp_matter_controller/esp_matter_controller_subscribe_command.cpp @@ -142,13 +142,13 @@ void subscribe_command::OnEventData(const chip::app::EventHeader &event_header, void subscribe_command::OnError(CHIP_ERROR error) { - ChipLogError(chipTool, "Subscribe Error: %s", chip::ErrorStr(error)); + ESP_LOGE(TAG, "Subscribe Error: %s", chip::ErrorStr(error)); } void subscribe_command::OnDeallocatePaths(chip::app::ReadPrepareParams &&aReadPrepareParams) { - // Intentionally eempty because the AttributePathParamsList or EventPathParamsList will be deleted with the - // read_command. + // Intentionally empty because the AttributePathParamsList or EventPathParamsList will be deleted with the + // subscribe_command. } void subscribe_command::OnSubscriptionEstablished(chip::SubscriptionId subscriptionId) diff --git a/components/esp_matter_controller/esp_matter_controller_utils.cpp b/components/esp_matter_controller/esp_matter_controller_utils.cpp index 23c8141d9..ee72b2474 100644 --- a/components/esp_matter_controller/esp_matter_controller_utils.cpp +++ b/components/esp_matter_controller/esp_matter_controller_utils.cpp @@ -44,3 +44,31 @@ int oct_str_to_byte_arr(char *oct_str, uint8_t *byte_array) } return byte_array_len; } + +uint64_t string_to_uint64(char *str) +{ + if (strlen(str) > 2 && str[0] == '0' && str[1] == 'x') { + return strtoull(&str[2], NULL, 16); + } else { + return strtoull(str, NULL, 10); + } +} + +uint32_t string_to_uint32(char *str) +{ + if (strlen(str) > 2 && str[0] == '0' && str[1] == 'x') { + return strtoul(&str[2], NULL, 16); + } else { + return strtoul(str, NULL, 10); + } +} + +uint16_t string_to_uint16(char *str) +{ + return (uint16_t)string_to_uint32(str); +} + +uint8_t string_to_uint8(char *str) +{ + return (uint8_t)string_to_uint32(str); +} diff --git a/components/esp_matter_controller/esp_matter_controller_utils.h b/components/esp_matter_controller/esp_matter_controller_utils.h index 0447538ac..4582357b3 100644 --- a/components/esp_matter_controller/esp_matter_controller_utils.h +++ b/components/esp_matter_controller/esp_matter_controller_utils.h @@ -17,3 +17,11 @@ #include int oct_str_to_byte_arr(char *oct_str, uint8_t *byte_array); + +uint64_t string_to_uint64(char *str); + +uint32_t string_to_uint32(char *str); + +uint16_t string_to_uint16(char *str); + +uint8_t string_to_uint8(char *str); diff --git a/components/esp_matter_controller/esp_matter_controller_write_command.cpp b/components/esp_matter_controller/esp_matter_controller_write_command.cpp index 0771047af..68c60ffa3 100644 --- a/components/esp_matter_controller/esp_matter_controller_write_command.cpp +++ b/components/esp_matter_controller/esp_matter_controller_write_command.cpp @@ -99,14 +99,14 @@ static esp_err_t write_attribute(uint64_t node_id, uint16_t endpoint_id, uint32_ case OnOff::Attributes::OnTime::Id: case OnOff::Attributes::OffWaitTime::Id: { write_command *cmd = New>(node_id, endpoint_id, OnOff::Id, attribute_id, - (uint16_t)strtol(attribute_val_str, NULL, 10)); + string_to_uint16(attribute_val_str)); ESP_RETURN_ON_FALSE(cmd, ESP_ERR_NO_MEM, TAG, "Failed to alloc memory for write_command"); return cmd->send_command(); break; } case OnOff::Attributes::StartUpOnOff::Id: { write_command *cmd = New>(node_id, endpoint_id, OnOff::Id, attribute_id, - (uint8_t)strtol(attribute_val_str, NULL, 10)); + string_to_uint8(attribute_val_str)); ESP_RETURN_ON_FALSE(cmd, ESP_ERR_NO_MEM, TAG, "Failed to alloc memory for write_command"); return cmd->send_command(); break; @@ -129,8 +129,8 @@ static esp_err_t write_attribute(uint64_t node_id, uint16_t endpoint_id, uint32_ case LevelControl::Attributes::OnOffTransitionTime::Id: case LevelControl::Attributes::OnTransitionTime::Id: case LevelControl::Attributes::OffTransitionTime::Id: { - write_command *cmd = New>( - node_id, endpoint_id, LevelControl::Id, attribute_id, (uint16_t)strtol(attribute_val_str, NULL, 10)); + write_command *cmd = New>(node_id, endpoint_id, LevelControl::Id, + attribute_id, string_to_uint16(attribute_val_str)); ESP_RETURN_ON_FALSE(cmd, ESP_ERR_NO_MEM, TAG, "Failed to alloc memory for write_command"); return cmd->send_command(); break; @@ -140,7 +140,7 @@ static esp_err_t write_attribute(uint64_t node_id, uint16_t endpoint_id, uint32_ case LevelControl::Attributes::Options::Id: case LevelControl::Attributes::StartUpCurrentLevel::Id: { write_command *cmd = New>(node_id, endpoint_id, LevelControl::Id, attribute_id, - (uint8_t)strtol(attribute_val_str, NULL, 10)); + string_to_uint8(attribute_val_str)); ESP_RETURN_ON_FALSE(cmd, ESP_ERR_NO_MEM, TAG, "Failed to alloc memory for write_command"); return cmd->send_command(); break; @@ -161,15 +161,15 @@ static esp_err_t write_attribute(uint64_t node_id, uint16_t endpoint_id, uint32_ esp_err_t err = ESP_OK; switch (attribute_id) { case ColorControl::Attributes::StartUpColorTemperatureMireds::Id: { - write_command *cmd = New>( - node_id, endpoint_id, ColorControl::Id, attribute_id, (uint16_t)strtol(attribute_val_str, NULL, 10)); + write_command *cmd = New>(node_id, endpoint_id, ColorControl::Id, + attribute_id, string_to_uint16(attribute_val_str)); ESP_RETURN_ON_FALSE(cmd, ESP_ERR_NO_MEM, TAG, "Failed to alloc memory for write_command"); return cmd->send_command(); break; } case ColorControl::Attributes::Options::Id: { write_command *cmd = New>(node_id, endpoint_id, ColorControl::Id, attribute_id, - (uint8_t)strtol(attribute_val_str, NULL, 10)); + string_to_uint8(attribute_val_str)); ESP_RETURN_ON_FALSE(cmd, ESP_ERR_NO_MEM, TAG, "Failed to alloc memory for write_command"); return cmd->send_command(); break; @@ -209,7 +209,7 @@ static esp_err_t parse_acl_json(char *json_str, acl_attr_t *acl, size_t *acl_siz { jparse_ctx_t jctx; ESP_RETURN_ON_FALSE(json_parse_start(&jctx, json_str, strlen(json_str)) == 0, ESP_ERR_INVALID_ARG, TAG, - "ACL json string is wrong"); + "Failed to parse the ACL json string on json_parse_start"); size_t acl_index = 0; while (acl_index < k_max_acl_entries && json_arr_get_object(&jctx, acl_index) == 0) { int int_val; @@ -219,21 +219,22 @@ static esp_err_t parse_acl_json(char *json_str, acl_attr_t *acl, size_t *acl_siz } // Privilege ESP_RETURN_ON_FALSE(json_obj_get_int(&jctx, "privilege", &int_val) == 0, ESP_ERR_INVALID_ARG, TAG, - "ACL json string is wrong on privilege"); + "Failed to get privilege from the ACL json string"); acl->acl_array[acl_index].privilege = Privilege(int_val); // AuthMode ESP_RETURN_ON_FALSE(json_obj_get_int(&jctx, "authMode", &int_val) == 0, ESP_ERR_INVALID_ARG, TAG, - "ACL json string is wrong on authMode"); + "Failed to get authMode from the ACL json string"); acl->acl_array[acl_index].authMode = AuthMode(int_val); // Subjects int subjects_num = 0; if (json_obj_get_array(&jctx, "subjects", &subjects_num) == 0 && subjects_num > 0) { ESP_RETURN_ON_FALSE(subjects_num <= k_max_subjects_per_acl, ESP_ERR_INVALID_ARG, TAG, - "ACL json string is wrong on subjects length"); + "Failed to get subjects from the ACL json string: Error on subjects_num"); for (size_t subj_index = 0; subj_index < subjects_num; ++subj_index) { int64_t subject_val; ESP_RETURN_ON_FALSE(json_arr_get_int64(&jctx, subj_index, &subject_val) == 0, ESP_ERR_INVALID_ARG, TAG, - "ACL json string is wrong subject value"); + "Failed to get subjects from the ACL json string: Error on subject-%u value", + subj_index); acl->subjects_array[acl_index][subj_index] = subject_val; } acl->acl_array[acl_index].subjects.SetNonNull(acl->subjects_array[acl_index], subjects_num); @@ -245,10 +246,10 @@ static esp_err_t parse_acl_json(char *json_str, acl_attr_t *acl, size_t *acl_siz int targets_num = 0; if (json_obj_get_array(&jctx, "targets", &targets_num) == 0 && targets_num > 0) { ESP_RETURN_ON_FALSE(targets_num <= k_max_targets_per_acl, ESP_ERR_INVALID_ARG, TAG, - "ACL json string is wrong on targets length"); + "Failed to get targets from the ACL json string: Error on targets length"); for (size_t targ_index = 0; targ_index < targets_num; ++targ_index) { ESP_RETURN_ON_FALSE(json_arr_get_object(&jctx, targ_index) == 0, ESP_ERR_INVALID_ARG, TAG, - "Failed to get target at index %d", targ_index); + "Failed to get targets from the ACL json string: Error on targets-%u value", targ_index); int64_t cluster_val, device_type_val; int endpoint_val; bool exist_cluster, exist_endpoint, exist_device_type; @@ -258,7 +259,7 @@ static esp_err_t parse_acl_json(char *json_str, acl_attr_t *acl, size_t *acl_siz exist_device_type = json_obj_get_int64(&jctx, "deviceType", &device_type_val) == 0; if ((!exist_cluster && !exist_endpoint && !exist_device_type) || (exist_endpoint && exist_device_type)) { - ESP_LOGE(TAG, "ACL json string is wrong targets value, skip"); + ESP_LOGE(TAG, "Target-%u value is invalid, skip it", targ_index); json_arr_leave_object(&jctx); continue; } @@ -316,7 +317,7 @@ static esp_err_t parse_extension_json(char *json_str, extension_attr_t *extensio { jparse_ctx_t jctx; ESP_RETURN_ON_FALSE(json_parse_start(&jctx, json_str, strlen(json_str)) == 0, ESP_ERR_INVALID_ARG, TAG, - "Extension json string is wrong"); + "Failed to parse the Extension json string on json_parse_start"); size_t index = 0; while (index < k_max_extension_entries && json_arr_get_object(&jctx, index) == 0) { int fabric_index; @@ -326,7 +327,7 @@ static esp_err_t parse_extension_json(char *json_str, extension_attr_t *extensio char data_oct_str[k_max_extension_data_len * 2 + 1] = {0}; if (json_obj_get_string(&jctx, "data", data_oct_str, k_max_extension_data_len * 2 + 1) != 0) { - ESP_LOGE(TAG, "Failed to parse the data json octstring"); + ESP_LOGE(TAG, "Failed to get data from the Extension json string"); return ESP_ERR_INVALID_ARG; } else { size_t data_len = oct_str_to_byte_arr(data_oct_str, extension->data_array[index]); @@ -350,7 +351,7 @@ static esp_err_t write_attribute(uint64_t node_id, uint16_t endpoint_id, uint32_ acl_attr_t *attr_val = New(); ESP_RETURN_ON_FALSE(attr_val, ESP_ERR_NO_MEM, TAG, "Failed to alloc acl_attr_t"); ESP_RETURN_ON_ERROR(parse_acl_json(attribute_val_str, attr_val, &acl_size), TAG, - "Failed to parse the acl json string"); + "Failed to parse the ACL json string"); List access_control_list(attr_val->acl_array, acl_size); write_command> *cmd = New>>(node_id, endpoint_id, AccessControl::Id, attribute_id, access_control_list); @@ -364,10 +365,11 @@ static esp_err_t write_attribute(uint64_t node_id, uint16_t endpoint_id, uint32_ extension_attr_t *attr_val = New(); ESP_RETURN_ON_FALSE(attr_val, ESP_ERR_NO_MEM, TAG, "Failed to alloc extension_attr_t"); ESP_RETURN_ON_ERROR(parse_extension_json(attribute_val_str, attr_val, &extension_size), TAG, - "Failed to parse the acl json string"); + "Failed to parse the Extension json string"); List extension_list(attr_val->extension_array, extension_size); write_command> *cmd = New>>( node_id, endpoint_id, AccessControl::Id, attribute_id, extension_list); + ESP_RETURN_ON_FALSE(cmd, ESP_ERR_NO_MEM, TAG, "Failed to alloc memory for write_command"); cmd->set_attribute_free_handler(extension_attr_free, attr_val); return cmd->send_command(); break; @@ -397,7 +399,7 @@ static esp_err_t parse_binding_json(char *json_str, binding_attr_t *binding, siz { jparse_ctx_t jctx; ESP_RETURN_ON_FALSE(json_parse_start(&jctx, json_str, strlen(json_str)) == 0, ESP_ERR_INVALID_ARG, TAG, - "Binding Table json string is wrong"); + "Failed to parse the Binding json string on json_parse_start"); size_t index = 0; while (index < CONFIG_MAX_BINDINGS && json_arr_get_object(&jctx, index) == 0) { int int_val; @@ -413,11 +415,11 @@ static esp_err_t parse_binding_json(char *json_str, binding_attr_t *binding, siz binding->binding_array[index].group.ClearValue(); ESP_RETURN_ON_FALSE(json_obj_get_int(&jctx, "endpoint", &int_val) == 0, ESP_ERR_INVALID_ARG, TAG, - "Binding Table json string is wrong"); + "Failed to get endpoint from the Binding json string"); binding->binding_array[index].endpoint.SetValue(int_val); ESP_RETURN_ON_FALSE(json_obj_get_int(&jctx, "cluster", &int_val) == 0, ESP_ERR_INVALID_ARG, TAG, - "Binding Table json string is wrong"); + "Failed to get cluster from the Binding json string"); binding->binding_array[index].cluster.SetValue(int_val); } else if (json_obj_get_int64(&jctx, "group", &int64_val) == 0) { // Group binding @@ -426,7 +428,7 @@ static esp_err_t parse_binding_json(char *json_str, binding_attr_t *binding, siz binding->binding_array[index].endpoint.ClearValue(); binding->binding_array[index].cluster.ClearValue(); } else { - ESP_LOGE(TAG, "Binding Table json string is wrong"); + ESP_LOGE(TAG, "The Binding json string is invalid"); return ESP_ERR_INVALID_ARG; } json_arr_leave_object(&jctx); @@ -445,7 +447,7 @@ static esp_err_t write_attribute(uint64_t node_id, uint16_t endpoint_id, uint32_ binding_attr_t *attr_val = chip::Platform::New(); ESP_RETURN_ON_FALSE(attr_val, ESP_ERR_NO_MEM, TAG, "Failed to alloc binding_attr_t"); ESP_RETURN_ON_ERROR(parse_binding_json(attribute_val_str, attr_val, &binding_size), TAG, - "Failed to parse binding json string"); + "Failed to parse the Binding json string"); List binding_list(attr_val->binding_array, binding_size); write_command> *cmd = New>>(node_id, endpoint_id, Binding::Id, attribute_id, binding_list);