Skip to content

Commit

Permalink
fix(modem): Moved generic.inc to inplace include
Browse files Browse the repository at this point in the history
  • Loading branch information
david-cermak committed Nov 1, 2024
1 parent 542547d commit 58026d0
Show file tree
Hide file tree
Showing 10 changed files with 303 additions and 254 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
Expand All @@ -15,7 +15,7 @@
#include <cstring>
#include "cxx_include/esp_modem_api.hpp"
#include "cxx_include/esp_modem_dce_module.hpp"
#include "generate/esp_modem_command_declare.inc"
//#include "generate/esp_modem_command_declare.inc"
#include "my_module_dce.hpp"

using namespace esp_modem;
Expand Down Expand Up @@ -45,7 +45,8 @@ using namespace esp_modem;
#define ESP_MODEM_DECLARE_DCE_COMMAND(name, return_type, arg_nr, ...) \
return_type Shiny::DCE::name(__VA_ARGS__) { return esp_modem::dce_commands::name(this ARGS(arg_nr) ); }

DECLARE_ALL_COMMAND_APIS(return_type name(...) )
//DECLARE_ALL_COMMAND_APIS(return_type name(...) )
#include "generate/esp_modem_command_declare.inc"

#undef ESP_MODEM_DECLARE_DCE_COMMAND

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class DCE : public esp_modem::DCE_T<GenericModule>, public CommandableIf {
#define ESP_MODEM_DECLARE_DCE_COMMAND(name, return_type, num, ...) \
esp_modem::return_type name(__VA_ARGS__);

DECLARE_ALL_COMMAND_APIS(forwards name(...))
// DECLARE_ALL_COMMAND_APIS(forwards name(...))
#include "generate/esp_modem_command_declare.inc"

#undef ESP_MODEM_DECLARE_DCE_COMMAND

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -9,7 +9,7 @@
#include "esp_modem_dte.hpp"
#include "esp_modem_dce_module.hpp"
#include "esp_modem_types.hpp"
#include "generate/esp_modem_command_declare.inc"
//#include "generate/esp_modem_command_declare.inc"

namespace esp_modem {
namespace dce_commands {
Expand Down Expand Up @@ -41,7 +41,8 @@ command_result generic_command(CommandableIf *t, const std::string &command,
#define ESP_MODEM_DECLARE_DCE_COMMAND(name, return_type, num, ...) \
return_type name(CommandableIf *t, ## __VA_ARGS__);

DECLARE_ALL_COMMAND_APIS(declare name(Commandable *p, ...);)
// DECLARE_ALL_COMMAND_APIS(declare name(Commandable *p, ...);)
#include "generate/esp_modem_command_declare.inc"

#undef ESP_MODEM_DECLARE_DCE_COMMAND

Expand Down
130 changes: 3 additions & 127 deletions components/esp_modem/include/cxx_include/esp_modem_dce.hpp
Original file line number Diff line number Diff line change
@@ -1,134 +1,10 @@
/*
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <utility>
#include "cxx_include/esp_modem_netif.hpp"
#include "cxx_include/esp_modem_dce_module.hpp"

namespace esp_modem {

/**
* @defgroup ESP_MODEM_DCE
* @brief Definition of DCE abstraction
*/
/** @addtogroup ESP_MODEM_DCE
* @{
*/


/**
* @brief Helper class responsible for switching modes of the DCE's
*/
class DCE_Mode {
public:
DCE_Mode(): mode(modem_mode::UNDEF) {}
~DCE_Mode() = default;
bool set(DTE *dte, ModuleIf *module, Netif &netif, modem_mode m);
modem_mode get();

private:
bool set_unsafe(DTE *dte, ModuleIf *module, Netif &netif, modem_mode m);
modem_mode mode;

};

/**
* @brief General DCE class templated on a specific module. It is responsible for all the necessary transactions
* related to switching modes and consequent synergy with aggregated objects of DTE, Netif and a specific Module
*/
template<class SpecificModule>
class DCE_T {
static_assert(std::is_base_of<ModuleIf, SpecificModule>::value, "DCE must be instantiated with Module class only");
public:
explicit DCE_T(const std::shared_ptr<DTE> &dte, std::shared_ptr<SpecificModule> dev, esp_netif_t *netif):
dte(dte), device(std::move(dev)), netif(dte, netif)
{ }

~DCE_T() = default;

/**
* @brief Set data mode!
*/
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);
}

SpecificModule *get_module()
{
return device.get();
}

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);
}

bool set_mode(modem_mode m)
{
return mode.set(dte.get(), device.get(), netif, m);
}

bool recover()
{
return dte->recover();
}

#ifdef CONFIG_ESP_MODEM_URC_HANDLER
void set_urc(got_line_cb on_read_cb)
{
dte->set_urc_cb(on_read_cb);
}
#endif

protected:
std::shared_ptr<DTE> dte;
std::shared_ptr<SpecificModule> device;
Netif netif;
DCE_Mode mode;
};

/**
* @brief Common abstraction of the modem DCE, specialized by the GenericModule which is a parent class for the supported
* devices and most common modems, as well.
*/
class DCE : public DCE_T<GenericModule> {
public:

using DCE_T<GenericModule>::DCE_T;
#define ESP_MODEM_DECLARE_DCE_COMMAND(name, return_type, num, ...) \
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

};

/**
* @}
*/

} // esp_modem
#include "cxx_include/esp_modem_dce_template.hpp"
#include "cxx_include/esp_modem_dce_generic.hpp"
55 changes: 55 additions & 0 deletions components/esp_modem/include/cxx_include/esp_modem_dce_generic.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

//#include <utility>
//#include "cxx_include/esp_modem_netif.hpp"
//#include "cxx_include/esp_modem_dce_module.hpp"
//#include "cxx_include/esp_modem_dce_template.hpp"
//#include "esp_modem_dce_template.hpp"


namespace esp_modem {

/**
* @defgroup ESP_MODEM_DCE
* @brief Definition of DCE abstraction
*/

/** @addtogroup ESP_MODEM_DCE
* @{
*/

/**
* @brief Common abstraction of the modem DCE, specialized by the GenericModule which is a parent class for the supported
* devices and most common modems, as well.
*/
class DCE : public DCE_T<GenericModule> {
public:

using DCE_T<GenericModule>::DCE_T;
#define ESP_MODEM_DECLARE_DCE_COMMAND(name, return_type, num, ...) \
template <typename ...Agrs> \
return_type name(Agrs&&... args) \
{ \
return device->name(std::forward<Agrs>(args)...); \
}
#include "generate/esp_modem_command_declare.inc"
// DECLARE_ALL_COMMAND_APIS(forwards name(...)
// {
// device->name(...);
// } )

#undef ESP_MODEM_DECLARE_DCE_COMMAND

};

/**
* @}
*/

} // esp_modem
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -8,7 +8,7 @@

#include <memory>
#include <utility>
#include "generate/esp_modem_command_declare.inc"
//#include "generate/esp_modem_command_declare.inc"
#include "cxx_include/esp_modem_command_library.hpp"
#include "cxx_include/esp_modem_types.hpp"
#include "esp_modem_dce_config.h"
Expand Down Expand Up @@ -113,7 +113,10 @@ class GenericModule: public ModuleIf {
#define ESP_MODEM_DECLARE_DCE_COMMAND(name, return_type, num, ...) \
virtual return_type name(__VA_ARGS__);

DECLARE_ALL_COMMAND_APIS(virtual return_type name(...); )
// DECLARE_ALL_COMMAND_APIS(virtual return_type name(...); )

#include "generate/esp_modem_command_declare.inc"


#undef ESP_MODEM_DECLARE_DCE_COMMAND

Expand Down
110 changes: 110 additions & 0 deletions components/esp_modem/include/cxx_include/esp_modem_dce_template.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <utility>
#include "cxx_include/esp_modem_netif.hpp"
#include "cxx_include/esp_modem_dce_module.hpp"

namespace esp_modem {

/**
* @defgroup ESP_MODEM_DCE
* @brief Definition of DCE abstraction
*/
/** @addtogroup ESP_MODEM_DCE
* @{
*/


/**
* @brief Helper class responsible for switching modes of the DCE's
*/
class DCE_Mode {
public:
DCE_Mode(): mode(modem_mode::UNDEF) {}
~DCE_Mode() = default;
bool set(DTE *dte, ModuleIf *module, Netif &netif, modem_mode m);
modem_mode get();

private:
bool set_unsafe(DTE *dte, ModuleIf *module, Netif &netif, modem_mode m);
modem_mode mode;

};

/**
* @brief General DCE class templated on a specific module. It is responsible for all the necessary transactions
* related to switching modes and consequent synergy with aggregated objects of DTE, Netif and a specific Module
*/
template<class SpecificModule>
class DCE_T {
static_assert(std::is_base_of<ModuleIf, SpecificModule>::value, "DCE must be instantiated with Module class only");
public:
explicit DCE_T(const std::shared_ptr<DTE> &dte, std::shared_ptr<SpecificModule> dev, esp_netif_t *netif):
dte(dte), device(std::move(dev)), netif(dte, netif)
{ }

~DCE_T() = default;

/**
* @brief Set data mode!
*/
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);
}

SpecificModule *get_module()
{
return device.get();
}

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);
}

bool set_mode(modem_mode m)
{
return mode.set(dte.get(), device.get(), netif, m);
}

bool recover()
{
return dte->recover();
}

#ifdef CONFIG_ESP_MODEM_URC_HANDLER
void set_urc(got_line_cb on_read_cb)
{
dte->set_urc_cb(on_read_cb);
}
#endif

protected:
std::shared_ptr<DTE> dte;
std::shared_ptr<SpecificModule> device;
Netif netif;
DCE_Mode mode;
};

/**
* @}
*/

} // esp_modem
Loading

0 comments on commit 58026d0

Please sign in to comment.