mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-06-25 17:31:33 +02:00
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 https://github.com/espressif/esp-protocols/issues/452
This commit is contained in:
@ -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
|
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
*/
|
*/
|
||||||
@ -17,26 +17,20 @@
|
|||||||
#include "cxx_include/esp_modem_dce_module.hpp"
|
#include "cxx_include/esp_modem_dce_module.hpp"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Definition of a custom modem which inherits from the GenericModule, uses all its methods
|
* @brief Definition of a custom DCE uses GenericModule and all its methods
|
||||||
* and could override any of them. Here, for demonstration purposes only, we redefine just `get_module_name()`
|
* 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 {
|
namespace Shiny {
|
||||||
|
|
||||||
using namespace esp_modem;
|
using namespace esp_modem;
|
||||||
|
|
||||||
class DCE : public esp_modem::DCE_T<MyShinyModem>, public CommandableIf {
|
class DCE : public esp_modem::DCE_T<GenericModule>, public CommandableIf {
|
||||||
public:
|
public:
|
||||||
using DCE_T<MyShinyModem>::DCE_T;
|
using DCE_T<GenericModule>::DCE_T;
|
||||||
|
|
||||||
command_result
|
command_result
|
||||||
command(const std::string &cmd, got_line_cb got_line, uint32_t time_ms) override
|
command(const std::string &cmd, got_line_cb got_line, uint32_t time_ms) override
|
||||||
@ -97,7 +91,7 @@ public:
|
|||||||
std::shared_ptr<esp_modem::DTE> dte,
|
std::shared_ptr<esp_modem::DTE> dte,
|
||||||
esp_netif_t *netif)
|
esp_netif_t *netif)
|
||||||
{
|
{
|
||||||
return build_generic_DCE<MyShinyModem, DCE, std::unique_ptr<DCE>>(config, std::move(dte), netif);
|
return build_generic_DCE<GenericModule, DCE, std::unique_ptr<DCE>>(config, std::move(dte), netif);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -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
|
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
|
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
|
representing this specific device and derive from the :cpp:class:`esp_modem::GenericModule` (or any other available
|
||||||
the appropriate DCE of this module, application could use :ref:`the DCE factory<dce_factory>`, and build the DCE with
|
module, that's close to your custom device). Then you can create the DCE using :ref:`the DCE factory<dce_factory>`
|
||||||
the specific module, using :cpp:func:`esp_modem::dce_factory::Factory::build`.
|
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 ``pppos_client`` example defines a trivial custom DCE which overrides one command, and adds a new command
|
||||||
|
|
||||||
Please note that the ``modem_console`` example defines a trivial custom modem DCE which overrides one command,
|
|
||||||
for demonstration purposes only.
|
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
|
Create new communication interface
|
||||||
----------------------------------
|
----------------------------------
|
||||||
|
Reference in New Issue
Block a user