forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchipinterface.cpp
152 lines (125 loc) · 5 KB
/
chipinterface.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
*
* Copyright (c) 2020 Project CHIP Authors
*
* 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_stdlib.h>
#include "CHIPDeviceManager.h"
#include "DeviceCallbacks.h"
#include "chip_porting.h"
#include <app/clusters/network-commissioning/network-commissioning.h>
#include <app/server/Server.h>
#include <credentials/DeviceAttestationCredsProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>
#include <lib/support/ErrorStr.h>
#include <platform/Ameba/AmebaConfig.h>
#include <platform/Ameba/NetworkCommissioningDriver.h>
#include <platform/CHIPDeviceLayer.h>
#include <support/CHIPMem.h>
#include <app/clusters/ota-requestor/BDXDownloader.h>
#include <app/clusters/ota-requestor/GenericOTARequestorDriver.h>
#include <app/clusters/ota-requestor/OTARequestor.h>
#include <platform/Ameba/AmebaOTAImageProcessor.h>
void * __dso_handle = 0;
using chip::AmebaOTAImageProcessor;
using chip::BDXDownloader;
using chip::ByteSpan;
using chip::EndpointId;
using chip::FabricIndex;
using chip::GetRequestorInstance;
using chip::NodeId;
using chip::OnDeviceConnected;
using chip::OnDeviceConnectionFailure;
using chip::OTADownloader;
using chip::OTAImageProcessorParams;
using chip::OTARequestor;
using chip::PeerId;
using chip::Server;
using chip::VendorId;
using chip::Callback::Callback;
using chip::System::Layer;
using chip::Transport::PeerAddress;
using namespace chip::Messaging;
using namespace chip::app::Clusters::OtaSoftwareUpdateProvider::Commands;
using namespace ::chip;
using namespace ::chip::Credentials;
using namespace ::chip::DeviceManager;
using namespace ::chip::DeviceLayer;
namespace {
app::Clusters::NetworkCommissioning::Instance
sWiFiNetworkCommissioningInstance(0 /* Endpoint Id */, &(NetworkCommissioning::AmebaWiFiDriver::GetInstance()));
} // namespace
void NetWorkCommissioningInstInit()
{
sWiFiNetworkCommissioningInstance.Init();
}
static DeviceCallbacks EchoCallbacks;
OTARequestor gRequestorCore;
GenericOTARequestorDriver gRequestorUser;
BDXDownloader gDownloader;
AmebaOTAImageProcessor gImageProcessor;
extern "C" void amebaQueryImageCmdHandler()
{
ChipLogProgress(DeviceLayer, "Calling amebaQueryImageCmdHandler");
static_cast<OTARequestor *>(GetRequestorInstance())->TriggerImmediateQuery();
}
extern "C" void amebaApplyUpdateCmdHandler()
{
ChipLogProgress(DeviceLayer, "Calling amebaApplyUpdateCmdHandler");
static_cast<OTARequestor *>(GetRequestorInstance())->ApplyUpdate();
}
static void InitOTARequestor(void)
{
// Initialize and interconnect the Requestor and Image Processor objects -- START
SetRequestorInstance(&gRequestorCore);
// Set server instance used for session establishment
gRequestorCore.Init(&(chip::Server::GetInstance()), &gRequestorUser, &gDownloader);
// WARNING: this is probably not realistic to know such details of the image or to even have an OTADownloader instantiated at
// the beginning of program execution. We're using hardcoded values here for now since this is a reference application.
// TODO: instatiate and initialize these values when QueryImageResponse tells us an image is available
// TODO: add API for OTARequestor to pass QueryImageResponse info to the application to use for OTADownloader init
OTAImageProcessorParams ipParams;
gImageProcessor.SetOTAImageProcessorParams(ipParams);
gImageProcessor.SetOTADownloader(&gDownloader);
// Connect the Downloader and Image Processor objects
gDownloader.SetImageProcessorDelegate(&gImageProcessor);
gRequestorUser.Init(&gRequestorCore, &gImageProcessor);
// Initialize and interconnect the Requestor and Image Processor objects -- END
}
static void InitServer(intptr_t context)
{
// Init ZCL Data Model and CHIP App Server
chip::Server::GetInstance().Init();
// Initialize device attestation config
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
NetWorkCommissioningInstInit();
InitOTARequestor();
}
extern "C" void ChipTest(void)
{
ChipLogProgress(SoftwareUpdate, "ota-requestor!");
CHIP_ERROR err = CHIP_NO_ERROR;
initPref();
CHIPDeviceManager & deviceMgr = CHIPDeviceManager::GetInstance();
err = deviceMgr.Init(&EchoCallbacks);
if (err != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "DeviceManagerInit() - ERROR!\r\n");
}
else
{
ChipLogProgress(DeviceLayer, "DeviceManagerInit() - OK\r\n");
}
chip::DeviceLayer::PlatformMgr().ScheduleWork(InitServer, 0);
}