Skip to content

Commit

Permalink
Add command line parameter -P to the Linux ota-provider-app so that t…
Browse files Browse the repository at this point in the history
…he BDX transfer poll frequency can be changed (#18377)

* add isNullable to the onoff cluster attributes OnTime, OffWaitTime and StartUpOnOff

* Revert "add isNullable to the onoff cluster attributes OnTime, OffWaitTime and StartUpOnOff"

This reverts commit 8444469.

* add pollFrequency cli parameter to ota-provider-app to modify the poll frequency for BDX transfers

* as requested rename poll frequency to poll interval

* add poll interval command line parameter information

* to have a faster OTA process we now use a poll interval of 50ms by default

* add pollInterval to wordlist

* fix typo to please CI

* Restyled by whitespace

* Restyled by clang-format

* Restyled by prettier-markdown

Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
2 people authored and pull[bot] committed Jun 26, 2023
1 parent 57e347c commit 1694209
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,7 @@ PlatformManagerImpl
plt
png
PollControl
pollInterval
polymorphism
POSIX
PosixConfig
Expand Down
1 change: 1 addition & 0 deletions examples/ota-provider-app/linux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ scripts/examples/gn_build_example.sh examples/ota-provider-app/linux out/debug c
| -u, --userConsentState \<granted \| denied \| deferred\> | The user consent state for the first QueryImageResponse. For all subsequent responses, the value of granted will be used.<br>Note that --queryImageStatus overrides this option.<li> granted: Status field in the first QueryImageResponse is set to updateAvailable <li> denied: Status field in the first QueryImageResponse is set to updateNotAvailable <li> deferred: Status field in the first QueryImageResponse is set to busy |
| -x, --ignoreQueryImage \<ignore count\> | The number of times to ignore the QueryImage Command and not send a response |
| -y, --ignoreApplyUpdate \<ignore count\> | The number of times to ignore the ApplyUpdate Request and not send a response |
| -P, --pollInterval <milliseconds> | Poll interval for the BDX transfer. |

**Using `--filepath` and `--otaImageList`**

Expand Down
16 changes: 15 additions & 1 deletion examples/ota-provider-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ constexpr uint16_t kOptionDelayedQueryActionTimeSec = 't';
constexpr uint16_t kOptionUserConsentState = 'u';
constexpr uint16_t kOptionIgnoreQueryImage = 'x';
constexpr uint16_t kOptionIgnoreApplyUpdate = 'y';
constexpr uint16_t kOptionPollInterval = 'P';

OTAProviderExample gOtaProvider;
chip::ota::DefaultOTAProviderUserConsent gUserConsentProvider;
Expand All @@ -70,6 +71,7 @@ static chip::ota::UserConsentState gUserConsentState = chip::ota::UserConsentSta
static bool gUserConsentNeeded = false;
static uint32_t gIgnoreQueryImageCount = 0;
static uint32_t gIgnoreApplyUpdateCount = 0;
static uint32_t gPollInterval = 0;

// Parses the JSON filepath and extracts DeviceSoftwareVersionModel parameters
static bool ParseJsonFileAndPopulateCandidates(const char * filepath,
Expand Down Expand Up @@ -241,6 +243,10 @@ bool HandleOptions(const char * aProgram, OptionSet * aOptions, int aIdentifier,
case kOptionUserConsentNeeded:
gUserConsentNeeded = true;
break;
case kOptionPollInterval:
gPollInterval = static_cast<uint32_t>(strtoul(aValue, NULL, 0));
break;

default:
PrintArgError("%s: INTERNAL ERROR: Unhandled option: %s\n", aProgram, aName);
retval = false;
Expand All @@ -262,6 +268,7 @@ OptionDef cmdLineOptionsDef[] = {
{ "userConsentState", chip::ArgParser::kArgumentRequired, kOptionUserConsentState },
{ "ignoreQueryImage", chip::ArgParser::kArgumentRequired, kOptionIgnoreQueryImage },
{ "ignoreApplyUpdate", chip::ArgParser::kArgumentRequired, kOptionIgnoreApplyUpdate },
{ "pollInterval", chip::ArgParser::kArgumentRequired, kOptionPollInterval },
{},
};

Expand Down Expand Up @@ -300,7 +307,9 @@ OptionSet cmdLineOptions = { HandleOptions, cmdLineOptionsDef, "PROGRAM OPTIONS"
" -x, --ignoreQueryImage <ignore count>\n"
" The number of times to ignore the QueryImage Command and not send a response.\n"
" -y, --ignoreApplyUpdate <ignore count>\n"
" The number of times to ignore the ApplyUpdateRequest Command and not send a response.\n" };
" The number of times to ignore the ApplyUpdateRequest Command and not send a response.\n"
" -P, --pollInterval <time in milliseconds>\n"
" Poll interval for the BDX transfer \n" };

OptionSet * allOptions[] = { &cmdLineOptions, nullptr };

Expand Down Expand Up @@ -348,6 +357,11 @@ void ApplicationInit()
gOtaProvider.SetUserConsentNeeded(true);
}

if (gPollInterval != 0)
{
gOtaProvider.SetPollInterval(gPollInterval);
}

ChipLogDetail(SoftwareUpdate, "Using ImageList file: %s", gOtaImageListFilepath ? gOtaImageListFilepath : "(none)");

if (gOtaImageListFilepath != nullptr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ constexpr uint8_t kUpdateTokenStrLen = kUpdateTokenLen * 2 + 1; // Hex string ne
constexpr size_t kOtaHeaderMaxSize = 1024;

// Arbitrary BDX Transfer Params
constexpr uint32_t kMaxBdxBlockSize = 1024;
constexpr chip::System::Clock::Timeout kBdxTimeout = chip::System::Clock::Seconds16(5 * 60); // OTA Spec mandates >= 5 minutes
constexpr chip::System::Clock::Timeout kBdxPollFreq = chip::System::Clock::Milliseconds32(500);
constexpr uint32_t kMaxBdxBlockSize = 1024;
constexpr chip::System::Clock::Timeout kBdxTimeout = chip::System::Clock::Seconds16(5 * 60); // OTA Spec mandates >= 5 minutes
constexpr uint32_t kBdxServerPollIntervalMillis = 50; // poll every 50ms by default

void GetUpdateTokenString(const chip::ByteSpan & token, char * buf, size_t bufSize)
{
Expand Down Expand Up @@ -89,6 +89,7 @@ OTAProviderExample::OTAProviderExample()
mDelayedApplyActionTimeSec = 0;
mUserConsentDelegate = nullptr;
mUserConsentNeeded = false;
mPollInterval = kBdxServerPollIntervalMillis;
mCandidates.clear();
}

Expand Down Expand Up @@ -273,8 +274,9 @@ void OTAProviderExample::SendQueryImageResponse(app::CommandHandler * commandObj
if (mBdxOtaSender.InitializeTransfer(commandObj->GetSubjectDescriptor().fabricIndex,
commandObj->GetSubjectDescriptor().subject) == CHIP_NO_ERROR)
{
CHIP_ERROR error = mBdxOtaSender.PrepareForTransfer(&chip::DeviceLayer::SystemLayer(), chip::bdx::TransferRole::kSender,
bdxFlags, kMaxBdxBlockSize, kBdxTimeout, kBdxPollFreq);
CHIP_ERROR error =
mBdxOtaSender.PrepareForTransfer(&chip::DeviceLayer::SystemLayer(), chip::bdx::TransferRole::kSender, bdxFlags,
kMaxBdxBlockSize, kBdxTimeout, chip::System::Clock::Milliseconds32(mPollInterval));
if (error != CHIP_NO_ERROR)
{
ChipLogError(SoftwareUpdate, "Cannot prepare for transfer: %" CHIP_ERROR_FORMAT, error.Format());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ class OTAProviderExample : public chip::app::Clusters::OTAProviderDelegate
void SetDelayedApplyActionTimeSec(uint32_t time) { mDelayedApplyActionTimeSec = time; }
void SetUserConsentDelegate(chip::ota::OTAProviderUserConsentDelegate * delegate) { mUserConsentDelegate = delegate; }
void SetUserConsentNeeded(bool needed) { mUserConsentNeeded = needed; }
void SetPollInterval(uint32_t interval)
{
if (interval != 0)
mPollInterval = interval;
}

private:
bool SelectOTACandidate(const uint16_t requestorVendorID, const uint16_t requestorProductID,
Expand Down Expand Up @@ -117,4 +122,5 @@ class OTAProviderExample : public chip::app::Clusters::OTAProviderDelegate
bool mUserConsentNeeded;
uint32_t mSoftwareVersion;
char mSoftwareVersionString[SW_VER_STR_MAX_LEN];
uint32_t mPollInterval;
};

0 comments on commit 1694209

Please sign in to comment.