Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ota-requestor] Switch shell commands to use the common code #12804

Merged
merged 3 commits into from
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions config/nrfconnect/chip-module/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,11 @@ config CHIP_OTA_REQUESTOR
imply DFU_TARGET
imply STREAM_FLASH
imply STREAM_FLASH_ERASE

config CHIP_OTA_REQUESTOR_BUFFER_SIZE
int "OTA Requestor image buffer size"
default 1024
depends on CHIP_OTA_REQUESTOR
help
Configures size of the buffer used by OTA Requestor when downloading and
writing a new firmware image to flash.
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
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
10 changes: 0 additions & 10 deletions src/lib/shell/commands/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,6 @@ source_set("commands") {
if (chip_enable_ota_requestor && chip_device_platform != "none") {
sources += [ "Ota.cpp" ]
configs += [ "${chip_root}/src/controller:config" ]

if (chip_device_platform == "nrfconnect") {
sources += [ "DFUManager_nrfconnect.h" ]
}
if (chip_device_platform == "esp32") {
sources += [
"DFUManager_esp32.h",
"OTAUpdater_esp32.h",
]
}
}

if (chip_device_platform != "none") {
Expand Down
147 changes: 0 additions & 147 deletions src/lib/shell/commands/DFUManager_esp32.h

This file was deleted.

Loading