Skip to content

Commit

Permalink
Restyled by clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
restyled-commits committed Sep 29, 2021
1 parent 70c6195 commit fe29cab
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 33 deletions.
14 changes: 7 additions & 7 deletions examples/ota-provider-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ using chip::Messaging::ExchangeManager;
// TODO: this should probably be done dynamically
constexpr chip::EndpointId kOtaProviderEndpoint = 0;

constexpr uint16_t kOptionFilepath = 'f';
constexpr uint16_t kOptionQueryImageBehavior = 'q';
constexpr uint16_t kOptionFilepath = 'f';
constexpr uint16_t kOptionQueryImageBehavior = 'q';
constexpr uint16_t kOptionDelayedActionTimeSec = 'd';
const char * gOtaFilepath = nullptr;
const char * gOtaFilepath = nullptr;

// Arbitrary BDX Transfer Params
constexpr uint32_t kMaxBdxBlockSize = 1024;
Expand All @@ -62,7 +62,7 @@ constexpr uint32_t kBdxPollFreqMs = 500;

// Global variables used for passing the CLI arguments to the OTAProviderExample object
OTAProviderExample::queryImageBehaviorType gQueryImageBehavior = OTAProviderExample::kRespondWithUpdateAvailable;
uint32_t gDelayedActionTimeSec = 0;
uint32_t gDelayedActionTimeSec = 0;

bool HandleOptions(const char * aProgram, OptionSet * aOptions, int aIdentifier, const char * aName, const char * aValue)
{
Expand Down Expand Up @@ -105,8 +105,8 @@ bool HandleOptions(const char * aProgram, OptionSet * aOptions, int aIdentifier,
retval = false;
}
break;
case kOptionDelayedActionTimeSec:
gDelayedActionTimeSec = static_cast<uint32_t>(strtol(aValue, NULL, 0));
case kOptionDelayedActionTimeSec:
gDelayedActionTimeSec = static_cast<uint32_t>(strtol(aValue, NULL, 0));
break;
default:
PrintArgError("%s: INTERNAL ERROR: Unhandled option: %s\n", aProgram, aName);
Expand All @@ -130,7 +130,7 @@ OptionSet cmdLineOptions = { HandleOptions, cmdLineOptionsDef, "PROGRAM OPTIONS"
" -q/--QueryImageBehavior <UpdateAvailable | Busy | UpdateNotAvailable>\n"
" Status value in the Query Image Response\n"
" -d/--DelayedActionTimeSec <time>\n"
" Value in seconds for the DelayedActionTime in the Query Image Response\n"};
" Value in seconds for the DelayedActionTime in the Query Image Response\n" };

HelpOptions helpOptions("ota-provider-app", "Usage: ota-provider-app [options]", "1.0");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ bool GenerateBdxUri(const Span<char> & fileDesignator, Span<char> outUri, size_t
OTAProviderExample::OTAProviderExample()
{
memset(mOTAFilePath, 0, kFilepathBufLen);
mQueryImageBehavior = kRespondWithNotAvailable;
mQueryImageBehavior = kRespondWithNotAvailable;
mDelayedActionTimeSec = 0;
}

Expand All @@ -105,8 +105,8 @@ EmberAfStatus OTAProviderExample::HandleQueryImage(chip::app::CommandHandler * c
// TODO: add confiuration for returning BUSY status

EmberAfOTAQueryStatus queryStatus = EMBER_ZCL_OTA_QUERY_STATUS_NOT_AVAILABLE;
uint32_t softwareVersion = currentVersion + 1; // This implementation will always indicate that an update is available
// (if the user provides a file).
uint32_t softwareVersion = currentVersion + 1; // This implementation will always indicate that an update is available
// (if the user provides a file).
bool userConsentNeeded = false;
uint8_t updateToken[kUpdateTokenLen] = { 0 };
char strBuf[kUpdateTokenStrLen] = { 0 };
Expand All @@ -124,26 +124,30 @@ EmberAfStatus OTAProviderExample::HandleQueryImage(chip::app::CommandHandler * c
}

// Set Status for the Query Image Response
switch(mQueryImageBehavior) {
case kRespondWithUpdateAvailable: {
if(strlen(mOTAFilePath) != 0) {
queryStatus = EMBER_ZCL_OTA_QUERY_STATUS_UPDATE_AVAILABLE;
} else {
queryStatus = EMBER_ZCL_OTA_QUERY_STATUS_NOT_AVAILABLE;
ChipLogError(SoftwareUpdate, "No OTA file configured on the Provider");
}
break;
}
case kRespondWithBusy: {
queryStatus = EMBER_ZCL_OTA_QUERY_STATUS_BUSY;
break;
switch (mQueryImageBehavior)
{
case kRespondWithUpdateAvailable: {
if (strlen(mOTAFilePath) != 0)
{
queryStatus = EMBER_ZCL_OTA_QUERY_STATUS_UPDATE_AVAILABLE;
}
case kRespondWithNotAvailable: {
else
{
queryStatus = EMBER_ZCL_OTA_QUERY_STATUS_NOT_AVAILABLE;
break;
ChipLogError(SoftwareUpdate, "No OTA file configured on the Provider");
}
default:
queryStatus = EMBER_ZCL_OTA_QUERY_STATUS_NOT_AVAILABLE;
break;
}
case kRespondWithBusy: {
queryStatus = EMBER_ZCL_OTA_QUERY_STATUS_BUSY;
break;
}
case kRespondWithNotAvailable: {
queryStatus = EMBER_ZCL_OTA_QUERY_STATUS_NOT_AVAILABLE;
break;
}
default:
queryStatus = EMBER_ZCL_OTA_QUERY_STATUS_NOT_AVAILABLE;
}

CommandPathParams cmdParams = { emberAfCurrentEndpoint(), 0 /* mGroupId */, ZCL_OTA_PROVIDER_CLUSTER_ID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ class OTAProviderExample : public OTAProviderDelegate
uint32_t newVersion) override;
EmberAfStatus HandleNotifyUpdateApplied(const chip::ByteSpan & updateToken, uint32_t currentVersion) override;

enum queryImageBehaviorType {
kRespondWithUpdateAvailable,
kRespondWithBusy,
kRespondWithNotAvailable
enum queryImageBehaviorType
{
kRespondWithUpdateAvailable,
kRespondWithBusy,
kRespondWithNotAvailable
};
void SetQueryImageBehavior(queryImageBehaviorType behavior) {mQueryImageBehavior = behavior;}
void SetDelayedActionTimeSec(uint32_t time) {mDelayedActionTimeSec = time;}
void SetQueryImageBehavior(queryImageBehaviorType behavior) { mQueryImageBehavior = behavior; }
void SetDelayedActionTimeSec(uint32_t time) { mDelayedActionTimeSec = time; }

private:
static constexpr size_t kFilepathBufLen = 256;
char mOTAFilePath[kFilepathBufLen]; // null-terminated
Expand Down

0 comments on commit fe29cab

Please sign in to comment.