Skip to content

Commit

Permalink
Synchronize OTA to TE9.
Browse files Browse the repository at this point in the history
Change-Id: I0c336e83cd1886912e65b2c556ed6eb19f3df5dd
  • Loading branch information
fuxingguo16 authored and jamesluo11 committed May 17, 2022
1 parent 623951e commit df88c00
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 72 deletions.
85 changes: 44 additions & 41 deletions examples/lighting-app/beken/main/chipinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@
#include <setup_payload/QRCodeSetupPayloadGenerator.h>

//#if CONFIG_ENABLE_OTA_REQUESTOR
#include <app/clusters/ota-requestor/OTADownloader.h>
#include <lib/core/OTAImageHeader.h>
#include <platform/CHIPDeviceLayer.h>
#include <platform/OTAImageProcessor.h>
#include "app/clusters/ota-requestor/DefaultOTARequestorStorage.h"
#include <app/clusters/ota-requestor/BDXDownloader.h>
#include <app/clusters/ota-requestor/DefaultOTARequestor.h>
#include <platform/Beken/OTAImageProcessorImpl.h>
#include <app/clusters/ota-requestor/DefaultOTARequestorDriver.h>
#include <app/clusters/ota-requestor/DefaultOTARequestorUserConsent.h>
#include <app/clusters/ota-requestor/ExtendedOTARequestorDriver.h>
Expand All @@ -45,41 +50,46 @@
//using chip::OTAImageProcessorImpl;
using chip::BDXDownloader;
using chip::ByteSpan;
using chip::DefaultOTARequestor;
using chip::EndpointId;
using chip::FabricIndex;
using chip::GetRequestorInstance;
using chip::NodeId;
using chip::OnDeviceConnected;
using chip::OnDeviceConnectionFailure;
using chip::OTADownloader;
//using chip::OTAImageProcessorParams;
//using chip::OTARequestor;
using chip::PeerId;
using chip::Server;
using chip::VendorId;
using chip::Callback::Callback;
using chip::System::Layer;
using chip::Transport::PeerAddress;
using namespace chip::Messaging;
using namespace chip::app::Clusters::OtaSoftwareUpdateProvider::Commands;


using namespace ::chip;
using namespace ::chip::Credentials;
using namespace ::chip::DeviceManager;
using namespace ::chip::DeviceLayer;
using namespace ::chip::System;

namespace {

static DeviceCallbacks EchoCallbacks;
//OTARequestor gRequestorCore;
//GenericOTARequestorDriver gRequestorUser;
BDXDownloader gDownloader;
//OTAImageProcessorImpl gImageProcessor;
namespace {
constexpr EndpointId kNetworkCommissioningEndpointMain = 0;
constexpr EndpointId kNetworkCommissioningEndpointSecondary = 0xFFFE;

app::Clusters::NetworkCommissioning::Instance
sWiFiNetworkCommissioningInstance(0 /* Endpoint Id */, &(NetworkCommissioning::BekenWiFiDriver::GetInstance()));
sWiFiNetworkCommissioningInstance(kNetworkCommissioningEndpointMain /* Endpoint Id */, &(NetworkCommissioning::BekenWiFiDriver::GetInstance()));
} // namespace

static DeviceCallbacks EchoCallbacks;
DefaultOTARequestor gRequestorCore;
DefaultOTARequestorStorage gRequestorStorage;
ExtendedOTARequestorDriver gRequestorUser;
BDXDownloader gDownloader;
OTAImageProcessorImpl gImageProcessor;
chip::ota::DefaultOTARequestorUserConsent gUserConsentProvider;
static chip::ota::UserConsentState gUserConsentState = chip::ota::UserConsentState::kGranted;

// need to check CONFIG_RENDEZVOUS_MODE
bool isRendezvousBLE()
{
Expand All @@ -91,21 +101,19 @@ bool isRendezvousBLE()
extern "C" void QueryImageCmdHandler()
{
ChipLogProgress(DeviceLayer, "Calling QueryImageCmdHandler");
//static_cast<OTARequestor *>(GetRequestorInstance())->TriggerImmediateQuery();
PlatformMgr().ScheduleWork([](intptr_t) { GetRequestorInstance()->TriggerImmediateQuery(); });
}

extern "C" void ApplyUpdateCmdHandler()
{
ChipLogProgress(DeviceLayer, "Calling ApplyUpdateCmdHandler");

//static_cast<OTARequestor *>(GetRequestorInstance())->ApplyUpdate();
PlatformMgr().ScheduleWork([](intptr_t) { GetRequestorInstance()->ApplyUpdate(); });
}

extern "C" void NotifyUpdateAppliedHandler(uint32_t version)
{
ChipLogProgress(DeviceLayer, "NotifyUpdateApplied");

//static_cast<OTARequestor *>(GetRequestorInstance())->NotifyUpdateApplied(version);
PlatformMgr().ScheduleWork([](intptr_t) { GetRequestorInstance()->NotifyUpdateApplied(); });
}

/*********************************************************************
Expand All @@ -118,7 +126,6 @@ extern "C" void NotifyUpdateAppliedHandler(uint32_t version)
*******************************************************************/
extern "C" void BkQueryImageCmdHandler(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv )
{
#if 0
uint32_t dwLoop = 0;
uint32_t nodeId = 0;
uint32_t fabricId = 0;
Expand Down Expand Up @@ -150,7 +157,6 @@ extern "C" void BkQueryImageCmdHandler(char *pcWriteBuffer, int xWriteBufferLen,

QueryImageCmdHandler();
ChipLogProgress(DeviceLayer,"QueryImageCmdHandler begin");
#endif

return ;
}
Expand Down Expand Up @@ -181,7 +187,6 @@ extern "C" void BkApplyUpdateCmdHandler(char *pcWriteBuffer, int xWriteBufferLen
*******************************************************************/
extern "C" void BkNotifyUpdateApplied(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv )
{
#if 0
uint32_t dwLoop = 0;
uint32_t version = 0;

Expand Down Expand Up @@ -209,37 +214,32 @@ extern "C" void BkNotifyUpdateApplied(char *pcWriteBuffer, int xWriteBufferLen,

NotifyUpdateAppliedHandler( version);
ChipLogProgress(DeviceLayer,"NotifyUpdateApplied send request");
#endif

return ;
}

static void InitOTARequestor(void)
{
#if 0
// Initialize and interconnect the Requestor and Image Processor objects -- START
SetRequestorInstance(&gRequestorCore);
ChipLogProgress(DeviceLayer,"InitOTARequestor gRequestorCore init");

gRequestorStorage.Init(Server::GetInstance().GetPersistentStorage());

// Set server instance used for session establishment
/* - Set server instance used to get access to the system resources necessary to open CASE sessions and drive
* - BDX transfers
* - Set the OTA requestor driver instance used to communicate download progress and errors
* - Set the BDX downloader instance used for initiating BDX downloads
*/
gRequestorCore.Init(&(chip::Server::GetInstance()), &gRequestorUser, &gDownloader);

// WARNING: this is probably not realistic to know such details of the image or to even have an OTADownloader instantiated at
// the beginning of program execution. We're using hardcoded values here for now since this is a reference application.
// TODO: instatiate and initialize these values when QueryImageResponse tells us an image is available
// TODO: add API for OTARequestor to pass QueryImageResponse info to the application to use for OTADownloader init
OTAImageProcessorParams ipParams;
gImageProcessor.SetOTAImageProcessorParams(ipParams);
gRequestorCore.Init(Server::GetInstance(), gRequestorStorage, gRequestorUser, gDownloader);

gImageProcessor.SetOTADownloader(&gDownloader);

// Connect the Downloader and Image Processor objects
gDownloader.SetImageProcessorDelegate(&gImageProcessor);
gRequestorUser.Init(&gRequestorCore, &gImageProcessor);
#endif

if (gUserConsentState != chip::ota::UserConsentState::kUnknown)
{
gUserConsentProvider.SetUserConsentState(gUserConsentState);
gRequestorUser.SetUserConsentDelegate(&gUserConsentProvider);
}

// Initialize and interconnect the Requestor and Image Processor objects -- END
}
//#endif // CONFIG_ENABLE_OTA_REQUESTOR
Expand Down Expand Up @@ -374,27 +374,29 @@ static void InitServer(intptr_t context)
// Initialize device attestation config
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
sWiFiNetworkCommissioningInstance.Init();
InitOTARequestor();
PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE));
}

extern "C" void ChipTest(void)
{
ChipLogProgress(Zcl, "ChipTest");
ChipLogProgress(DeviceLayer, "Lighting App Demo!");
CHIP_ERROR err = CHIP_NO_ERROR;

//initPref();

CHIPDeviceManager & deviceMgr = CHIPDeviceManager::GetInstance();
err = deviceMgr.Init(&EchoCallbacks); //start the CHIP task
if (err != CHIP_NO_ERROR)
{
ChipLogProgress(Zcl, "DeviceManagerInit() - ERROR!");
ChipLogError(DeviceLayer, "DeviceManagerInit() - ERROR!\r\n");
}
else
{
ChipLogProgress(Zcl, "DeviceManagerInit() - OK");
ChipLogProgress(DeviceLayer, "DeviceManagerInit() - OK\r\n");
}
chip::DeviceLayer::PlatformMgr().ScheduleWork(InitServer, reinterpret_cast<intptr_t>(nullptr));
InitOTARequestor();
chip::DeviceLayer::PlatformMgr().ScheduleWork(InitServer, 0);

while (true)
vTaskDelay(pdMS_TO_TICKS(50)); //Just server the application event handler
ChipLogProgress(SoftwareUpdate, "Exited");
Expand All @@ -405,3 +407,4 @@ bool lowPowerClusterSleep()
{
return true;
}

4 changes: 2 additions & 2 deletions src/platform/Beken/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ static_library("Beken") {
"KeyValueStoreManagerImpl.h",
"Logging.cpp",
"LwIPCoreLock.cpp",
#"OTAImageProcessorImpl.cpp",
#"OTAImageProcessorImpl.h",
"OTAImageProcessorImpl.cpp",
"OTAImageProcessorImpl.h",
"PlatformManagerImpl.cpp",
"PlatformManagerImpl.h",
"SoftwareUpdateManagerImpl.h",
Expand Down
Loading

0 comments on commit df88c00

Please sign in to comment.