Applied astyle code formatting

This commit is contained in:
David Cermak
2021-06-01 10:21:51 +02:00
parent dc64f862c4
commit a61e9e2d40
43 changed files with 865 additions and 662 deletions

View File

@ -55,7 +55,7 @@ class CMuxInstance;
class CMux {
public:
explicit CMux(std::unique_ptr<Terminal> t, std::unique_ptr<uint8_t[]> b, size_t buff_size):
term(std::move(t)), buffer_size(buff_size), buffer(std::move(b)), payload_start(nullptr), total_payload_size(0) {}
term(std::move(t)), buffer_size(buff_size), buffer(std::move(b)), payload_start(nullptr), total_payload_size(0) {}
~CMux() = default;
[[nodiscard]] bool init();
void set_read_cb(int inst, std::function<bool(uint8_t *data, size_t len)> f);
@ -92,9 +92,18 @@ class CMuxInstance: public Terminal {
public:
explicit CMuxInstance(std::shared_ptr<CMux> parent, int i): cmux(std::move(parent)), instance(i) {}
int write(uint8_t *data, size_t len) override { return cmux->write(instance, data, len); }
void set_read_cb(std::function<bool(uint8_t *data, size_t len)> f) override { return cmux->set_read_cb(instance, std::move(f)); }
int read(uint8_t *data, size_t len) override { return 0; }
int write(uint8_t *data, size_t len) override
{
return cmux->write(instance, data, len);
}
void set_read_cb(std::function<bool(uint8_t *data, size_t len)> f) override
{
return cmux->set_read_cb(instance, std::move(f));
}
int read(uint8_t *data, size_t len) override
{
return 0;
}
void start() override { }
void stop() override { }
private:

View File

@ -36,17 +36,17 @@ namespace dce_commands {
#define ESP_MODEM_DECLARE_DCE_COMMAND(name, return_type, num, ...) \
return_type name(CommandableIf *t, ## __VA_ARGS__);
DECLARE_ALL_COMMAND_APIS(declare name(Commandable *p, ...);)
DECLARE_ALL_COMMAND_APIS(declare name(Commandable *p, ...);)
#undef ESP_MODEM_DECLARE_DCE_COMMAND
/**
* @brief Following commands that are different for some specific modules
*/
command_result get_battery_status_sim7xxx(CommandableIf* t, int& voltage, int &bcs, int &bcl);
command_result power_down_sim7xxx(CommandableIf* t);
command_result power_down_sim8xx(CommandableIf* t);
command_result set_data_mode_sim8xx(CommandableIf* t);
command_result get_battery_status_sim7xxx(CommandableIf *t, int &voltage, int &bcs, int &bcl);
command_result power_down_sim7xxx(CommandableIf *t);
command_result power_down_sim8xx(CommandableIf *t);
command_result set_data_mode_sim8xx(CommandableIf *t);
/**
* @}

View File

@ -52,8 +52,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> dev, esp_netif_t * netif):
dte(dte), device(std::move(dev)), 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;
@ -61,20 +61,35 @@ public:
/**
* @brief Set data mode!
*/
void set_data() { set_mode(modem_mode::DATA_MODE); }
void set_data()
{
set_mode(modem_mode::DATA_MODE);
}
void exit_data() { set_mode(modem_mode::COMMAND_MODE); }
void exit_data()
{
set_mode(modem_mode::COMMAND_MODE);
}
void set_cmux() { set_mode(modem_mode::CMUX_MODE); }
void set_cmux()
{
set_mode(modem_mode::CMUX_MODE);
}
SpecificModule* get_module() { return device.get(); }
SpecificModule *get_module()
{
return device.get();
}
command_result command(const std::string& command, got_line_cb got_line, uint32_t time_ms)
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(), device.get(), netif, m); }
bool set_mode(modem_mode m)
{
return mode.set(dte.get(), device.get(), netif, m);
}
protected:
std::shared_ptr<DTE> dte;
@ -98,7 +113,10 @@ public:
return device->name(std::forward<Agrs>(args)...); \
}
DECLARE_ALL_COMMAND_APIS(forwards name(...) { device->name(...); } )
DECLARE_ALL_COMMAND_APIS(forwards name(...)
{
device->name(...);
} )
#undef ESP_MODEM_DECLARE_DCE_COMMAND

View File

@ -38,19 +38,19 @@ public:
static std::unique_ptr<PdpContext> create_pdp_context(std::string &apn);
template <typename T, typename T_Ptr, typename ...Args>
static auto make(Args&&... args) -> typename std::enable_if<std::is_same<T_Ptr, T*>::value, T*>::type
static auto make(Args &&... args) -> typename std::enable_if<std::is_same<T_Ptr, T *>::value, T *>::type
{
return new T(std::forward<Args>(args)...);
}
template <typename T, typename T_Ptr, typename ...Args>
static auto make(Args&&... args) -> typename std::enable_if<std::is_same<T_Ptr, std::shared_ptr<T>>::value, std::shared_ptr<T>>::type
static auto make(Args &&... args) -> typename std::enable_if<std::is_same<T_Ptr, std::shared_ptr<T>>::value, std::shared_ptr<T>>::type
{
return std::make_shared<T>(std::forward<Args>(args)...);
}
template <typename T, typename T_Ptr = std::unique_ptr<T>, typename ...Args>
static auto make(Args&&... args) -> typename std::enable_if<std::is_same<T_Ptr, std::unique_ptr<T>>::value, std::unique_ptr<T>>::type
static auto make(Args && ... args) -> typename std::enable_if<std::is_same<T_Ptr, std::unique_ptr<T>>::value, std::unique_ptr<T>>::type
{
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
@ -67,12 +67,12 @@ template<typename T_Module>
class Builder {
static_assert(std::is_base_of<ModuleIf, T_Module>::value, "Builder must be used only for Module classes");
public:
Builder(std::shared_ptr<DTE> dte, esp_netif_t* esp_netif): dte(std::move(dte)), device(nullptr), netif(esp_netif)
Builder(std::shared_ptr<DTE> dte, esp_netif_t *esp_netif): dte(std::move(dte)), 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<T_Module> dev): dte(std::move(dte)), device(std::move(dev)), netif(esp_netif)
Builder(std::shared_ptr<DTE> dte, esp_netif_t *esp_netif, std::shared_ptr<T_Module> dev): dte(std::move(dte)), device(std::move(dev)), netif(esp_netif)
{
throw_if_false(netif != nullptr, "Null netif");
}
@ -93,12 +93,14 @@ public:
template<typename T_Dce, typename T_Ptr>
auto create(const esp_modem_dce_config *config) -> T_Ptr
{
if (dte == nullptr)
if (dte == nullptr) {
return nullptr;
}
if (device == nullptr) {
device = create_module<decltype(device)>(config);
if (device == nullptr)
if (device == nullptr) {
return nullptr;
}
}
return FactoryHelper::make<T_Dce, T_Ptr>(std::move(dte), std::move(device), netif);
}
@ -136,7 +138,7 @@ public:
* @return unique_ptr DCE of the created DCE on success
*/
template <typename T_Module, typename ...Args>
static std::unique_ptr<DCE> build_unique(const config *cfg, Args&&... args)
static std::unique_ptr<DCE> build_unique(const config *cfg, Args &&... args)
{
return build_generic_DCE<T_Module, DCE, std::unique_ptr<DCE>>(cfg, std::forward<Args>(args)...);
}
@ -150,33 +152,33 @@ public:
* @return DCE pointer the created DCE on success
*/
template <typename T_Module, typename ...Args>
static DCE* build(const config *cfg, Args&&... args)
static DCE *build(const config *cfg, Args &&... args)
{
return build_generic_DCE<T_Module, DCE>(cfg, std::forward<Args>(args)...);
}
template <typename T_Module, typename ...Args>
static std::shared_ptr<T_Module> build_shared_module(const config *cfg, Args&&... args)
static std::shared_ptr<T_Module> build_shared_module(const config *cfg, Args &&... args)
{
return build_module_T<T_Module>(cfg, std::forward<Args>(args)...);
}
template <typename ...Args>
std::shared_ptr<GenericModule> build_shared_module(const config *cfg, Args&&... args)
std::shared_ptr<GenericModule> build_shared_module(const config *cfg, Args &&... args)
{
switch (m) {
case ModemType::SIM800:
return build_shared_module<SIM800>(cfg, std::forward<Args>(args)...);
case ModemType::SIM7600:
return build_shared_module<SIM7600>(cfg, std::forward<Args>(args)...);
case ModemType::BG96:
return build_shared_module<BG96>(cfg, std::forward<Args>(args)...);
case ModemType::GenericModule:
return build_shared_module<GenericModule>(cfg, std::forward<Args>(args)...);
default:
break;
case ModemType::SIM800:
return build_shared_module<SIM800>(cfg, std::forward<Args>(args)...);
case ModemType::SIM7600:
return build_shared_module<SIM7600>(cfg, std::forward<Args>(args)...);
case ModemType::BG96:
return build_shared_module<BG96>(cfg, std::forward<Args>(args)...);
case ModemType::GenericModule:
return build_shared_module<GenericModule>(cfg, std::forward<Args>(args)...);
default:
break;
}
return nullptr;
}
@ -189,37 +191,37 @@ public:
* @return unique_ptr DCE of the created DCE on success
*/
template <typename ...Args>
std::unique_ptr<DCE> build_unique(const config *cfg, Args&&... args)
std::unique_ptr<DCE> build_unique(const config *cfg, Args &&... args)
{
switch (m) {
case ModemType::SIM800:
return build_unique<SIM800>(cfg, std::forward<Args>(args)...);
case ModemType::SIM7600:
return build_unique<SIM7600>(cfg, std::forward<Args>(args)...);
case ModemType::BG96:
return build_unique<BG96>(cfg, std::forward<Args>(args)...);
case ModemType::GenericModule:
return build_unique<GenericModule>(cfg, std::forward<Args>(args)...);
default:
break;
case ModemType::SIM800:
return build_unique<SIM800>(cfg, std::forward<Args>(args)...);
case ModemType::SIM7600:
return build_unique<SIM7600>(cfg, std::forward<Args>(args)...);
case ModemType::BG96:
return build_unique<BG96>(cfg, std::forward<Args>(args)...);
case ModemType::GenericModule:
return build_unique<GenericModule>(cfg, std::forward<Args>(args)...);
default:
break;
}
return nullptr;
}
template <typename ...Args>
DCE* build(const config *cfg, Args&&... args)
DCE *build(const config *cfg, Args &&... args)
{
switch (m) {
case ModemType::SIM800:
return build<SIM800>(cfg, std::forward<Args>(args)...);
case ModemType::SIM7600:
return build<SIM7600>(cfg, std::forward<Args>(args)...);
case ModemType::BG96:
return build<BG96>(cfg, std::forward<Args>(args)...);
case ModemType::GenericModule:
return build<GenericModule>(cfg, std::forward<Args>(args)...);
default:
break;
case ModemType::SIM800:
return build<SIM800>(cfg, std::forward<Args>(args)...);
case ModemType::SIM7600:
return build<SIM7600>(cfg, std::forward<Args>(args)...);
case ModemType::BG96:
return build<BG96>(cfg, std::forward<Args>(args)...);
case ModemType::GenericModule:
return build<GenericModule>(cfg, std::forward<Args>(args)...);
default:
break;
}
return nullptr;
}
@ -229,15 +231,15 @@ private:
protected:
template <typename T_Module, typename Ptr = std::shared_ptr<T_Module>, typename ...Args>
static Ptr build_module_T(const config *cfg, Args&&... args)
static Ptr build_module_T(const config *cfg, Args && ... args)
{
Builder<T_Module> b(std::forward<Args>(args)...);
return b.template create_module<Ptr>(cfg);
}
template <typename T_Module, typename T_Dce = DCE_T<T_Module>, typename T_DcePtr = T_Dce*, typename ...Args>
static auto build_generic_DCE(const config *cfg, Args&&... args) -> T_DcePtr
template <typename T_Module, typename T_Dce = DCE_T<T_Module>, typename T_DcePtr = T_Dce *, typename ...Args>
static auto build_generic_DCE(const config *cfg, Args && ... args) -> T_DcePtr
{
Builder<T_Module> b(std::forward<Args>(args)...);
return b.template create<T_Dce, T_DcePtr>(cfg);

View File

@ -47,8 +47,8 @@ public:
* 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);
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
@ -58,10 +58,12 @@ public:
*/
bool setup_data_mode() override
{
if (set_echo(false) != command_result::OK)
if (set_echo(false) != command_result::OK) {
return false;
if (set_pdp_context(*pdp) != command_result::OK)
}
if (set_pdp_context(*pdp) != command_result::OK) {
return false;
}
return true;
}
@ -72,8 +74,9 @@ public:
bool set_mode(modem_mode mode) override
{
if (mode == modem_mode::DATA_MODE) {
if (set_data_mode() != command_result::OK)
if (set_data_mode() != command_result::OK) {
return resume_data_mode() == command_result::OK;
}
return true;
} else if (mode == modem_mode::COMMAND_MODE) {
return set_command_mode() == command_result::OK;
@ -115,8 +118,8 @@ protected:
class SIM7600: public GenericModule {
using GenericModule::GenericModule;
public:
command_result get_module_name(std::string& name) override;
command_result get_battery_status(int& voltage, int &bcs, int &bcl) override;
command_result get_module_name(std::string &name) override;
command_result get_battery_status(int &voltage, int &bcs, int &bcl) override;
command_result power_down() override;
};
@ -126,7 +129,7 @@ public:
class SIM800: public GenericModule {
using GenericModule::GenericModule;
public:
command_result get_module_name(std::string& name) override;
command_result get_module_name(std::string &name) override;
command_result power_down() override;
command_result set_data_mode() override;
};
@ -137,7 +140,7 @@ public:
class BG96: public GenericModule {
using GenericModule::GenericModule;
public:
command_result get_module_name(std::string& name) override;
command_result get_module_name(std::string &name) override;
};
/**

View File

@ -26,9 +26,13 @@ public:
explicit esp_err_exception(esp_err_t err): esp_err(err) {}
explicit esp_err_exception(std::string msg): esp_err(ESP_FAIL), message(std::move(msg)) {}
explicit esp_err_exception(std::string msg, esp_err_t err): esp_err(err), message(std::move(msg)) {}
virtual esp_err_t get_err_t() { return esp_err; }
virtual esp_err_t get_err_t()
{
return esp_err;
}
~esp_err_exception() noexcept override = default;
virtual const char* what() const noexcept {
virtual const char *what() const noexcept
{
return message.c_str();
}
private:

View File

@ -73,7 +73,7 @@ private:
std::shared_ptr<DTE> ppp_dte;
esp_netif_t *netif;
struct ppp_netif_driver driver{};
struct ppp_netif_driver driver {};
SignalGroup signal;
static const size_t PPP_STARTED = SignalGroup::bit0;
static const size_t PPP_EXIT = SignalGroup::bit1;

View File

@ -24,7 +24,7 @@
#else
// forward declarations of FreeRTOS primitives
struct QueueDefinition;
typedef void * EventGroupHandle_t;
typedef void *EventGroupHandle_t;
#endif
@ -32,7 +32,7 @@ namespace esp_modem {
// Forward declaration for both linux/FreeRTOS targets
//
using TaskFunction_t = void (*)(void*);
using TaskFunction_t = void (*)(void *);
#if !defined(CONFIG_IDF_TARGET_LINUX)
struct Lock {
using MutexT = QueueHandle_t;
@ -56,11 +56,17 @@ static constexpr uint32_t portMAX_DELAY = UINT32_MAX;
template<class T>
class Scoped {
public:
explicit Scoped(T &l):lock(l) { lock.lock(); }
~Scoped() { lock.unlock(); }
explicit Scoped(T &l): lock(l)
{
lock.lock();
}
~Scoped()
{
lock.unlock();
}
private:
T& lock;
T &lock;
};
class Task {

View File

@ -50,9 +50,15 @@ class Terminal {
public:
virtual ~Terminal() = default;
void set_error_cb(std::function<void(terminal_error)> f) { on_error = std::move(f); }
void set_error_cb(std::function<void(terminal_error)> f)
{
on_error = std::move(f);
}
virtual void set_read_cb(std::function<bool(uint8_t *data, size_t len)> f) { on_read = std::move(f); }
virtual void set_read_cb(std::function<bool(uint8_t *data, size_t len)> f)
{
on_read = std::move(f);
}
/**
* @brief Writes data to the terminal