Add license headers, update namespaces

This commit is contained in:
David Cermak
2021-03-29 19:34:45 +02:00
parent 30bde53d46
commit 246572d286
27 changed files with 813 additions and 437 deletions

View File

@ -1,6 +1,17 @@
// 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.
#include "cxx_include/esp_modem_dte.hpp"
#include "uart_terminal.hpp"
#include "esp_log.h"
@ -10,69 +21,46 @@
#include "esp_modem_config.h"
#include "exception_stub.hpp"
namespace esp_modem {
struct PdpContext;
using namespace esp_modem;
static const char *TAG = "modem_api";
std::shared_ptr<DTE> create_uart_dte(const esp_modem_dte_config *config)
{
std::shared_ptr<DTE> create_uart_dte(const dte_config *config) {
TRY_CATCH_RET_NULL(
auto term = create_uart_terminal(config);
return std::make_shared<DTE>(std::move(term));
auto term = create_uart_terminal(config);
return std::make_shared<DTE>(std::move(term));
)
}
template<typename SpecificModule>
std::unique_ptr<DCE_T<SpecificModule>> create_dce(const std::shared_ptr<DTE>& dte, const std::shared_ptr<SpecificModule>& dev, esp_netif_t *netif)
{
TRY_CATCH_RET_NULL(
return std::make_unique<DCE_T<SpecificModule>>(dte, dev, netif);
)
}
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)
{
TRY_CATCH_RET_NULL(
return std::make_unique<DCE>(dte, dev, netif);
)
}
//std::unique_ptr<DCE> create_SIM7600_dce(const std::shared_ptr<DTE>& dte, esp_netif_t *netif, std::string &apn)
//{
// auto pdp = std::make_unique<PdpContext>(apn);
// auto dev = std::make_shared<SIM7600>(dte, std::move(pdp));
//
// return create_generic_dce_from_module(dte, std::move(dev), netif);
//}
static inline std::unique_ptr<DCE> create_modem_dce(dce_factory::Modem m, const esp_modem_dce_config *config, std::shared_ptr<DTE> dte, esp_netif_t *netif)
{
static inline std::unique_ptr<DCE>
create_modem_dce(dce_factory::Modem m, const dce_config *config, std::shared_ptr<DTE> dte, esp_netif_t *netif) {
dce_factory::Factory f(m);
TRY_CATCH_RET_NULL(
return f.build_unique(config, std::move(dte), netif);
return f.build_unique(config, std::move(dte), 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_SIM7600_dce(const dce_config *config, std::shared_ptr<DTE> dte, esp_netif_t *netif) {
return create_modem_dce(dce_factory::Modem::SIM7600, config, std::move(dte), 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_SIM800_dce(const dce_config *config, std::shared_ptr<DTE> dte, esp_netif_t *netif) {
return create_modem_dce(dce_factory::Modem::SIM800, config, std::move(dte), netif);
}
std::unique_ptr<DCE> create_BG96_dce(const esp_modem_dce_config *config, std::shared_ptr<DTE> dte, esp_netif_t *netif)
{
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::Modem::BG96, config, std::move(dte), netif);
}
} // namespace esp_modem
//
// C API definitions
struct PdpContext;
using namespace esp_modem;
struct esp_modem_dce_wrap // need to mimic the polymorphic dispatch as CPP uses templated dispatch
{
@ -134,4 +122,3 @@ extern "C" esp_err_t esp_modem_read_pin(esp_modem_dce_t * dce, bool &x)
return command_response_to_esp_err(dce_sim7600->read_pin(x));
}
// define all commands manually, as we have to convert char* strings to CPP strings and references to