Files
esp-protocols/esp_modem/include/cxx_include/esp_modem_dce_module.hpp

126 lines
3.5 KiB
C++
Raw Normal View History

2021-03-29 19:34:45 +02:00
// 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"
#include "cxx_include/esp_modem_command_library.hpp"
#include "cxx_include/esp_modem_types.hpp"
2021-03-28 13:38:20 +02:00
#include "esp_modem_dce_config.h"
2021-03-29 19:34:45 +02:00
namespace esp_modem {
2021-04-14 17:57:42 +02:00
/**
* @defgroup ESP_MODEM_MODULE
* @brief Definition of modules representing specific modem devices
*/
/** @addtogroup ESP_MODEM_MODULE
* @{
*/
enum class command_result;
class DTE;
2021-03-29 19:34:45 +02:00
struct PdpContext;
2021-04-14 17:57:42 +02:00
/**
* @brief This is a basic building block for custom modules as well as for the supported modules in the esp-modem component
* It derives from the ModuleIf.
*/
2021-03-28 09:12:58 +02:00
class GenericModule: public ModuleIf {
public:
2021-03-28 09:12:58 +02:00
explicit GenericModule(std::shared_ptr<DTE> dte, std::unique_ptr<PdpContext> pdp):
dte(std::move(dte)), pdp(std::move(pdp)) {}
2021-03-28 20:22:44 +02:00
explicit GenericModule(std::shared_ptr<DTE> dte, const esp_modem_dce_config* config);
bool setup_data_mode() override
{
if (set_echo(false) != command_result::OK)
return false;
if (set_pdp_context(*pdp) != command_result::OK)
return false;
return true;
}
bool set_mode(modem_mode mode) override
{
if (mode == modem_mode::DATA_MODE) {
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;
} else if (mode == modem_mode::CMUX_MODE) {
return set_cmux() == command_result::OK;
}
return true;
}
2021-04-15 14:59:30 +02:00
#define ESP_MODEM_DECLARE_DCE_COMMAND(name, return_type, num, ...) \
2021-03-24 21:06:27 +01:00
virtual return_type name(__VA_ARGS__);
2021-03-28 09:12:58 +02:00
DECLARE_ALL_COMMAND_APIS(virtual return_type name(...); )
#undef ESP_MODEM_DECLARE_DCE_COMMAND
2021-03-28 09:08:47 +02:00
2021-03-28 09:12:58 +02:00
protected:
std::shared_ptr<DTE> dte;
std::unique_ptr<PdpContext> pdp;
};
2021-04-19 11:28:53 +02:00
// Definitions of other supported modules with some specific commands overwritten
2021-04-14 17:57:42 +02:00
/**
* @brief Specific definition of the SIM7600 module
*/
class SIM7600: public GenericModule {
using GenericModule::GenericModule;
public:
2021-03-28 20:22:44 +02:00
command_result get_module_name(std::string& name) override;
2021-04-19 11:28:53 +02:00
command_result get_battery_status(int& voltage, int &bcs, int &bcl) override;
command_result power_down() override;
};
2021-04-14 17:57:42 +02:00
/**
* @brief Specific definition of the SIM800 module
*/
class SIM800: public GenericModule {
using GenericModule::GenericModule;
public:
2021-03-24 21:06:27 +01:00
command_result get_module_name(std::string& name) override;
2021-04-19 11:28:53 +02:00
command_result power_down() override;
command_result set_data_mode() override;
};
2021-04-14 17:57:42 +02:00
/**
* @brief Specific definition of the BG96 module
*/
class BG96: public GenericModule {
2021-03-28 13:38:20 +02:00
using GenericModule::GenericModule;
public:
2021-03-24 21:06:27 +01:00
command_result get_module_name(std::string& name) override;
};
2021-03-29 19:34:45 +02:00
2021-04-14 17:57:42 +02:00
/**
* @}
*/
2021-03-29 19:34:45 +02:00
} // namespace esp_modem
#endif // _ESP_MODEM_DCE_MODULE_