diff --git a/examples/chip-tool/commands/clusters/ModelCommand.h b/examples/chip-tool/commands/clusters/ModelCommand.h index 5b7dc2349f1305..c70d35477f80c4 100644 --- a/examples/chip-tool/commands/clusters/ModelCommand.h +++ b/examples/chip-tool/commands/clusters/ModelCommand.h @@ -46,7 +46,7 @@ class ModelCommand : public CHIPCommand /////////// CHIPCommand Interface ///////// CHIP_ERROR RunCommand() override; - uint16_t GetWaitDurationInSeconds() const override { return 10; } + chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(10); } virtual CHIP_ERROR SendCommand(ChipDevice * device, uint8_t endPointId) = 0; diff --git a/examples/chip-tool/commands/common/CHIPCommand.cpp b/examples/chip-tool/commands/common/CHIPCommand.cpp index 37c3b907ef7df6..2f2a7449bccc75 100644 --- a/examples/chip-tool/commands/common/CHIPCommand.cpp +++ b/examples/chip-tool/commands/common/CHIPCommand.cpp @@ -77,7 +77,7 @@ CHIP_ERROR CHIPCommand::Run() ReturnLogErrorOnFailure(DeviceControllerFactory::GetInstance().SetupCommissioner(commissionerParams, mController)); chip::DeviceLayer::PlatformMgr().ScheduleWork(RunQueuedCommand, reinterpret_cast(this)); - ReturnLogErrorOnFailure(StartWaiting(GetWaitDurationInSeconds())); + ReturnLogErrorOnFailure(StartWaiting(GetWaitDuration())); Shutdown(); @@ -108,12 +108,12 @@ static void OnResponseTimeout(chip::System::Layer *, void * appState) } #endif // !CONFIG_USE_SEPARATE_EVENTLOOP -CHIP_ERROR CHIPCommand::StartWaiting(uint16_t seconds) +CHIP_ERROR CHIPCommand::StartWaiting(chip::System::Clock::Timeout duration) { #if CONFIG_USE_SEPARATE_EVENTLOOP // ServiceEvents() calls StartEventLoopTask(), which is paired with the StopEventLoopTask() below. ReturnLogErrorOnFailure(DeviceControllerFactory::GetInstance().ServiceEvents()); - auto waitingUntil = std::chrono::system_clock::now() + std::chrono::seconds(seconds); + auto waitingUntil = std::chrono::system_clock::now() + std::chrono::duration_cast(duration); { std::unique_lock lk(cvWaitingForResponseMutex); if (!cvWaitingForResponse.wait_until(lk, waitingUntil, [this]() { return !this->mWaitingForResponse; })) @@ -123,8 +123,7 @@ CHIP_ERROR CHIPCommand::StartWaiting(uint16_t seconds) } LogErrorOnFailure(chip::DeviceLayer::PlatformMgr().StopEventLoopTask()); #else - ReturnLogErrorOnFailure( - chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(seconds), OnResponseTimeout, this)); + ReturnLogErrorOnFailure(chip::DeviceLayer::SystemLayer().StartTimer(duration, OnResponseTimeout, this)); chip::DeviceLayer::PlatformMgr().RunEventLoop(); #endif // CONFIG_USE_SEPARATE_EVENTLOOP diff --git a/examples/chip-tool/commands/common/CHIPCommand.h b/examples/chip-tool/commands/common/CHIPCommand.h index 8680acb48c5375..eca1a8466e9220 100644 --- a/examples/chip-tool/commands/common/CHIPCommand.h +++ b/examples/chip-tool/commands/common/CHIPCommand.h @@ -57,7 +57,7 @@ class CHIPCommand : public Command virtual CHIP_ERROR RunCommand() = 0; // Get the wait duration, in seconds, before the command times out. - virtual uint16_t GetWaitDurationInSeconds() const = 0; + virtual chip::System::Clock::Timeout GetWaitDuration() const = 0; // Shut down the command, in case any work needs to be done after the event // loop has been stopped. @@ -72,7 +72,7 @@ class CHIPCommand : public Command CHIP_ERROR mCommandExitStatus = CHIP_ERROR_INTERNAL; chip::Controller::ExampleOperationalCredentialsIssuer mOpCredsIssuer; - CHIP_ERROR StartWaiting(uint16_t seconds); + CHIP_ERROR StartWaiting(chip::System::Clock::Timeout seconds); void StopWaiting(); #if CONFIG_USE_SEPARATE_EVENTLOOP diff --git a/examples/chip-tool/commands/discover/DiscoverCommand.h b/examples/chip-tool/commands/discover/DiscoverCommand.h index 778e7ed9afbabf..6e651a5fc94c8a 100644 --- a/examples/chip-tool/commands/discover/DiscoverCommand.h +++ b/examples/chip-tool/commands/discover/DiscoverCommand.h @@ -36,7 +36,7 @@ class DiscoverCommand : public CHIPCommand, public chip::Controller::DeviceAddre /////////// CHIPCommand Interface ///////// CHIP_ERROR RunCommand() override; - uint16_t GetWaitDurationInSeconds() const override { return 30; } + chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(30); } virtual CHIP_ERROR RunCommand(NodeId remoteId, uint64_t fabricId) = 0; diff --git a/examples/chip-tool/commands/discover/DiscoverCommissionablesCommand.h b/examples/chip-tool/commands/discover/DiscoverCommissionablesCommand.h index 1a12e944c703a1..af4f61c21ccfc8 100644 --- a/examples/chip-tool/commands/discover/DiscoverCommissionablesCommand.h +++ b/examples/chip-tool/commands/discover/DiscoverCommissionablesCommand.h @@ -30,5 +30,5 @@ class DiscoverCommissionablesCommand : public CHIPCommand, public chip::Controll /////////// CHIPCommand Interface ///////// CHIP_ERROR RunCommand() override; - uint16_t GetWaitDurationInSeconds() const override { return 30; } + chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(30); } }; diff --git a/examples/chip-tool/commands/discover/DiscoverCommissionersCommand.cpp b/examples/chip-tool/commands/discover/DiscoverCommissionersCommand.cpp index 40b2d2ebad8f56..23e9b474a91dd5 100644 --- a/examples/chip-tool/commands/discover/DiscoverCommissionersCommand.cpp +++ b/examples/chip-tool/commands/discover/DiscoverCommissionersCommand.cpp @@ -41,5 +41,5 @@ void DiscoverCommissionersCommand::Shutdown() } ChipLogProgress(chipTool, "Total of %d commissioner(s) discovered in %" PRIu16 " sec", commissionerCount, - GetWaitDurationInSeconds()); + std::chrono::duration_cast(GetWaitDuration()).count()); } diff --git a/examples/chip-tool/commands/discover/DiscoverCommissionersCommand.h b/examples/chip-tool/commands/discover/DiscoverCommissionersCommand.h index 225fdeac5bb5ac..118ef7ac3a95fa 100644 --- a/examples/chip-tool/commands/discover/DiscoverCommissionersCommand.h +++ b/examples/chip-tool/commands/discover/DiscoverCommissionersCommand.h @@ -28,7 +28,7 @@ class DiscoverCommissionersCommand : public CHIPCommand /////////// CHIPCommand Interface ///////// CHIP_ERROR RunCommand() override; - uint16_t GetWaitDurationInSeconds() const override { return 3; } + chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(3); } void Shutdown() override; private: diff --git a/examples/chip-tool/commands/pairing/PairingCommand.h b/examples/chip-tool/commands/pairing/PairingCommand.h index 6dcfbdb1cfd98a..38eda6840f653e 100644 --- a/examples/chip-tool/commands/pairing/PairingCommand.h +++ b/examples/chip-tool/commands/pairing/PairingCommand.h @@ -149,7 +149,7 @@ class PairingCommand : public CHIPCommand, /////////// CHIPCommand Interface ///////// CHIP_ERROR RunCommand() override; - uint16_t GetWaitDurationInSeconds() const override { return 120; } + chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(120); } void Shutdown() override; /////////// DevicePairingDelegate Interface ///////// diff --git a/examples/chip-tool/commands/reporting/ReportingCommand.h b/examples/chip-tool/commands/reporting/ReportingCommand.h index 763a2054723deb..aba585685f81af 100644 --- a/examples/chip-tool/commands/reporting/ReportingCommand.h +++ b/examples/chip-tool/commands/reporting/ReportingCommand.h @@ -40,7 +40,7 @@ class ReportingCommand : public CHIPCommand /////////// CHIPCommand Interface ///////// CHIP_ERROR RunCommand() override; - uint16_t GetWaitDurationInSeconds() const override { return UINT16_MAX; } + chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(UINT16_MAX); } virtual void AddReportCallbacks(NodeId remoteId, uint8_t endPointId) = 0; diff --git a/examples/chip-tool/commands/tests/TestCommand.cpp b/examples/chip-tool/commands/tests/TestCommand.cpp index c5d7b912b0c4b3..e8d19276ee61d9 100644 --- a/examples/chip-tool/commands/tests/TestCommand.cpp +++ b/examples/chip-tool/commands/tests/TestCommand.cpp @@ -47,9 +47,9 @@ void TestCommand::OnWaitForMsFn(chip::System::Layer * systemLayer, void * contex command->NextTest(); } -CHIP_ERROR TestCommand::WaitForMs(uint32_t ms) +CHIP_ERROR TestCommand::Wait(chip::System::Clock::Timeout duration) { - return chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Milliseconds32(ms), OnWaitForMsFn, this); + return chip::DeviceLayer::SystemLayer().StartTimer(duration, OnWaitForMsFn, this); } CHIP_ERROR TestCommand::Log(const char * message) diff --git a/examples/chip-tool/commands/tests/TestCommand.h b/examples/chip-tool/commands/tests/TestCommand.h index bb5d2b82cb7632..80054e2b9feb0e 100644 --- a/examples/chip-tool/commands/tests/TestCommand.h +++ b/examples/chip-tool/commands/tests/TestCommand.h @@ -38,12 +38,13 @@ class TestCommand : public CHIPCommand /////////// CHIPCommand Interface ///////// CHIP_ERROR RunCommand() override; - uint16_t GetWaitDurationInSeconds() const override { return 30; } + chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(30); } virtual void NextTest() = 0; /////////// GlobalCommands Interface ///////// - CHIP_ERROR WaitForMs(uint32_t ms); + CHIP_ERROR Wait(chip::System::Clock::Timeout ms); + CHIP_ERROR WaitForMs(uint16_t ms) { return Wait(chip::System::Clock::Milliseconds32(ms)); } CHIP_ERROR Log(const char * message); protected: