mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-20 14:02:21 +02:00
Final cleanup of the docs and examples
This commit is contained in:
@ -49,7 +49,13 @@ using dte_config = ::esp_modem_dte_config;
|
||||
*/
|
||||
std::shared_ptr<DTE> create_uart_dte(const dte_config *config);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Create VFS DTE
|
||||
* @param config DTE configuration
|
||||
* @return shared ptr to DTE on success
|
||||
* nullptr on failure (either due to insufficient memory or wrong dte configuration)
|
||||
* if exceptions are disabled the API abort()'s on error
|
||||
*/
|
||||
std::shared_ptr<DTE> create_vfs_dte(const dte_config *config);
|
||||
|
||||
|
||||
|
@ -53,8 +53,8 @@ template<class SpecificModule>
|
||||
class DCE_T {
|
||||
static_assert(std::is_base_of<ModuleIf, SpecificModule>::value, "DCE must be instantiated with Module class only");
|
||||
public:
|
||||
explicit DCE_T(const std::shared_ptr<DTE>& dte, std::shared_ptr<SpecificModule> device, esp_netif_t * netif):
|
||||
dte(dte), module(std::move(device)), netif(dte, netif)
|
||||
explicit DCE_T(const std::shared_ptr<DTE>& dte, std::shared_ptr<SpecificModule> dev, esp_netif_t * netif):
|
||||
dte(dte), device(std::move(dev)), netif(dte, netif)
|
||||
{ }
|
||||
|
||||
~DCE_T() = default;
|
||||
@ -68,21 +68,18 @@ public:
|
||||
|
||||
void set_cmux() { set_mode(modem_mode::CMUX_MODE); }
|
||||
|
||||
ModuleIf* get_module() { return module.get(); }
|
||||
|
||||
SpecificModule* get_module() { return device.get(); }
|
||||
|
||||
command_result command(const std::string& command, got_line_cb got_line, uint32_t time_ms)
|
||||
{
|
||||
return dte->command(command, std::move(got_line), time_ms);
|
||||
}
|
||||
|
||||
bool set_mode(modem_mode m) { return mode.set(dte.get(), module.get(), netif, m); }
|
||||
bool set_mode(modem_mode m) { return mode.set(dte.get(), device.get(), netif, m); }
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
std::shared_ptr<DTE> dte;
|
||||
std::shared_ptr<SpecificModule> module;
|
||||
std::shared_ptr<SpecificModule> device;
|
||||
Netif netif;
|
||||
DCE_Mode mode;
|
||||
};
|
||||
@ -99,7 +96,7 @@ public:
|
||||
template <typename ...Agrs> \
|
||||
return_type name(Agrs&&... args) \
|
||||
{ \
|
||||
return module->name(std::forward<Agrs>(args)...); \
|
||||
return device->name(std::forward<Agrs>(args)...); \
|
||||
}
|
||||
|
||||
DECLARE_ALL_COMMAND_APIS(forwards name(...) { device->name(...); } )
|
||||
|
@ -64,19 +64,19 @@ template<typename Module>
|
||||
class Builder {
|
||||
static_assert(std::is_base_of<ModuleIf, Module>::value, "Builder must be used only for Module classes");
|
||||
public:
|
||||
Builder(std::shared_ptr<DTE> x, esp_netif_t* esp_netif): dte(std::move(x)), module(nullptr), netif(esp_netif)
|
||||
Builder(std::shared_ptr<DTE> x, esp_netif_t* esp_netif): dte(std::move(x)), device(nullptr), netif(esp_netif)
|
||||
{
|
||||
throw_if_false(netif != nullptr, "Null netif");
|
||||
}
|
||||
|
||||
Builder(std::shared_ptr<DTE> dte, esp_netif_t* esp_netif, std::shared_ptr<Module> dev): dte(std::move(dte)), module(std::move(dev)), netif(esp_netif)
|
||||
Builder(std::shared_ptr<DTE> dte, esp_netif_t* esp_netif, std::shared_ptr<Module> dev): dte(std::move(dte)), device(std::move(dev)), netif(esp_netif)
|
||||
{
|
||||
throw_if_false(netif != nullptr, "Null netif");
|
||||
}
|
||||
|
||||
~Builder()
|
||||
{
|
||||
throw_if_false(module == nullptr, "module was captured or created but never used");
|
||||
throw_if_false(device == nullptr, "module was captured or created but never used");
|
||||
}
|
||||
|
||||
template<typename Ptr>
|
||||
@ -90,17 +90,17 @@ public:
|
||||
{
|
||||
if (dte == nullptr)
|
||||
return nullptr;
|
||||
if (module == nullptr) {
|
||||
module = create_module<decltype(module)>(config);
|
||||
if (module == nullptr)
|
||||
if (device == nullptr) {
|
||||
device = create_module<decltype(device)>(config);
|
||||
if (device == nullptr)
|
||||
return nullptr;
|
||||
}
|
||||
return FactoryHelper::make<DceT, Ptr>(std::move(dte), std::move(module), netif);
|
||||
return FactoryHelper::make<DceT, Ptr>(std::move(dte), std::move(device), netif);
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<DTE> dte;
|
||||
std::shared_ptr<Module> module;
|
||||
std::shared_ptr<Module> device;
|
||||
esp_netif_t *netif;
|
||||
};
|
||||
|
||||
|
@ -43,10 +43,20 @@ struct PdpContext;
|
||||
*/
|
||||
class GenericModule: public ModuleIf {
|
||||
public:
|
||||
/**
|
||||
* @brief We can construct a generic device with an existent DTE and it's configuration
|
||||
* The configuration could be either the dce-config struct or just a pdp context
|
||||
*/
|
||||
explicit GenericModule(std::shared_ptr<DTE> dte, std::unique_ptr<PdpContext> pdp):
|
||||
dte(std::move(dte)), pdp(std::move(pdp)) {}
|
||||
explicit GenericModule(std::shared_ptr<DTE> dte, const esp_modem_dce_config* config);
|
||||
|
||||
/**
|
||||
* @brief This is a mandatory method for ModuleIf class, which sets up the device
|
||||
* to be able to connect to the network. This typically consists of setting basic
|
||||
* communication parameters and setting the PDP (defining logical access point
|
||||
* to cellular network)
|
||||
*/
|
||||
bool setup_data_mode() override
|
||||
{
|
||||
if (set_echo(false) != command_result::OK)
|
||||
@ -56,6 +66,10 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This is a mandatory method of ModuleIf class, which defines
|
||||
* basic commands for switching between DATA, COMMAND and CMUX modes
|
||||
*/
|
||||
bool set_mode(modem_mode mode) override
|
||||
{
|
||||
if (mode == modem_mode::DATA_MODE) {
|
||||
@ -70,7 +84,17 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Additional method providing runtime configuration of PDP context
|
||||
*/
|
||||
void configure_pdp_context(std::unique_ptr<PdpContext> new_pdp)
|
||||
{
|
||||
pdp = std::move(new_pdp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Common DCE commands generated from the API AT list
|
||||
*/
|
||||
#define ESP_MODEM_DECLARE_DCE_COMMAND(name, return_type, num, ...) \
|
||||
virtual return_type name(__VA_ARGS__);
|
||||
|
||||
@ -80,8 +104,8 @@ public:
|
||||
|
||||
|
||||
protected:
|
||||
std::shared_ptr<DTE> dte;
|
||||
std::unique_ptr<PdpContext> pdp;
|
||||
std::shared_ptr<DTE> dte; /*!< Generic device needs the DTE as a channel talk to the module using AT commands */
|
||||
std::unique_ptr<PdpContext> pdp; /*!< It also needs a PDP data, const information used for setting up cellular network */
|
||||
};
|
||||
|
||||
// Definitions of other supported modules with some specific commands overwritten
|
||||
|
Reference in New Issue
Block a user