Skip to content

Commit

Permalink
Fix build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
restyled-commits authored and Damian-Nordic committed Dec 15, 2021
1 parent 0b3d1a3 commit 733f3a3
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 234 deletions.
4 changes: 3 additions & 1 deletion examples/lighting-app/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ target_sources(app PRIVATE
${GEN_DIR}/lighting-app/zap-generated/CHIPClusters.cpp
${GEN_DIR}/lighting-app/zap-generated/IMClusterCommandHandler.cpp
${NRFCONNECT_COMMON}/util/LEDWidget.cpp
${NRFCONNECT_COMMON}/util/ThreadUtil.cpp)
${NRFCONNECT_COMMON}/util/ThreadUtil.cpp
${CHIP_ROOT}/src/app/clusters/ota-requestor/OTARequestor.cpp
${CHIP_ROOT}/src/app/clusters/ota-requestor/BDXDownloader.cpp)

chip_configure_data_model(app
INCLUDE_CLIENT_CALLBACKS
Expand Down
47 changes: 38 additions & 9 deletions examples/lighting-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,34 @@
#include "LEDWidget.h"
#include "LightingManager.h"
#include "ThreadUtil.h"
#include <app/server/OnboardingCodesUtil.h>
#include <app/server/Server.h>

#include <app-common/zap-generated/attribute-id.h>
#include <app-common/zap-generated/attribute-type.h>
#include <app-common/zap-generated/cluster-id.h>
#include <app/server/OnboardingCodesUtil.h>
#include <app/server/Server.h>
#include <app/util/attribute-storage.h>

#include <credentials/DeviceAttestationCredsProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>

#include <platform/CHIPDeviceLayer.h>

#include <lib/support/ErrorStr.h>
#include <platform/CHIPDeviceLayer.h>
#include <system/SystemClock.h>

#if CONFIG_CHIP_OTA_REQUESTOR
#include <app/clusters/ota-requestor/BDXDownloader.h>
#include <app/clusters/ota-requestor/OTARequestor.h>
#include <platform/nrfconnect/OTAImageProcessorImpl.h>
#endif

#include <dk_buttons_and_leds.h>
#include <logging/log.h>
#include <zephyr.h>

LOG_MODULE_DECLARE(app);

using namespace ::chip::Credentials;
using namespace ::chip::DeviceLayer;

namespace {

constexpr int kFactoryResetTriggerTimeout = 3000;
Expand All @@ -65,10 +71,20 @@ bool sIsThreadProvisioned = false;
bool sIsThreadEnabled = false;
bool sHaveBLEConnections = false;

} // namespace
#if CONFIG_CHIP_OTA_REQUESTOR
class DummyOTARequestorDriver : public chip::OTARequestorDriver
{
bool CheckImageDownloadAllowed() override { return true; }
chip::UserConsentAction RequestUserConsent() override { return chip::ImmediateYes; }
void ImageDownloadComplete() override {}
} sOTARequestorDriver;

OTAImageProcessorImpl sOTAImageProcessor;
chip::BDXDownloader sBDXDownloader;
chip::OTARequestor sOTARequestor;
#endif

using namespace ::chip::Credentials;
using namespace ::chip::DeviceLayer;
} // namespace

AppTask AppTask::sAppTask;

Expand Down Expand Up @@ -119,9 +135,22 @@ int AppTask::Init()
PlatformMgr().AddEventHandler(ChipEventHandler, 0);
#endif

InitOTARequestor();

return 0;
}

void AppTask::InitOTARequestor()
{
#if CONFIG_CHIP_OTA_REQUESTOR
sBDXDownloader.SetImageProcessorDelegate(&sOTAImageProcessor);
sOTARequestor.SetOtaRequestorDriver(&sOTARequestorDriver);
sOTARequestor.SetBDXDownloader(&sBDXDownloader);
sOTARequestor.SetServerInstance(&chip::Server::GetInstance());
chip::SetRequestorInstance(&sOTARequestor);
#endif
}

int AppTask::StartApp()
{
int ret = Init();
Expand Down
1 change: 1 addition & 0 deletions examples/lighting-app/nrfconnect/main/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class AppTask

friend AppTask & GetAppTask(void);
int Init();
void InitOTARequestor();

static void ActionInitiated(LightingManager::Action_t aAction, int32_t aActor);
static void ActionCompleted(LightingManager::Action_t aAction, int32_t aActor);
Expand Down
1 change: 1 addition & 0 deletions src/app/clusters/ota-requestor/ClusterInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* to the OTA Requestor object that handles them
*/

#include <app/util/af.h>
#include <platform/OTARequestorInterface.h>

// OTA Software Update Requestor Cluster AnnounceOtaProvider Command callback
Expand Down
2 changes: 1 addition & 1 deletion src/app/clusters/ota-requestor/OTARequestor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ void OTARequestor::OnConnected(void * context, OperationalDeviceProxy * devicePr
}
}

OTARequestor::OTATriggerResult OTARequestor::TriggerImmediateQuery()
OTARequestorInterface::OTATriggerResult OTARequestor::TriggerImmediateQuery()
{

if (mProviderNodeId != kUndefinedNodeId)
Expand Down
15 changes: 4 additions & 11 deletions src/app/clusters/ota-requestor/OTARequestor.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,12 @@ class OTARequestor : public OTARequestorInterface

// Application interface declarations -- start

// Return value for various trigger-type APIs
enum OTATriggerResult
{
kTriggerSuccessful = 0,
kNoProviderKnown = 1
};

// Application directs the Requestor to start the Image Query process
// and download the new image if available
OTATriggerResult TriggerImmediateQuery();
OTATriggerResult TriggerImmediateQuery() override;

// Send ApplyImage
void ApplyUpdate();
void ApplyUpdate() override;

// A setter for the delegate class pointer
void SetOtaRequestorDriver(OTARequestorDriver * driver) { mOtaRequestorDriver = driver; }
Expand Down Expand Up @@ -95,7 +88,7 @@ class OTARequestor : public OTARequestorInterface
// Handler for the AnnounceOTAProvider command
EmberAfStatus HandleAnnounceOTAProvider(
app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath,
const app::Clusters::OtaSoftwareUpdateRequestor::Commands::AnnounceOtaProvider::DecodableType & commandData);
const app::Clusters::OtaSoftwareUpdateRequestor::Commands::AnnounceOtaProvider::DecodableType & commandData) override;

// Virtual functions from OTARequestorInterface -- end
/**
Expand All @@ -120,7 +113,7 @@ class OTARequestor : public OTARequestorInterface
* Called to indicate test mode. This is when the Requestor is used as a test tool and the the provider parameters are supplied
* explicitly.
*/
void TestModeSetProviderParameters(NodeId nodeId, FabricIndex fabIndex, EndpointId endpointId)
void TestModeSetProviderParameters(NodeId nodeId, FabricIndex fabIndex, EndpointId endpointId) override
{
mProviderNodeId = nodeId;
mProviderFabricIndex = fabIndex;
Expand Down
2 changes: 1 addition & 1 deletion src/app/zap_cluster_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
'ON_OFF_SWITCH_CONFIG_CLUSTER': [],
'OPERATIONAL_CREDENTIALS_CLUSTER': [],
'OTA_BOOTLOAD_CLUSTER': [],
'OTA_PROVIDER_CLUSTER': ['ota-requestor'],
'OTA_PROVIDER_CLUSTER': [],
'OTA_REQUESTOR_CLUSTER': [],
'POLL_CONTROL_CLUSTER': [],
'POWER_CONFIG_CLUSTER': [],
Expand Down
19 changes: 17 additions & 2 deletions src/include/platform/OTARequestorInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@

#include <app-common/zap-generated/cluster-objects.h>
#include <app/CommandHandler.h>

#include <app/util/util.h>
#include <app/util/af-enums.h>

#pragma once

Expand All @@ -35,6 +34,13 @@ namespace chip {
class OTARequestorInterface
{
public:
// Return value for various trigger-type APIs
enum OTATriggerResult
{
kTriggerSuccessful = 0,
kNoProviderKnown = 1
};

// Handler for the AnnounceOTAProvider command
virtual EmberAfStatus HandleAnnounceOTAProvider(
chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath,
Expand All @@ -48,6 +54,15 @@ class OTARequestorInterface

// Destructor
virtual ~OTARequestorInterface() = default;

// Send QueryImage command
virtual OTATriggerResult TriggerImmediateQuery() = 0;

// Send ApplyImage command
virtual void ApplyUpdate() = 0;

// Manually set OTA Provider parameters
virtual void TestModeSetProviderParameters(NodeId nodeId, FabricIndex fabIndex, EndpointId endpointId) = 0;
};

// The instance of the class implementing OTARequestorInterface must be managed through
Expand Down
4 changes: 1 addition & 3 deletions src/lib/shell/commands/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ source_set("commands") {

if (chip_enable_ota_requestor && chip_device_platform != "none") {
sources += [ "Ota.cpp" ]
public_deps += [ "${chip_root}/src/app/clusters/ota-requestor:headers" ]
# TODO: remove dependency of OTA shell on controller-clusters
include_dirs = [ "${chip_root}/zzz_generated/controller-clusters" ]
configs += [ "${chip_root}/src/controller:config" ]
}

if (chip_device_platform != "none") {
Expand Down
48 changes: 7 additions & 41 deletions src/lib/shell/commands/Ota.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,82 +15,48 @@
* limitations under the License.
*/

#include <app/CASEClientPool.h>
#include <app/OperationalDeviceProxyPool.h>
#include <app/clusters/ota-requestor/BDXDownloader.h>
#include <app/clusters/ota-requestor/OTARequestor.h>
#include <app/server/Server.h>
#include <lib/dnssd/Resolver.h>
#include <lib/shell/Commands.h>
#include <lib/shell/Engine.h>
#include <lib/shell/commands/Help.h>
#include <lib/support/logging/CHIPLogging.h>
#include <platform/CHIPDeviceLayer.h>
#include <platform/OTAImageProcessor.h>
#include <platform/OTARequestorDriver.h>

#if CHIP_DEVICE_LAYER_TARGET_NRFCONNECT
#include <platform/nrfconnect/OTAImageProcessorImpl.h>
#elif CHIP_DEVICE_LAYER_TARGET_ESP32
#include <platform/esp32/OTAImageProcessorImpl.h>
#endif
#include <platform/OTARequestorInterface.h>

using namespace chip::DeviceLayer;

namespace chip {
namespace Shell {
namespace {

class DummyOTARequestorDriver : public OTARequestorDriver
{
bool CheckImageDownloadAllowed() override { return true; }
void ImageDownloadComplete() override {}
} sOTARequestorDriver;

constexpr size_t kActiveSessions = 1;
DeviceLayer::OTAImageProcessorImpl sOTAImageProcessor;
BDXDownloader sBDXDownloader;
CASEClientPool<kActiveSessions> sCASEClientPool;
OperationalDeviceProxyPool<kActiveSessions> sDevicePool;
OTARequestor sOTARequestor;
Shell::Engine sSubShell;

void InitRequestor()
{
Server::GetInstance().SetCASEClientPool(&sCASEClientPool);
Server::GetInstance().SetDevicePool(&sDevicePool);
sBDXDownloader.SetImageProcessorDelegate(&sOTAImageProcessor);
sOTARequestor.SetOtaRequestorDriver(&sOTARequestorDriver);
sOTARequestor.SetBDXDownloader(&sBDXDownloader);
sOTARequestor.SetServerInstance(&Server::GetInstance());
SetRequestorInstance(&sOTARequestor);
}

CHIP_ERROR QueryImageHandler(int argc, char ** argv)
{
VerifyOrReturnError(GetRequestorInstance() != nullptr, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(argc == 3, CHIP_ERROR_INVALID_ARGUMENT);

const FabricIndex fabricIndex = static_cast<FabricIndex>(strtoul(argv[0], nullptr, 10));
const NodeId providerNodeId = static_cast<NodeId>(strtoull(argv[1], nullptr, 10));
const EndpointId providerEndpointId = static_cast<EndpointId>(strtoul(argv[2], nullptr, 10));

InitRequestor();
sOTARequestor.TestModeSetProviderParameters(providerNodeId, fabricIndex, providerEndpointId);
PlatformMgr().ScheduleWork([](intptr_t) { sOTARequestor.TriggerImmediateQuery(); });
GetRequestorInstance()->TestModeSetProviderParameters(providerNodeId, fabricIndex, providerEndpointId);
PlatformMgr().ScheduleWork([](intptr_t) { GetRequestorInstance()->TriggerImmediateQuery(); });
return CHIP_NO_ERROR;
}

CHIP_ERROR ApplyImageHandler(int argc, char ** argv)
{
VerifyOrReturnError(GetRequestorInstance() != nullptr, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(argc == 3, CHIP_ERROR_INVALID_ARGUMENT);

const FabricIndex fabricIndex = static_cast<FabricIndex>(strtoul(argv[0], nullptr, 10));
const NodeId providerNodeId = static_cast<NodeId>(strtoull(argv[1], nullptr, 10));
const EndpointId providerEndpointId = static_cast<EndpointId>(strtoul(argv[2], nullptr, 10));

InitRequestor();
sOTARequestor.TestModeSetProviderParameters(providerNodeId, fabricIndex, providerEndpointId);
PlatformMgr().ScheduleWork([](intptr_t) { sOTARequestor.ApplyUpdate(); });
GetRequestorInstance()->TestModeSetProviderParameters(providerNodeId, fabricIndex, providerEndpointId);
PlatformMgr().ScheduleWork([](intptr_t) { GetRequestorInstance()->ApplyUpdate(); });
return CHIP_NO_ERROR;
}

Expand Down
Loading

0 comments on commit 733f3a3

Please sign in to comment.