Skip to content

Commit

Permalink
Change AT+QISEND to AT+QISENDEX
Browse files Browse the repository at this point in the history
  • Loading branch information
matsujirushi committed Jan 29, 2025
1 parent 6dce997 commit e0fb3da
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 24 deletions.
19 changes: 11 additions & 8 deletions src/client/WioCellularTcpClient2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,16 +319,19 @@ namespace wiocellular::client
*/
bool send(const void *data, size_t dataSize)
{
if (getState() != State::Connected)
for (size_t offset = 0; offset < dataSize; offset += Module_.SEND_SOCKET_SIZE_MAX)
{
LastResult_ = WioCellularResult::InvalidOperation;
return false;
}
if (getState() != State::Connected)
{
LastResult_ = WioCellularResult::InvalidOperation;
return false;
}

if (const auto result = Module_.sendSocket2(ConnectId_, data, dataSize); result != WioCellularResult::Ok)
{
LastResult_ = result;
return false;
if (const auto result = Module_.sendSocket2(ConnectId_, static_cast<const uint8_t *>(data) + offset, std::min(dataSize - offset, Module_.SEND_SOCKET_SIZE_MAX)); result != WioCellularResult::Ok)
{
LastResult_ = result;
return false;
}
}

LastResult_ = WioCellularResult::Ok;
Expand Down
4 changes: 1 addition & 3 deletions src/module/bg770a/Bg770a.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,7 @@ namespace wiocellular
std::string response;
while (true)
{
if ((response = at_client::AtClient<Bg770a<INTERFACE>>::readResponse(timeout, [](const std::string &response) -> bool
{ return response == "> "; }))
.empty())
if ((response = at_client::AtClient<Bg770a<INTERFACE>>::readResponse(timeout)).empty())
{
return WioCellularResult::ReadResponseTimeout;
}
Expand Down
35 changes: 22 additions & 13 deletions src/module/bg770a/commands/Bg770aTcpipCommands2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#ifndef BG770ATCPIPCOMMANDS2_HPP
#define BG770ATCPIPCOMMANDS2_HPP

#include <memory>
#include <vector>
#include "module/at_client/AtParameterParser.hpp"
#include "internal/Misc.hpp"
Expand Down Expand Up @@ -42,6 +43,12 @@ namespace wiocellular
*/
static constexpr size_t RECEIVE_SOCKET_SIZE_MAX = 1500;

/**
* @~Japanese
* @brief ソケットへ送信する最大バイト数
*/
static constexpr size_t SEND_SOCKET_SIZE_MAX = 512;

public:
/**
* @~Japanese
Expand Down Expand Up @@ -223,13 +230,13 @@ namespace wiocellular
*
* @param [in] connectId 接続ID。
* @param [in] data データ。nullptrを指定すると送信しません。
* @param [in] dataSize データサイズ。0を指定すると送信しません。
* @param [in] dataSize データサイズ。0を指定すると送信しません。最大サイズは512です。
* @return 実行結果。
*
* ソケットへ送信します。
*
* > BG770A-GL&BG95xA-GL TCP/IP Application Note @n
* > 2.3.8. AT+QISEND Send Data
* > 2.3.12. AT+QISENDEX Send Hex String Data
*/
WioCellularResult sendSocket2(int connectId, const void *data, size_t dataSize)
{
Expand All @@ -239,18 +246,20 @@ namespace wiocellular
{
return WioCellularResult::Ok;
}
if (dataSize > SEND_SOCKET_SIZE_MAX)
{
return WioCellularResult::ArgumentOutOfRange;
}

return static_cast<MODULE &>(*this).sendCommand(
internal::stringFormat("AT+QISEND=%d,%d", connectId, dataSize), [this, data, dataSize](const std::string &response) -> bool
{
if (response == "> ")
{
static_cast<MODULE &>(*this).writeBinary(data, dataSize);
static_cast<MODULE &>(*this).readBinaryDiscard(dataSize, COMMAND_ECHO_TIMEOUT);
return true;
}
return false; },
120000);
std::unique_ptr<char[]> dataHex = std::make_unique<char[]>(dataSize * 2 + 1);
for (size_t i = 0; i < dataSize; ++i)
{
dataHex[i * 2 + 0] = "0123456789ABCDEF"[static_cast<const uint8_t *>(data)[i] >> 4];
dataHex[i * 2 + 1] = "0123456789ABCDEF"[static_cast<const uint8_t *>(data)[i] & 0x0f];
}
dataHex[dataSize * 2] = '\0';

return static_cast<MODULE &>(*this).sendCommand(internal::stringFormat("AT+QISENDEX=%d,\"%s\"", connectId, dataHex.get()), nullptr, 120000);
}

/**
Expand Down

0 comments on commit e0fb3da

Please sign in to comment.