Files
esp-protocols/esp_modem/include/cxx_include/esp_modem_dce_module.hpp

82 lines
2.9 KiB
C++
Raw Normal View History

#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;
2021-03-28 09:08:47 +02:00
class MinimalModule: public ModuleIf {
public:
2021-03-28 09:08:47 +02:00
explicit MinimalModule(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;
}
2021-03-28 09:08:47 +02:00
template <typename ...T> command_result set_echo(T&&... args) { return esp_modem::dce_commands::set_echo(dte.get(),std::forward<T>(args)...); }
template <typename ...T> command_result set_pdp_context(T&&... args) { return esp_modem::dce_commands::set_pdp_context(dte.get(),std::forward<T>(args)...); }
template <typename ...T> command_result set_data_mode(T&&... args) { return esp_modem::dce_commands::set_data_mode(dte.get(),std::forward<T>(args)...); }
template <typename ...T> command_result resume_data_mode(T&&... args) { return esp_modem::dce_commands::resume_data_mode(dte.get(),std::forward<T>(args)...); }
template <typename ...T> command_result set_command_mode(T&&... args) { return esp_modem::dce_commands::set_command_mode(dte.get(),std::forward<T>(args)...); }
template <typename ...T> command_result set_cmux(T&&... args) { return esp_modem::dce_commands::set_cmux(dte.get(),std::forward<T>(args)...); }
protected:
std::shared_ptr<DTE> dte;
std::unique_ptr<PdpContext> pdp;
};
class GenericModule: public MinimalModule {
using MinimalModule::MinimalModule;
public:
#define ESP_MODEM_DECLARE_DCE_COMMAND(name, return_type, TEMPLATE_ARG, MUX_ARG, ...) \
2021-03-24 21:06:27 +01:00
virtual return_type name(__VA_ARGS__);
2021-03-28 09:08:47 +02:00
DECLARE_ALL_COMMAND_APIS(virtual return_type name(...);)
#undef ESP_MODEM_DECLARE_DCE_COMMAND
};
2021-03-28 09:08:47 +02:00
// Definitions of other modules
class SIM7600: public GenericModule {
using GenericModule::GenericModule;
public:
2021-03-24 21:06:27 +01:00
// command_result get_module_name(std::string& name) override;
};
class SIM800: public GenericModule {
using GenericModule::GenericModule;
public:
2021-03-24 21:06:27 +01:00
command_result get_module_name(std::string& name) override;
};
class BG96: public GenericModule {
2021-03-28 09:08:47 +02:00
using GenericModule::GenericModule;
public:
2021-03-24 21:06:27 +01:00
command_result get_module_name(std::string& name) override;
};