Skip to content

Commit 4b92a95

Browse files
committed
fix(modem): Use nicer way to override modules
1 parent 26b75f9 commit 4b92a95

File tree

7 files changed

+72
-24
lines changed

7 files changed

+72
-24
lines changed

components/esp_modem/examples/modem_tcp_client/main/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
set(module_dir "generic_module")
12
if (CONFIG_EXAMPLE_MODEM_DEVICE_BG96)
23
set(device_srcs sock_commands_bg96.cpp)
34
elseif(CONFIG_EXAMPLE_MODEM_DEVICE_SIM7600)
45
set(device_srcs sock_commands_sim7600.cpp)
56
elseif(CONFIG_EXAMPLE_MODEM_DEVICE_ESPAT)
67
set(device_srcs sock_commands_espat.cpp)
8+
set(module_dir "espat_module")
79
endif()
810

911
if(CONFIG_ESP_MODEM_ENABLE_DEVELOPMENT_MODE)
@@ -16,4 +18,4 @@ idf_component_register(SRCS "modem_client.cpp"
1618
"${command_dir}/sock_dce.cpp"
1719
"tcp_transport_at.cpp"
1820
"${device_srcs}"
19-
INCLUDE_DIRS "." "${command_dir}")
21+
INCLUDE_DIRS "." "${command_dir}" "${module_dir}")

components/esp_modem/examples/modem_tcp_client/main/command/sock_dce.cpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
#include <sys/socket.h>
99
#include "esp_vfs.h"
1010
#include "esp_vfs_eventfd.h"
11+
1112
#include "sock_dce.hpp"
12-
#include "cxx_include/esp_modem_command_library_utils.hpp"
1313

1414
namespace sock_dce {
1515

@@ -305,21 +305,6 @@ std::unique_ptr<DCE> create(const esp_modem::dce_config *config, std::shared_ptr
305305
}
306306

307307

308-
esp_modem::command_result DCE::sync()
309-
{
310-
return esp_modem::dce_commands::generic_command_common(dte.get(), "AT\r\n");
311-
}
312-
313-
esp_modem::command_result DCE::set_echo(bool on)
314-
{
315-
return esp_modem::dce_commands::generic_command_common(dte.get(), "ATE0\r\n");
316-
}
317-
318-
esp_modem::command_result DCE::set_pdp_context(esp_modem::PdpContext &pdp)
319-
{
320-
return esp_modem::command_result::OK;
321-
}
322-
323308
/**
324309
* @brief Opens network in AT command mode
325310
* @return OK, FAIL or TIMEOUT

components/esp_modem/examples/modem_tcp_client/main/command/sock_dce.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "cxx_include/esp_modem_api.hpp"
99
#include <cxx_include/esp_modem_dce_factory.hpp>
1010
#include "sock_commands.hpp"
11+
#include "sock_module.hpp"
1112
#include <sys/socket.h>
1213

1314
#pragma once
@@ -97,13 +98,10 @@ class Responder {
9798
std::shared_ptr<esp_modem::DTE> &dte;
9899
};
99100

100-
class DCE : public ::esp_modem::GenericModule {
101-
using esp_modem::GenericModule::GenericModule;
101+
class DCE : public Module {
102+
using Module::Module;
102103
public:
103104

104-
esp_modem::command_result sync() override;
105-
esp_modem::command_result set_echo(bool on) override;
106-
esp_modem::command_result set_pdp_context(esp_modem::PdpContext &pdp) override;
107105
/**
108106
* @brief Opens network in AT command mode
109107
* @return OK, FAIL or TIMEOUT
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include "esp_modem_config.h"
8+
#include "cxx_include/esp_modem_api.hpp"
9+
10+
#pragma once
11+
12+
namespace sock_dce {
13+
14+
class Module: public esp_modem::GenericModule {
15+
using esp_modem::GenericModule::GenericModule;
16+
public:
17+
18+
esp_modem::command_result sync() override;
19+
esp_modem::command_result set_echo(bool on) override;
20+
esp_modem::command_result set_pdp_context(esp_modem::PdpContext &pdp) override;
21+
22+
};
23+
24+
}

components/esp_modem/examples/modem_tcp_client/main/generate/sock_dce.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "cxx_include/esp_modem_api.hpp"
99
#include <cxx_include/esp_modem_dce_factory.hpp>
1010
#include "sock_commands.hpp"
11+
#include "sock_module.hpp"
1112
#include <sys/socket.h>
1213

1314
#pragma once
@@ -97,8 +98,8 @@ class Responder {
9798
std::shared_ptr<esp_modem::DTE> &dte;
9899
};
99100

100-
class DCE : public ::esp_modem::GenericModule {
101-
using esp_modem::GenericModule::GenericModule;
101+
class DCE : public Module {
102+
using Module::Module;
102103
public:
103104

104105
// --- ESP-MODEM command module starts here ---
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include "esp_modem_config.h"
8+
#include "cxx_include/esp_modem_api.hpp"
9+
10+
#pragma once
11+
12+
namespace sock_dce {
13+
14+
using Module = esp_modem::GenericModule;
15+
16+
}

components/esp_modem/examples/modem_tcp_client/main/sock_commands_espat.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,31 @@
99
#include "sock_commands.hpp"
1010
#include "cxx_include/esp_modem_command_library_utils.hpp"
1111
#include "sock_dce.hpp"
12+
#include "sock_module.hpp"
1213

1314
static const char *TAG = "sock_commands_espat";
1415

16+
namespace sock_dce {
17+
18+
using namespace esp_modem;
19+
20+
command_result Module::sync()
21+
{
22+
return dce_commands::generic_command_common(dte.get(), "AT\r\n");
23+
}
24+
25+
command_result Module::set_echo(bool on)
26+
{
27+
return dce_commands::generic_command_common(dte.get(), "ATE0\r\n");
28+
}
29+
30+
command_result Module::set_pdp_context(PdpContext &pdp)
31+
{
32+
return command_result::OK;
33+
}
34+
35+
}
36+
1537
namespace sock_commands {
1638

1739
using namespace esp_modem;

0 commit comments

Comments
 (0)