diff --git a/components/esp_modem/examples/modem_console/main/my_module_dce.hpp b/components/esp_modem/examples/modem_console/main/my_module_dce.hpp index 43205bfb2..fe9fb4450 100644 --- a/components/esp_modem/examples/modem_console/main/my_module_dce.hpp +++ b/components/esp_modem/examples/modem_console/main/my_module_dce.hpp @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -17,26 +17,20 @@ #include "cxx_include/esp_modem_dce_module.hpp" /** - * @brief Definition of a custom modem which inherits from the GenericModule, uses all its methods - * and could override any of them. Here, for demonstration purposes only, we redefine just `get_module_name()` + * @brief Definition of a custom DCE uses GenericModule and all its methods + * but could override command processing. Here, for demonstration purposes only, + * we "inject" URC handler to the actual command processing. + * This is possible since we inherit from `CommandableIf` and redefine `command()` method. + * Then we're able to use declare all common methods from the command library + * to be processed using "our" `command()` method (with custom URC handler). */ -class MyShinyModem: public esp_modem::GenericModule { - using GenericModule::GenericModule; -public: - esp_modem::command_result get_module_name(std::string &name) override - { - name = "Custom Shiny Module"; - return esp_modem::command_result::OK; - } -}; - namespace Shiny { using namespace esp_modem; -class DCE : public esp_modem::DCE_T, public CommandableIf { +class DCE : public esp_modem::DCE_T, public CommandableIf { public: - using DCE_T::DCE_T; + using DCE_T::DCE_T; command_result command(const std::string &cmd, got_line_cb got_line, uint32_t time_ms) override @@ -97,7 +91,7 @@ public: std::shared_ptr dte, esp_netif_t *netif) { - return build_generic_DCE>(config, std::move(dte), netif); + return build_generic_DCE>(config, std::move(dte), netif); } }; diff --git a/docs/esp_modem/en/advanced_api.rst b/docs/esp_modem/en/advanced_api.rst index a487398b3..4df349f8f 100644 --- a/docs/esp_modem/en/advanced_api.rst +++ b/docs/esp_modem/en/advanced_api.rst @@ -26,15 +26,17 @@ Create custom module Creating a custom module is necessary if the application needs to use a specific device that is not supported and their commands differ from any of the supported devices. In this case it is recommended to define a new class -representing this specific device and derive from the :cpp:class:`esp_modem::GenericModule`. In order to instantiate -the appropriate DCE of this module, application could use :ref:`the DCE factory`, and build the DCE with -the specific module, using :cpp:func:`esp_modem::dce_factory::Factory::build`. +representing this specific device and derive from the :cpp:class:`esp_modem::GenericModule` (or any other available +module, that's close to your custom device). Then you can create the DCE using :ref:`the DCE factory` +public method :cpp:func:`esp_modem::dce_factory::Factory::create_unique_dce_from`. -Please refer to the implementation of the existing modules. - -Please note that the ``modem_console`` example defines a trivial custom modem DCE which overrides one command, +Please note that the ``pppos_client`` example defines a trivial custom DCE which overrides one command, and adds a new command for demonstration purposes only. +It is also possible to create a specific DCE class that would conform to the generic ``DCE`` API and use all generic commands, +work with commands differently. This might be useful to add some custom preprocessing of commands or replies. +Please check the ``modem_console`` example with ``CONFIG_EXAMPLE_MODEM_DEVICE_SHINY=y`` configuration which demonstrates +overriding default ``command()`` method to implement URC processing in user space. Create new communication interface ----------------------------------