Skip to content

Commit

Permalink
Add commandTimeoutMin and commandEchoTimeout at Bg770a
Browse files Browse the repository at this point in the history
  • Loading branch information
matsujirushi committed Jan 31, 2025
1 parent 4811a20 commit d863119
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
31 changes: 21 additions & 10 deletions src/module/bg770a/Bg770a.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,22 @@ namespace wiocellular
{
friend class at_client::AtClient<Bg770a<INTERFACE>>;

private:
static constexpr int COMMAND_ECHO_TIMEOUT = 60000;

private:
INTERFACE &Interface_;

public:
/**
* @~Japanese
* @brief ATコマンドのタイムアウト時間下限[ミリ秒]
*/
int commandTimeoutMin;

/**
* @~Japanese
* @brief ATコマンドのエコー待ちタイムアウト時間[ミリ秒]
*/
int commandEchoTimeout;

/**
* @~Japanese
* @brief コンストラクタ
Expand All @@ -63,7 +72,9 @@ namespace wiocellular
* interfaceにインターフェースのインスタンスを指定します。
*/
explicit Bg770a(INTERFACE &interface) : at_client::AtClient<Bg770a<INTERFACE>>{},
Interface_{interface}
Interface_{interface},
commandTimeoutMin{10000},
commandEchoTimeout{60000}
{
at_client::AtClient<Bg770a<INTERFACE>>::registerUrcHandler([](const std::string &response) -> bool
{
Expand Down Expand Up @@ -99,7 +110,7 @@ namespace wiocellular
{
printf("CMD> %s\n", command.c_str());
const auto start = millis();
if (!at_client::AtClient<Bg770a<INTERFACE>>::writeAndWaitCommand(command, COMMAND_ECHO_TIMEOUT))
if (!at_client::AtClient<Bg770a<INTERFACE>>::writeAndWaitCommand(command, std::max(commandEchoTimeout, commandTimeoutMin)))
{
return WioCellularResult::WaitCommandTimeout;
}
Expand All @@ -108,7 +119,7 @@ namespace wiocellular
std::string response;
while (true)
{
if ((response = at_client::AtClient<Bg770a<INTERFACE>>::readResponse(timeout)).empty())
if ((response = at_client::AtClient<Bg770a<INTERFACE>>::readResponse(std::max(timeout, commandTimeoutMin))).empty())
{
return WioCellularResult::ReadResponseTimeout;
}
Expand Down Expand Up @@ -149,7 +160,7 @@ namespace wiocellular
{
printf("CMD> %s\n", command.c_str());
const auto start = millis();
if (!at_client::AtClient<Bg770a<INTERFACE>>::writeAndWaitCommand(command, COMMAND_ECHO_TIMEOUT))
if (!at_client::AtClient<Bg770a<INTERFACE>>::writeAndWaitCommand(command, std::max(commandEchoTimeout, commandTimeoutMin)))
{
return WioCellularResult::WaitCommandTimeout;
}
Expand All @@ -158,7 +169,7 @@ namespace wiocellular
std::string response;
while (true)
{
if ((response = at_client::AtClient<Bg770a<INTERFACE>>::readResponse(timeout)).empty())
if ((response = at_client::AtClient<Bg770a<INTERFACE>>::readResponse(std::max(timeout, commandTimeoutMin))).empty())
{
return WioCellularResult::ReadResponseTimeout;
}
Expand Down Expand Up @@ -206,7 +217,7 @@ namespace wiocellular
{
printf("CMD> %s\n", command.c_str());
const auto start = millis();
if (!at_client::AtClient<Bg770a<INTERFACE>>::writeAndWaitCommand(command, COMMAND_ECHO_TIMEOUT))
if (!at_client::AtClient<Bg770a<INTERFACE>>::writeAndWaitCommand(command, std::max(commandEchoTimeout, commandTimeoutMin)))
{
return WioCellularResult::WaitCommandTimeout;
}
Expand All @@ -215,7 +226,7 @@ namespace wiocellular
std::string response;
while (true)
{
if ((response = at_client::AtClient<Bg770a<INTERFACE>>::readResponse(timeout)).empty())
if ((response = at_client::AtClient<Bg770a<INTERFACE>>::readResponse(std::max(timeout, commandTimeoutMin))).empty())
{
return WioCellularResult::ReadResponseTimeout;
}
Expand Down
7 changes: 2 additions & 5 deletions src/module/bg770a/commands/Bg770aTcpipCommands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ namespace wiocellular
template <typename MODULE>
class Bg770aTcpipCommands
{
private:
static constexpr int COMMAND_ECHO_TIMEOUT = 10000;

private:
bool UrcSocketReceiveAttached_;
std::map<int, bool> UrcSocketReceiveNofity_;
Expand Down Expand Up @@ -257,7 +254,7 @@ namespace wiocellular
if (response == "> ")
{
static_cast<MODULE &>(*this).writeBinary(data, dataSize);
static_cast<MODULE &>(*this).readBinaryDiscard(dataSize, COMMAND_ECHO_TIMEOUT);
static_cast<MODULE &>(*this).readBinaryDiscard(dataSize, static_cast<MODULE &>(*this).commandEchoTimeout);
return true;
}
return false; },
Expand Down Expand Up @@ -359,7 +356,7 @@ namespace wiocellular
assert(actualDataSize <= dataSize);
if (actualDataSize >= 1)
{
if (!static_cast<MODULE &>(*this).readBinary(data, actualDataSize, 120000))
if (!static_cast<MODULE &>(*this).readBinary(data, actualDataSize, 120000)) // TODO WIP
{
return false;
}
Expand Down
5 changes: 1 addition & 4 deletions src/module/bg770a/commands/Bg770aTcpipCommands2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ namespace wiocellular
template <typename MODULE>
class Bg770aTcpipCommands2
{
private:
static constexpr int COMMAND_ECHO_TIMEOUT = 10000;

public:
/**
* @~Japanese
Expand Down Expand Up @@ -302,7 +299,7 @@ namespace wiocellular
assert(actualDataSize <= dataSize);
if (actualDataSize >= 1)
{
if (!static_cast<MODULE &>(*this).readBinary(data, actualDataSize, 120000))
if (!static_cast<MODULE &>(*this).readBinary(data, actualDataSize, 120000)) // TODO WIP
{
return false;
}
Expand Down

0 comments on commit d863119

Please sign in to comment.