Skip to content

Commit

Permalink
fix(modem): One step closer to perfect forwarding
Browse files Browse the repository at this point in the history
  • Loading branch information
david-cermak committed Nov 4, 2024
1 parent 9b334e7 commit a738300
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 76 deletions.
6 changes: 3 additions & 3 deletions components/esp_modem/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ set(srcs ${platform_srcs}
"src/esp_modem_modules.cpp")

if(CONFIG_USE_INPLACE_COMMAND_TEMPLATES)
set(include_dirs "include" "include/generate")
set(include_dirs "include" "generate/include")
else()
set(include_dirs "include" "include/commands")
set(include_dirs "include" "generate/include")
endif()

idf_component_register(SRCS "${srcs}"
INCLUDE_DIRS "include" "include/commands"
INCLUDE_DIRS "${include_dirs}"
PRIV_INCLUDE_DIRS private_include
REQUIRES ${dependencies})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class DCE : public esp_modem::DCE_T<GenericModule>, public CommandableIf {
esp_modem::return_type name(__VA_ARGS__);

// DECLARE_ALL_COMMAND_APIS(forwards name(...))
#include "generate/esp_modem_command_declare.inc"
#include "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 @@ -40,10 +40,9 @@ command_result generic_command(CommandableIf *t, const std::string &command,
* @brief Declaration of all commands is generated from esp_modem_command_declare.inc
*/
#define ESP_MODEM_DECLARE_DCE_COMMAND(name, return_type, ...) \
return_type name(CommandableIf *t, ## __VA_ARGS__);
return_type name(CommandableIf *t ESP_MODEM_COMMAND_PARAMS_AFTER(__VA_ARGS__));

// DECLARE_ALL_COMMAND_APIS(declare name(Commandable *p, ...);)
#include "generate/esp_modem_command_declare.inc"
#include "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 @@ -117,7 +117,7 @@ class GenericModule: public ModuleIf {

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

#include "generate/esp_modem_command_declare.inc"
#include "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 @@ -13,7 +13,7 @@
// limitations under the License.
//#pragma once

#include "generate/esp_modem_command_declare_helper.inc"
#include "esp_modem_command_declare_helper.inc"


/**
Expand All @@ -28,7 +28,7 @@ ESP_MODEM_DECLARE_DCE_COMMAND(sync, command_result)
* @param[out] act access technology
* @return OK, FAIL or TIMEOUT
*/
ESP_MODEM_DECLARE_DCE_COMMAND(get_operator_name, command_result, STRING_OUT(name), INT_OUT(act))
ESP_MODEM_DECLARE_DCE_COMMAND(get_operator_name, command_result, STR_OUT(name), INT_OUT(act))

/**
* @brief Stores current user profile
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
//#define INT_IN(name) int name
//#ifdef __cplusplus
//#define STRING_IN(name) const std::string& name
//#define STRING_OUT(name) std::string& name
//#define BOOL_IN(name) const bool name
//#define BOOL_OUT(name) bool& name
//#define INT_OUT(name) int& name
//#define INTEGER_LIST_IN(name) const int* name
//#define STRUCT_OUT(struct_name, name) struct_name& name
//#else
//#define STRING_IN(name) const char* name
//#define STRING_OUT(name) char* name
//#define BOOL_IN(name) const bool name
//#define BOOL_OUT(name) bool* name
//#define INT_OUT(name) int* name
//#define INTEGER_LIST_IN(name) const int* name
//#define STRUCT_OUT(struct_name, name) esp_modem_ ## struct_name ## _t* name
//#endif
//
//#define FORWARD_INT_IN(name) name
//#define FORWARD_STRING_IN(name) name
//#define FORWARD_STRING_OUT(name) name
//#define FORWARD_BOOL_IN(name) name
//#define FORWARD_BOOL_OUT(name) name
//#define FORWARD_INT_OUT(name) name
//#define FORWARD_INTEGER_LIST_IN(name) name
//#define FORWARD_STRUCT_OUT(struct_name, name) name

// Utility to count arguments (works for up to two parameters here)
#define ESP_MODEM_GET_MACRO(_0, _1, _2, _3, _4, _5, _6, ESP_MODEM_MACRO_NAME, ...) ESP_MODEM_MACRO_NAME
#define ESP_MODEM_COMMAND_PARAMS(...) ESP_MODEM_GET_MACRO(_0, ##__VA_ARGS__, ESP_MODEM_HELPER6, ESP_MODEM_HELPER5, ESP_MODEM_HELPER4, ESP_MODEM_HELPER3, ESP_MODEM_HELPER2, ESP_MODEM_HELPER1, ESP_MODEM_HELPER0)(PARAM_, ESP_MODEM_NO_COMMA, ESP_MODEM_NO_COMMA, ##__VA_ARGS__)
#define ESP_MODEM_COMMAND_PARAMS_AFTER(...) ESP_MODEM_GET_MACRO(_0, ##__VA_ARGS__, ESP_MODEM_HELPER6, ESP_MODEM_HELPER5, ESP_MODEM_HELPER4, ESP_MODEM_HELPER3, ESP_MODEM_HELPER2, ESP_MODEM_HELPER1, ESP_MODEM_HELPER0)(PARAM_, ESP_MODEM_COMMA, ESP_MODEM_NO_COMMA, ##__VA_ARGS__)
#define ESP_MODEM_COMMAND_FORWARD(...) ESP_MODEM_GET_MACRO(_0, ##__VA_ARGS__, ESP_MODEM_HELPER6, ESP_MODEM_HELPER5, ESP_MODEM_HELPER4, ESP_MODEM_HELPER3, ESP_MODEM_HELPER2, ESP_MODEM_HELPER1, ESP_MODEM_HELPER0)(FORWARD_, ESP_MODEM_NO_COMMA, ESP_MODEM_NO_COMMA, ##__VA_ARGS__)
#define ESP_MODEM_COMMAND_FORWARD_AFTER(...) ESP_MODEM_GET_MACRO(_0, ##__VA_ARGS__, ESP_MODEM_HELPER6, ESP_MODEM_HELPER5, ESP_MODEM_HELPER4, ESP_MODEM_HELPER3, ESP_MODEM_HELPER2, ESP_MODEM_HELPER1, ESP_MODEM_HELPER0)(FORWARD_, ESP_MODEM_COMMA, ESP_MODEM_NO_COMMA, ##__VA_ARGS__)

#define PARAM_STR_OUT(name) std::string& name
#define FORWARD_STR_OUT(name) name
#define PARAM_STR_IN(name) const std::string& name
#define FORWARD_STR_IN(name) name
#define PARAM_INT_OUT(name) int& name
#define FORWARD_INT_OUT(name) name
#define PARAM_INT_IN(name) int name
#define FORWARD_INT_IN(name) name
#define ESP_MODEM_COMMA ,
#define ESP_MODEM_NO_COMMA

#define ESP_MODEM_HELPER_EVAL(x) x
#define ESP_MODEM_HELPER_GENERIC(a, b) ESP_MODEM_HELPER_EVAL(a ## b)
#define ESP_MODEM_HELPER0(prefix, lead_comma, trail_comma)
#define ESP_MODEM_HELPER1(prefix, lead_comma, trail_comma, p1) lead_comma ESP_MODEM_HELPER_GENERIC(prefix, p1) trail_comma
#define ESP_MODEM_HELPER2(prefix, lead_comma, trail_comma, p1, p2) lead_comma ESP_MODEM_HELPER_GENERIC(prefix, p1), ESP_MODEM_HELPER_GENERIC(prefix, p2) trail_comma
#define ESP_MODEM_HELPER3(prefix, lead_comma, trail_comma, p1, p2, p3) lead_comma ESP_MODEM_HELPER_GENERIC(prefix, p1), ESP_MODEM_HELPER_GENERIC(prefix, p2), ESP_MODEM_HELPER_GENERIC(prefix, p3) trail_comma
#define ESP_MODEM_HELPER4(prefix, lead_comma, trail_comma, p1, p2, p3, p4) lead_comma \
ESP_MODEM_HELPER_GENERIC(prefix, p1), \
ESP_MODEM_HELPER_GENERIC(prefix, p2), \
ESP_MODEM_HELPER_GENERIC(prefix, p3), \
ESP_MODEM_HELPER_GENERIC(prefix, p4) trail_comma
#define ESP_MODEM_HELPER5(prefix, lead_comma, trail_comma, p1, p2, p3, p4, p5) lead_comma \
ESP_MODEM_HELPER_GENERIC(prefix, p1), \
ESP_MODEM_HELPER_GENERIC(prefix, p2), \
ESP_MODEM_HELPER_GENERIC(prefix, p3), \
ESP_MODEM_HELPER_GENERIC(prefix, p4), \
ESP_MODEM_HELPER_GENERIC(prefix, p5) trail_comma

This file was deleted.

1 change: 1 addition & 0 deletions components/esp_modem/scripts/generate.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@


for i in esp_modem_dce_generic.hpp esp_modem_dce_module.hpp esp_modem_command_library.hpp; do
out_file="../include/commands/cxx_include/$i";
in_file="../include/generate/$i";
Expand Down
40 changes: 2 additions & 38 deletions components/esp_modem/src/esp_modem_modules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,10 @@ namespace esp_modem {
GenericModule::GenericModule(std::shared_ptr<DTE> dte, const dce_config *config) :
dte(std::move(dte)), pdp(std::make_unique<PdpContext>(config->apn)) {}

// Utility to count arguments (works for up to two parameters here)
#define GET_MACRO(_0, _1, _2, _3, NAME, ...) NAME
#define FOO(...) GET_MACRO(_0, ##__VA_ARGS__, FOO3, FOO2, FOO1, FOO0)(PARAM_, NO_COMMA, NO_COMMA, ##__VA_ARGS__)
#define GOO(...) GET_MACRO(_0, ##__VA_ARGS__, FOO3, FOO2, FOO1, FOO0)(FORWARD_, COMMA, NO_COMMA, ##__VA_ARGS__)
//#define GOO(...) GET_MACRO(_0, ##__VA_ARGS__, GOO3, GOO2, GOO1, GOO0)(__VA_ARGS__)

#define PARAM_STR_OUT(name) std::string& name
#define FORWARD_STR_OUT(name) name
#define PARAM_STR_IN(name) const std::string& name
#define FORWARD_STR_IN(name) name
#define PARAM_INT_OUT(name) int& name
#define FORWARD_INT_OUT(name) name
#define PARAM_INT_IN(name) int name
#define FORWARD_INT_IN(name) name
#define COMMA ,
#define NO_COMMA

#define EVAL(x) x
#define FOO_GENERIC(a, b) EVAL(a ## b)
#define FOO0(prefix, lead_comma, trail_comma)
#define FOO1(prefix, lead_comma, trail_comma, p1) lead_comma FOO_GENERIC(prefix, p1) trail_comma
#define FOO2(prefix, lead_comma, trail_comma, p1, p2) lead_comma FOO_GENERIC(prefix, p1), FOO_GENERIC(prefix, p2) trail_comma
#define FOO3(prefix, lead_comma, trail_comma, p1, p2, p3) lead_comma FOO_GENERIC(prefix, p1), FOO_GENERIC(prefix, p2), FOO_GENERIC(prefix, p3) trail_comma

#define GOO1(p1) , FOO_GENERIC(FORWARD_, p1)

//#define FOO1(p1) EVAL(PARAM_ ## p1)
//#define FOO2(p1, p2) EVAL(PARAM_ ## p1), EVAL(PARAM_ ## p2)
//#define FOO3(p1, p2, p3) EVAL(PARAM_ ## p1), \
// EVAL(PARAM_ ## p2), \
// EVAL(PARAM_ ## p3)

#define GOO0()
//#define GOO1(p1) , EVAL(FORWARD_ ## p1)
#define GOO2(p1, p2) , EVAL(FORWARD_ ## p1), EVAL(FORWARD_ ## p2)
#define GOO3(p1, p2, p3) , EVAL(FORWARD_ ## p1), EVAL(FORWARD_ ## p2), EVAL(FORWARD_ ## p3)


#define COMMAND(name, type, ...) \
type GenericModule::name(FOO(__VA_ARGS__)) { return esp_modem::dce_commands::name(dte.get() GOO(__VA_ARGS__)); }
type GenericModule::name(ESP_MODEM_COMMAND_PARAMS(__VA_ARGS__)) { \
return esp_modem::dce_commands::name(dte.get() ESP_MODEM_COMMAND_FORWARD_AFTER(__VA_ARGS__)); }

COMMAND(sync, command_result)
COMMAND(set_pin, command_result, STR_IN(pin));
Expand Down

0 comments on commit a738300

Please sign in to comment.