Skip to content

Commit

Permalink
[sdk] Optimize ameba data model, Add Matter core and prov control, an…
Browse files Browse the repository at this point in the history
…d Fix Build
  • Loading branch information
SirRu24 committed May 29, 2024
1 parent f3b6f69 commit 62bd7fa
Show file tree
Hide file tree
Showing 33 changed files with 1,397 additions and 1,482 deletions.
39 changes: 37 additions & 2 deletions component/common/application/matter/common/atcmd/atcmd_matter.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,50 @@ void fATchipapp2(void *arg)
#endif
}

__weak void MatterCoreStatusCommandHandler(void)
{
printf("MatterCoreStatusCommandHandler() not implemented\r\n");
}

__weak void MatterCoreStartCommandHandler(void)
{
printf("MatterCoreStartCommandHandler() not implemented\r\n");
}

__weak void MatterCoreStopCommandHandler(void)
{
printf("MatterCoreStopCommandHandler() not implemented\r\n");
}

void fATmattershell(void *arg)
{
if (arg != NULL)
{
xQueueSend(shell_queue, arg, pdMS_TO_TICKS(10));
if(strcmp((const char *) arg, "status") == 0)
{
MatterCoreStatusCommandHandler();
}
else if(strcmp((const char *) arg, "start") == 0)
{
MatterCoreStartCommandHandler();
}
else if(strcmp((const char *) arg, "stop") == 0)
{
MatterCoreStopCommandHandler();
}
else
{
xQueueSend(shell_queue, arg, pdMS_TO_TICKS(10));
}
}
else
{
printf("No arguments provided for matter shell\r\n");
printf("%s\n%s\n%s\n%s\n%s\r\n",
"No arguments provided for matter shell",
"ATMS=status to check matter server status",
"ATMS=start to turn on matter server",
"ATMS=stop to turn off matter server",
"ATMS=help to check built in matter commands while matter server is on");
}
}

Expand Down
226 changes: 226 additions & 0 deletions component/common/application/matter/core/matter_control.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
/*
*
* Copyright (c) 2022 Project CHIP Authors
* All rights reserved.
*
* 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 "platform_opts_matter.h"
#include "matter_control.h"
#include "matter_core.h"
#include "matter_interaction.h"
#include "matter_prov.h"

#include "app/server/Server.h"
#include "platform/CHIPDeviceLayer.h"
#include <lib/support/CodeUtils.h>

#if defined(CONFIG_ENABLE_CHIP_SHELL) && (CONFIG_ENABLE_CHIP_SHELL == 1)
#include "lib/shell/Engine.h"
#include "lib/shell/commands/Help.h"
#endif // defined(CONFIG_ENABLE_CHIP_SHELL) && (CONFIG_ENABLE_CHIP_SHELL == 1)

using namespace chip;
using namespace chip::app;

#if defined(CONFIG_ENABLE_CHIP_SHELL) && (CONFIG_ENABLE_CHIP_SHELL == 1)
using Shell::Engine;
using Shell::shell_command_t;
using Shell::streamer_get;
using Shell::streamer_printf;

Engine sShellMatterProvisioningSubCommands;
#endif // defined(CONFIG_ENABLE_CHIP_SHELL) && (CONFIG_ENABLE_CHIP_SHELL == 1)

namespace {
#if defined(CONFIG_ENABLE_CHIP_SHELL) && (CONFIG_ENABLE_CHIP_SHELL == 1)

/********************************************************
* Matter Core shell functions, controlled by Ameba Shell
*********************************************************/

extern "C" void MatterCoreStatusCommandHandler()
{
if (matter_core_server_is_running())
{
ChipLogProgress(DeviceLayer, "Matter device is running!");
}
else
{
ChipLogProgress(DeviceLayer, "Matter device is not running!");
}
}

extern "C" void MatterCoreStartCommandHandler()
{
CHIP_ERROR err = CHIP_NO_ERROR;

if(matter_core_server_is_running())
{
ChipLogProgress(DeviceLayer, "Matter device is already started!");
}
else
{
err = matter_core_start();
if (err != CHIP_NO_ERROR)
ChipLogProgress(DeviceLayer, "matter_core_start failed!\n");

#if !(defined(CONFIG_EXAMPLE_MATTER_AIRCON) && CONFIG_EXAMPLE_MATTER_AIRCON) // aircon example does not include downlink
err = matter_interaction_start_downlink();
if (err != CHIP_NO_ERROR)
ChipLogProgress(DeviceLayer, "matter_interaction_start_downlink failed!\n");
#endif

err = matter_interaction_start_uplink();
if (err != CHIP_NO_ERROR)
ChipLogProgress(DeviceLayer, "matter_interaction_start_uplink failed!\n");
}
}

extern "C" void MatterCoreStopCommandHandler()
{
CHIP_ERROR err = CHIP_NO_ERROR;

if(matter_core_server_is_running())
{
err = matter_core_stop();
if (err != CHIP_NO_ERROR)
ChipLogProgress(DeviceLayer, "matter_core_stop failed!\n");

matter_interaction_clean_up();
}
else
{
ChipLogProgress(DeviceLayer, "Matter device is already stopped!");
}
}

/********************************************************
* Matter Provisioning shell functions
*********************************************************/

CHIP_ERROR MatterProvisioningCommandHelpHandler(int argc, char ** argv)
{
sShellMatterProvisioningSubCommands.ForEachCommand(Shell::PrintCommandHelp, nullptr);
return CHIP_NO_ERROR;
}

CHIP_ERROR MatterProvisioningCommandHandler(int argc, char ** argv)
{
if (argc == 0)
{
return MatterProvisioningCommandHelpHandler(argc, argv);
}

return sShellMatterProvisioningSubCommands.ExecCommand(argc, argv);
}

CHIP_ERROR MatterProvisioningStatusCommandHandler(int argc, char ** argv)
{
if (argc != 0)
{
return MatterProvisioningCommandHelpHandler(argc, argv);
}

if (matter_prov_is_provisioned())
{
ChipLogProgress(DeviceLayer, "Matter device is provisioned!");
}
else
{
ChipLogProgress(DeviceLayer, "Matter device is not provisioned!");
}

return CHIP_NO_ERROR;
}

CHIP_ERROR MatterProvisioningEnterProvModeCommandHandler(int argc, char ** argv)
{
if (argc != 0)
{
return MatterProvisioningCommandHelpHandler(argc, argv);
}

return matter_prov_start();
}

CHIP_ERROR MatterProvisioningExitProvModeCommandHandler(int argc, char ** argv)
{
if (argc != 0)
{
return MatterProvisioningCommandHelpHandler(argc, argv);
}

return matter_prov_stop();
}

CHIP_ERROR MatterProvisioningPrintProvTableCommandHandler(int argc, char ** argv)
{
if (argc != 0)
{
return MatterProvisioningCommandHelpHandler(argc, argv);
}

return matter_prov_print_fabric_table();
}

CHIP_ERROR MatterProvisioningEraseRowCommandHandler(int argc, char ** argv)
{
if (argc != 1)
{
return MatterProvisioningCommandHelpHandler(argc, argv);
}

uint8_t row = atoi(argv[0]);
return matter_prov_delete_fabric_table_row(row);
}
/**
* @brief configures matter control shell
*
*/
static void RegisterMatterProvisioningCommands()
{
static const shell_command_t sMatterProvisioningSubCommands[] = {
{ &MatterProvisioningCommandHelpHandler, "help", "Usage: prov help" },
{ &MatterProvisioningStatusCommandHandler, "status", "status Usage: prov status" },
{ &MatterProvisioningEnterProvModeCommandHandler, "enterprovmode", "enterprovmode Usage: prov enterprovmode" },
{ &MatterProvisioningExitProvModeCommandHandler, "exitprovmode", "exitprovmode Usage: prov exitprovmode" },
{ &MatterProvisioningPrintProvTableCommandHandler, "printprovtable", "printprovtable Usage: prov printprovtable" },
{ &MatterProvisioningEraseRowCommandHandler, "eraserow", "eraserow Usage: prov eraserow <row_number>" },
};

static const shell_command_t sMatterProvisioningCommand = { &MatterProvisioningCommandHandler, "prov",
"Matter Provisioning commands. Usage: prov <subcommand>" };

// Register commands
sShellMatterProvisioningSubCommands.RegisterCommands(sMatterProvisioningSubCommands,
ArraySize(sMatterProvisioningSubCommands));

Engine::Root().RegisterCommands(&sMatterProvisioningCommand, 1);
}
#endif // defined(CONFIG_ENABLE_CHIP_SHELL) && (CONFIG_ENABLE_CHIP_SHELL == 1)

} // namespace

/********************************************************
* Switch functions
*********************************************************/

CHIP_ERROR InitMatterProvisioningControl()
{
#if CONFIG_ENABLE_CHIP_SHELL
RegisterMatterProvisioningCommands();
#endif
return CHIP_NO_ERROR;
}
26 changes: 26 additions & 0 deletions component/common/application/matter/core/matter_control.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
*
* Copyright (c) 2022 Project CHIP Authors
* All rights reserved.
*
* 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 "app-common/zap-generated/ids/Attributes.h"
#include "app-common/zap-generated/ids/Clusters.h"
#include "app-common/zap-generated/ids/Commands.h"
#include "lib/core/CHIPError.h"

CHIP_ERROR InitMatterProvisioningControl();
Loading

0 comments on commit 62bd7fa

Please sign in to comment.