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

[QPG] Initialize OTA Requestor 3 seconds after Thread attach #20860

Merged
merged 1 commit into from
Jul 18, 2022
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/lighting-app/qpg/include/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
/**
* CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID
*
* 0xFFF1: Test vendor.
* 0xFFF1: Test Vendor.
*/
#define CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID 0xFFF1

Expand Down
9 changes: 3 additions & 6 deletions examples/lighting-app/qpg/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
#include <setup_payload/SetupPayload.h>

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

#include <platform/CHIPDeviceLayer.h>

Expand Down Expand Up @@ -243,9 +243,6 @@ CHIP_ERROR AppTask::Init()
initParams.endpointNativeParams = static_cast<void *>(&nativeParams);
chip::Server::GetInstance().Init(initParams);

// Init OTA engine
InitializeOTARequestor();

// Initialize device attestation config
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());

Expand Down
11 changes: 4 additions & 7 deletions examples/lock-app/qpg/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ void UnlockOpenThreadTask(void)
CHIP_ERROR AppTask::StartAppTask()
{
sAppEventQueue = xQueueCreateStatic(APP_EVENT_QUEUE_SIZE, sizeof(AppEvent), sAppEventQueueBuffer, &sAppEventQueueStruct);
if (sAppEventQueue == NULL)
if (sAppEventQueue == nullptr)
{
ChipLogError(NotSpecified, "Failed to allocate app event queue");
return CHIP_ERROR_NO_MEMORY;
}

// Start App task.
sAppTaskHandle = xTaskCreateStatic(AppTaskMain, APP_TASK_NAME, ArraySize(appStack), NULL, 1, appStack, &appTaskStruct);
if (sAppTaskHandle == NULL)
sAppTaskHandle = xTaskCreateStatic(AppTaskMain, APP_TASK_NAME, ArraySize(appStack), nullptr, 1, appStack, &appTaskStruct);
if (sAppTaskHandle == nullptr)
{
return CHIP_ERROR_NO_MEMORY;
}
Expand Down Expand Up @@ -145,9 +145,6 @@ CHIP_ERROR AppTask::Init()
initParams.endpointNativeParams = static_cast<void *>(&nativeParams);
chip::Server::GetInstance().Init(initParams);

// Init OTA engine
InitializeOTARequestor();

// Initialize device attestation config
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());

Expand All @@ -167,7 +164,7 @@ void AppTask::AppTaskMain(void * pvParameter)
if (err != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "AppTask.Init() failed: %" CHIP_ERROR_FORMAT, err.Format());
// appError(err);
return;
}

ChipLogProgress(NotSpecified, "App Task started");
Expand Down
32 changes: 30 additions & 2 deletions examples/platform/qpg/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,17 @@

// Application level logic
#include "AppTask.h"
#include "ota.h"

using namespace ::chip;
using namespace ::chip::Inet;
using namespace ::chip::DeviceLayer;
using namespace ::chip::DeviceLayer::Internal;

namespace {
constexpr int extDiscTimeoutSecs = 20;
}
constexpr uint32_t kInitOTARequestorDelaySec = 3;
constexpr int extDiscTimeoutSecs = 20;
} // namespace

/*****************************************************************************
* Macro Definitions
Expand All @@ -71,6 +73,13 @@ constexpr int extDiscTimeoutSecs = 20;
*****************************************************************************/
CHIP_ERROR CHIP_Init(void);

#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
void InitOTARequestorHandler(System::Layer * systemLayer, void * appState)
{
InitializeOTARequestor();
}
#endif

void Application_Init(void)
{
CHIP_ERROR error;
Expand All @@ -96,6 +105,24 @@ void Application_Init(void)
}
}

void ChipEventHandler(const ChipDeviceEvent * aEvent, intptr_t /* arg */)
{
switch (aEvent->Type)
{
case DeviceEventType::kThreadConnectivityChange:
#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
if (aEvent->ThreadConnectivityChange.Result == kConnectivity_Established)
{
chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(kInitOTARequestorDelaySec),
InitOTARequestorHandler, nullptr);
}
#endif
break;
default:
break;
}
}

CHIP_ERROR CHIP_Init(void)
{
CHIP_ERROR ret = CHIP_NO_ERROR;
Expand Down Expand Up @@ -163,6 +190,7 @@ CHIP_ERROR CHIP_Init(void)
#endif // CHIP_ENABLE_OPENTHREAD

ChipLogProgress(NotSpecified, "Starting Platform Manager Event Loop");
PlatformMgr().AddEventHandler(ChipEventHandler, 0);
ret = PlatformMgr().StartEventLoopTask();
if (ret != CHIP_NO_ERROR)
{
Expand Down
1 change: 1 addition & 0 deletions examples/platform/qpg/ota/ota.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ bool OtaHeaderValidationCb(qvCHIP_Ota_ImageHeader_t imageHeader)

void InitializeOTARequestor(void)
{
ChipLogDetail(DeviceLayer, "Initialising OTA Requestor");
// Initialize and interconnect the Requestor and Image Processor objects
SetRequestorInstance(&gRequestorCore);

Expand Down
6 changes: 5 additions & 1 deletion examples/shell/qpg/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ qpg_executable("shell_app") {

sources = [
"${examples_plat_dir}/app/main.cpp",
"${examples_plat_dir}/ota/ota.cpp",
"src/AppTask.cpp",
]

Expand All @@ -58,7 +59,10 @@ qpg_executable("shell_app") {
#chip datamodel is given [import("${chip_root}/src/app/chip_data_model.gni")]
deps += [ "${chip_root}/examples/lock-app/lock-common" ]

include_dirs = [ "include" ]
include_dirs = [
"include",
"${examples_plat_dir}/ota",
]

defines = []

Expand Down
3 changes: 2 additions & 1 deletion src/platform/qpg/ConnectivityManagerImpl.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
*
* Copyright (c) 2020 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -98,7 +99,7 @@ inline ConnectivityManager & ConnectivityMgr(void)
* Returns the platform-specific implementation of the ConnectivityManager singleton object.
*
* Chip applications can use this to gain access to features of the ConnectivityManager
* that are specific to the ESP32 platform.
* that are specific to the QPG platform.
*/
inline ConnectivityManagerImpl & ConnectivityMgrImpl(void)
{
Expand Down
16 changes: 9 additions & 7 deletions src/platform/qpg/OTAImageProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ CHIP_ERROR OTAImageProcessorImpl::ConfirmCurrentImage()
}

uint32_t currentVersion;
uint32_t targetVersion = requestor->GetTargetVersion();
ReturnErrorOnFailure(DeviceLayer::ConfigurationMgr().GetSoftwareVersion(currentVersion));

if (currentVersion != requestor->GetTargetVersion())
if (currentVersion != targetVersion)
{
ChipLogError(SoftwareUpdate, "Current software version = %" PRIu32 ", expected software version = %" PRIu32, currentVersion,
targetVersion);
return CHIP_ERROR_INCORRECT_STATE;
}

Expand Down Expand Up @@ -122,18 +125,17 @@ CHIP_ERROR OTAImageProcessorImpl::Abort()

CHIP_ERROR OTAImageProcessorImpl::ProcessBlock(ByteSpan & block)
{
CHIP_ERROR err;

if ((block.data() == nullptr) || block.empty())
{
return CHIP_ERROR_INVALID_ARGUMENT;
}

// Process block header info
err = ProcessHeader(block);
CHIP_ERROR err = ProcessHeader(block);

if (err != CHIP_NO_ERROR)
{
ChipLogError(SoftwareUpdate, "Cannot process block header: %" CHIP_ERROR_FORMAT, err.Format());
ChipLogError(SoftwareUpdate, "Matter image header parser error %s", chip::ErrorStr(err));
this->mDownloader->EndDownload(CHIP_ERROR_INVALID_FILE_IDENTIFIER);
return err;
}

Expand Down Expand Up @@ -223,7 +225,7 @@ void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context)
return;
}

ChipLogProgress(SoftwareUpdate, "Q: HandleProcessBlock");
ChipLogDetail(SoftwareUpdate, "Q: HandleProcessBlock");

status =
qvCHIP_OtaWriteChunk(imageProcessor->mParams.downloadedBytes, static_cast<std::uint16_t>(imageProcessor->mBlock.size()),
Expand Down