Skip to content

Commit 1227459

Browse files
bauerschwanrestyled-commits
authored andcommitted
Add command line parameter -P to the Linux ota-provider-app so that the 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>
1 parent 1bcb681 commit 1227459

File tree

5 files changed

+30
-6
lines changed

5 files changed

+30
-6
lines changed

.github/.wordlist.txt

+1
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,7 @@ PlatformManagerImpl
985985
plt
986986
png
987987
PollControl
988+
pollInterval
988989
polymorphism
989990
POSIX
990991
PosixConfig

examples/ota-provider-app/linux/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ scripts/examples/gn_build_example.sh examples/ota-provider-app/linux out/debug c
2626
| -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 |
2727
| -x, --ignoreQueryImage \<ignore count\> | The number of times to ignore the QueryImage Command and not send a response |
2828
| -y, --ignoreApplyUpdate \<ignore count\> | The number of times to ignore the ApplyUpdate Request and not send a response |
29+
| -P, --pollInterval <milliseconds> | Poll interval for the BDX transfer. |
2930

3031
**Using `--filepath` and `--otaImageList`**
3132

examples/ota-provider-app/linux/main.cpp

+15-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ constexpr uint16_t kOptionDelayedQueryActionTimeSec = 't';
5454
constexpr uint16_t kOptionUserConsentState = 'u';
5555
constexpr uint16_t kOptionIgnoreQueryImage = 'x';
5656
constexpr uint16_t kOptionIgnoreApplyUpdate = 'y';
57+
constexpr uint16_t kOptionPollInterval = 'P';
5758

5859
OTAProviderExample gOtaProvider;
5960
chip::ota::DefaultOTAProviderUserConsent gUserConsentProvider;
@@ -70,6 +71,7 @@ static chip::ota::UserConsentState gUserConsentState = chip::ota::UserConsentSta
7071
static bool gUserConsentNeeded = false;
7172
static uint32_t gIgnoreQueryImageCount = 0;
7273
static uint32_t gIgnoreApplyUpdateCount = 0;
74+
static uint32_t gPollInterval = 0;
7375

7476
// Parses the JSON filepath and extracts DeviceSoftwareVersionModel parameters
7577
static bool ParseJsonFileAndPopulateCandidates(const char * filepath,
@@ -241,6 +243,10 @@ bool HandleOptions(const char * aProgram, OptionSet * aOptions, int aIdentifier,
241243
case kOptionUserConsentNeeded:
242244
gUserConsentNeeded = true;
243245
break;
246+
case kOptionPollInterval:
247+
gPollInterval = static_cast<uint32_t>(strtoul(aValue, NULL, 0));
248+
break;
249+
244250
default:
245251
PrintArgError("%s: INTERNAL ERROR: Unhandled option: %s\n", aProgram, aName);
246252
retval = false;
@@ -262,6 +268,7 @@ OptionDef cmdLineOptionsDef[] = {
262268
{ "userConsentState", chip::ArgParser::kArgumentRequired, kOptionUserConsentState },
263269
{ "ignoreQueryImage", chip::ArgParser::kArgumentRequired, kOptionIgnoreQueryImage },
264270
{ "ignoreApplyUpdate", chip::ArgParser::kArgumentRequired, kOptionIgnoreApplyUpdate },
271+
{ "pollInterval", chip::ArgParser::kArgumentRequired, kOptionPollInterval },
265272
{},
266273
};
267274

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

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

@@ -348,6 +357,11 @@ void ApplicationInit()
348357
gOtaProvider.SetUserConsentNeeded(true);
349358
}
350359

360+
if (gPollInterval != 0)
361+
{
362+
gOtaProvider.SetPollInterval(gPollInterval);
363+
}
364+
351365
ChipLogDetail(SoftwareUpdate, "Using ImageList file: %s", gOtaImageListFilepath ? gOtaImageListFilepath : "(none)");
352366

353367
if (gOtaImageListFilepath != nullptr)

examples/ota-provider-app/ota-provider-common/OTAProviderExample.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ constexpr uint8_t kUpdateTokenStrLen = kUpdateTokenLen * 2 + 1; // Hex string ne
5555
constexpr size_t kOtaHeaderMaxSize = 1024;
5656

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

6262
void GetUpdateTokenString(const chip::ByteSpan & token, char * buf, size_t bufSize)
6363
{
@@ -89,6 +89,7 @@ OTAProviderExample::OTAProviderExample()
8989
mDelayedApplyActionTimeSec = 0;
9090
mUserConsentDelegate = nullptr;
9191
mUserConsentNeeded = false;
92+
mPollInterval = kBdxServerPollIntervalMillis;
9293
mCandidates.clear();
9394
}
9495

@@ -273,8 +274,9 @@ void OTAProviderExample::SendQueryImageResponse(app::CommandHandler * commandObj
273274
if (mBdxOtaSender.InitializeTransfer(commandObj->GetSubjectDescriptor().fabricIndex,
274275
commandObj->GetSubjectDescriptor().subject) == CHIP_NO_ERROR)
275276
{
276-
CHIP_ERROR error = mBdxOtaSender.PrepareForTransfer(&chip::DeviceLayer::SystemLayer(), chip::bdx::TransferRole::kSender,
277-
bdxFlags, kMaxBdxBlockSize, kBdxTimeout, kBdxPollFreq);
277+
CHIP_ERROR error =
278+
mBdxOtaSender.PrepareForTransfer(&chip::DeviceLayer::SystemLayer(), chip::bdx::TransferRole::kSender, bdxFlags,
279+
kMaxBdxBlockSize, kBdxTimeout, chip::System::Clock::Milliseconds32(mPollInterval));
278280
if (error != CHIP_NO_ERROR)
279281
{
280282
ChipLogError(SoftwareUpdate, "Cannot prepare for transfer: %" CHIP_ERROR_FORMAT, error.Format());

examples/ota-provider-app/ota-provider-common/OTAProviderExample.h

+6
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ class OTAProviderExample : public chip::app::Clusters::OTAProviderDelegate
8383
void SetDelayedApplyActionTimeSec(uint32_t time) { mDelayedApplyActionTimeSec = time; }
8484
void SetUserConsentDelegate(chip::ota::OTAProviderUserConsentDelegate * delegate) { mUserConsentDelegate = delegate; }
8585
void SetUserConsentNeeded(bool needed) { mUserConsentNeeded = needed; }
86+
void SetPollInterval(uint32_t interval)
87+
{
88+
if (interval != 0)
89+
mPollInterval = interval;
90+
}
8691

8792
private:
8893
bool SelectOTACandidate(const uint16_t requestorVendorID, const uint16_t requestorProductID,
@@ -117,4 +122,5 @@ class OTAProviderExample : public chip::app::Clusters::OTAProviderDelegate
117122
bool mUserConsentNeeded;
118123
uint32_t mSoftwareVersion;
119124
char mSoftwareVersionString[SW_VER_STR_MAX_LEN];
125+
uint32_t mPollInterval;
120126
};

0 commit comments

Comments
 (0)