Skip to content

Commit

Permalink
[OTA EFR32] Add chip-shell to the EFR32 ota-requestor-app, move OTA i…
Browse files Browse the repository at this point in the history
…nitialization to AppTask (project-chip#13894)

* Move OTA initialization to AppTask.cpp to happen after Server::Init()

* Enable CHIP shell in the EFR32 OTA Requestor app

* Restyled by clang-format

* Fix parsing of a command with a trailing empty space

Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
selissia and restyled-commits authored Jan 25, 2022
1 parent 0902641 commit be9582b
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 33 deletions.
7 changes: 3 additions & 4 deletions examples/ota-requestor-app/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ efr32_sdk("sdk") {
"${chip_root}/src/platform/EFR32",
"${efr32_project_dir}/include",
"${examples_plat_dir}",
"${chip_root}/src/lib",
]

defines = [
Expand All @@ -81,6 +82,8 @@ efr32_sdk("sdk") {

efr32_executable("ota_requestor_app") {
output_name = "chip-efr32-ota-requestor-example.out"
include_dirs = [ "include" ]
defines = []

sources = [
"${examples_plat_dir}/LEDWidget.cpp",
Expand Down Expand Up @@ -116,10 +119,6 @@ efr32_executable("ota_requestor_app") {
]
}

include_dirs = [ "include" ]

defines = []

if (show_qr_code) {
sources += [ "${examples_plat_dir}/display/lcd.c" ]
defines += [ "DISPLAY_ENABLED" ]
Expand Down
1 change: 1 addition & 0 deletions examples/ota-requestor-app/efr32/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ chip_openthread_ftd = false

declare_args() {
chip_enable_ota_requestor = true
chip_build_libshell = true
}
2 changes: 2 additions & 0 deletions examples/ota-requestor-app/efr32/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class AppTask

void DispatchEvent(AppEvent * event);

void InitOTARequestor();

static void FunctionTimerEventHandler(AppEvent * aEvent);
static void FunctionHandler(AppEvent * aEvent);
static void LightActionEventHandler(AppEvent * aEvent);
Expand Down
35 changes: 35 additions & 0 deletions examples/ota-requestor-app/efr32/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
#include <app/server/Server.h>
#include <app/util/attribute-storage.h>

#include "app/clusters/ota-requestor/BDXDownloader.h"
#include "app/clusters/ota-requestor/OTARequestor.h"
#include "platform/EFR32/OTAImageProcessorImpl.h"
#include "platform/GenericOTARequestorDriver.h"

#include <assert.h>

#include <credentials/DeviceAttestationCredsProvider.h>
Expand Down Expand Up @@ -86,10 +91,17 @@ StaticTask_t appTaskStruct;

} // namespace

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

// Global OTA objects
OTARequestor gRequestorCore;
DeviceLayer::GenericOTARequestorDriver gRequestorUser;
BDXDownloader gDownloader;
OTAImageProcessorImpl gImageProcessor;

AppTask AppTask::sAppTask;

CHIP_ERROR AppTask::StartAppTask()
Expand Down Expand Up @@ -164,6 +176,9 @@ CHIP_ERROR AppTask::Init()
PrintOnboardingCodes(chip::RendezvousInformationFlag(chip::RendezvousInformationFlag::kBLE));
#endif

// Initialize OTA components
InitOTARequestor();

return err;
}

Expand Down Expand Up @@ -511,3 +526,23 @@ void AppTask::DispatchEvent(AppEvent * aEvent)
}

void AppTask::UpdateClusterState(void) {}

void AppTask::InitOTARequestor()
{

// Initialize and interconnect the Requestor and Image Processor objects -- START
SetRequestorInstance(&gRequestorCore);

gRequestorCore.Init(&(chip::Server::GetInstance()), &gRequestorUser, &gDownloader);

gRequestorUser.Init(&gRequestorCore, &gImageProcessor);

OTAImageProcessorParams ipParams;
ipParams.imageFile = CharSpan("test.txt");
gImageProcessor.SetOTAImageProcessorParams(ipParams);
gImageProcessor.SetOTADownloader(&gDownloader);

// Connect the Downloader and Image Processor objects
gDownloader.SetImageProcessorDelegate(&gImageProcessor);
// Initialize and interconnect the Requestor and Image Processor objects -- END
}
29 changes: 1 addition & 28 deletions examples/ota-requestor-app/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@
#include "sl_system_kernel.h"
#include <app/server/Server.h>

#include "app/clusters/ota-requestor/BDXDownloader.h"
#include "app/clusters/ota-requestor/OTARequestor.h"
#include "platform/EFR32/OTAImageProcessorImpl.h"
#include "platform/GenericOTARequestorDriver.h"

#ifdef HEAP_MONITORING
#include "MemMonitoring.h"
#endif
Expand Down Expand Up @@ -81,12 +76,6 @@ using namespace ::chip::DeviceLayer;

#define UNUSED_PARAMETER(a) (a = a)

// Global OTA objects
OTARequestor gRequestorCore;
DeviceLayer::GenericOTARequestorDriver gRequestorUser;
BDXDownloader gDownloader;
OTAImageProcessorImpl gImageProcessor;

volatile int apperror_cnt;

#include "platform/bootloader/api/application_properties.h"
Expand Down Expand Up @@ -117,7 +106,7 @@ __attribute__((used)) ApplicationProperties_t sl_app_properties = {

/// Bitfield representing type of application
/// e.g. @ref APPLICATION_TYPE_BLUETOOTH_APP
.type = APPLICATION_TYPE_ZIGBEE,
.type = APPLICATION_TYPE_THREAD,

/// Version number for this application
.version = APP_PROPERTIES_VERSION,
Expand Down Expand Up @@ -211,22 +200,6 @@ int main(void)
}
#endif // CHIP_ENABLE_OPENTHREAD

// Initialize and interconnect the Requestor and Image Processor objects -- START
SetRequestorInstance(&gRequestorCore);

gRequestorCore.Init(&(chip::Server::GetInstance()), &gRequestorUser, &gDownloader);

gRequestorUser.Init(&gRequestorCore, &gImageProcessor);

OTAImageProcessorParams ipParams;
ipParams.imageFile = CharSpan("test.txt");
gImageProcessor.SetOTAImageProcessorParams(ipParams);
gImageProcessor.SetOTADownloader(&gDownloader);

// Connect the Downloader and Image Processor objects
gDownloader.SetImageProcessorDelegate(&gImageProcessor);
// Initialize and interconnect the Requestor and Image Processor objects -- END

EFR32_LOG("Starting Platform Manager Event Loop");
ret = PlatformMgr().StartEventLoopTask();
if (ret != CHIP_NO_ERROR)
Expand Down
4 changes: 3 additions & 1 deletion src/lib/shell/MainLoopEFR32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ int TokenizeLine(char * buffer, char ** tokens, int max_tokens)
else if (IsSeparator(buffer[i]))
{
buffer[i] = 0;
if (!IsSeparator(buffer[i + 1]))
// Don't treat the previous character as a separator if this one is 0
// otherwise the trailing space will become a token
if (!IsSeparator(buffer[i + 1]) && buffer[i + 1] != 0)
{
tokens[cursor++] = &buffer[i + 1];
}
Expand Down

0 comments on commit be9582b

Please sign in to comment.