2021-03-03 20:35:08 +01:00
|
|
|
#pragma once
|
2021-03-07 19:43:45 +01:00
|
|
|
#include "cxx_include/esp_modem_netif.hpp"
|
|
|
|
#include "generate/esp_modem_command_declare.inc"
|
2021-03-03 20:35:08 +01:00
|
|
|
|
2021-03-07 19:43:45 +01:00
|
|
|
template<class SpecificModule>
|
2021-03-03 20:35:08 +01:00
|
|
|
class DCE {
|
2021-03-07 19:43:45 +01:00
|
|
|
static_assert(std::is_base_of<ModuleIf, SpecificModule>::value, "DCE must be instantiated with Module class only");
|
2021-03-03 20:35:08 +01:00
|
|
|
public:
|
2021-03-07 19:43:45 +01:00
|
|
|
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)
|
|
|
|
{ }
|
2021-03-03 20:35:08 +01:00
|
|
|
void set_data() {
|
|
|
|
device->setup_data_mode();
|
2021-03-07 19:43:45 +01:00
|
|
|
device->set_mode(modem_mode::DATA_MODE);
|
|
|
|
dce_dte->set_mode(modem_mode::DATA_MODE);
|
2021-03-03 20:35:08 +01:00
|
|
|
ppp_netif.start();
|
|
|
|
}
|
2021-03-07 19:43:45 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
#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)...); \
|
|
|
|
}
|
|
|
|
|
|
|
|
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)...);
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
2021-03-03 20:35:08 +01:00
|
|
|
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);
|
|
|
|
}
|
2021-03-07 19:43:45 +01:00
|
|
|
void set_cmux() { device->set_mode(modem_mode::CMUX_MODE);
|
|
|
|
dce_dte->set_mode(modem_mode::CMUX_MODE); }
|
2021-03-03 20:35:08 +01:00
|
|
|
private:
|
|
|
|
std::shared_ptr<DTE> dce_dte;
|
2021-03-07 19:43:45 +01:00
|
|
|
std::shared_ptr<SpecificModule> device;
|
2021-03-04 20:19:18 +01:00
|
|
|
PPP ppp_netif;
|
2021-03-03 20:35:08 +01:00
|
|
|
};
|