update per design review

This commit is contained in:
David Cermak
2021-03-24 21:06:27 +01:00
parent a93cb68078
commit 8314e163fa
12 changed files with 228 additions and 94 deletions

View File

@ -18,8 +18,8 @@ std::shared_ptr<DTE> create_uart_dte(const esp_modem_dte_config *config);
std::shared_ptr<GenericModule> create_generic_module(const std::shared_ptr<DTE>& dte, std::string &apn);
std::shared_ptr<SIM7600> create_SIM7600_module(const std::shared_ptr<DTE>& dte, std::string &apn);
std::unique_ptr<DCE<GenericModule>> create_generic_dce_from_module(const std::shared_ptr<DTE>& dte, const std::shared_ptr<GenericModule>& dev, esp_netif_t *netif);
std::unique_ptr<DCE<SIM7600>> create_SIM7600_dce_from_module(const std::shared_ptr<DTE>& dte, const std::shared_ptr<SIM7600>& dev, esp_netif_t *netif);
std::unique_ptr<DCE> create_generic_dce_from_module(const std::shared_ptr<DTE>& dte, const std::shared_ptr<GenericModule>& dev, esp_netif_t *netif);
std::unique_ptr<DCE> create_SIM7600_dce_from_module(const std::shared_ptr<DTE>& dte, const std::shared_ptr<SIM7600>& dev, esp_netif_t *netif);
std::unique_ptr<DCE<SIM7600>> create_SIM7600_dce(const std::shared_ptr<DTE>& dte, esp_netif_t *netif, std::string &apn);
std::unique_ptr<DCE> create_SIM7600_dce(const std::shared_ptr<DTE>& dte, esp_netif_t *netif, std::string &apn);

View File

@ -1,65 +1,72 @@
#pragma once
#include <utility>
#include "cxx_include/esp_modem_netif.hpp"
#include "cxx_include/esp_modem_dce_module.hpp"
#include "generate/esp_modem_command_declare.inc"
namespace esp_modem::DCE {
class Modes {
public:
Modes(): mode(modem_mode::COMMAND_MODE) {}
~Modes() = default;
bool set(DTE *dte, ModuleIf *module, PPP &netif, modem_mode m);
modem_mode get();
private:
modem_mode mode;
};
}
template<class SpecificModule>
class DCE {
class DCE_T {
static_assert(std::is_base_of<ModuleIf, SpecificModule>::value, "DCE must be instantiated with Module class only");
public:
explicit DCE(const std::shared_ptr<DTE>& dte, std::shared_ptr<SpecificModule> device, esp_netif_t * netif):
dce_dte(dte), device(std::move(device)), ppp_netif(dte, netif)
explicit DCE_T(const std::shared_ptr<DTE>& dte, std::shared_ptr<SpecificModule> device, esp_netif_t * netif):
dte(dte), module(std::move(device)), netif(dte, netif)
{ }
void set_data() {
device->setup_data_mode();
device->set_mode(modem_mode::DATA_MODE);
dce_dte->set_mode(modem_mode::DATA_MODE);
ppp_netif.start();
}
void exit_data() {
ppp_netif.stop();
device->set_mode(modem_mode::COMMAND_MODE);
// uint8_t* data;
dce_dte->set_data_cb([&](size_t len) -> bool {
// auto actual_len = dce_dte->read(&data, 64);
// ESP_LOG_BUFFER_HEXDUMP("esp-modem: debug_data", data, actual_len, ESP_LOG_INFO);
return false;
});
ppp_netif.wait_until_ppp_exits();
dce_dte->set_data_cb(nullptr);
dce_dte->set_mode(modem_mode::COMMAND_MODE);
~DCE_T() = default;
void set_data() { set_mode(modem_mode::DATA_MODE); }
void exit_data() { set_mode(modem_mode::COMMAND_MODE); }
void set_cmux() { set_mode(modem_mode::CMUX_MODE); }
command_result command(const std::string& command, got_line_cb got_line, uint32_t time_ms)
{
return dte->command(command, std::move(got_line), time_ms);
}
protected:
bool set_mode(modem_mode m) { return mode.set(dte.get(), module.get(), netif, m); }
std::shared_ptr<DTE> dte;
std::shared_ptr<SpecificModule> module;
PPP netif;
esp_modem::DCE::Modes mode;
};
class DCE: public DCE_T<GenericModule> {
public:
using DCE_T<GenericModule>::DCE_T;
#define ESP_MODEM_DECLARE_DCE_COMMAND(name, return_type, TEMPLATE_ARG, MUX_ARG, ...) \
template <typename ...Agrs> \
return_type name(Agrs&&... args) \
{ \
return device->name(std::forward<Agrs>(args)...); \
return module->name(std::forward<Agrs>(args)...); \
}
DECLARE_ALL_COMMAND_APIS(forwards name(...) { device->name(...); } )
#undef ESP_MODEM_DECLARE_DCE_COMMAND
// template <typename ...Params>
// command_result get_module_name(Params&&... params)
// {
// return device->get_module_name(std::forward<Params>(params)...);
// }
// template <typename ...Params>
// command_result set_data_mode(Params&&... params)
// {
// return device->set_data_mode(std::forward<Params>(params)...);
// }
command_result command(const std::string& command, got_line_cb got_line, uint32_t time_ms) {
return dce_dte->command(command, got_line, time_ms);
}
void set_cmux() { device->set_mode(modem_mode::CMUX_MODE);
dce_dte->set_mode(modem_mode::CMUX_MODE); }
private:
std::shared_ptr<DTE> dce_dte;
std::shared_ptr<SpecificModule> device;
PPP ppp_netif;
};

View File

@ -38,10 +38,9 @@ public:
#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)...); }
virtual return_type name(__VA_ARGS__);
DECLARE_ALL_COMMAND_APIS(return_type name(...); )
DECLARE_ALL_COMMAND_APIS(virtual return_type name(...); )
#undef ESP_MODEM_DECLARE_DCE_COMMAND
@ -55,16 +54,16 @@ protected:
class SIM7600: public GenericModule {
using GenericModule::GenericModule;
public:
command_result get_module_name(std::string& name);
// command_result get_module_name(std::string& name) override;
};
class SIM800: public GenericModule {
using GenericModule::GenericModule;
public:
command_result get_module_name(std::string& name);
command_result get_module_name(std::string& name) override;
};
class BG96: public GenericModule {
public:
command_result get_module_name(std::string& name);
command_result get_module_name(std::string& name) override;
};