Skip to content

Commit

Permalink
Move Mbed OTA implementation to platform/mbed directory
Browse files Browse the repository at this point in the history
Adaptation to the new API
  • Loading branch information
ATmobica committed Dec 6, 2021
1 parent 0f4cdda commit a19fb29
Show file tree
Hide file tree
Showing 14 changed files with 255 additions and 268 deletions.
6 changes: 2 additions & 4 deletions examples/ota-requestor-app/mbed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,15 @@ target_include_directories(${APP_TARGET} PRIVATE
${APP_ROOT}/ota-requestor-common
${MBED_COMMON}/util/include
${CHIP_ROOT}/src/app/clusters/ota-requestor
${CHIP_ROOT}/src/platform/mbed
)

target_sources(${APP_TARGET} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/main/main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/main/ZclCallbacks.cpp
${CMAKE_CURRENT_SOURCE_DIR}/main/AppTask.cpp
${CMAKE_CURRENT_SOURCE_DIR}/main/MbedOTARequestorDriver.cpp
${MBED_COMMON}/util/LEDWidget.cpp
${CMAKE_CURRENT_SOURCE_DIR}/main/OTARequestorImpl.cpp
${CMAKE_CURRENT_SOURCE_DIR}/main/OTARequestorDriverImpl.cpp
${CMAKE_CURRENT_SOURCE_DIR}/main/OTADownloaderImpl.cpp
${CMAKE_CURRENT_SOURCE_DIR}/main/OTAImageProcessorImpl.cpp

${GEN_DIR}/ota-requestor-app/zap-generated/attribute-size.cpp
${GEN_DIR}/ota-requestor-app/zap-generated/callback-stub.cpp
Expand Down
69 changes: 41 additions & 28 deletions examples/ota-requestor-app/mbed/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@
#include "events/EventQueue.h"
#include "platform/Callback.h"

#include <OTADownloaderImpl.h>
#include <OTAImageProcessorImpl.h>
#include <MbedOTADownloader.h>
#include <MbedOTAImageProcessor.h>
#include <MbedOTARequestor.h>
#include <MbedOTARequestorDriver.h>

static bool sIsWiFiStationProvisioned = false;
static bool sIsWiFiStationEnabled = false;
Expand All @@ -62,9 +64,6 @@ using namespace ::chip::DeviceLayer;

static LEDWidget sStatusLED(MBED_CONF_APP_SYSTEM_STATE_LED);

static OTARequestorDriverImpl sRequestorDriver;
static OTAImageProcessorImpl sImageProcessor;

AppTask AppTask::sAppTask;

int AppTask::Init()
Expand All @@ -91,11 +90,27 @@ int AppTask::Init()
ConnectivityMgr().SetBLEAdvertisingEnabled(true);
}

OTARequestorImpl::GetInstance().Init(OnConnectProviderCallback, OnProviderResponseCallback);
OTARequestorImpl::GetInstance().SetOtaRequestorDriver(&sRequestorDriver);
// Initialize and interconnect the Requestor and Image Processor objects -- START
// Initialize the instance of the main Requestor Class
MbedOTARequestor * requestorCore = new MbedOTARequestor(OnAnnounceProviderCallback, OnProviderResponseCallback);
SetRequestorInstance(requestorCore);

// Initialize an instance of the Requestor Driver
MbedOTARequestorDriver * requestorUser = new MbedOTARequestorDriver;

// Connect the Requestor and Requestor Driver objects
requestorCore->SetOtaRequestorDriver(requestorUser);

// Initialize the Downloader object
MbedOTADownloader * downloaderCore = new MbedOTADownloader(OnDownloadCompletedCallback);
SetDownloaderInstance(downloaderCore);

// Initialize the Image Processor object
MbedOTAImageProcessor * downloaderUser = new MbedOTAImageProcessor;

OTADownloaderImpl::GetInstance().Init(OnDownloadCompletedCallback);
OTADownloaderImpl::GetInstance().SetImageProcessorDelegate(&sImageProcessor);
// Connect the Downloader and Image Processor objects
downloaderCore->SetImageProcessorDelegate(downloaderUser);
// Initialize and interconnect the Requestor and Image Processor objects -- END

chip::DeviceLayer::ConnectivityMgrImpl().StartWiFiManagement();

Expand Down Expand Up @@ -175,17 +190,18 @@ void AppTask::OnOtaEventHandler(AppEvent * aEvent)
{
switch (aEvent->Type)
{
case AppEvent::kEventType_ota_provider_connect:
ChipLogProgress(NotSpecified, "OTA provider connect event");

OTARequestorImpl::GetInstance().ConnectProvider(aEvent->OTAProviderConnectEvent.nodeId,
aEvent->OTAProviderConnectEvent.fabricIndex,
aEvent->OTAProviderConnectEvent.ipAddress);
case AppEvent::kEventType_ota_provider_announce: {
ChipLogProgress(NotSpecified, "OTA provider announce event");
MbedOTARequestor * requestor = static_cast<MbedOTARequestor *>(GetRequestorInstance());
requestor->ConnectProvider();
break;
}

case AppEvent::kEventType_ota_provider_response: {
ChipLogProgress(NotSpecified, "OTA provider response event");
OTADownloaderImpl::GetInstance().SetDownloadImageInfo(aEvent->OTAProviderResponseEvent.imageDatails->updateFileName);
OTADownloaderImpl::GetInstance().BeginDownload();
MbedOTADownloader * downloader = static_cast<MbedOTADownloader *>(GetDownloaderInstance());
downloader->SetDownloadImageInfo(aEvent->OTAProviderResponseEvent.imageDatails->updateFileName);
downloader->BeginPrepareDownload();
break;
}
case AppEvent::kEventType_ota_download_completed:
Expand All @@ -200,18 +216,15 @@ void AppTask::OnOtaEventHandler(AppEvent * aEvent)
}
}

void AppTask::OnConnectProviderCallback(NodeId nodeId, FabricIndex fabricIndex, chip::Optional<chip::ByteSpan> ipAddress)
void AppTask::OnAnnounceProviderCallback()
{
AppEvent ota_connect_provider_event;
ota_connect_provider_event.Type = AppEvent::kEventType_ota_provider_connect;
ota_connect_provider_event.OTAProviderConnectEvent.nodeId = nodeId;
ota_connect_provider_event.OTAProviderConnectEvent.fabricIndex = fabricIndex;
ota_connect_provider_event.OTAProviderConnectEvent.ipAddress = reinterpret_cast<const char *>(ipAddress.Value().data());
ota_connect_provider_event.Handler = OnOtaEventHandler;
sAppTask.PostEvent(&ota_connect_provider_event);
AppEvent ota_announce_provider_event;
ota_announce_provider_event.Type = AppEvent::kEventType_ota_provider_announce;
ota_announce_provider_event.Handler = OnOtaEventHandler;
sAppTask.PostEvent(&ota_announce_provider_event);
}

void AppTask::OnProviderResponseCallback(OTARequestorImpl::OTAUpdateDetails * updateDetails)
void AppTask::OnProviderResponseCallback(MbedOTARequestor::OTAUpdateDetails * updateDetails)
{
AppEvent ota_provider_response_event;
ota_provider_response_event.Type = AppEvent::kEventType_ota_provider_response;
Expand All @@ -220,7 +233,7 @@ void AppTask::OnProviderResponseCallback(OTARequestorImpl::OTAUpdateDetails * up
sAppTask.PostEvent(&ota_provider_response_event);
}

void AppTask::OnDownloadCompletedCallback(OTADownloaderImpl::ImageInfo * imageInfo)
void AppTask::OnDownloadCompletedCallback(MbedOTADownloader::ImageInfo * imageInfo)
{
AppEvent ota_download_completed_event;
ota_download_completed_event.Type = AppEvent::kEventType_ota_download_completed;
Expand Down Expand Up @@ -248,4 +261,4 @@ void AppTask::DispatchEvent(const AppEvent * aEvent)
{
ChipLogError(NotSpecified, "Event received with no handler. Dropping event.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
* limitations under the License.
*/

#include <OTARequestorDriverImpl.h>
#include <MbedOTARequestorDriver.h>

bool CheckImageDownloadAllowed()
bool MbedOTARequestorDriver::CheckImageDownloadAllowed()
{
return true;
}

void ImageDownloadComplete() {}
void MbedOTARequestorDriver::ImageDownloadComplete() {}
19 changes: 0 additions & 19 deletions examples/ota-requestor-app/mbed/main/ZclCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <app/ConcreteAttributePath.h>
#include <lib/support/logging/CHIPLogging.h>

#include "OTARequestorImpl.h"
#include <app-common/zap-generated/cluster-objects.h>
#include <app/CommandHandler.h>
#include <app/util/af.h>
Expand All @@ -36,21 +35,3 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath &
AttributeId attributeId = attributePath.mAttributeId;
ChipLogProgress(Zcl, "Cluster callback: " ChipLogFormatMEI, ChipLogValueMEI(clusterId));
}

// OTA Software Update Requestor Cluster AnnounceOtaProvider Command callback (from client)
bool emberAfOtaSoftwareUpdateRequestorClusterAnnounceOtaProviderCallback(
chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath,
const chip::app::Clusters::OtaSoftwareUpdateRequestor::Commands::AnnounceOtaProvider::DecodableType & commandData)
{

EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS;

auto ret = OTARequestorImpl::GetInstance().HandleAnnounceOTAProvider(commandObj, commandPath, commandData);
if (ret)
{
status = EMBER_ZCL_STATUS_FAILURE;
}

emberAfSendImmediateDefaultResponse(status);
return true;
}
17 changes: 5 additions & 12 deletions examples/ota-requestor-app/mbed/main/include/AppEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

#pragma once

#include <OTADownloaderImpl.h>
#include <OTARequestorImpl.h>
#include <app-common/zap-generated/cluster-objects.h>
#include <cstdint>
#include <platform/mbed/MbedOTADownloader.h>
#include <platform/mbed/MbedOTARequestor.h>

struct AppEvent;
typedef void (*EventHandler)(AppEvent *);
Expand All @@ -31,7 +31,7 @@ struct AppEvent
{
enum AppEventTypes
{
kEventType_ota_provider_connect = 0,
kEventType_ota_provider_announce = 0,
kEventType_ota_provider_response,
kEventType_ota_download_completed,
};
Expand All @@ -42,19 +42,12 @@ struct AppEvent
{
struct
{
chip::NodeId nodeId;
chip::FabricIndex fabricIndex;
const char * ipAddress;
} OTAProviderConnectEvent;

struct
{
OTARequestorImpl::OTAUpdateDetails * imageDatails;
MbedOTARequestor::OTAUpdateDetails * imageDatails;
} OTAProviderResponseEvent;

struct
{
OTADownloaderImpl::ImageInfo * imageInfo;
chip::MbedOTADownloader::ImageInfo * imageInfo;
} OTADownloadCompletedEvent;
};

Expand Down
11 changes: 5 additions & 6 deletions examples/ota-requestor-app/mbed/main/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
#pragma once

#include "AppEvent.h"
#include <OTADownloaderImpl.h>
#include <OTARequestorImpl.h>
#include <MbedOTADownloader.h>
#include <MbedOTARequestor.h>

class AppTask
{
Expand All @@ -38,12 +38,11 @@ class AppTask

static void OnOtaEventHandler(AppEvent * aEvent);

static void OnConnectProviderCallback(chip::NodeId nodeId, chip::FabricIndex fabricIndex,
chip::Optional<chip::ByteSpan> ipAddress);
static void OnAnnounceProviderCallback();

static void OnProviderResponseCallback(OTARequestorImpl::OTAUpdateDetails * updateDetails);
static void OnProviderResponseCallback(MbedOTARequestor::OTAUpdateDetails * updateDetails);

static void OnDownloadCompletedCallback(OTADownloaderImpl::ImageInfo * imageInfo);
static void OnDownloadCompletedCallback(chip::MbedOTADownloader::ImageInfo * imageInfo);

static AppTask sAppTask;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@

#pragma once

class OTARequestorDriverImpl
#include "app/clusters/ota-requestor/OTARequestorDriver.h"

class MbedOTARequestorDriver : public OTARequestorDriver
{
public:
// A call into the application logic to give it a chance to allow or stop the Requestor
// from proceeding with actual image download. Returning TRUE will allow the download
// to proceed, returning FALSE will abort the download process.
bool CheckImageDownloadAllowed() { return true; }
bool CheckImageDownloadAllowed();

// Notify the application that the download is complete and the image can be applied
void ImageDownloadComplete() {}
};
void ImageDownloadComplete();
};
11 changes: 11 additions & 0 deletions src/platform/mbed/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,15 @@ static_library("mbed") {
sources += [ "../OpenThread/DnssdImpl.cpp" ]
deps += [ "${chip_root}/src/lib/dnssd:platform_header" ]
}

if (chip_enable_ota_requestor) {
sources += [
"${chip_root}/src/app/clusters/ota-requestor/ClusterInterface.cpp",
"MbedOTADownloader.cpp",
"MbedOTAImageProcessor.cpp",
"MbedOTARequestor.cpp",
]

include_dirs = [ "${chip_root}/zzz_generated/ota-requestor-app" ]
}
}
Loading

0 comments on commit a19fb29

Please sign in to comment.