Skip to content

Commit

Permalink
[ESP32] Init OTA requestor in all-clusters-app (#13246)
Browse files Browse the repository at this point in the history
Also, enabled OTA_PROVIDER_CLIENT.
Removed the weak function definitions from OTA command handlers.
  • Loading branch information
shubhamdp authored and pull[bot] committed Nov 6, 2023
1 parent 9b48b0b commit 5051080
Show file tree
Hide file tree
Showing 15 changed files with 582 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1357,31 +1357,31 @@
"mfgCode": null,
"define": "OTA_PROVIDER_CLUSTER",
"side": "client",
"enabled": 0,
"enabled": 1,
"commands": [
{
"name": "QueryImage",
"code": 0,
"mfgCode": null,
"source": "client",
"incoming": 1,
"incoming": 0,
"outgoing": 1
},
{
"name": "ApplyUpdateRequest",
"code": 2,
"mfgCode": null,
"source": "client",
"incoming": 1,
"incoming": 0,
"outgoing": 1
},
{
"name": "NotifyUpdateApplied",
"code": 4,
"mfgCode": null,
"source": "client",
"incoming": 1,
"outgoing": 0
"incoming": 0,
"outgoing": 1
}
],
"attributes": [
Expand Down
1 change: 1 addition & 0 deletions examples/all-clusters-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ set(SRC_DIRS_LIST
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/low-power-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/keypad-input-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/media-playback-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/ota-requestor"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/ota-provider"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/target-navigator-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/thermostat-server"
Expand Down
31 changes: 28 additions & 3 deletions examples/all-clusters-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
#include <app-common/zap-generated/attribute-type.h>
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app-common/zap-generated/cluster-id.h>
#include <app/clusters/door-lock-server/door-lock-server.h>
#include <app/clusters/on-off-server/on-off-server.h>
#include <app/clusters/ota-requestor/BDXDownloader.h>
#include <app/clusters/ota-requestor/OTARequestor.h>
#include <app/server/AppDelegate.h>
#include <app/server/Dnssd.h>
#include <app/server/OnboardingCodesUtil.h>
Expand All @@ -62,12 +66,11 @@
#include <lib/support/CHIPMem.h>
#include <lib/support/ErrorStr.h>
#include <platform/CHIPDeviceLayer.h>
#include <platform/ESP32/OTAImageProcessorImpl.h>
#include <platform/GenericOTARequestorDriver.h>
#include <setup_payload/ManualSetupPayloadGenerator.h>
#include <setup_payload/QRCodeSetupPayloadGenerator.h>

#include <app/clusters/door-lock-server/door-lock-server.h>
#include <app/clusters/on-off-server/on-off-server.h>

#if CONFIG_ENABLE_PW_RPC
#include "Rpc.h"
#endif
Expand Down Expand Up @@ -122,6 +125,13 @@ std::vector<gpio_num_t> button_gpios = { BUTTON_1_GPIO_NUM, BUTTON_2_GPIO_NUM, B

#endif

#if CONFIG_ENABLE_OTA_REQUESTOR
OTARequestor gRequestorCore;
GenericOTARequestorDriver gRequestorUser;
BDXDownloader gDownloader;
OTAImageProcessorImpl gImageProcessor;
#endif

// Pretend these are devices with endpoints with clusters with attributes
typedef std::tuple<std::string, std::string> Attribute;
typedef std::vector<Attribute> Attributes;
Expand Down Expand Up @@ -517,6 +527,19 @@ static void InitServer(intptr_t context)
SetupPretendDevices();
}

static void InitOTARequestor(void)
{
#if CONFIG_ENABLE_OTA_REQUESTOR
SetRequestorInstance(&gRequestorCore);
gRequestorCore.SetServerInstance(&Server::GetInstance());
gRequestorCore.SetOtaRequestorDriver(&gRequestorUser);
gImageProcessor.SetOTADownloader(&gDownloader);
gDownloader.SetImageProcessorDelegate(&gImageProcessor);
gRequestorUser.Init(&gRequestorCore, &gImageProcessor);
gRequestorCore.SetBDXDownloader(&gDownloader);
#endif
}

extern "C" void app_main()
{
ESP_LOGI(TAG, "All Clusters Demo!");
Expand Down Expand Up @@ -575,6 +598,8 @@ extern "C" void app_main()
// Print QR Code URL
PrintOnboardingCodes(chip::RendezvousInformationFlags(CONFIG_RENDEZVOUS_MODE));

InitOTARequestor();

#if CONFIG_HAVE_DISPLAY
std::string qrCodeText;

Expand Down
4 changes: 3 additions & 1 deletion src/app/tests/suites/TestDescriptorCluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ tests:
command: "readAttribute"
attribute: "Client List"
response:
value: []
value: [
0x0029, # OTA Software Update Provider
]

- label: "Read attribute Parts list"
command: "readAttribute"
Expand Down
3 changes: 2 additions & 1 deletion src/darwin/Framework/CHIPTests/CHIPClustersTests.m

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions src/lib/shell/commands/Ota.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@
using namespace chip::DeviceLayer;

namespace chip {

// TODO: Remove weak functions when ESP32 all-clusters-app includes code from src/app/clusters/ota-requestor
// The code requires OTA Provider client cluster which interferes with OTA Provider server cluster,
// already enabled in the all-clusters-app.
__attribute__((weak)) void SetRequestorInstance(OTARequestorInterface * instance) {}
__attribute__((weak)) OTARequestorInterface * GetRequestorInstance()
{
return nullptr;
}

namespace Shell {
namespace {

Expand Down
129 changes: 129 additions & 0 deletions zzz_generated/all-clusters-app/zap-generated/CHIPClientCallbacks.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions zzz_generated/all-clusters-app/zap-generated/CHIPClientCallbacks.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5051080

Please sign in to comment.