mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-18 04:52:18 +02:00
Implement perfect forwarding for command lib
This commit is contained in:
70
esp_modem/include/cxx_include/esp_modem_dce_module.hpp
Normal file
70
esp_modem/include/cxx_include/esp_modem_dce_module.hpp
Normal file
@ -0,0 +1,70 @@
|
||||
#pragma once
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include "generate/esp_modem_command_declare.inc"
|
||||
#include "cxx_include/esp_modem_command_library.hpp"
|
||||
#include "cxx_include/esp_modem_types.hpp"
|
||||
|
||||
enum class command_result;
|
||||
class DTE;
|
||||
|
||||
class GenericModule: public ModuleIf {
|
||||
public:
|
||||
explicit GenericModule(std::shared_ptr<DTE> dte, std::unique_ptr<PdpContext> pdp):
|
||||
dte(std::move(dte)), pdp(std::move(pdp)) {}
|
||||
|
||||
bool setup_data_mode() override
|
||||
{
|
||||
if (set_echo(false) != command_result::OK)
|
||||
return false;
|
||||
if (set_pdp_context(*pdp) != command_result::OK)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool set_mode(modem_mode mode) override
|
||||
{
|
||||
if (mode == modem_mode::DATA_MODE) {
|
||||
if (set_data_mode() != command_result::OK)
|
||||
return resume_data_mode() == command_result::OK;
|
||||
return true;
|
||||
} else if (mode == modem_mode::COMMAND_MODE) {
|
||||
return set_command_mode() == command_result::OK;
|
||||
} else if (mode == modem_mode::CMUX_MODE) {
|
||||
return set_cmux() == command_result::OK;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
#define ESP_MODEM_DECLARE_DCE_COMMAND(name, return_type, TEMPLATE_ARG, MUX_ARG, ...) \
|
||||
template <typename ...Agrs> \
|
||||
return_type name(Agrs&&... args) { return esp_modem::dce_commands::name(dte.get(), std::forward<Agrs>(args)...); }
|
||||
|
||||
DECLARE_ALL_COMMAND_APIS(return_type name(...); )
|
||||
|
||||
#undef ESP_MODEM_DECLARE_DCE_COMMAND
|
||||
|
||||
|
||||
protected:
|
||||
std::shared_ptr<DTE> dte;
|
||||
std::unique_ptr<PdpContext> pdp;
|
||||
};
|
||||
|
||||
// Definitions of other modules
|
||||
class SIM7600: public GenericModule {
|
||||
using GenericModule::GenericModule;
|
||||
public:
|
||||
command_result get_module_name(std::string& name);
|
||||
};
|
||||
|
||||
class SIM800: public GenericModule {
|
||||
using GenericModule::GenericModule;
|
||||
public:
|
||||
command_result get_module_name(std::string& name);
|
||||
};
|
||||
|
||||
class BG96: public GenericModule {
|
||||
public:
|
||||
command_result get_module_name(std::string& name);
|
||||
};
|
Reference in New Issue
Block a user