From 1649588d820a7a5822928df5de05f6f267312549 Mon Sep 17 00:00:00 2001 From: jrhees-cae <61466710+jrhees-cae@users.noreply.github.com> Date: Thu, 20 Jul 2023 16:58:05 -0600 Subject: [PATCH] [TIMESYNC] Add "time-zone" and "dst-offset" arguments to chip-tool pairing commands (#28132) * Add "time-zone" and "dst-offset" arguments to chip-tool pairing commands. * Restyled by clang-format --------- Co-authored-by: Restyled.io --- .../chip-tool/commands/common/Command.cpp | 14 +++++++---- examples/chip-tool/commands/common/Command.h | 5 +++- .../commands/pairing/PairingCommand.cpp | 16 +++++++++++++ .../commands/pairing/PairingCommand.h | 23 +++++++++++++++++-- 4 files changed, 51 insertions(+), 7 deletions(-) diff --git a/examples/chip-tool/commands/common/Command.cpp b/examples/chip-tool/commands/common/Command.cpp index 1c054c1b530e25..4848fe3e1e7183 100644 --- a/examples/chip-tool/commands/common/Command.cpp +++ b/examples/chip-tool/commands/common/Command.cpp @@ -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 class. + // Instead, they must be explicitly specified as optional using the kOptional flag, + // and the base TypedComplexArgument class is still referenced. auto complexArgument = static_cast(arg.value); return CHIP_NO_ERROR == complexArgument->Parse(arg.name, argValue); } @@ -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(value); - arg.flags = 0; + arg.flags = flags; arg.desc = desc; return AddArgumentToList(std::move(arg)); @@ -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 class. + // Instead, they must be explicitly specified as optional using the kOptional flag, + // and the base TypedComplexArgument class is referenced. + auto argument = static_cast(arg.value); + argument->Reset(); break; } case ArgumentType::Custom: { diff --git a/examples/chip-tool/commands/common/Command.h b/examples/chip-tool/commands/common/Command.h index 06bf5ef6f3dc8b..cf8077b13c0546 100644 --- a/examples/chip-tool/commands/common/Command.h +++ b/examples/chip-tool/commands/common/Command.h @@ -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 * 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 class. + // Instead, they must be explicitly specified as optional using kOptional in the flags parameter, + // and the base TypedComplexArgument 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) { diff --git a/examples/chip-tool/commands/pairing/PairingCommand.cpp b/examples/chip-tool/commands/pairing/PairingCommand.cpp index 76dbbcb721cad0..ed0b06f7c4363a 100644 --- a/examples/chip-tool/commands/pairing/PairingCommand.cpp +++ b/examples/chip-tool/commands/pairing/PairingCommand.cpp @@ -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 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 class, + // we will use mTimeZoneList.data() value to determine if the argument was provided. + if (mDSTOffsetList.data()) + { + params.SetDSTOffsets(mDSTOffsetList); + } + return params; } diff --git a/examples/chip-tool/commands/pairing/PairingCommand.h b/examples/chip-tool/commands/pairing/PairingCommand.h index 0e3dd8024d09cb..40de54e083d2a0 100644 --- a/examples/chip-tool/commands/pairing/PairingCommand.h +++ b/examples/chip-tool/commands/pairing/PairingCommand.h @@ -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, @@ -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 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 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); @@ -210,6 +223,12 @@ class PairingCommand : public CHIPCommand, chip::Optional mBypassAttestationVerifier; chip::Optional> mCASEAuthTags; chip::Optional mCountryCode; + chip::app::DataModel::List mTimeZoneList; + TypedComplexArgument> + mComplex_TimeZones; + chip::app::DataModel::List mDSTOffsetList; + TypedComplexArgument> + mComplex_DSTOffsets; uint16_t mRemotePort; uint16_t mDiscriminator; uint32_t mSetupPINCode;