Skip to content

Commit

Permalink
Merge branch 'controller/json_attribute_write' into 'main'
Browse files Browse the repository at this point in the history
esp_matter_controller: Add json_parser support for write-attr command

See merge request app-frameworks/esp-matter!240
  • Loading branch information
chshu committed Dec 12, 2022
2 parents e3ce60e + aec8bd7 commit 1baf476
Show file tree
Hide file tree
Showing 6 changed files with 399 additions and 37 deletions.
2 changes: 1 addition & 1 deletion components/esp_matter_controller/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ endif()

idf_component_register(SRC_DIRS ${src_dirs_list}
INCLUDE_DIRS ${include_dirs_list}
REQUIRES chip esp_matter esp_matter_console)
REQUIRES chip esp_matter esp_matter_console json_parser)
46 changes: 46 additions & 0 deletions components/esp_matter_controller/esp_matter_controller_utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2022 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <esp_matter_controller_utils.h>
#include <string.h>

static uint8_t char_to_hex_digit(char c)
{
if (c >= '0' && c <= '9') {
return c - '0';
} else if (c >= 'a' && c <= 'f') {
return c - 'a' + 10;
} else if (c >= 'A' && c <= 'F') {
return c - 'A' + 10;
} else {
return 0xFF;
}
}

int oct_str_to_byte_arr(char *oct_str, uint8_t *byte_array)
{
if (strlen(oct_str) % 2 != 0) {
return -1;
}
size_t byte_array_len = strlen(oct_str) / 2;
for (size_t idx = 0; idx < byte_array_len; ++idx) {
uint8_t digit1 = char_to_hex_digit(oct_str[2 * idx]);
uint8_t digit2 = char_to_hex_digit(oct_str[2 * idx + 1]);
if (digit1 == 0xFF || digit2 == 0xFF) {
return -1;
}
byte_array[idx] = (digit1 << 4) + digit2;
}
return byte_array_len;
}
19 changes: 19 additions & 0 deletions components/esp_matter_controller/esp_matter_controller_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2022 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include <stdint.h>

int oct_str_to_byte_arr(char *oct_str, uint8_t *byte_array);
Loading

0 comments on commit 1baf476

Please sign in to comment.