Skip to content

Commit

Permalink
ota-provider-app: Adding SoftwareVersionString option to cli (#14880)
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhamdp authored and pull[bot] committed Jul 25, 2023
1 parent 4f6f1b4 commit 872e4ec
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
28 changes: 28 additions & 0 deletions examples/ota-provider-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ constexpr uint16_t kOptionUserConsentState = 'u';
constexpr uint16_t kOptionDelayedActionTimeSec = 't';
constexpr uint16_t kOptionDiscriminator = 'd';
constexpr uint16_t kOptionSoftwareVersion = 's';
constexpr uint16_t kOptionSoftwareVersionStr = 'S';
constexpr uint16_t kOptionUserConsentNeeded = 'c';

static constexpr uint16_t kMaximumDiscriminatorValue = 0xFFF;
Expand All @@ -70,6 +71,7 @@ static chip::ota::UserConsentState gUserConsentState = chip::ot
static bool gUserConsentNeeded = false;
static chip::Optional<uint16_t> gSetupDiscriminator;
static chip::Optional<uint32_t> gSoftwareVersion;
static const char * gSoftwareVersionString = nullptr;

// Parses the JSON filepath and extracts DeviceSoftwareVersionModel parameters
static bool ParseJsonFileAndPopulateCandidates(const char * filepath,
Expand Down Expand Up @@ -233,6 +235,22 @@ bool HandleOptions(const char * aProgram, OptionSet * aOptions, int aIdentifier,
case kOptionUserConsentNeeded:
gUserConsentNeeded = true;
break;
case kOptionSoftwareVersionStr:
if (aValue == NULL)
{
PrintArgError("%s: ERROR: NULL SoftwareVersionStr parameter\n", aProgram);
retval = false;
}
else if ((strlen(aValue) < 1 || strlen(aValue) > 64))
{
PrintArgError("%s: ERROR: SoftwareVersionStr parameter length is out of range \n", aProgram);
retval = false;
}
else
{
gSoftwareVersionString = aValue;
}
break;
default:
PrintArgError("%s: INTERNAL ERROR: Unhandled option: %s\n", aProgram, aName);
retval = false;
Expand All @@ -250,6 +268,7 @@ OptionDef cmdLineOptionsDef[] = {
{ "UserConsentState", chip::ArgParser::kArgumentRequired, kOptionUserConsentState },
{ "discriminator", chip::ArgParser::kArgumentRequired, kOptionDiscriminator },
{ "softwareVersion", chip::ArgParser::kArgumentRequired, kOptionSoftwareVersion },
{ "softwareVersionStr", chip::ArgParser::kArgumentRequired, kOptionSoftwareVersionStr },
{ "UserConsentNeeded", chip::ArgParser::kNoArgument, kOptionUserConsentNeeded },
{},
};
Expand Down Expand Up @@ -277,6 +296,11 @@ OptionSet cmdLineOptions = { HandleOptions, cmdLineOptionsDef, "PROGRAM OPTIONS"
" If ota image list is present along with this option\n"
" then value from ota image list is used.\n"
" Otherwise, this value will be used is then value from that will be used\n"
" -S/--softwareVersionStr <version string>\n"
" Value of SoftwareVersionString in the Query Image Response\n"
" If ota image list is present along with this option\n"
" then value from ota image list is used.\n"
" Otherwise, this value will be used is then value from that will be used\n"
" -c/--UserConsentNeeded\n"
" If provided, value of UserConsentNeeded in the Query Image Response is set to true\n" };

Expand Down Expand Up @@ -349,6 +373,10 @@ int main(int argc, char * argv[])
{
otaProvider.SetSoftwareVersion(gSoftwareVersion.Value());
}
if (gSoftwareVersionString)
{
otaProvider.SetSoftwareVersionString(gSoftwareVersionString);
}

if (gUserConsentState != chip::ota::UserConsentState::kUnknown)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,16 @@ EmberAfStatus OTAProviderExample::HandleQueryImage(chip::app::CommandHandler * c
newSoftwareVersion = mSoftwareVersion.Value();
}

// If software version string is provided using command line then use it.
// Otherwise, use default string.
newSoftwareVersionString = "Example-Image-V0.1";
otaFilePath = mOTAFilePath;
queryStatus = OTAQueryStatus::kUpdateAvailable;
if (mSoftwareVersionString)
{
newSoftwareVersionString = mSoftwareVersionString;
}

otaFilePath = mOTAFilePath;
queryStatus = OTAQueryStatus::kUpdateAvailable;
}
else if (!mCandidates.empty()) // If list of OTA candidates is supplied instead
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class OTAProviderExample : public chip::app::Clusters::OTAProviderDelegate
void SetDelayedActionTimeSec(uint32_t time) { mDelayedActionTimeSec = time; }
void SetUserConsentDelegate(chip::ota::UserConsentDelegate * delegate) { mUserConsentDelegate = delegate; }
void SetSoftwareVersion(uint32_t softwareVersion) { mSoftwareVersion.SetValue(softwareVersion); }
void SetSoftwareVersionString(const char * versionString) { mSoftwareVersionString = versionString; }
void SetUserConsentNeeded(bool needed) { mUserConsentNeeded = needed; }

private:
Expand All @@ -91,5 +92,6 @@ class OTAProviderExample : public chip::app::Clusters::OTAProviderDelegate
const chip::app::Clusters::OtaSoftwareUpdateProvider::Commands::QueryImage::DecodableType & commandData,
uint32_t targetVersion);
chip::Optional<uint32_t> mSoftwareVersion;
bool mUserConsentNeeded = false;
const char * mSoftwareVersionString = nullptr;
bool mUserConsentNeeded = false;
};

0 comments on commit 872e4ec

Please sign in to comment.