Files
esp-protocols/components/esp_modem/src/esp_modem_api.cpp

73 lines
2.5 KiB
C++
Raw Normal View History

2021-03-29 19:34:45 +02:00
// Copyright 2021 Espressif Systems (Shanghai) PTE LTD
2021-03-03 20:35:08 +01:00
//
2021-03-29 19:34:45 +02:00
// 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
2021-03-03 20:35:08 +01:00
//
2021-03-29 19:34:45 +02:00
// 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.
2021-04-04 22:15:46 +02:00
#include <cassert>
#include "esp_log.h"
2021-03-03 20:35:08 +01:00
#include "cxx_include/esp_modem_dte.hpp"
#include "uart_terminal.hpp"
#include "vfs_termial.hpp"
2021-03-03 20:35:08 +01:00
#include "cxx_include/esp_modem_api.hpp"
2021-03-28 20:22:44 +02:00
#include "cxx_include/esp_modem_dce_factory.hpp"
2021-03-08 15:10:15 +01:00
#include "esp_modem_config.h"
2021-03-16 21:36:13 +01:00
#include "exception_stub.hpp"
2021-03-03 20:35:08 +01:00
2021-03-29 19:34:45 +02:00
namespace esp_modem {
2021-03-29 19:34:45 +02:00
struct PdpContext;
2021-03-03 20:35:08 +01:00
2021-04-15 09:46:28 +02:00
#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2021-03-29 19:34:45 +02:00
static const char *TAG = "modem_api";
2021-04-15 09:46:28 +02:00
#endif
2021-03-03 20:35:08 +01:00
2021-03-29 19:34:45 +02:00
std::shared_ptr<DTE> create_uart_dte(const dte_config *config) {
2021-03-24 21:06:27 +01:00
TRY_CATCH_RET_NULL(
2021-03-29 19:34:45 +02:00
auto term = create_uart_terminal(config);
2021-04-18 19:14:22 +02:00
return std::make_shared<DTE>(config, std::move(term));
2021-03-24 21:06:27 +01:00
)
}
std::shared_ptr<DTE> create_vfs_dte(const dte_config *config) {
TRY_CATCH_RET_NULL(
2021-05-17 14:59:03 +02:00
auto term = create_vfs_terminal(config);
return std::make_shared<DTE>(config, std::move(term));
)
}
2021-03-29 19:34:45 +02:00
static inline std::unique_ptr<DCE>
create_modem_dce(dce_factory::ModemType m, const dce_config *config, std::shared_ptr<DTE> dte, esp_netif_t *netif) {
2021-03-28 20:22:44 +02:00
dce_factory::Factory f(m);
TRY_CATCH_RET_NULL(
2021-03-29 19:34:45 +02:00
return f.build_unique(config, std::move(dte), netif);
2021-03-28 20:22:44 +02:00
)
}
2021-03-29 19:34:45 +02:00
std::unique_ptr<DCE> create_SIM7600_dce(const dce_config *config, std::shared_ptr<DTE> dte, esp_netif_t *netif) {
return create_modem_dce(dce_factory::ModemType::SIM7600, config, std::move(dte), netif);
}
2021-03-29 19:34:45 +02:00
std::unique_ptr<DCE> create_SIM800_dce(const dce_config *config, std::shared_ptr<DTE> dte, esp_netif_t *netif) {
return create_modem_dce(dce_factory::ModemType::SIM800, config, std::move(dte), netif);
2021-03-28 20:22:44 +02:00
}
2021-03-29 19:34:45 +02:00
std::unique_ptr<DCE> create_BG96_dce(const dce_config *config, std::shared_ptr<DTE> dte, esp_netif_t *netif) {
return create_modem_dce(dce_factory::ModemType::BG96, config, std::move(dte), netif);
2021-03-28 20:22:44 +02:00
}
2021-04-18 19:14:22 +02:00
std::unique_ptr<DCE> create_generic_dce(const dce_config *config, std::shared_ptr<DTE> dte, esp_netif_t *netif) {
return create_modem_dce(dce_factory::ModemType::GenericModule, config, std::move(dte), netif);
2021-04-18 19:14:22 +02:00
}
2021-03-29 19:34:45 +02:00
} // namespace esp_modem