mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-16 12:02:11 +02:00
esp_modem: Move common C definitions in to separate header
Separate header for C API created. It can be used by C DTE extensions.
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
version: "0.1.22"
|
version: "0.1.23"
|
||||||
description: esp modem
|
description: esp modem
|
||||||
url: https://github.com/espressif/esp-protocols/tree/master/components/esp_modem
|
url: https://github.com/espressif/esp-protocols/tree/master/components/esp_modem
|
||||||
dependencies:
|
dependencies:
|
||||||
|
45
components/esp_modem/include/esp_private/c_api_wrapper.hpp
Normal file
45
components/esp_modem/include/esp_private/c_api_wrapper.hpp
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
// Copyright 2022 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.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "cxx_include/esp_modem_dce_factory.hpp"
|
||||||
|
#include "esp_modem_c_api_types.h"
|
||||||
|
|
||||||
|
using namespace esp_modem;
|
||||||
|
|
||||||
|
struct esp_modem_dce_wrap { // need to mimic the polymorphic dispatch as CPP uses templated dispatch
|
||||||
|
enum class modem_wrap_dte_type { UART, VFS, USB } dte_type;
|
||||||
|
dce_factory::ModemType modem_type;
|
||||||
|
DCE *dce;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline dce_factory::ModemType convert_modem_enum(esp_modem_dce_device_t module)
|
||||||
|
{
|
||||||
|
switch (module) {
|
||||||
|
case ESP_MODEM_DCE_SIM7600:
|
||||||
|
return esp_modem::dce_factory::ModemType::SIM7600;
|
||||||
|
case ESP_MODEM_DCE_SIM7070:
|
||||||
|
return esp_modem::dce_factory::ModemType::SIM7070;
|
||||||
|
case ESP_MODEM_DCE_SIM7000:
|
||||||
|
return esp_modem::dce_factory::ModemType::SIM7000;
|
||||||
|
case ESP_MODEM_DCE_BG96:
|
||||||
|
return esp_modem::dce_factory::ModemType::BG96;
|
||||||
|
case ESP_MODEM_DCE_SIM800:
|
||||||
|
return esp_modem::dce_factory::ModemType::SIM800;
|
||||||
|
default:
|
||||||
|
case ESP_MODEM_DCE_GENETIC:
|
||||||
|
return esp_modem::dce_factory::ModemType::GenericModule;
|
||||||
|
}
|
||||||
|
}
|
@ -21,6 +21,7 @@
|
|||||||
#include "esp_modem_c_api_types.h"
|
#include "esp_modem_c_api_types.h"
|
||||||
#include "esp_modem_config.h"
|
#include "esp_modem_config.h"
|
||||||
#include "exception_stub.hpp"
|
#include "exception_stub.hpp"
|
||||||
|
#include "esp_private/c_api_wrapper.hpp"
|
||||||
#include "cstring"
|
#include "cstring"
|
||||||
|
|
||||||
#ifndef ESP_MODEM_C_API_STR_MAX
|
#ifndef ESP_MODEM_C_API_STR_MAX
|
||||||
@ -35,12 +36,6 @@ size_t strlcpy(char *dest, const char *src, size_t len);
|
|||||||
// C API definitions
|
// C API definitions
|
||||||
using namespace esp_modem;
|
using namespace esp_modem;
|
||||||
|
|
||||||
struct esp_modem_dce_wrap { // need to mimic the polymorphic dispatch as CPP uses templated dispatch
|
|
||||||
enum class modem_wrap_dte_type { UART, } dte_type;
|
|
||||||
dce_factory::ModemType modem_type;
|
|
||||||
DCE *dce;
|
|
||||||
};
|
|
||||||
|
|
||||||
static inline esp_err_t command_response_to_esp_err(command_result res)
|
static inline esp_err_t command_response_to_esp_err(command_result res)
|
||||||
{
|
{
|
||||||
switch (res) {
|
switch (res) {
|
||||||
@ -54,25 +49,6 @@ static inline esp_err_t command_response_to_esp_err(command_result res)
|
|||||||
return ESP_ERR_INVALID_ARG;
|
return ESP_ERR_INVALID_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline dce_factory::ModemType convert_modem_enum(esp_modem_dce_device_t module)
|
|
||||||
{
|
|
||||||
switch (module) {
|
|
||||||
case ESP_MODEM_DCE_SIM7600:
|
|
||||||
return esp_modem::dce_factory::ModemType::SIM7600;
|
|
||||||
case ESP_MODEM_DCE_SIM7070:
|
|
||||||
return esp_modem::dce_factory::ModemType::SIM7070;
|
|
||||||
case ESP_MODEM_DCE_SIM7000:
|
|
||||||
return esp_modem::dce_factory::ModemType::SIM7000;
|
|
||||||
case ESP_MODEM_DCE_BG96:
|
|
||||||
return esp_modem::dce_factory::ModemType::BG96;
|
|
||||||
case ESP_MODEM_DCE_SIM800:
|
|
||||||
return esp_modem::dce_factory::ModemType::SIM800;
|
|
||||||
default:
|
|
||||||
case ESP_MODEM_DCE_GENETIC:
|
|
||||||
return esp_modem::dce_factory::ModemType::GenericModule;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" esp_modem_dce_t *esp_modem_new_dev(esp_modem_dce_device_t module, const esp_modem_dte_config_t *dte_config, const esp_modem_dce_config_t *dce_config, esp_netif_t *netif)
|
extern "C" esp_modem_dce_t *esp_modem_new_dev(esp_modem_dce_device_t module, const esp_modem_dte_config_t *dte_config, const esp_modem_dce_config_t *dce_config, esp_netif_t *netif)
|
||||||
{
|
{
|
||||||
auto dce_wrap = new (std::nothrow) esp_modem_dce_wrap;
|
auto dce_wrap = new (std::nothrow) esp_modem_dce_wrap;
|
||||||
|
Reference in New Issue
Block a user