Skip to content

Commit

Permalink
Updating Infineon P6 example lock application to support NtifyUpdate …
Browse files Browse the repository at this point in the history
…after OTA (#21092)
  • Loading branch information
keithmwheeler authored and web-flow committed Jul 22, 2022
1 parent cf37a25 commit cc719ce
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 25 deletions.
24 changes: 2 additions & 22 deletions examples/lock-app/p6/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ using chip::FabricIndex;
using chip::GetRequestorInstance;
using chip::NodeId;
using chip::OTADownloader;
using chip::OTAImageProcessorImpl;
using chip::DeviceLayer::OTAImageProcessorImpl;
using chip::System::Layer;

using namespace ::chip;
Expand Down Expand Up @@ -662,34 +662,14 @@ void vApplicationStackOverflowHook(TaskHandle_t pxTask, char * pcTaskName)
#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
void AppTask::InitOTARequestor()
{
CHIP_ERROR err = CHIP_NO_ERROR;
SetRequestorInstance(&gRequestorCore);
gRequestorStorage.Init(chip::Server::GetInstance().GetPersistentStorage());
gRequestorCore.Init(chip::Server::GetInstance(), gRequestorStorage, gRequestorUser, gDownloader);
gImageProcessor.SetOTADownloader(&gDownloader);
gDownloader.SetImageProcessorDelegate(&gImageProcessor);
ConfigurationMgr().StoreSoftwareVersion(CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION);
gRequestorUser.Init(&gRequestorCore, &gImageProcessor);

uint32_t savedSoftwareVersion;
err = ConfigurationMgr().GetSoftwareVersion(savedSoftwareVersion);
if (err != CHIP_NO_ERROR)
{
P6_LOG("Can't get saved software version");
appError(err);
}

if (savedSoftwareVersion != CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION)
{
ConfigurationMgr().StoreSoftwareVersion(CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION);

P6_LOG("Confirming update to version: %u", CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION);
chip::OTARequestorInterface * requestor = chip::GetRequestorInstance();
if (requestor != nullptr)
{
requestor->NotifyUpdateApplied();
}
}

P6_LOG("Current Software Version: %u", CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION);
P6_LOG("Current Software Version String: %s", CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING);
}
Expand Down
41 changes: 40 additions & 1 deletion src/platform/P6/OTAImageProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@
* limitations under the License.
*/

#include "OTAImageProcessorImpl.h"
#include <app/clusters/ota-requestor/OTADownloader.h>
#include <app/clusters/ota-requestor/OTARequestorInterface.h>
#include <lib/support/CodeUtils.h>
#include <platform/CHIPDeviceLayer.h>

#include "OTAImageProcessorImpl.h"
using namespace ::chip::DeviceLayer::Internal;

namespace chip {
namespace DeviceLayer {

#ifdef P6_OTA
CHIP_ERROR OTAImageProcessorImpl::PrepareDownload()
Expand Down Expand Up @@ -99,6 +104,39 @@ CHIP_ERROR OTAImageProcessorImpl::ProcessBlock(ByteSpan & block)
return CHIP_NO_ERROR;
}

bool OTAImageProcessorImpl::IsFirstImageRun()
{
OTARequestorInterface * requestor = GetRequestorInstance();
ReturnErrorCodeIf(requestor == nullptr, false);

uint32_t currentVersion;
ReturnErrorCodeIf(ConfigurationMgr().GetSoftwareVersion(currentVersion) != CHIP_NO_ERROR, false);

ChipLogProgress(SoftwareUpdate, "%ld", currentVersion);
ChipLogProgress(SoftwareUpdate, "%ld", requestor->GetTargetVersion());

return ((requestor->GetCurrentUpdateState() == OTARequestorInterface::OTAUpdateStateEnum::kApplying) &&
(requestor->GetTargetVersion() == currentVersion));
}

CHIP_ERROR OTAImageProcessorImpl::ConfirmCurrentImage()
{
OTARequestorInterface * requestor = chip::GetRequestorInstance();
if (requestor == nullptr)
{
return CHIP_ERROR_INTERNAL;
}

uint32_t currentVersion;
ReturnErrorOnFailure(DeviceLayer::ConfigurationMgr().GetSoftwareVersion(currentVersion));
if (currentVersion != requestor->GetTargetVersion())
{
return CHIP_ERROR_INCORRECT_STATE;
}

return CHIP_NO_ERROR;
}

void OTAImageProcessorImpl::HandlePrepareDownload(intptr_t context)
{
auto * imageProcessor = reinterpret_cast<OTAImageProcessorImpl *>(context);
Expand Down Expand Up @@ -264,4 +302,5 @@ CHIP_ERROR OTAImageProcessorImpl::ReleaseBlock()
}
#endif // P6_OTA

} // namespace DeviceLayer
} // namespace chip
6 changes: 4 additions & 2 deletions src/platform/P6/OTAImageProcessorImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ extern "C" {
}

namespace chip {
namespace DeviceLayer {

class OTAImageProcessorImpl : public OTAImageProcessorInterface
{
Expand All @@ -43,8 +44,8 @@ class OTAImageProcessorImpl : public OTAImageProcessorInterface
CHIP_ERROR Apply() override;
CHIP_ERROR Abort() override;
CHIP_ERROR ProcessBlock(ByteSpan & block) override;
bool IsFirstImageRun() override { return false; }
CHIP_ERROR ConfirmCurrentImage() override { return CHIP_NO_ERROR; }
bool IsFirstImageRun() override;
CHIP_ERROR ConfirmCurrentImage() override;

void SetOTADownloader(OTADownloader * downloader) { mDownloader = downloader; }

Expand Down Expand Up @@ -80,5 +81,6 @@ class OTAImageProcessorImpl : public OTAImageProcessorInterface
OTAImageHeaderParser mHeaderParser;
};

} // namespace DeviceLayer
} // namespace chip
#endif

0 comments on commit cc719ce

Please sign in to comment.