forked from espressif/esp-protocols
Reduce heap allocations by getting rid of temporary std::list and std::string
This commit is contained in:
1 parent
09e68cc0c0
commit
37cac66e7e
8 files changed
+35
-33
No files matched your search
@@ -31,9 +31,9 @@ namespace dce_commands {
|
||||
* @param fail_phrase String to be present in the reply to fail this command
|
||||
* @param timeout_ms Timeout in ms
|
||||
*/
|
||||
command_result generic_command(CommandableIf *t, const std::string &command,
|
||||
const std::string &pass_phrase,
|
||||
const std::string &fail_phrase, uint32_t timeout_ms);
|
||||
command_result generic_command(CommandableIf *t, std::string_view command,
|
||||
std::string_view pass_phrase,
|
||||
std::string_view fail_phrase, uint32_t timeout_ms);
|
||||
|
||||
/**
|
||||
* @brief Declaration of all commands is generated from esp_modem_command_declare.inc
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string_view>
|
||||
#include <span>
|
||||
|
||||
namespace esp_modem::dce_commands {
|
||||
|
||||
/**
|
||||
@@ -17,9 +20,9 @@ namespace esp_modem::dce_commands {
|
||||
* @param timeout_ms Command timeout in ms
|
||||
* @return Generic command return type (OK, FAIL, TIMEOUT)
|
||||
*/
|
||||
command_result generic_command(CommandableIf *t, const std::string &command,
|
||||
const std::string &pass_phrase,
|
||||
const std::string &fail_phrase, uint32_t timeout_ms);
|
||||
command_result generic_command(CommandableIf *t, std::string_view command,
|
||||
std::string_view pass_phrase,
|
||||
std::string_view fail_phrase, uint32_t timeout_ms);
|
||||
|
||||
/**
|
||||
* @brief Utility command to send command and return reply (after DCE says OK)
|
||||
@@ -29,7 +32,7 @@ command_result generic_command(CommandableIf *t, const std::string &command,
|
||||
* @param timeout_ms Command timeout in ms
|
||||
* @return Generic command return type (OK, FAIL, TIMEOUT)
|
||||
*/
|
||||
template <typename T> command_result generic_get_string(CommandableIf *t, const std::string &command, T &output, uint32_t timeout_ms = 500);
|
||||
template <typename T> command_result generic_get_string(CommandableIf *t, std::string_view command, T &output, uint32_t timeout_ms = 500);
|
||||
|
||||
/**
|
||||
* @brief Generic command that passes on "OK" and fails on "ERROR"
|
||||
@@ -38,6 +41,6 @@ template <typename T> command_result generic_get_string(CommandableIf *t, const
|
||||
* @param timeout_ms Command timeout in ms
|
||||
* @return Generic command return type (OK, FAIL, TIMEOUT)
|
||||
*/
|
||||
command_result generic_command_common(CommandableIf *t, const std::string &command, uint32_t timeout_ms = 500);
|
||||
command_result generic_command_common(CommandableIf *t, std::string_view command, uint32_t timeout_ms = 500);
|
||||
|
||||
} // esp_modem::dce_commands
|
||||
@@ -74,7 +74,7 @@ public:
|
||||
return device.get();
|
||||
}
|
||||
|
||||
command_result command(const std::string &command, got_line_cb got_line, uint32_t time_ms)
|
||||
command_result command(std::string_view command, got_line_cb got_line, uint32_t time_ms)
|
||||
{
|
||||
return dte->command(command, std::move(got_line), time_ms);
|
||||
}
|
||||
|
||||
@@ -108,12 +108,12 @@ public:
|
||||
* @param time_ms Time in ms to wait for the answer
|
||||
* @return OK, FAIL, TIMEOUT
|
||||
*/
|
||||
command_result command(const std::string &command, got_line_cb got_line, uint32_t time_ms) override;
|
||||
command_result command(std::string_view command, got_line_cb got_line, uint32_t time_ms) override;
|
||||
|
||||
/**
|
||||
* @brief Sends the command (same as above) but with a specific separator
|
||||
*/
|
||||
command_result command(const std::string &command, got_line_cb got_line, uint32_t time_ms, char separator) override;
|
||||
command_result command(std::string_view command, got_line_cb got_line, uint32_t time_ms, char separator) override;
|
||||
|
||||
/**
|
||||
* @brief Allows this DTE to recover from a generic connection issue
|
||||
|
||||
@@ -79,8 +79,8 @@ public:
|
||||
* @param separator Character treated as a line separator, typically '\n'
|
||||
* @return OK, FAIL or TIMEOUT
|
||||
*/
|
||||
virtual command_result command(const std::string &command, got_line_cb got_line, uint32_t time_ms, const char separator) = 0;
|
||||
virtual command_result command(const std::string &command, got_line_cb got_line, uint32_t time_ms) = 0;
|
||||
virtual command_result command(std::string_view command, got_line_cb got_line, uint32_t time_ms, const char separator) = 0;
|
||||
virtual command_result command(std::string_view command, got_line_cb got_line, uint32_t time_ms) = 0;
|
||||
|
||||
virtual int write(uint8_t *data, size_t len) = 0;
|
||||
virtual void on_read(got_line_cb on_data) = 0;
|
||||
|
||||
Reference in new issue
Block a user