Skip to content

Commit 577de67

Browse files
committed
fix(modem): Fixed documentation and example on creating custom device
Updates docs and examples per recent changes: * Modem example does no longer demonstrate how to overwrite an AT method * PPPoS client example now contains much simpler custom module definition Closes #452
1 parent ae38110 commit 577de67

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

components/esp_modem/examples/modem_console/main/my_module_dce.hpp

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Unlicense OR CC0-1.0
55
*/
@@ -17,26 +17,20 @@
1717
#include "cxx_include/esp_modem_dce_module.hpp"
1818

1919
/**
20-
* @brief Definition of a custom modem which inherits from the GenericModule, uses all its methods
21-
* and could override any of them. Here, for demonstration purposes only, we redefine just `get_module_name()`
20+
* @brief Definition of a custom DCE uses GenericModule and all its methods
21+
* but could override command processing. Here, for demonstration purposes only,
22+
* we "inject" URC handler to the actual command processing.
23+
* This is possible since we inherit from `CommandableIf` and redefine `command()` method.
24+
* Then we're able to use declare all common methods from the command library
25+
* to be processed using "our" `command()` method (with custom URC handler).
2226
*/
23-
class MyShinyModem: public esp_modem::GenericModule {
24-
using GenericModule::GenericModule;
25-
public:
26-
esp_modem::command_result get_module_name(std::string &name) override
27-
{
28-
name = "Custom Shiny Module";
29-
return esp_modem::command_result::OK;
30-
}
31-
};
32-
3327
namespace Shiny {
3428

3529
using namespace esp_modem;
3630

37-
class DCE : public esp_modem::DCE_T<MyShinyModem>, public CommandableIf {
31+
class DCE : public esp_modem::DCE_T<GenericModule>, public CommandableIf {
3832
public:
39-
using DCE_T<MyShinyModem>::DCE_T;
33+
using DCE_T<GenericModule>::DCE_T;
4034

4135
command_result
4236
command(const std::string &cmd, got_line_cb got_line, uint32_t time_ms) override
@@ -97,7 +91,7 @@ class Factory: public ::esp_modem::dce_factory::Factory {
9791
std::shared_ptr<esp_modem::DTE> dte,
9892
esp_netif_t *netif)
9993
{
100-
return build_generic_DCE<MyShinyModem, DCE, std::unique_ptr<DCE>>(config, std::move(dte), netif);
94+
return build_generic_DCE<GenericModule, DCE, std::unique_ptr<DCE>>(config, std::move(dte), netif);
10195
}
10296

10397
};

docs/esp_modem/en/advanced_api.rst

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,17 @@ Create custom module
2626

2727
Creating a custom module is necessary if the application needs to use a specific device that is not supported
2828
and their commands differ from any of the supported devices. In this case it is recommended to define a new class
29-
representing this specific device and derive from the :cpp:class:`esp_modem::GenericModule`. In order to instantiate
30-
the appropriate DCE of this module, application could use :ref:`the DCE factory<dce_factory>`, and build the DCE with
31-
the specific module, using :cpp:func:`esp_modem::dce_factory::Factory::build`.
29+
representing this specific device and derive from the :cpp:class:`esp_modem::GenericModule` (or any other available
30+
module, that's close to your custom device). Then you can create the DCE using :ref:`the DCE factory<dce_factory>`
31+
public method :cpp:func:`esp_modem::dce_factory::Factory::create_unique_dce_from`.
3232

33-
Please refer to the implementation of the existing modules.
34-
35-
Please note that the ``modem_console`` example defines a trivial custom modem DCE which overrides one command,
33+
Please note that the ``pppos_client`` example defines a trivial custom DCE which overrides one command, and adds a new command
3634
for demonstration purposes only.
3735

36+
It is also possible to create a specific DCE class that would conform to the generic ``DCE`` API and use all generic commands,
37+
work with commands differently. This might be useful to add some custom preprocessing of commands or replies.
38+
Please check the ``modem_console`` example with ``CONFIG_EXAMPLE_MODEM_DEVICE_SHINY=y`` configuration which demonstrates
39+
overriding default ``command()`` method to implement URC processing in user space.
3840

3941
Create new communication interface
4042
----------------------------------

0 commit comments

Comments
 (0)