-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathAppTask.cpp
125 lines (100 loc) · 4.27 KB
/
AppTask.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
*
* Copyright (c) 2021 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 "AppTask.h"
#include "AppConfig.h"
#include "CHIPDeviceManager.h"
#include "DeviceCallbacks.h"
#include "SubDeviceManager.h"
#include "init_Matter.h"
#include "qrcodegen.h"
#include <app/clusters/network-commissioning/network-commissioning.h>
#include <app/util/attribute-storage.h>
#include <app/util/endpoint-config-api.h>
#include <assert.h>
#include <bridged-actions-stub.h>
#include <platform/ASR/NetworkCommissioningDriver.h>
#include <platform/CHIPDeviceLayer.h>
#include <setup_payload/OnboardingCodesUtil.h>
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
#include <setup_payload/SetupPayload.h>
namespace {
TaskHandle_t sAppTaskHandle;
} // namespace
using namespace ::chip;
using namespace ::chip::Credentials;
using namespace ::chip::DeviceManager;
using namespace ::chip::DeviceLayer;
using namespace ::chip::System;
AppTask AppTask::sAppTask;
namespace {
constexpr EndpointId kNetworkCommissioningEndpointMain = 0;
constexpr EndpointId kNetworkCommissioningEndpointSecondary = 0xFFFE;
app::Clusters::NetworkCommissioning::Instance
sWiFiNetworkCommissioningInstance(kNetworkCommissioningEndpointMain /* Endpoint Id */,
&(NetworkCommissioning::ASRWiFiDriver::GetInstance()));
std::unique_ptr<app::Clusters::Actions::ActionsDelegateImpl> sActionsDelegateImpl;
std::unique_ptr<app::Clusters::Actions::ActionsServer> sActionsServer;
} // namespace
void NetWorkCommissioningInstInit()
{
sWiFiNetworkCommissioningInstance.Init();
// We only have network commissioning on endpoint 0.
emberAfEndpointEnableDisable(kNetworkCommissioningEndpointSecondary, false);
}
void emberAfActionsClusterInitCallback(EndpointId endpoint)
{
VerifyOrReturn(endpoint == 1,
ChipLogError(Zcl, "Actions cluster delegate is not implemented for endpoint with id %d.", endpoint));
VerifyOrReturn(emberAfContainsServer(endpoint, app::Clusters::Actions::Id) == true,
ChipLogError(Zcl, "Endpoint %d does not support Actions cluster.", endpoint));
VerifyOrReturn(!sActionsDelegateImpl && !sActionsServer);
sActionsDelegateImpl = std::make_unique<app::Clusters::Actions::ActionsDelegateImpl>();
sActionsServer = std::make_unique<app::Clusters::Actions::ActionsServer>(endpoint, *sActionsDelegateImpl.get());
sActionsServer->Init();
}
static DeviceCallbacks EchoCallbacks;
CHIP_ERROR AppTask::StartAppTask()
{
// Start App task.
xTaskCreate(AppTaskMain, APP_TASK_NAME, APP_TASK_STACK_SIZE, 0, 2, &sAppTaskHandle);
return (sAppTaskHandle == nullptr) ? CHIP_APPLICATION_ERROR(0x02) : CHIP_NO_ERROR;
}
void AppTask::AppTaskMain(void * pvParameter)
{
ASR_LOG("App Task started");
if (MatterInitializer::Init_Matter_Stack(MATTER_DEVICE_NAME) != CHIP_NO_ERROR)
appError(CHIP_ERROR_INTERNAL);
CHIPDeviceManager & deviceMgr = CHIPDeviceManager::GetInstance();
if (deviceMgr.Init(&EchoCallbacks) != CHIP_NO_ERROR)
appError(CHIP_ERROR_INTERNAL);
if (MatterInitializer::Init_Matter_Server() != CHIP_NO_ERROR)
appError(CHIP_ERROR_INTERNAL);
NetWorkCommissioningInstInit();
ASR_LOG("Current Firmware Version: %s", CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING);
ConfigurationMgr().LogDeviceConfig();
// Print setup info
#if CONFIG_NETWORK_LAYER_BLE
PrintOnboardingCodes(chip::RendezvousInformationFlag(chip::RendezvousInformationFlag::kBLE));
#else
PrintOnboardingCodes(chip::RendezvousInformationFlag(chip::RendezvousInformationFlag::kOnNetwork));
#endif /* CONFIG_NETWORK_LAYER_BLE */
/* Init Device Endpoint */
Init_Bridge_Endpoint();
/* Delete task */
vTaskDelete(NULL);
}