forked from espressif/esp-matter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'controller/json_attribute_write' into 'main'
esp_matter_controller: Add json_parser support for write-attr command See merge request app-frameworks/esp-matter!240
- Loading branch information
Showing
6 changed files
with
399 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
components/esp_matter_controller/esp_matter_controller_utils.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
components/esp_matter_controller/esp_matter_controller_utils.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Oops, something went wrong.