mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-18 13:02:21 +02:00
Add license headers, update namespaces
This commit is contained in:
@ -1,27 +1,88 @@
|
||||
#pragma once
|
||||
// Copyright 2021 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef _ESP_MODEM_API_HPP_
|
||||
#define _ESP_MODEM_API_HPP_
|
||||
|
||||
#include <memory>
|
||||
#include "cxx_include/esp_modem_dce.hpp"
|
||||
#include "cxx_include/esp_modem_dce_module.hpp"
|
||||
|
||||
class DTE;
|
||||
class GenericModule;
|
||||
class SIM7600;
|
||||
class SIM800;
|
||||
class BG96;
|
||||
struct esp_modem_dte_config;
|
||||
struct esp_modem_dce_config;
|
||||
|
||||
|
||||
namespace esp_modem {
|
||||
|
||||
class DTE;
|
||||
using dce_config = ::esp_modem_dce_config;
|
||||
using dte_config = ::esp_modem_dte_config;
|
||||
|
||||
typedef struct esp_netif_obj esp_netif_t;
|
||||
|
||||
std::shared_ptr<DTE> create_uart_dte(const esp_modem_dte_config *config);
|
||||
|
||||
/**
|
||||
* @defgroup ESP_MODEM_INIT_DTE ESP_MODEM Initialization API for DTE
|
||||
* @brief Create DTE's
|
||||
*/
|
||||
/** @addtogroup ESP_MODEM_INIT_DTE
|
||||
* @{
|
||||
*/
|
||||
|
||||
std::shared_ptr<GenericModule> create_generic_module(const std::shared_ptr<DTE>& dte, std::string &apn);
|
||||
std::shared_ptr<SIM7600> create_SIM7600_module(const std::shared_ptr<DTE>& dte, std::string &apn);
|
||||
/**
|
||||
* @brief Create UART DTE
|
||||
* @param config DTE configuration
|
||||
* @return shared ptr to DTE
|
||||
*/
|
||||
std::shared_ptr<DTE> create_uart_dte(const dte_config *config);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
std::unique_ptr<DCE> create_generic_dce_from_module(const std::shared_ptr<DTE>& dte, const std::shared_ptr<GenericModule>& dev, esp_netif_t *netif);
|
||||
std::unique_ptr<DCE> create_SIM7600_dce_from_module(const std::shared_ptr<DTE>& dte, const std::shared_ptr<SIM7600>& dev, esp_netif_t *netif);
|
||||
/**
|
||||
* @defgroup ESP_MODEM_INIT_DCE ESP_MODEM Initialization API for DCE
|
||||
* @brief Create DCE's
|
||||
*/
|
||||
/** @addtogroup ESP_MODEM_INIT_DCE
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Create DCE based on SIM7600 module
|
||||
* @param config DCE configuration
|
||||
* @param DTE reference to the communicating DTE
|
||||
* @param netif reference to the network interface
|
||||
*
|
||||
* @return unique ptr to the created DCE on success
|
||||
* nullptr on failure
|
||||
*/
|
||||
std::unique_ptr<DCE> create_SIM7600_dce(const dce_config *config, std::shared_ptr<DTE> dte, esp_netif_t *netif);
|
||||
|
||||
std::unique_ptr<DCE> create_SIM7600_dce(const esp_modem_dce_config *config, std::shared_ptr<DTE> dte, esp_netif_t *netif);
|
||||
std::unique_ptr<DCE> create_SIM800_dce(const esp_modem_dce_config *config, std::shared_ptr<DTE> dte, esp_netif_t *netif);
|
||||
std::unique_ptr<DCE> create_BG96_dce(const esp_modem_dce_config *config, std::shared_ptr<DTE> dte, esp_netif_t *netif);
|
||||
/**
|
||||
* @brief Create DCE based on SIM800 module
|
||||
*/
|
||||
std::unique_ptr<DCE> create_SIM800_dce(const dce_config *config, std::shared_ptr<DTE> dte, esp_netif_t *netif);
|
||||
|
||||
/**
|
||||
* @brief Create DCE based on BG96 module
|
||||
*/
|
||||
std::unique_ptr<DCE> create_BG96_dce(const dce_config *config, std::shared_ptr<DTE> dte, esp_netif_t *netif);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
} // namespace esp_modem
|
||||
|
||||
#endif // _ESP_MODEM_API_HPP_
|
@ -1,10 +1,32 @@
|
||||
// Copyright 2021 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Created by david on 3/8/21.
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SIMPLE_CXX_CLIENT_ESP_MODEM_CMUX_HPP
|
||||
#define SIMPLE_CXX_CLIENT_ESP_MODEM_CMUX_HPP
|
||||
#ifndef _ESP_MODEM_CMUX_HPP_
|
||||
#define _ESP_MODEM_CMUX_HPP_
|
||||
|
||||
namespace esp_modem {
|
||||
/**
|
||||
* @defgroup ESP_MODEM_CMUX ESP_MODEM CMUX class
|
||||
* @brief Definition of CMUX terminal
|
||||
*/
|
||||
/** @addtogroup ESP_MODEM_CMUX
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief CMUX state machine
|
||||
*/
|
||||
enum class cmux_state {
|
||||
INIT,
|
||||
HEADER,
|
||||
@ -13,6 +35,14 @@ enum class cmux_state {
|
||||
RECOVER,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief CMUX terminal abstraction
|
||||
*
|
||||
* This class inherits from Terminal class, as it is a Terminal, but is also composed of another Terminal,
|
||||
* which is used to communicate with the modem, i.e. the original Terminal which has been multiplexed.
|
||||
*
|
||||
* @note Implementation of CMUX protocol is experimental
|
||||
*/
|
||||
class CMUXedTerminal: public Terminal {
|
||||
public:
|
||||
explicit CMUXedTerminal(std::unique_ptr<Terminal> t, std::unique_ptr<uint8_t[]> b, size_t buff_size):
|
||||
@ -38,8 +68,12 @@ private:
|
||||
size_t consumed;
|
||||
std::unique_ptr<uint8_t[]> buffer;
|
||||
bool on_cmux(size_t len);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif //SIMPLE_CXX_CLIENT_ESP_MODEM_CMUX_HPP
|
||||
} // namespace esp_modem
|
||||
|
||||
#endif // _ESP_MODEM_CMUX_HPP_
|
||||
|
@ -1,9 +1,19 @@
|
||||
// Copyright 2021 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Created by david on 3/2/21.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
#ifndef SIMPLE_CXX_CLIENT_ESP_MODEM_COMMAND_LIBRARY_HPP
|
||||
#define SIMPLE_CXX_CLIENT_ESP_MODEM_COMMAND_LIBRARY_HPP
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef _ESP_MODEM_COMMAND_LIBRARY_HPP_
|
||||
#define _ESP_MODEM_COMMAND_LIBRARY_HPP_
|
||||
|
||||
#include "esp_modem_dte.hpp"
|
||||
#include "esp_modem_dce_module.hpp"
|
||||
@ -13,6 +23,17 @@
|
||||
namespace esp_modem {
|
||||
namespace dce_commands {
|
||||
|
||||
/**
|
||||
* @defgroup ESP_MODEM_DCE_COMMAND ESP_MODEM DCE command library
|
||||
* @brief Library of the most useful DCE commands
|
||||
*/
|
||||
/** @addtogroup ESP_MODEM_DCE_COMMAND
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Declaration of all commands is generated from esp_modem_command_declare.inc
|
||||
*/
|
||||
#define ESP_MODEM_DECLARE_DCE_COMMAND(name, return_type, TEMPLATE_ARG, MUX_ARG, ...) \
|
||||
return_type name(CommandableIf *t, ## __VA_ARGS__);
|
||||
|
||||
@ -20,8 +41,11 @@ namespace dce_commands {
|
||||
|
||||
#undef ESP_MODEM_DECLARE_DCE_COMMAND
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
} // dce_commands
|
||||
} // esp_modem
|
||||
|
||||
|
||||
#endif //SIMPLE_CXX_CLIENT_ESP_MODEM_COMMAND_LIBRARY_HPP
|
||||
#endif //_ESP_MODEM_COMMAND_LIBRARY_HPP_
|
||||
|
@ -1,16 +1,30 @@
|
||||
#pragma once
|
||||
#include <utility>
|
||||
// Copyright 2021 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef _ESP_MODEM_DCE_HPP_
|
||||
#define _ESP_MODEM_DCE_HPP_
|
||||
|
||||
#include <utility>
|
||||
#include "cxx_include/esp_modem_netif.hpp"
|
||||
#include "cxx_include/esp_modem_dce_module.hpp"
|
||||
//#include "generate/esp_modem_command_declare.inc"
|
||||
|
||||
namespace esp_modem::dce_factory {
|
||||
namespace esp_modem {
|
||||
|
||||
class Modes {
|
||||
class DCE_Mode {
|
||||
public:
|
||||
Modes(): mode(modem_mode::COMMAND_MODE) {}
|
||||
~Modes() = default;
|
||||
DCE_Mode(): mode(modem_mode::COMMAND_MODE) {}
|
||||
~DCE_Mode() = default;
|
||||
bool set(DTE *dte, ModuleIf *module, Netif &netif, modem_mode m);
|
||||
modem_mode get();
|
||||
|
||||
@ -18,7 +32,7 @@ private:
|
||||
modem_mode mode;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
template<class SpecificModule>
|
||||
class DCE_T {
|
||||
@ -51,13 +65,10 @@ protected:
|
||||
std::shared_ptr<DTE> dte;
|
||||
std::shared_ptr<SpecificModule> module;
|
||||
Netif netif;
|
||||
esp_modem::dce_factory::Modes mode;
|
||||
DCE_Mode mode;
|
||||
};
|
||||
|
||||
|
||||
//typedef DCE_T<GenericModule> DCE;
|
||||
//
|
||||
//#if 0
|
||||
class DCE: public DCE_T<GenericModule> {
|
||||
public:
|
||||
|
||||
@ -74,4 +85,7 @@ public:
|
||||
#undef ESP_MODEM_DECLARE_DCE_COMMAND
|
||||
|
||||
};
|
||||
//#endif
|
||||
|
||||
} // esp_modem
|
||||
|
||||
#endif // _ESP_MODEM_DCE_HPP_
|
@ -1,194 +1,204 @@
|
||||
// Copyright 2021 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Created by david on 3/28/21.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
#ifndef AP_TO_PPPOS_ESP_MODEM_DCE_FACTORY_HPP
|
||||
#define AP_TO_PPPOS_ESP_MODEM_DCE_FACTORY_HPP
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef _ESP_MODEM_DCE_FACTORY_HPP_
|
||||
#define _ESP_MODEM_DCE_FACTORY_HPP_
|
||||
|
||||
namespace esp_modem::dce_factory {
|
||||
|
||||
using config = esp_modem_dce_config;
|
||||
using config = ::esp_modem_dce_config;
|
||||
|
||||
class FactoryHelper {
|
||||
public:
|
||||
static std::unique_ptr<PdpContext> create_pdp_context(std::string &apn);
|
||||
class FactoryHelper {
|
||||
public:
|
||||
static std::unique_ptr<PdpContext> create_pdp_context(std::string &apn);
|
||||
|
||||
template <typename T, typename ...Args>
|
||||
static bool make(T* &t, Args&&... args)
|
||||
{
|
||||
t = new T(std::forward<Args>(args)...);
|
||||
return true;
|
||||
}
|
||||
template <typename T, typename ...Args>
|
||||
static bool make(T* &t, Args&&... args)
|
||||
{
|
||||
t = new T(std::forward<Args>(args)...);
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T, typename ...Args>
|
||||
static bool make(std::shared_ptr<T> &t, Args&&... args)
|
||||
{
|
||||
t = std::make_shared<T>(std::forward<Args>(args)...);
|
||||
return true;
|
||||
}
|
||||
template <typename T, typename ...Args>
|
||||
static bool make(std::shared_ptr<T> &t, Args&&... args)
|
||||
{
|
||||
t = std::make_shared<T>(std::forward<Args>(args)...);
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T, typename ...Args>
|
||||
static bool make(std::unique_ptr<T> &t, Args&&... args)
|
||||
{
|
||||
t = std::unique_ptr<T>(new T(std::forward<Args>(args)...));
|
||||
return true;
|
||||
}
|
||||
template <typename T, typename ...Args>
|
||||
static bool make(std::unique_ptr<T> &t, Args&&... args)
|
||||
{
|
||||
t = std::unique_ptr<T>(new T(std::forward<Args>(args)...));
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class Builder {
|
||||
public:
|
||||
explicit Builder(std::shared_ptr<DTE> dte): dte(std::move(dte))
|
||||
{
|
||||
esp_netif_config_t netif_config = ESP_NETIF_DEFAULT_PPP();
|
||||
netif = esp_netif_new(&netif_config);
|
||||
throw_if_false(netif != nullptr, "Cannot create default PPP netif");
|
||||
}
|
||||
template<typename T>
|
||||
class Builder {
|
||||
public:
|
||||
explicit Builder(std::shared_ptr<DTE> dte): dte(std::move(dte))
|
||||
{
|
||||
esp_netif_config_t netif_config = ESP_NETIF_DEFAULT_PPP();
|
||||
netif = esp_netif_new(&netif_config);
|
||||
throw_if_false(netif != nullptr, "Cannot create default PPP netif");
|
||||
}
|
||||
|
||||
Builder(std::shared_ptr<DTE> x, esp_netif_t* esp_netif): dte(std::move(x)), module(nullptr), netif(esp_netif)
|
||||
{
|
||||
throw_if_false(netif != nullptr, "Null netif");
|
||||
}
|
||||
Builder(std::shared_ptr<DTE> x, esp_netif_t* esp_netif): dte(std::move(x)), module(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<T> dev): dte(std::move(dte)), module(std::move(dev)), netif(esp_netif)
|
||||
{
|
||||
throw_if_false(netif != nullptr, "Null netif");
|
||||
}
|
||||
Builder(std::shared_ptr<DTE> dte, esp_netif_t* esp_netif, std::shared_ptr<T> dev): dte(std::move(dte)), module(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");
|
||||
}
|
||||
~Builder()
|
||||
{
|
||||
throw_if_false(module == nullptr, "module was captured or created but never used");
|
||||
}
|
||||
|
||||
|
||||
template<typename Ptr>
|
||||
bool create_module(Ptr &t, const esp_modem_dce_config *config)
|
||||
{
|
||||
return FactoryHelper::make<T>(t, dte, config);
|
||||
}
|
||||
template<typename Ptr>
|
||||
bool create_module(Ptr &t, const esp_modem_dce_config *config)
|
||||
{
|
||||
return FactoryHelper::make<T>(t, dte, config);
|
||||
}
|
||||
|
||||
template<typename DceT, typename Ptr>
|
||||
bool create(Ptr &t, const esp_modem_dce_config *config)
|
||||
{
|
||||
if (dte == nullptr)
|
||||
template<typename DceT, typename Ptr>
|
||||
bool create(Ptr &t, const esp_modem_dce_config *config)
|
||||
{
|
||||
if (dte == nullptr)
|
||||
return false;
|
||||
if (module == nullptr) {
|
||||
if (!create_module(module, config)) {
|
||||
return false;
|
||||
if (module == nullptr) {
|
||||
if (!create_module(module, config)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return FactoryHelper::make<DceT>(t, std::move(dte), std::move(module), netif);
|
||||
}
|
||||
return FactoryHelper::make<DceT>(t, std::move(dte), std::move(module), netif);
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<DTE> dte;
|
||||
std::shared_ptr<T> module;
|
||||
esp_netif_t *netif;
|
||||
};
|
||||
private:
|
||||
std::shared_ptr<DTE> dte;
|
||||
std::shared_ptr<T> module;
|
||||
esp_netif_t *netif;
|
||||
};
|
||||
|
||||
enum class Modem {
|
||||
SIM800,
|
||||
SIM7600,
|
||||
BG96,
|
||||
MinModule
|
||||
};
|
||||
enum class Modem {
|
||||
SIM800,
|
||||
SIM7600,
|
||||
BG96,
|
||||
MinModule
|
||||
};
|
||||
|
||||
class Factory {
|
||||
public:
|
||||
explicit Factory(Modem modem): m(modem) {}
|
||||
class Factory {
|
||||
public:
|
||||
explicit Factory(Modem modem): m(modem) {}
|
||||
|
||||
template <typename T, typename ...Args>
|
||||
static std::unique_ptr<DCE> build_unique(const config *cfg, Args&&... args)
|
||||
{
|
||||
return build_generic_DCE<DCE, std::unique_ptr<DCE>, T>(cfg, std::forward<Args>(args)...);
|
||||
template <typename T, typename ...Args>
|
||||
static std::unique_ptr<DCE> build_unique(const config *cfg, Args&&... args)
|
||||
{
|
||||
return build_generic_DCE<DCE, std::unique_ptr<DCE>, T>(cfg, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename T, typename ...Args>
|
||||
static DCE* build(const config *cfg, Args&&... args)
|
||||
{
|
||||
return build_generic_DCE<DCE, DCE*, T>(cfg, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
|
||||
template <typename T, typename ...Args>
|
||||
static std::shared_ptr<T> build_shared_module(const config *cfg, Args&&... args)
|
||||
{
|
||||
return build_module_T<std::shared_ptr<T>, T>(cfg, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
|
||||
template <typename ...Args>
|
||||
std::shared_ptr<GenericModule> build_shared_module(const config *cfg, Args&&... args)
|
||||
{
|
||||
switch (m) {
|
||||
case Modem::SIM800:
|
||||
return build_shared_module<SIM800>(cfg, std::forward<Args>(args)...);
|
||||
case Modem::SIM7600:
|
||||
return build_shared_module<SIM7600>(cfg, std::forward<Args>(args)...);
|
||||
case Modem::BG96:
|
||||
return build_shared_module<BG96>(cfg, std::forward<Args>(args)...);
|
||||
case Modem::MinModule:
|
||||
break;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template <typename T, typename ...Args>
|
||||
static DCE* build(const config *cfg, Args&&... args)
|
||||
{
|
||||
return build_generic_DCE<DCE, DCE*, T>(cfg, std::forward<Args>(args)...);
|
||||
template <typename ...Args>
|
||||
std::unique_ptr<DCE> build_unique(const config *cfg, Args&&... args)
|
||||
{
|
||||
switch (m) {
|
||||
case Modem::SIM800:
|
||||
return build_unique<SIM800>(cfg, std::forward<Args>(args)...);
|
||||
case Modem::SIM7600:
|
||||
return build_unique<SIM7600>(cfg, std::forward<Args>(args)...);
|
||||
case Modem::BG96:
|
||||
return build_unique<BG96>(cfg, std::forward<Args>(args)...);
|
||||
case Modem::MinModule:
|
||||
break;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
template <typename T, typename ...Args>
|
||||
static std::shared_ptr<T> build_shared_module(const config *cfg, Args&&... args)
|
||||
{
|
||||
return build_module_T<std::shared_ptr<T>, T>(cfg, std::forward<Args>(args)...);
|
||||
}
|
||||
private:
|
||||
Modem m;
|
||||
|
||||
template <typename T, typename U, typename ...Args>
|
||||
static bool build_module_T(U &t, const config *cfg, Args&&... args)
|
||||
{
|
||||
Builder<T> b(std::forward<Args>(args)...);
|
||||
return b.create_module(t, cfg);
|
||||
}
|
||||
|
||||
template <typename ...Args>
|
||||
std::shared_ptr<GenericModule> build_shared_module(const config *cfg, Args&&... args)
|
||||
{
|
||||
switch (m) {
|
||||
case Modem::SIM800:
|
||||
return build_shared_module<SIM800>(cfg, std::forward<Args>(args)...);
|
||||
case Modem::SIM7600:
|
||||
return build_shared_module<SIM7600>(cfg, std::forward<Args>(args)...);
|
||||
case Modem::BG96:
|
||||
return build_shared_module<BG96>(cfg, std::forward<Args>(args)...);
|
||||
case Modem::MinModule:
|
||||
break;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
template <typename T, typename U, typename ...Args>
|
||||
static T build_module_T(const config *cfg, Args&&... args)
|
||||
{
|
||||
T module;
|
||||
if (build_module_T<U>(module, cfg, std::forward<Args>(args)...))
|
||||
return module;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template <typename ...Args>
|
||||
std::unique_ptr<DCE> build_unique(const config *cfg, Args&&... args)
|
||||
{
|
||||
switch (m) {
|
||||
case Modem::SIM800:
|
||||
return build_unique<SIM800>(cfg, std::forward<Args>(args)...);
|
||||
case Modem::SIM7600:
|
||||
return build_unique<SIM7600>(cfg, std::forward<Args>(args)...);
|
||||
case Modem::BG96:
|
||||
return build_unique<BG96>(cfg, std::forward<Args>(args)...);
|
||||
case Modem::MinModule:
|
||||
break;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
template <typename Dce, typename DcePtr, typename Module, typename ...Args>
|
||||
static bool build_generic_DCE(DcePtr &t, const config *cfg, Args&&... args)
|
||||
{
|
||||
Builder<Module> b(std::forward<Args>(args)...);
|
||||
return b.template create<Dce>(t, cfg);
|
||||
}
|
||||
|
||||
protected:
|
||||
template <typename Dce, typename DcePtr, typename Module, typename ...Args>
|
||||
static DcePtr build_generic_DCE(const config *cfg, Args&&... args)
|
||||
{
|
||||
DcePtr dce;
|
||||
if (build_generic_DCE<Dce, DcePtr, Module>(dce, cfg, std::forward<Args>(args)...))
|
||||
return dce;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
Modem m;
|
||||
};
|
||||
|
||||
template <typename T, typename U, typename ...Args>
|
||||
static bool build_module_T(U &t, const config *cfg, Args&&... args)
|
||||
{
|
||||
Builder<T> b(std::forward<Args>(args)...);
|
||||
return b.create_module(t, cfg);
|
||||
}
|
||||
} // namespace esp_modem::dce_factory
|
||||
|
||||
template <typename T, typename U, typename ...Args>
|
||||
static T build_module_T(const config *cfg, Args&&... args)
|
||||
{
|
||||
T module;
|
||||
if (build_module_T<U>(module, cfg, std::forward<Args>(args)...))
|
||||
return module;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template <typename Dce, typename DcePtr, typename Module, typename ...Args>
|
||||
static bool build_generic_DCE(DcePtr &t, const config *cfg, Args&&... args)
|
||||
{
|
||||
Builder<Module> b(std::forward<Args>(args)...);
|
||||
return b.template create<Dce>(t, cfg);
|
||||
}
|
||||
|
||||
protected:
|
||||
template <typename Dce, typename DcePtr, typename Module, typename ...Args>
|
||||
static DcePtr build_generic_DCE(const config *cfg, Args&&... args)
|
||||
{
|
||||
DcePtr dce;
|
||||
if (build_generic_DCE<Dce, DcePtr, Module>(dce, cfg, std::forward<Args>(args)...))
|
||||
return dce;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // esp_modem
|
||||
|
||||
#endif //AP_TO_PPPOS_ESP_MODEM_DCE_FACTORY_HPP
|
||||
#endif // _ESP_MODEM_DCE_FACTORY_HPP_
|
||||
|
@ -1,4 +1,20 @@
|
||||
#pragma once
|
||||
// Copyright 2021 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef _ESP_MODEM_DCE_MODULE_
|
||||
#define _ESP_MODEM_DCE_MODULE_
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include "generate/esp_modem_command_declare.inc"
|
||||
@ -6,8 +22,11 @@
|
||||
#include "cxx_include/esp_modem_types.hpp"
|
||||
#include "esp_modem_dce_config.h"
|
||||
|
||||
namespace esp_modem {
|
||||
|
||||
enum class command_result;
|
||||
class DTE;
|
||||
struct PdpContext;
|
||||
|
||||
class GenericModule: public ModuleIf {
|
||||
public:
|
||||
@ -70,3 +89,8 @@ class BG96: public GenericModule {
|
||||
public:
|
||||
command_result get_module_name(std::string& name) override;
|
||||
};
|
||||
|
||||
|
||||
} // namespace esp_modem
|
||||
|
||||
#endif // _ESP_MODEM_DCE_MODULE_
|
@ -1,81 +1,84 @@
|
||||
#ifndef SIMPLE_CXX_CLIENT_ESP_MODEM_DTE_HPP
|
||||
#define SIMPLE_CXX_CLIENT_ESP_MODEM_DTE_HPP
|
||||
// Copyright 2021 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef _ESP_MODEM_DTE_HPP_
|
||||
#define _ESP_MODEM_DTE_HPP_
|
||||
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include <exception>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <utility>
|
||||
#include "esp_err.h"
|
||||
#include "cxx_include/esp_modem_primitives.hpp"
|
||||
#include "cxx_include/esp_modem_terminal.hpp"
|
||||
#include "cxx_include/esp_modem_cmux.hpp"
|
||||
#include "cxx_include/esp_modem_types.hpp"
|
||||
|
||||
namespace esp_modem {
|
||||
|
||||
const int DTE_BUFFER_SIZE = 1024;
|
||||
|
||||
|
||||
class DTE: public CommandableIf {
|
||||
class DTE : public CommandableIf {
|
||||
public:
|
||||
explicit DTE(std::unique_ptr<Terminal> t);
|
||||
~DTE() = default;
|
||||
explicit DTE(std::unique_ptr<Terminal> t);
|
||||
|
||||
// std::unique_ptr<Terminal> detach() { return std::move(term); }
|
||||
// void attach(std::unique_ptr<Terminal> t) { term = std::move(t); }
|
||||
// void set_line_cb(got_line f) { on_line_cb = std::move(f); }
|
||||
int write(uint8_t *data, size_t len) { return term->write(data, len); }
|
||||
int read(uint8_t **d, size_t len) {
|
||||
~DTE() = default;
|
||||
|
||||
int write(uint8_t *data, size_t len) { return term->write(data, len); }
|
||||
|
||||
int read(uint8_t **d, size_t len) {
|
||||
auto data_to_read = std::min(len, buffer_size);
|
||||
auto data = buffer.get();
|
||||
auto actual_len = term->read(data, data_to_read);
|
||||
*d = data;
|
||||
return actual_len;
|
||||
}
|
||||
void set_data_cb(std::function<bool(size_t len)> f)
|
||||
{
|
||||
// on_data = std::move(f);
|
||||
term->set_data_cb(std::move(f));
|
||||
|
||||
void set_data_cb(std::function<bool(size_t len)> f) {
|
||||
term->set_data_cb(std::move(f));
|
||||
}
|
||||
// std::shared_ptr<uint8_t[]> get_buffer() { return buffer;}
|
||||
|
||||
void start() { term->start(); }
|
||||
|
||||
void data_mode_closed() { term->stop(); }
|
||||
void set_mode(modem_mode m) {
|
||||
term->start(); mode = m;
|
||||
|
||||
void set_mode(modem_mode m) {
|
||||
term->start();
|
||||
mode = m;
|
||||
if (m == modem_mode::DATA_MODE) {
|
||||
term->set_data_cb(on_data);
|
||||
} else if (m == modem_mode::CMUX_MODE) {
|
||||
setup_cmux();
|
||||
}
|
||||
}
|
||||
command_result command(const std::string& command, got_line_cb got_line, uint32_t time_ms) override;
|
||||
// std::shared_ptr<uint8_t[]> buffer;
|
||||
|
||||
void send_cmux_command(uint8_t i, const std::string& command);
|
||||
command_result command(const std::string &command, got_line_cb got_line, uint32_t time_ms) override;
|
||||
|
||||
void send_cmux_command(uint8_t i, const std::string &command);
|
||||
|
||||
private:
|
||||
Lock lock;
|
||||
// std::unique_ptr<CMUXedTerminal> cmux;
|
||||
|
||||
void setup_cmux();
|
||||
// void send_sabm(size_t dlci);
|
||||
// CMUXHelper cmux;
|
||||
|
||||
static const size_t GOT_LINE = BIT0;
|
||||
size_t buffer_size;
|
||||
size_t consumed;
|
||||
// std::shared_ptr<std::vector<uint8_t>> buffer;
|
||||
std::unique_ptr<uint8_t[]> buffer;
|
||||
std::unique_ptr<Terminal> term;
|
||||
// got_line_cb on_line;
|
||||
modem_mode mode;
|
||||
signal_group signal;
|
||||
std::function<bool(size_t len)> on_data;
|
||||
|
||||
|
||||
};
|
||||
|
||||
} // namespace esp_modem
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif //SIMPLE_CXX_CLIENT_ESP_MODEM_DTE_HPP
|
||||
#endif // _ESP_MODEM_DTE_HPP_
|
||||
|
@ -1,13 +1,25 @@
|
||||
// Copyright 2021 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Created by david on 2/26/21.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
#ifndef SIMPLE_CXX_CLIENT_ESP_MODEM_NETIF_HPP
|
||||
#define SIMPLE_CXX_CLIENT_ESP_MODEM_NETIF_HPP
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef _ESP_MODEM_NETIF_HPP
|
||||
#define _ESP_MODEM_NETIF_HPP
|
||||
|
||||
#include "esp_netif.h"
|
||||
#include "cxx_include/esp_modem_primitives.hpp"
|
||||
|
||||
namespace esp_modem {
|
||||
|
||||
class DTE;
|
||||
class Netif;
|
||||
|
||||
@ -16,19 +28,25 @@ struct ppp_netif_driver {
|
||||
Netif *ppp;
|
||||
};
|
||||
|
||||
|
||||
class Netif {
|
||||
public:
|
||||
explicit Netif(std::shared_ptr<DTE> e, esp_netif_t *netif);
|
||||
|
||||
~Netif();
|
||||
|
||||
void start();
|
||||
// void notify_ppp_exit() { signal.set(PPP_EXIT); }
|
||||
void wait_until_ppp_exits() { signal.wait(PPP_EXIT, 50000); }
|
||||
|
||||
void wait_until_ppp_exits() { signal.wait(PPP_EXIT, 30000); }
|
||||
|
||||
void stop();
|
||||
|
||||
private:
|
||||
void receive(uint8_t *data, size_t len);
|
||||
|
||||
static esp_err_t esp_modem_dte_transmit(void *h, void *buffer, size_t len);
|
||||
static esp_err_t esp_modem_post_attach(esp_netif_t * esp_netif, void * args);
|
||||
|
||||
static esp_err_t esp_modem_post_attach(esp_netif_t *esp_netif, void *args);
|
||||
|
||||
static void on_ppp_changed(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data);
|
||||
|
||||
std::shared_ptr<DTE> ppp_dte;
|
||||
@ -37,8 +55,8 @@ private:
|
||||
signal_group signal;
|
||||
static const size_t PPP_STARTED = BIT0;
|
||||
static const size_t PPP_EXIT = BIT1;
|
||||
|
||||
};
|
||||
|
||||
} // namespace esp_modem
|
||||
|
||||
#endif //SIMPLE_CXX_CLIENT_ESP_MODEM_NETIF_HPP
|
||||
#endif // _ESP_MODEM_NETIF_HPP
|
||||
|
@ -1,13 +1,25 @@
|
||||
// Copyright 2021 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Created by david on 2/26/21.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
#ifndef SIMPLE_CXX_CLIENT_ESP_MODEM_PRIMITIVES_HPP
|
||||
#define SIMPLE_CXX_CLIENT_ESP_MODEM_PRIMITIVES_HPP
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef _ESP_MODEM_PRIMITIVES_HPP_
|
||||
#define _ESP_MODEM_PRIMITIVES_HPP_
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
namespace esp_modem {
|
||||
|
||||
#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
|
||||
#define THROW(exception) throw(exception)
|
||||
class esp_err_exception: virtual public std::exception {
|
||||
@ -114,4 +126,6 @@ struct signal_group {
|
||||
EventGroupHandle_t event_group;
|
||||
};
|
||||
|
||||
#endif //SIMPLE_CXX_CLIENT_ESP_MODEM_PRIMITIVES_HPP
|
||||
} // namespace esp_modem
|
||||
|
||||
#endif // _ESP_MODEM_PRIMITIVES_HPP_
|
||||
|
@ -1,10 +1,19 @@
|
||||
// Copyright 2021 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Created by david on 3/3/21.
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SIMPLE_CXX_CLIENT_ESP_MODEM_TERMINAL_HPP
|
||||
#define SIMPLE_CXX_CLIENT_ESP_MODEM_TERMINAL_HPP
|
||||
|
||||
#ifndef _ESP_MODEM_TERMINAL_HPP_
|
||||
#define _ESP_MODEM_TERMINAL_HPP_
|
||||
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
@ -15,6 +24,7 @@
|
||||
#include "esp_err.h"
|
||||
#include "esp_modem_primitives.hpp"
|
||||
|
||||
namespace esp_modem {
|
||||
|
||||
enum class terminal_error {
|
||||
BUFFER_OVERFLOW,
|
||||
@ -25,12 +35,19 @@ enum class terminal_error {
|
||||
class Terminal {
|
||||
public:
|
||||
virtual ~Terminal() = default;
|
||||
|
||||
virtual void set_data_cb(std::function<bool(size_t len)> f) { on_data = std::move(f); }
|
||||
|
||||
void set_error_cb(std::function<void(terminal_error)> f) { on_error = std::move(f); }
|
||||
|
||||
virtual int write(uint8_t *data, size_t len) = 0;
|
||||
|
||||
virtual int read(uint8_t *data, size_t len) = 0;
|
||||
|
||||
virtual void start() = 0;
|
||||
|
||||
virtual void stop() = 0;
|
||||
|
||||
virtual size_t max_virtual_terms() { return 1; }
|
||||
|
||||
protected:
|
||||
@ -38,6 +55,6 @@ protected:
|
||||
std::function<void(terminal_error)> on_error;
|
||||
};
|
||||
|
||||
} // namespace esp_modem
|
||||
|
||||
|
||||
#endif //SIMPLE_CXX_CLIENT_ESP_MODEM_TERMINAL_HPP
|
||||
#endif // _ESP_MODEM_TERMINAL_HPP_
|
||||
|
@ -1,10 +1,21 @@
|
||||
// Copyright 2021 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Created by david on 3/8/21.
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SIMPLE_CXX_CLIENT_ESP_MODEM_TYPES_HPP
|
||||
#define SIMPLE_CXX_CLIENT_ESP_MODEM_TYPES_HPP
|
||||
#ifndef _ESP_MODEM_TYPES_HPP_
|
||||
#define _ESP_MODEM_TYPES_HPP_
|
||||
|
||||
namespace esp_modem {
|
||||
|
||||
enum class modem_mode {
|
||||
UNDEF,
|
||||
@ -22,8 +33,10 @@ enum class command_result {
|
||||
typedef std::function<command_result(uint8_t *data, size_t len)> got_line_cb;
|
||||
|
||||
struct PdpContext {
|
||||
explicit PdpContext(std::string& apn): context_id(1), protocol_type("IP"), apn(apn) {}
|
||||
explicit PdpContext(const char *apn): context_id(1), protocol_type("IP"), apn(apn) {}
|
||||
explicit PdpContext(std::string &apn) : context_id(1), protocol_type("IP"), apn(apn) {}
|
||||
|
||||
explicit PdpContext(const char *apn) : context_id(1), protocol_type("IP"), apn(apn) {}
|
||||
|
||||
size_t context_id;
|
||||
std::string protocol_type;
|
||||
std::string apn;
|
||||
@ -31,13 +44,16 @@ struct PdpContext {
|
||||
|
||||
class CommandableIf {
|
||||
public:
|
||||
virtual command_result command(const std::string& command, got_line_cb got_line, uint32_t time_ms) = 0;
|
||||
virtual command_result command(const std::string &command, got_line_cb got_line, uint32_t time_ms) = 0;
|
||||
};
|
||||
|
||||
class ModuleIf {
|
||||
public:
|
||||
virtual bool setup_data_mode() = 0;
|
||||
|
||||
virtual bool set_mode(modem_mode mode) = 0;
|
||||
};
|
||||
|
||||
#endif //SIMPLE_CXX_CLIENT_ESP_MODEM_TYPES_HPP
|
||||
} // namespace esp_modem
|
||||
|
||||
#endif // _ESP_MODEM_TYPES_HPP_
|
||||
|
Reference in New Issue
Block a user