matter_controller: Updated the JSON parsing for Invoke command structure changes

This commit is contained in:
Sayon Deep
2024-02-01 16:34:22 +08:00
committed by Hrishikesh Dhayagude
parent eaa455d102
commit 8a201e0db0
9 changed files with 166 additions and 181 deletions

View File

@@ -40,10 +40,9 @@ void on_device_list_update()
static void send_toggle_command(intptr_t context)
{
const char* cmd_data[] = { "0x6" /* on-off-cluster*/, "0x2" /* toggle */ };
if (s_selected_device) {
esp_matter::controller::send_invoke_cluster_command(s_selected_device->node_id, s_selected_device->endpoints[0].endpoint_id,
2, (char**)cmd_data);
OnOff::Id, OnOff::Commands::Toggle::Id, NULL);
}
}

View File

@@ -16,26 +16,26 @@
```
$ cd $RMAKER_PATH/cli
$ ./rainmaker.py login --email <rainmaker-account-email>
$ ./rainmaker.py getparams <rainmaker-node-id-of-controller>
$ ./rainmaker.py login --email <rainmaker-account-email>
$ ./rainmaker.py getparams <rainmaker-node-id-of-controller>
```
**Note**:
**Note**:
1) Please use the same account credentials that are used to claim the controller and signed into the Rainmaker app.
2) Get the rainmaker-node-id-of-controller by logging into [ESP Rainmaker Dashboard](https://dashboard.rainmaker.espressif.com/login).
2) Get the rainmaker-node-id-of-controller by logging into [ESP Rainmaker Dashboard](https://dashboard.rainmaker.espressif.com/login).
## Controlling the devices remotely using rainmaker cli:
```
$ cd $RMAKER_PATH/cli
$ ./rainmaker.py login --email <rainmaker-account-email>
$ ./rainmaker.py login --email <rainmaker-account-email>
```
_Toggle command:_
```
$ ./rainmaker.py setparams --data '{"matter-controller":{"matter-controller-data":{"matter-nodes":[{"matter-node-id": "<matter-node-id-of-device>","endpoints":[{"endpoint-id":"0x1","clusters":[{"cluster-id":"0x6","commands":[{"command-id":"0x2"}]}]}]}]}}}' <rainmaker-node-id-of-controller>
$ ./rainmaker.py setparams --data '{"Matter-Controller":{"Matter-Devices":{"matter-nodes":[{"matter-node-id":"<matter-node-id-of-device>","endpoints":[{"endpoint-id":"0x1","clusters":[{"cluster-id":"0x6","commands":[{"command-id":"0x2"}]}]}]}]}}}' <rainmaker-node-id-of-controller>
```
_Set Brightness command:_
```
./rainmaker.py setparams --data '{"matter-controller":{"matter-controller-data":{"matter-nodes":[{"matter-node-id":"<matter-node-id-of-device>","endpoints":[{"endpoint-id":"0x1","clusters":[{"cluster-id":"0x8","commands":[{"command-id":"0x0","data":{"0":"10","1":"0","2":"0","3":"0"}}]}]}]}]}}}' <rainmaker-node-id-of-controller>
$ ./rainmaker.py setparams --data '{"Matter-Controller":{"Matter-Devices":{"matter-nodes":[{"matter-node-id":"<matter-node-id-of-device>","endpoints":[{"endpoint-id":"0x1","clusters":[{"cluster-id":"0x8","commands":[{"command-id":"0x0","data":{"0:U8": 10, "1:U16": 0, "2:U8": 0, "3:U8": 0}}]}]}]}]}}}' <rainmaker-node-id-of-controller>
```
**Note**:
**Note**:
1) Get the matter-node-id-of-device from the details reported by the controller using getparams command.

View File

@@ -293,10 +293,9 @@ static void send_command_cb(intptr_t arg)
{
device_list_lock my_device_lock;
node_endpoint_id_list_t *ptr = (node_endpoint_id_list_t *)arg;
const char *cmd_data[] = {"0x6" /* on-off-cluster*/, "0x2" /* toggle */};
if (ptr) {
ESP_LOGI(TAG, "send command to node %llx endpoint %d", ptr->node_id, ptr->endpoint_id);
esp_matter::controller::send_invoke_cluster_command(ptr->node_id, ptr->endpoint_id, 2, (char **)cmd_data);
esp_matter::controller::send_invoke_cluster_command(ptr->node_id, ptr->endpoint_id,OnOff::Id, OnOff::Commands::Toggle::Id, NULL);
} else
ESP_LOGE(TAG, "send command with null ptr");
}
@@ -526,7 +525,7 @@ void read_dev_info(void)
std::vector<uint64_t> nid_list;
node_endpoint_id_list_t *dev_ptr = device_to_control.dev_list;
while (dev_ptr) {
//if (dev_ptr->is_Rainmaker_device && dev_ptr->is_online && !dev_ptr->is_subscribed)
//if (dev_ptr->is_Rainmaker_device && dev_ptr->is_online && !dev_ptr->is_subscribed)
//{
//chip::DeviceLayer::PlatformMgr().ScheduleWork(_read_device_state, (intptr_t)dev_ptr);
//dev_ptr->is_subscribed = true;
@@ -535,7 +534,7 @@ void read_dev_info(void)
ESP_LOGI(TAG,"\nnodeid-> %llx\n",dev_ptr->node_id);
dev_ptr = dev_ptr->next;
}
read_node_info(nid_list);
nid_list.clear();

View File

@@ -23,7 +23,7 @@ typedef void *app_driver_handle_t;
* This initializes the button driver associated with the selected board.
*
* @param[in] user_data Custom user data that will be used in button toggle callback.
*
*
* @return Handle on success.
* @return NULL in case of failure.
*/

View File

@@ -28,31 +28,24 @@ using namespace chip::app::Clusters;
static const char *TAG = "controller-ctrl";
static void send_command_cb(intptr_t arg)
static void send_command_cb(intptr_t arg)
{
send_cmd_format*ptr = (send_cmd_format *)arg;
// const char *cmd_data[] = { "0x6"/* on-off-cluster*/, "0x2" /* toggle */};
const char* cmd_data_cstr[ptr->cmd_data.size()];
if(ptr->cmd_data)
ESP_LOGI(TAG,"\ncmd_data: %s\n",ptr->cmd_data);
for (size_t i = 0; i < ptr->cmd_data.size(); ++i)
{
cmd_data_cstr[i] = ptr->cmd_data[i].c_str();
ESP_LOGI(TAG,"\ndata: %d : %s\n",i,cmd_data_cstr[i]);
}
if (ptr) {
ESP_LOGI(TAG, "send command to node %llx endpoint %d", ptr->node_id, ptr->endpoint_id);
esp_matter::controller::send_invoke_cluster_command(ptr->node_id, ptr->endpoint_id, ptr->cmd_data.size(), (char **)cmd_data_cstr);
ESP_LOGI(TAG, "send command to node %llx endpoint %d cluster %d command %d", ptr->node_id, ptr->endpoint_id, ptr->cluster_id, ptr->command_id);
esp_matter::controller::send_invoke_cluster_command(ptr->node_id, ptr->endpoint_id, ptr->cluster_id, ptr->command_id, ptr->cmd_data);
}
else
ESP_LOGE(TAG, "send command with null ptr");
ptr->cmd_data.clear();
free(ptr);
delete ptr;
}
void send_command(intptr_t arg)
CHIP_ERROR send_command(intptr_t arg)
{
chip::DeviceLayer::PlatformMgr().ScheduleWork(send_command_cb, arg);
return chip::DeviceLayer::PlatformMgr().ScheduleWork(send_command_cb, arg);
}

View File

@@ -4,6 +4,7 @@
#include <vector>
#include <string.h>
#include <esp_system.h>
#include <esp_matter.h>
#include <esp_rmaker_work_queue.h>
#include <esp_rmaker_core.h>
#include <esp_rmaker_standard_types.h>
@@ -12,19 +13,31 @@ typedef struct send_command_format
{
uint64_t node_id;
uint16_t endpoint_id;
std::vector<std::string> cmd_data;
uint32_t cluster_id;
uint32_t command_id;
char* cmd_data;
send_command_format(uint64_t remote_nodeid, uint16_t endpointid, std::vector<std::string> cmd)
send_command_format(uint64_t remote_nodeid, uint16_t endpointid,uint32_t clusterid, uint32_t commandid, char* cmd)
{
this->node_id = remote_nodeid;
this->endpoint_id = endpointid;
for(std::string str: cmd)
this->cluster_id = clusterid;
this->command_id = commandid;
this->cmd_data = NULL;
if(cmd!= NULL)
{
this->cmd_data.push_back(str);
this->cmd_data = new char[strlen(cmd) + 1];
strcpy(this->cmd_data, cmd);
}
}
~send_command_format()
{
delete[] this->cmd_data;
}
}send_cmd_format;
void send_command(intptr_t arg);
CHIP_ERROR send_command(intptr_t arg);

View File

@@ -7,11 +7,11 @@
static const char *TAG = "esp_matter_controller_service";
#define ESP_MATTER_CONTROLLER_SERV_NAME "matter-controller"
#define ESP_MATTER_CONTROLLER_SERV_NAME "Matter-Controller"
#define ESP_MATTER_CONTROLLER_SERV_TYPE "esp.service.matter-controller"
#define ESP_MATTER_CONTROLLER_DATA_PARAM_NAME "matter-controller-data"
#define ESP_MATTER_CONTROLLER_DATA_PARAM_TYPE "esp.param.matter-controller-data"
#define ESP_MATTER_CONTROLLER_DATA_VERSION_PARAM_NAME "matter-controller-data-version"
#define ESP_MATTER_CONTROLLER_DATA_PARAM_NAME "Matter-Devices"
#define ESP_MATTER_CONTROLLER_DATA_PARAM_TYPE "esp.param.matter-devices"
#define ESP_MATTER_CONTROLLER_DATA_VERSION_PARAM_NAME "Matter-Controller-Data-Version"
#define ESP_MATTER_CONTROLLER_DATA_VERSION_PARAM_TYPE "esp.param.matter-controller-data-version"
@@ -30,7 +30,7 @@ static esp_err_t controller_parse_json_get_node_id(jparse_ctx_t* jctx, void *dat
if(json_arr_get_object(jctx,node_index)==0)
{
int val_size = 0;
if (json_obj_get_strlen(jctx, "matter-node-id", &val_size) == 0)
if (json_obj_get_strlen(jctx, "matter-node-id", &val_size) == 0)
{
val_size++; /* For NULL termination */
char* node_id = (char*)calloc(1, val_size);
@@ -42,12 +42,12 @@ static esp_err_t controller_parse_json_get_node_id(jparse_ctx_t* jctx, void *dat
ESP_LOGI(TAG,"\nnode-id: %s\n",node_id);
*nodeid = std::stoull(node_id, nullptr, 16);
}
else
ESP_LOGE(TAG,"\nError in matter-node-id retrieval.\n");
free(node_id);
}
else
@@ -57,7 +57,7 @@ static esp_err_t controller_parse_json_get_node_id(jparse_ctx_t* jctx, void *dat
ESP_LOGE(TAG,"\nError in matter-nodes array.\n");
}
return ESP_OK;
}
@@ -70,13 +70,13 @@ static esp_err_t controller_parse_json_get_endpoint_id(jparse_ctx_t* jctx, void
ESP_LOGI(TAG,"\nendpoints: %d\n",num_endpoints);
else
ESP_LOGE(TAG,"\nendpoint error.\n");
for(int ep_index=0;ep_index<num_endpoints;ep_index++)
{
if(json_arr_get_object(jctx,ep_index)==0)
{
int val_size = 0;
if (json_obj_get_strlen(jctx, "endpoint-id", &val_size) == 0)
if (json_obj_get_strlen(jctx, "endpoint-id", &val_size) == 0)
{
val_size++; /* For NULL termination */
char* ep_id = (char*)calloc(1, val_size);
@@ -92,7 +92,7 @@ static esp_err_t controller_parse_json_get_endpoint_id(jparse_ctx_t* jctx, void
else
ESP_LOGE(TAG,"\nError in endpoint-id retrieval.\n");
free(ep_id);
}
else
@@ -106,7 +106,7 @@ static esp_err_t controller_parse_json_get_endpoint_id(jparse_ctx_t* jctx, void
}
static esp_err_t controller_parse_json_get_cluster_id(jparse_ctx_t* jctx, void *data, char* &cl_id)
static esp_err_t controller_parse_json_get_cluster_id(jparse_ctx_t* jctx, void *data, uint32_t* cluster_id)
{
int num_clusters=0;
@@ -114,13 +114,13 @@ static esp_err_t controller_parse_json_get_cluster_id(jparse_ctx_t* jctx, void *
ESP_LOGI(TAG,"\nclusters: %d\n",num_clusters);
else
ESP_LOGE(TAG,"\nclusters error.\n");
for(int cls_index=0;cls_index<num_clusters;cls_index++)
{
if(json_arr_get_object(jctx,cls_index)==0)
{
int val_size = 0;
if (json_obj_get_strlen(jctx, "cluster-id", &val_size) == 0)
if (json_obj_get_strlen(jctx, "cluster-id", &val_size) == 0)
{
val_size++; /* For NULL termination */
char* cls_id = (char*)calloc(1, val_size);
@@ -130,14 +130,14 @@ static esp_err_t controller_parse_json_get_cluster_id(jparse_ctx_t* jctx, void *
if(json_obj_get_string(jctx, "cluster-id", cls_id, val_size)==0)
{
ESP_LOGI(TAG,"\ncluster-id: %s\n",cls_id);
cl_id = new char[strlen(cls_id) + 1];
strcpy(cl_id,cls_id);
free(cls_id);
*cluster_id = std::stoul(cls_id, nullptr, 16);
}
else
ESP_LOGE(TAG,"\nError in cluster-id retrieval.\n");
free(cls_id);
}
else
@@ -151,7 +151,7 @@ static esp_err_t controller_parse_json_get_cluster_id(jparse_ctx_t* jctx, void *
}
static esp_err_t controller_parse_json_get_command_id(jparse_ctx_t* jctx, void *data, char* &cmdid)
static esp_err_t controller_parse_json_get_command_id(jparse_ctx_t* jctx, void *data, uint32_t* command_id)
{
int num_commands=0;
@@ -159,13 +159,13 @@ static esp_err_t controller_parse_json_get_command_id(jparse_ctx_t* jctx, void *
ESP_LOGI(TAG,"\ncommands: %d\n",num_commands);
else
ESP_LOGE(TAG,"\ncommands error.\n");
for(int cmd_index=0;cmd_index<num_commands;cmd_index++)
{
if(json_arr_get_object(jctx,cmd_index)==0)
{
int val_size = 0;
if (json_obj_get_strlen(jctx, "command-id", &val_size) == 0)
if (json_obj_get_strlen(jctx, "command-id", &val_size) == 0)
{
val_size++; /* For NULL termination */
char* cmd_id = (char*)calloc(1, val_size);
@@ -175,15 +175,14 @@ static esp_err_t controller_parse_json_get_command_id(jparse_ctx_t* jctx, void *
if(json_obj_get_string(jctx, "command-id", cmd_id, val_size)==0)
{
ESP_LOGI(TAG,"\ncommand-id: %s\n",cmd_id);
cmdid = new char[strlen(cmd_id) + 1];
strcpy(cmdid,cmd_id);
free(cmd_id);
*command_id = std::stoul(cmd_id, nullptr, 16);
}
else
ESP_LOGE(TAG,"\nError in command-id retrieval.\n");
free(cmd_id);
}
else
@@ -197,52 +196,37 @@ static esp_err_t controller_parse_json_get_command_id(jparse_ctx_t* jctx, void *
}
static esp_err_t controller_parse_json_get_data(jparse_ctx_t* jctx, void *data, std::vector<std::string>& cmd_data)
static esp_err_t controller_parse_json_get_data(jparse_ctx_t* jctx, void *data, char* &cmd_data)
{
//data
if(json_obj_get_object(jctx,"data")== OS_SUCCESS)
ESP_LOGI(TAG,"\ndata present\n");
else
ESP_LOGE(TAG,"\ndata absent\n");
int data_id = 0;
while(true)
{
int val_size = 0;
if (json_obj_get_strlen(jctx, std::to_string(data_id).c_str(), &val_size) == 0)
{
val_size++; /* For NULL termination */
char* data_val = (char*)calloc(1, val_size);
if (!data_val) {
return ESP_ERR_NO_MEM;
}
if(json_obj_get_string(jctx, std::to_string(data_id).c_str(), data_val, val_size)==0)
{
ESP_LOGI(TAG,"\ndata val: %s\n",data_val);
std::string val(data_val);
cmd_data.push_back(val);
free(data_val);
}
else
ESP_LOGE(TAG,"\nError in data val retrieval.\n");
}
else
{
ESP_LOGE(TAG,"\nError in data val retrieval or end of data object\n");
break;
}
data_id++;
}
//data
int data_len = 0;
if(json_obj_get_object_strlen(jctx,"data",&data_len)==OS_SUCCESS)
printf("\ndata len: %d\n",data_len);
else
{
ESP_LOGE(TAG,"\ndata absent\n");
return ESP_OK;
}
data_len++;
char* cmd_data_json = (char*)calloc(1, data_len);
if (!cmd_data_json)
return ESP_ERR_NO_MEM;
if(json_obj_get_object_str(jctx,"data",cmd_data_json,data_len)==OS_SUCCESS)
{
ESP_LOGI(TAG,"\ncommand-data: %s\n",cmd_data_json);
cmd_data = new char[strlen(cmd_data_json) + 1];
strcpy(cmd_data,cmd_data_json);
}
else
{
ESP_LOGE(TAG,"\nError in data json retrieval.\n");
}
free(cmd_data_json);
return ESP_OK;
}
static esp_err_t controller_parse_json(void *data, size_t data_len, esp_rmaker_req_src_t src)
@@ -260,28 +244,25 @@ static esp_err_t controller_parse_json(void *data, size_t data_len, esp_rmaker_r
controller_parse_json_get_node_id(&jctx,data,&node_id);
uint16_t endpoint_id;
controller_parse_json_get_endpoint_id(&jctx,data,&endpoint_id);
uint32_t cluster_id;
controller_parse_json_get_cluster_id(&jctx,data,&cluster_id);
uint32_t command_id;
controller_parse_json_get_command_id(&jctx,data,&command_id);
std::vector<std::string> cmd_data;
char* cl_id;
controller_parse_json_get_cluster_id(&jctx,data,cl_id);
char* cmd_id;
controller_parse_json_get_command_id(&jctx,data,cmd_id);
cmd_data.push_back(cl_id);
cmd_data.push_back(cmd_id);
char* cmd_data=NULL;
controller_parse_json_get_data(&jctx,data,cmd_data);
send_cmd_format* cmd = new send_command_format(node_id,endpoint_id,cmd_data);
cmd_data.clear();
send_cmd_format* cmd = new send_command_format(node_id,endpoint_id,cluster_id,command_id,cmd_data);
send_command((intptr_t)cmd);
delete cmd_data;
CHIP_ERROR err = send_command((intptr_t)cmd);
if(err !=CHIP_NO_ERROR)
{
ChipLogError(chipSystemLayer, "Failed to schedule send command: %" CHIP_ERROR_FORMAT, err.Format());
delete cmd;
return ESP_FAIL;
}
json_parse_end(&jctx);
return ESP_OK;
@@ -298,20 +279,20 @@ static esp_err_t controller_write_cb(const esp_rmaker_device_t *device, const es
if (ctx) {
ESP_LOGI(TAG, "Received write request via : %s", esp_rmaker_device_cb_src_to_str(ctx->src));
}
/* Check if the write is on the "Trigger" parameter. We aren't really checking true/false as that
* is not much of a concern in this context. But you can add checks on the values too.
*/
// printf("\n%s\n",esp_rmaker_param_get_name(param));
if (strcmp(esp_rmaker_param_get_name(param), ESP_MATTER_CONTROLLER_DATA_PARAM_NAME) == 0)
if (strcmp(esp_rmaker_param_get_name(param), ESP_MATTER_CONTROLLER_DATA_PARAM_NAME) == 0)
{
/* Here we start some dummy diagnostics and populate the appropriate values to be passed
* to "Timestamp" and "Data".
*/
/* The values are reported by updating appropriate parameters */
ESP_LOGI(TAG, "Received value = %s for %s - %s",
val.val.s, esp_rmaker_device_get_name(device), esp_rmaker_param_get_name(param));
// esp_rmaker_param_update_and_report(esp_rmaker_device_get_param_by_name(device, "controller-data"),
@@ -327,20 +308,20 @@ static esp_err_t controller_write_cb(const esp_rmaker_device_t *device, const es
esp_rmaker_device_t *esp_rmaker_controller_service_create(const char *serv_name, void *priv_data)
{
esp_rmaker_device_t *matter_ctrl_service = esp_rmaker_service_create(serv_name, ESP_MATTER_CONTROLLER_SERV_TYPE,priv_data);
if (matter_ctrl_service)
if (matter_ctrl_service)
{
esp_rmaker_device_add_cb(matter_ctrl_service,controller_write_cb, NULL);
esp_rmaker_device_add_param(matter_ctrl_service, esp_rmaker_param_create(ESP_MATTER_CONTROLLER_DATA_PARAM_NAME, ESP_MATTER_CONTROLLER_DATA_PARAM_TYPE, esp_rmaker_obj("{}"), PROP_FLAG_READ));
esp_rmaker_device_add_param(matter_ctrl_service, esp_rmaker_param_create(ESP_MATTER_CONTROLLER_DATA_VERSION_PARAM_NAME, ESP_MATTER_CONTROLLER_DATA_VERSION_PARAM_TYPE, esp_rmaker_str("1.0.0"), PROP_FLAG_READ));
esp_rmaker_device_add_param(matter_ctrl_service, esp_rmaker_param_create(ESP_MATTER_CONTROLLER_DATA_VERSION_PARAM_NAME, ESP_MATTER_CONTROLLER_DATA_VERSION_PARAM_TYPE, esp_rmaker_str("1.0.1"), PROP_FLAG_READ));
esp_err_t err = esp_rmaker_node_add_device(esp_rmaker_get_node(), matter_ctrl_service);
if (err == ESP_OK)
if (err == ESP_OK)
{
ESP_LOGI(TAG, "Matter Controller service enabled.");
} else
} else
{
esp_rmaker_device_delete(matter_ctrl_service);
}
@@ -351,7 +332,7 @@ esp_rmaker_device_t *esp_rmaker_controller_service_create(const char *serv_name,
esp_err_t esp_rmaker_controller_service_enable()
{
esp_rmaker_device_t *service = esp_rmaker_controller_service_create(ESP_MATTER_CONTROLLER_SERV_NAME, NULL);
if (service)
return ESP_OK;
@@ -367,10 +348,10 @@ esp_err_t esp_rmaker_controller_report_status_using_params(char *additional_info
return ESP_FAIL;
}
esp_rmaker_param_t *controller_param = esp_rmaker_device_get_param_by_type(device, ESP_MATTER_CONTROLLER_DATA_PARAM_TYPE);
esp_rmaker_param_update_and_report(controller_param, esp_rmaker_obj(additional_info));
// esp_err_t err = esp_rmaker_param_update(info_param, esp_rmaker_obj(additional_info));
return ESP_OK;
}

View File

@@ -57,17 +57,17 @@ void clear_data_model()
if(dev_ptr.second->get_endpoint_ptr.size()>0)
{
for(const auto &node_ptr : dev_ptr.second->get_endpoint_ptr)
{
{
if(node_ptr.second->get_cluster_ptr.size()>0)
{
for(const auto &cluster_ptr : node_ptr.second->get_cluster_ptr)
{
if(cluster_ptr.second->get_attribute_ptr.size()>0)
{
{
for(const auto& attribute_ptr : cluster_ptr.second->get_attribute_ptr)
{
delete (attribute_ptr.second);
}
}
cluster_ptr.second->get_attribute_ptr.clear();
}
delete (cluster_ptr.second);
@@ -75,7 +75,7 @@ void clear_data_model()
node_ptr.second->get_cluster_ptr.clear();
}
delete (node_ptr.second);
delete (node_ptr.second);
}
dev_ptr.second->get_endpoint_ptr.clear();
}
@@ -97,10 +97,10 @@ void print_data_model()
// {
// printf("\"endpoints\": \n\t{ \n");
// for(const auto &node_ptr : dev_ptr.second->get_endpoint_ptr)
// {
// {
// std::cout<<std::hex<<"“endpoint-id”: "<< node_ptr.second->endpoint_id <<std::endl;
// std::cout<<std::hex<<"“device-type-id”: "<< node_ptr.second->device_type <<std::endl;
// std::cout<<std::hex<<"“device-type-id”: "<< node_ptr.second->device_type <<std::endl;
// if(node_ptr.second->get_cluster_ptr.size()>0)
// {
// printf("\"clusters\": \n\t{ \n");
@@ -109,12 +109,12 @@ void print_data_model()
// std::cout<<std::hex<<"\t“cluster-id”: "<< cluster_ptr.second->cluster_id <<std::endl;
// if(cluster_ptr.second->get_attribute_ptr.size()>0)
// {
// {
// printf("\t\t\t{\n");
// for(const auto& attribute_ptr : cluster_ptr.second->get_attribute_ptr)
// {
// std::cout<<"\t\t\t\""<<std::hex<<attribute_ptr.second->attribute_id<<"\" : "<<std::hex<<attribute_ptr.second->value<<std::endl;
// }
// }
// printf("\t\t\t}\n");
// }
// }
@@ -260,7 +260,7 @@ static esp_err_t json_gen(json_gen_str_t *jstr)
sprintf(cl_id,"%x",cluster_ptr.second->cluster_id);
std::string val = "0x";
val+= cl_id;
if(cluster_ptr.second->get_attribute_ptr.size()>0)
{
json_gen_push_object(jstr,(char*)val.c_str());
@@ -279,7 +279,7 @@ static esp_err_t json_gen(json_gen_str_t *jstr)
}
json_gen_pop_object(jstr);
}
}
}
@@ -305,35 +305,35 @@ static void parse_cb_response(cb_data* _data)
{
// printf("\ncb_response Node_id: %016llx Endpoint: %u Cluster: " ChipLogFormatMEI " Attribute " ChipLogFormatMEI "\n",
// _data->node_id,_data->attr_path.mEndpointId, ChipLogValueMEI(_data->attr_path.mClusterId), ChipLogValueMEI(_data->attr_path.mAttributeId));
chip::app::DataModel::DecodableList<chip::EndpointId> value;
CHIP_ERROR err = chip::app::DataModel::Decode(*_data->tlv_data, value);
if (err !=CHIP_NO_ERROR)
ESP_LOGE(TAG,"\nparts Decode not OK err %d\n",err);
auto iter = value.begin();
while (iter.Next())
{
chip::EndpointId ep = iter.GetValue();
data_model *node_info = new data_model(_data->node_id,ep);
get_ep_ptr[ep]=node_info;
get_dev_ptr[_data->node_id]->get_endpoint_ptr[ep]=node_info;
}
}
else if(_data->attr_path.mEndpointId!=0x0 && _data->attr_path.mClusterId== Descriptor::Id && _data->attr_path.mAttributeId == Descriptor::Attributes::DeviceTypeList::Id)
{
{
chip::app::DataModel::DecodableList<chip::app::Clusters::Descriptor::Structs::DeviceTypeStruct::DecodableType> value;
if(chip::app::DataModel::Decode(*_data->tlv_data, value)!=CHIP_NO_ERROR)
{
ESP_LOGE(TAG,"\ndevtype Decode OK\n");
}
auto iter = value.begin();
while(iter.Next())
@@ -341,16 +341,16 @@ static void parse_cb_response(cb_data* _data)
chip::app::Clusters::Descriptor::Structs::DeviceTypeStruct::DecodableType val = iter.GetValue();
get_ep_ptr[_data->attr_path.mEndpointId]->device_type = val.deviceType;
}
}
else if(_data->attr_path.mEndpointId!=0x0 && _data->attr_path.mClusterId== Descriptor::Id && _data->attr_path.mAttributeId == Descriptor::Attributes::ServerList::Id)
{
{
chip::app::DataModel::DecodableList<chip::ClusterId> value;
if(chip::app::DataModel::Decode(*_data->tlv_data, value)==CHIP_NO_ERROR){};
auto iter = value.begin();
// size_t i = 0;
@@ -359,13 +359,13 @@ static void parse_cb_response(cb_data* _data)
chip::ClusterId val = iter.GetValue();
ep_cluster* ncluster = new ep_cluster(val);
get_ep_ptr[_data->attr_path.mEndpointId]->get_cluster_ptr[val] = ncluster;
get_ep_ptr[_data->attr_path.mEndpointId]->get_cluster_ptr[val] = ncluster;
}
}
else if(_data->attr_path.mEndpointId!=0x0 && _data->attr_path.mClusterId!=0x1d && _data->attr_path.mAttributeId != 0xFFF8 &&
else if(_data->attr_path.mEndpointId!=0x0 && _data->attr_path.mClusterId!=0x1d && _data->attr_path.mAttributeId != 0xFFF8 &&
_data->attr_path.mAttributeId != 0xFFF9 && _data->attr_path.mAttributeId != 0xFFFA && _data->attr_path.mAttributeId != 0xFFFB && _data->attr_path.mAttributeId != 0xFFFC && _data->attr_path.mAttributeId != 0xFFFD)
{
data_model* node_ptr = get_ep_ptr[_data->attr_path.mEndpointId];
@@ -380,7 +380,7 @@ static void parse_cb_response(cb_data* _data)
// {
// int attribute_value;
// if(chip::app::DataModel::Decode(*_data->tlv_data, attribute_value)==CHIP_NO_ERROR)
// {
// {
// printf("\nattribute decode OK.\n");
// val = std::to_string(attribute_value);
// }
@@ -388,12 +388,12 @@ static void parse_cb_response(cb_data* _data)
// printf("\nattribute decode not OK.\n");
// break;
// }
case 0x4:
{
u_int16_t attribute_value;
if(chip::app::DataModel::Decode(*_data->tlv_data, attribute_value)==CHIP_NO_ERROR)
{
{
val = std::to_string(attribute_value);
}
else
@@ -404,14 +404,14 @@ static void parse_cb_response(cb_data* _data)
{
bool attribute_value;
if(chip::app::DataModel::Decode(*_data->tlv_data, attribute_value)==CHIP_NO_ERROR)
{
{
val = std::to_string(attribute_value);
}
else
ESP_LOGE(TAG,"\nattribute decode not OK.\n");
break;
}
}
default:
val = "Unhandled type";
break;
@@ -422,24 +422,24 @@ static void parse_cb_response(cb_data* _data)
{
ep_cluster* curr_cluster = node_ptr->get_cluster_ptr[_data->attr_path.mClusterId];
cl_attribute* nattribute = new cl_attribute(_data->attr_path.mAttributeId,val);
curr_cluster->get_attribute_ptr[_data->attr_path.mAttributeId] = nattribute;
}
}
delete _data;
}
static void attribute_data_read_done(uint64_t remote_node_id, const chip::app::AttributePathParams &path)
static void attribute_data_read_done(uint64_t remote_node_id, const ScopedMemoryBufferWithSize<AttributePathParams> &attr_path, const ScopedMemoryBufferWithSize<EventPathParams> &event_path)
{
ESP_LOGI(TAG,"\nRead Info done for Nodeid: %016llx Endpoint: %u Cluster: " ChipLogFormatMEI " Attribute " ChipLogFormatMEI "\n",
remote_node_id,path.mEndpointId, ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mAttributeId));
ESP_LOGI(TAG,"\nRead Info done for Nodeid: %016llx Endpoint: %u Cluster: " ChipLogFormatMEI " Attribute " ChipLogFormatMEI "\n",
remote_node_id,attr_path[0].mEndpointId, ChipLogValueMEI(attr_path[0].mClusterId), ChipLogValueMEI(attr_path[0].mAttributeId));
node_id_list_index++;
if(node_id_list_index<node_id_list.size())
@@ -453,25 +453,25 @@ static void attribute_data_cb(uint64_t remote_node_id, const chip::app::Concrete
ChipLogProgress(chipTool, "Nodeid: %016llx Endpoint: %u Cluster: " ChipLogFormatMEI " Attribute " ChipLogFormatMEI " DataVersion: %" PRIu32,
remote_node_id,path.mEndpointId, ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mAttributeId),
path.mDataVersion.ValueOr(0));
if(path.mEndpointId==0x0 && path.mClusterId== Descriptor::Id && path.mAttributeId == Descriptor::Attributes::PartsList::Id)
{
cb_data* _data = new callback_data(remote_node_id,path,data);
parse_cb_response(_data);
}
else if (path.mEndpointId!=0x0 )
{
callback_data* _data = new callback_data(remote_node_id,path,data);
parse_cb_response(_data);
}
}
static void _read_node_info(intptr_t arg)
static void _read_node_info(intptr_t arg)
{
dev_data *ptr = (dev_data *)arg;
if (!ptr) {
@@ -483,11 +483,11 @@ static void _read_node_info(intptr_t arg)
}
static void _read_node_wild_info(uint64_t nodeid)
static void _read_node_wild_info(uint64_t nodeid)
{
esp_matter::controller::read_command* cmd = chip::Platform::New<read_command>(nodeid, 0xFFFF , 0xFFFFFFFF, 0xFFFFFFFF,
esp_matter::controller::READ_ATTRIBUTE, attribute_data_cb,attribute_data_read_done, nullptr);
if (!cmd) {
ESP_LOGE(TAG, "Failed to alloc memory for read_command");
return;

View File

@@ -60,7 +60,7 @@ typedef struct callback_data
chip::TLV::TLVReader* tlv_data;
callback_data(uint64_t nodeid, chip::app::ConcreteDataAttributePath attrpath, chip::TLV::TLVReader * tlvdata): node_id(nodeid),attr_path(attrpath), tlv_data(tlvdata){}
}cb_data;
void print_data_model();