Skip to content

Commit

Permalink
[TIMESYNC] Add "time-zone" and "dst-offset" arguments to chip-tool pa…
Browse files Browse the repository at this point in the history
…iring commands (#28132)

* Add "time-zone" and "dst-offset" arguments to chip-tool pairing commands.

* Restyled by clang-format

---------

Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
2 people authored and pull[bot] committed Oct 10, 2023
1 parent 137ffbf commit 1649588
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 7 deletions.
14 changes: 10 additions & 4 deletions examples/chip-tool/commands/common/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ bool Command::InitArgument(size_t argIndex, char * argValue)
switch (arg.type)
{
case ArgumentType::Complex: {
// Complex arguments may be optional, but they are not currently supported via the <chip::Optional> class.
// Instead, they must be explicitly specified as optional using the kOptional flag,
// and the base TypedComplexArgument<T> class is still referenced.
auto complexArgument = static_cast<ComplexArgument *>(arg.value);
return CHIP_NO_ERROR == complexArgument->Parse(arg.name, argValue);
}
Expand Down Expand Up @@ -731,13 +734,13 @@ size_t Command::AddArgument(const char * name, int64_t min, uint64_t max, chip::
return AddArgumentToList(std::move(arg));
}

size_t Command::AddArgument(const char * name, ComplexArgument * value, const char * desc)
size_t Command::AddArgument(const char * name, ComplexArgument * value, const char * desc, uint8_t flags)
{
Argument arg;
arg.type = ArgumentType::Complex;
arg.name = name;
arg.value = static_cast<void *>(value);
arg.flags = 0;
arg.flags = flags;
arg.desc = desc;

return AddArgumentToList(std::move(arg));
Expand Down Expand Up @@ -955,8 +958,11 @@ void Command::ResetArguments()
switch (type)
{
case ArgumentType::Complex: {
// No optional complex arguments so far.
VerifyOrDie(false);
// Optional Complex arguments are not currently supported via the <chip::Optional> class.
// Instead, they must be explicitly specified as optional using the kOptional flag,
// and the base TypedComplexArgument<T> class is referenced.
auto argument = static_cast<ComplexArgument *>(arg.value);
argument->Reset();
break;
}
case ArgumentType::Custom: {
Expand Down
5 changes: 4 additions & 1 deletion examples/chip-tool/commands/common/Command.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ class Command
size_t AddArgument(const char * name, chip::ByteSpan * value, const char * desc = "", uint8_t flags = 0);
size_t AddArgument(const char * name, chip::Span<const char> * value, const char * desc = "", uint8_t flags = 0);
size_t AddArgument(const char * name, AddressWithInterface * out, const char * desc = "", uint8_t flags = 0);
size_t AddArgument(const char * name, ComplexArgument * value, const char * desc = "");
// Optional Complex arguments are not currently supported via the <chip::Optional> class.
// Instead, they must be explicitly specified as optional using kOptional in the flags parameter,
// and the base TypedComplexArgument<T> class is referenced.
size_t AddArgument(const char * name, ComplexArgument * value, const char * desc = "", uint8_t flags = 0);
size_t AddArgument(const char * name, CustomArgument * value, const char * desc = "");
size_t AddArgument(const char * name, int64_t min, uint64_t max, bool * out, const char * desc = "", uint8_t flags = 0)
{
Expand Down
16 changes: 16 additions & 0 deletions examples/chip-tool/commands/pairing/PairingCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,22 @@ CommissioningParameters PairingCommand::GetCommissioningParameters()
params.SetCountryCode(CharSpan::fromCharString(mCountryCode.Value()));
}

// mTimeZoneList is an optional argument managed by TypedComplexArgument mComplex_TimeZones.
// Since optional Complex arguments are not currently supported via the <chip::Optional> class,
// we will use mTimeZoneList.data() value to determine if the argument was provided.
if (mTimeZoneList.data())
{
params.SetTimeZone(mTimeZoneList);
}

// miDSTOffsetList is an optional argument managed by TypedComplexArgument mComplex_DSTOffsets.
// Since optional Complex arguments are not currently supported via the <chip::Optional> class,
// we will use mTimeZoneList.data() value to determine if the argument was provided.
if (mDSTOffsetList.data())
{
params.SetDSTOffsets(mDSTOffsetList);
}

return params;
}

Expand Down
23 changes: 21 additions & 2 deletions examples/chip-tool/commands/pairing/PairingCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class PairingCommand : public CHIPCommand,
chip::Dnssd::DiscoveryFilterType filterType = chip::Dnssd::DiscoveryFilterType::kNone) :
CHIPCommand(commandName, credIssuerCmds),
mPairingMode(mode), mNetworkType(networkType),
mFilterType(filterType), mRemoteAddr{ IPAddress::Any, chip::Inet::InterfaceId::Null() },
mCurrentFabricRemoveCallback(OnCurrentFabricRemove, this)
mFilterType(filterType), mRemoteAddr{ IPAddress::Any, chip::Inet::InterfaceId::Null() }, mComplex_TimeZones(&mTimeZoneList),
mComplex_DSTOffsets(&mDSTOffsetList), mCurrentFabricRemoveCallback(OnCurrentFabricRemove, this)
{
AddArgument("node-id", 0, UINT64_MAX, &mNodeId);
AddArgument("bypass-attestation-verifier", 0, 1, &mBypassAttestationVerifier,
Expand Down Expand Up @@ -162,6 +162,19 @@ class PairingCommand : public CHIPCommand,
{
AddArgument("country-code", &mCountryCode,
"Country code to use to set the Basic Information cluster's Location attribute");

// mTimeZoneList is an optional argument managed by TypedComplexArgument mComplex_TimeZones.
// Since optional Complex arguments are not currently supported via the <chip::Optional> class,
// we explicitly set the kOptional flag.
AddArgument("time-zone", &mComplex_TimeZones,
"TimeZone list to use when setting Time Synchronization cluster's TimeZone attribute", Argument::kOptional);

// mDSTOffsetList is an optional argument managed by TypedComplexArgument mComplex_DSTOffsets.
// Since optional Complex arguments are not currently supported via the <chip::Optional> class,
// we explicitly set the kOptional flag.
AddArgument("dst-offset", &mComplex_DSTOffsets,
"DSTOffset list to use when setting Time Synchronization cluster's DSTOffset attribute",
Argument::kOptional);
}

AddArgument("timeout", 0, UINT16_MAX, &mTimeout);
Expand Down Expand Up @@ -210,6 +223,12 @@ class PairingCommand : public CHIPCommand,
chip::Optional<bool> mBypassAttestationVerifier;
chip::Optional<std::vector<uint32_t>> mCASEAuthTags;
chip::Optional<char *> mCountryCode;
chip::app::DataModel::List<chip::app::Clusters::TimeSynchronization::Structs::TimeZoneStruct::Type> mTimeZoneList;
TypedComplexArgument<chip::app::DataModel::List<chip::app::Clusters::TimeSynchronization::Structs::TimeZoneStruct::Type>>
mComplex_TimeZones;
chip::app::DataModel::List<chip::app::Clusters::TimeSynchronization::Structs::DSTOffsetStruct::Type> mDSTOffsetList;
TypedComplexArgument<chip::app::DataModel::List<chip::app::Clusters::TimeSynchronization::Structs::DSTOffsetStruct::Type>>
mComplex_DSTOffsets;
uint16_t mRemotePort;
uint16_t mDiscriminator;
uint32_t mSetupPINCode;
Expand Down

0 comments on commit 1649588

Please sign in to comment.