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

[ESP32] Fix ota-provider-app build failure #13394

Merged
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
2 changes: 1 addition & 1 deletion examples/ota-provider-app/esp32/main/BdxOtaSender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

#include <BdxOtaSender.h>
#include <ota-provider-common/BdxOtaSender.h>

#include <lib/core/CHIPError.h>
#include <lib/support/BitFlags.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ class BdxOtaSender : public chip::bdx::Responder
*/
uint64_t GetTransferLength(void);

/* ota-provider-common/OTAProviderExample.cpp requires this */
void SetFilepath(const char * path) {}

private:
// Inherited from bdx::TransferFacilitator
void HandleTransferSessionOutput(chip::bdx::TransferSession::OutputEvent & event) override;
Expand Down
43 changes: 16 additions & 27 deletions examples/ota-provider-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,11 @@

#include <lib/support/ErrorStr.h>

#include <BdxOtaSender.h>
#include <app/clusters/ota-provider/ota-provider.h>
#include <ota-provider-common/BdxOtaSender.h>
#include <ota-provider-common/OTAProviderExample.h>

using chip::BitFlags;
using chip::app::Clusters::OTAProviderDelegate;
using chip::bdx::TransferControlFlags;
using chip::Callback::Callback;
using chip::Messaging::ExchangeManager;
using namespace ::chip;
using namespace ::chip::System;
using namespace ::chip::Credentials;
Expand All @@ -64,17 +60,13 @@ namespace {
const char * TAG = "ota-provider-app";
const uint8_t kMaxImagePathlen = 35;
static DeviceCallbacks EchoCallbacks;
BdxOtaSender bdxServer;

// TODO: this should probably be done dynamically
constexpr chip::EndpointId kOtaProviderEndpoint = 0;
constexpr uint32_t kMaxBdxBlockSize = 1024;
constexpr chip::System::Clock::Timeout kBdxTimeout = chip::System::Clock::Seconds16(5 * 60); // Specification mandates >= 5 minutes
constexpr chip::System::Clock::Timeout kBdxPollFreq = chip::System::Clock::Milliseconds32(500);
const char * otaFilename = CONFIG_OTA_IMAGE_NAME;
FILE * otaImageFile = NULL;
uint32_t otaImageLen = 0;
uint32_t otaTransferInProgress = false;
constexpr chip::EndpointId kOtaProviderEndpoint = 0;
const char * otaFilename = CONFIG_OTA_IMAGE_NAME;
FILE * otaImageFile = NULL;
uint32_t otaImageLen = 0;
uint32_t otaTransferInProgress = false;
static OTAProviderExample otaProvider;

chip::Callback::Callback<OnBdxBlockQuery> onBlockQueryCallback(OnBlockQuery, nullptr);
Expand All @@ -93,8 +85,12 @@ CHIP_ERROR OnBlockQuery(void * context, chip::System::PacketBufferHandle & block
}
otaTransferInProgress = true;
}

BdxOtaSender * bdxOtaSender = otaProvider.GetBdxOtaSender();
VerifyOrReturnError(bdxOtaSender != nullptr, CHIP_ERROR_INCORRECT_STATE);

uint16_t blockBufAvailableLength = blockBuf->AvailableDataLength();
uint16_t transferBlockSize = bdxServer.GetTransferBlockSize();
uint16_t transferBlockSize = bdxOtaSender->GetTransferBlockSize();

size = (blockBufAvailableLength < transferBlockSize) ? blockBufAvailableLength : transferBlockSize;
if (offset + size >= otaImageLen)
Expand Down Expand Up @@ -167,9 +163,12 @@ extern "C" void app_main()
// Initialize device attestation config
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());

BdxOtaSender * bdxOtaSender = otaProvider.GetBdxOtaSender();
VerifyOrReturn(bdxOtaSender != nullptr, ESP_LOGE(TAG, "bdxOtaSender is nullptr"));

// Register handler to handle bdx messages
error = chip::Server::GetInstance().GetExchangeManager().RegisterUnsolicitedMessageHandlerForProtocol(chip::Protocols::BDX::Id,
&bdxServer);
bdxOtaSender);
if (error != CHIP_NO_ERROR)
{
ESP_LOGE(TAG, "RegisterUnsolicitedMessageHandler failed: %s", chip::ErrorStr(error));
Expand All @@ -180,7 +179,7 @@ extern "C" void app_main()
callbacks.onBlockQuery = &onBlockQueryCallback;
callbacks.onTransferComplete = &onTransferCompleteCallback;
callbacks.onTransferFailed = &onTransferFailedCallback;
bdxServer.SetCallbacks(callbacks);
bdxOtaSender->SetCallbacks(callbacks);

esp_vfs_spiffs_conf_t spiffs_conf = {
.base_path = "/spiffs",
Expand Down Expand Up @@ -217,14 +216,4 @@ extern "C" void app_main()
}

chip::app::Clusters::OTAProvider::SetDelegate(kOtaProviderEndpoint, &otaProvider);

BitFlags<TransferControlFlags> bdxFlags;
bdxFlags.Set(TransferControlFlags::kReceiverDrive);
error = bdxServer.PrepareForTransfer(&chip::DeviceLayer::SystemLayer(), chip::bdx::TransferRole::kSender, bdxFlags,
kMaxBdxBlockSize, kBdxTimeout, kBdxPollFreq);
if (error != CHIP_NO_ERROR)
{
ChipLogError(BDX, "Failed to init BDX server: %s", chip::ErrorStr(error));
return;
}
}