mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-24 07:47:30 +02:00
Applied astyle code formatting
This commit is contained in:
@ -32,13 +32,13 @@ using NetDCE = DCE_T<NetModule>;
|
||||
class NetDCE_Factory: public Factory {
|
||||
public:
|
||||
template <typename Module, typename ...Args>
|
||||
static DCE_T<Module>* create(const config *cfg, Args&&... args)
|
||||
static DCE_T<Module> *create(const config *cfg, Args &&... args)
|
||||
{
|
||||
return build_generic_DCE<Module>(cfg, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename Module, typename ...Args>
|
||||
static std::shared_ptr<Module> create_module(const config *cfg, Args&&... args)
|
||||
static std::shared_ptr<Module> create_module(const config *cfg, Args &&... args)
|
||||
{
|
||||
return build_shared_module<Module>(cfg, std::forward<Args>(args)...);
|
||||
}
|
||||
@ -53,44 +53,48 @@ public:
|
||||
class NetModule: public ModuleIf {
|
||||
public:
|
||||
explicit NetModule(std::shared_ptr<DTE> dte, const esp_modem_dce_config *cfg):
|
||||
dte(std::move(dte)), apn(std::string(cfg->apn)) {}
|
||||
dte(std::move(dte)), apn(std::string(cfg->apn)) {}
|
||||
|
||||
[[nodiscard]] bool setup_data_mode() override
|
||||
{
|
||||
PdpContext pdp(apn);
|
||||
if (set_pdp_context(pdp) != command_result::OK)
|
||||
if (set_pdp_context(pdp) != command_result::OK) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool set_mode(modem_mode mode) override
|
||||
{
|
||||
switch (mode) {
|
||||
case esp_modem::modem_mode::DATA_MODE:
|
||||
if (set_data_mode() != command_result::OK) {
|
||||
return resume_data_mode() == command_result::OK;
|
||||
}
|
||||
return true;
|
||||
case esp_modem::modem_mode::COMMAND_MODE:
|
||||
return set_command_mode() == command_result::OK;
|
||||
default:
|
||||
return false;
|
||||
case esp_modem::modem_mode::DATA_MODE:
|
||||
if (set_data_mode() != command_result::OK) {
|
||||
return resume_data_mode() == command_result::OK;
|
||||
}
|
||||
return true;
|
||||
case esp_modem::modem_mode::COMMAND_MODE:
|
||||
return set_command_mode() == command_result::OK;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[[maybe_unused]] bool init_sim(const std::string& pin)
|
||||
[[maybe_unused]] bool init_sim(const std::string &pin)
|
||||
{
|
||||
// switch to command mode (in case we were in PPP mode)
|
||||
static_cast<void>(set_command_mode()); // ignore the potential failure, as we might be in command mode after startup
|
||||
bool is_pin_ok;
|
||||
if (read_pin(is_pin_ok) != command_result::OK)
|
||||
if (read_pin(is_pin_ok) != command_result::OK) {
|
||||
return false;
|
||||
}
|
||||
if (!is_pin_ok) {
|
||||
if (set_pin(pin) != command_result::OK)
|
||||
if (set_pin(pin) != command_result::OK) {
|
||||
return false;
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
if (read_pin(is_pin_ok) != command_result::OK || !is_pin_ok)
|
||||
if (read_pin(is_pin_ok) != command_result::OK || !is_pin_ok) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -99,12 +103,30 @@ private:
|
||||
std::shared_ptr<DTE> dte;
|
||||
std::string apn;
|
||||
|
||||
[[nodiscard]] command_result set_pdp_context(PdpContext& pdp) { return dce_commands::set_pdp_context(dte.get(),pdp); }
|
||||
[[nodiscard]] command_result set_pin(const std::string &pin) { return dce_commands::set_pin(dte.get(), pin); }
|
||||
[[nodiscard]] command_result read_pin(bool& pin_ok) { return dce_commands::read_pin(dte.get(), pin_ok); }
|
||||
[[nodiscard]] command_result set_data_mode() { return dce_commands::set_data_mode(dte.get()); }
|
||||
[[nodiscard]] command_result resume_data_mode() { return dce_commands::resume_data_mode(dte.get()); }
|
||||
[[nodiscard]] command_result set_command_mode() { return dce_commands::set_command_mode(dte.get()); }
|
||||
[[nodiscard]] command_result set_pdp_context(PdpContext &pdp)
|
||||
{
|
||||
return dce_commands::set_pdp_context(dte.get(), pdp);
|
||||
}
|
||||
[[nodiscard]] command_result set_pin(const std::string &pin)
|
||||
{
|
||||
return dce_commands::set_pin(dte.get(), pin);
|
||||
}
|
||||
[[nodiscard]] command_result read_pin(bool &pin_ok)
|
||||
{
|
||||
return dce_commands::read_pin(dte.get(), pin_ok);
|
||||
}
|
||||
[[nodiscard]] command_result set_data_mode()
|
||||
{
|
||||
return dce_commands::set_data_mode(dte.get());
|
||||
}
|
||||
[[nodiscard]] command_result resume_data_mode()
|
||||
{
|
||||
return dce_commands::resume_data_mode(dte.get());
|
||||
}
|
||||
[[nodiscard]] command_result set_command_mode()
|
||||
{
|
||||
return dce_commands::set_command_mode(dte.get());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -132,13 +154,15 @@ extern "C" esp_err_t modem_init_network(esp_netif_t *netif)
|
||||
// create the specific device (and initialize it)
|
||||
auto dev = NetDCE_Factory::create_module<NetModule>(&dce_config, uart_dte, netif);
|
||||
#if CONFIG_EXAMPLE_NEED_SIM_PIN == 1
|
||||
if (!dev->init_sim(CONFIG_EXAMPLE_SIM_PIN))
|
||||
if (!dev->init_sim(CONFIG_EXAMPLE_SIM_PIN)) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
#endif
|
||||
// now create the DCE from our already existent device
|
||||
dce = NetDCE_Factory::create<NetModule>(&dce_config, uart_dte, netif, dev);
|
||||
if (dce == nullptr)
|
||||
if (dce == nullptr) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user