From d8631191332a6c1f0558caea925a7f6d4e56d6fe Mon Sep 17 00:00:00 2001 From: MATSUOKA Takashi Date: Fri, 31 Jan 2025 11:36:08 +0900 Subject: [PATCH] Add commandTimeoutMin and commandEchoTimeout at Bg770a --- src/module/bg770a/Bg770a.hpp | 31 +++++++++++++------ .../bg770a/commands/Bg770aTcpipCommands.hpp | 7 ++--- .../bg770a/commands/Bg770aTcpipCommands2.hpp | 5 +-- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/module/bg770a/Bg770a.hpp b/src/module/bg770a/Bg770a.hpp index 0c8730d..5e72975 100644 --- a/src/module/bg770a/Bg770a.hpp +++ b/src/module/bg770a/Bg770a.hpp @@ -46,13 +46,22 @@ namespace wiocellular { friend class at_client::AtClient>; - private: - static constexpr int COMMAND_ECHO_TIMEOUT = 60000; - private: INTERFACE &Interface_; public: + /** + * @~Japanese + * @brief ATコマンドのタイムアウト時間下限[ミリ秒] + */ + int commandTimeoutMin; + + /** + * @~Japanese + * @brief ATコマンドのエコー待ちタイムアウト時間[ミリ秒] + */ + int commandEchoTimeout; + /** * @~Japanese * @brief コンストラクタ @@ -63,7 +72,9 @@ namespace wiocellular * interfaceにインターフェースのインスタンスを指定します。 */ explicit Bg770a(INTERFACE &interface) : at_client::AtClient>{}, - Interface_{interface} + Interface_{interface}, + commandTimeoutMin{10000}, + commandEchoTimeout{60000} { at_client::AtClient>::registerUrcHandler([](const std::string &response) -> bool { @@ -99,7 +110,7 @@ namespace wiocellular { printf("CMD> %s\n", command.c_str()); const auto start = millis(); - if (!at_client::AtClient>::writeAndWaitCommand(command, COMMAND_ECHO_TIMEOUT)) + if (!at_client::AtClient>::writeAndWaitCommand(command, std::max(commandEchoTimeout, commandTimeoutMin))) { return WioCellularResult::WaitCommandTimeout; } @@ -108,7 +119,7 @@ namespace wiocellular std::string response; while (true) { - if ((response = at_client::AtClient>::readResponse(timeout)).empty()) + if ((response = at_client::AtClient>::readResponse(std::max(timeout, commandTimeoutMin))).empty()) { return WioCellularResult::ReadResponseTimeout; } @@ -149,7 +160,7 @@ namespace wiocellular { printf("CMD> %s\n", command.c_str()); const auto start = millis(); - if (!at_client::AtClient>::writeAndWaitCommand(command, COMMAND_ECHO_TIMEOUT)) + if (!at_client::AtClient>::writeAndWaitCommand(command, std::max(commandEchoTimeout, commandTimeoutMin))) { return WioCellularResult::WaitCommandTimeout; } @@ -158,7 +169,7 @@ namespace wiocellular std::string response; while (true) { - if ((response = at_client::AtClient>::readResponse(timeout)).empty()) + if ((response = at_client::AtClient>::readResponse(std::max(timeout, commandTimeoutMin))).empty()) { return WioCellularResult::ReadResponseTimeout; } @@ -206,7 +217,7 @@ namespace wiocellular { printf("CMD> %s\n", command.c_str()); const auto start = millis(); - if (!at_client::AtClient>::writeAndWaitCommand(command, COMMAND_ECHO_TIMEOUT)) + if (!at_client::AtClient>::writeAndWaitCommand(command, std::max(commandEchoTimeout, commandTimeoutMin))) { return WioCellularResult::WaitCommandTimeout; } @@ -215,7 +226,7 @@ namespace wiocellular std::string response; while (true) { - if ((response = at_client::AtClient>::readResponse(timeout)).empty()) + if ((response = at_client::AtClient>::readResponse(std::max(timeout, commandTimeoutMin))).empty()) { return WioCellularResult::ReadResponseTimeout; } diff --git a/src/module/bg770a/commands/Bg770aTcpipCommands.hpp b/src/module/bg770a/commands/Bg770aTcpipCommands.hpp index a927ea9..e340fe4 100644 --- a/src/module/bg770a/commands/Bg770aTcpipCommands.hpp +++ b/src/module/bg770a/commands/Bg770aTcpipCommands.hpp @@ -35,9 +35,6 @@ namespace wiocellular template class Bg770aTcpipCommands { - private: - static constexpr int COMMAND_ECHO_TIMEOUT = 10000; - private: bool UrcSocketReceiveAttached_; std::map UrcSocketReceiveNofity_; @@ -257,7 +254,7 @@ namespace wiocellular if (response == "> ") { static_cast(*this).writeBinary(data, dataSize); - static_cast(*this).readBinaryDiscard(dataSize, COMMAND_ECHO_TIMEOUT); + static_cast(*this).readBinaryDiscard(dataSize, static_cast(*this).commandEchoTimeout); return true; } return false; }, @@ -359,7 +356,7 @@ namespace wiocellular assert(actualDataSize <= dataSize); if (actualDataSize >= 1) { - if (!static_cast(*this).readBinary(data, actualDataSize, 120000)) + if (!static_cast(*this).readBinary(data, actualDataSize, 120000)) // TODO WIP { return false; } diff --git a/src/module/bg770a/commands/Bg770aTcpipCommands2.hpp b/src/module/bg770a/commands/Bg770aTcpipCommands2.hpp index 58abe4e..6c703a6 100644 --- a/src/module/bg770a/commands/Bg770aTcpipCommands2.hpp +++ b/src/module/bg770a/commands/Bg770aTcpipCommands2.hpp @@ -33,9 +33,6 @@ namespace wiocellular template class Bg770aTcpipCommands2 { - private: - static constexpr int COMMAND_ECHO_TIMEOUT = 10000; - public: /** * @~Japanese @@ -302,7 +299,7 @@ namespace wiocellular assert(actualDataSize <= dataSize); if (actualDataSize >= 1) { - if (!static_cast(*this).readBinary(data, actualDataSize, 120000)) + if (!static_cast(*this).readBinary(data, actualDataSize, 120000)) // TODO WIP { return false; }