CI: fixing the files to be complient with pre-commit hooks

This commit is contained in:
Suren Gabrielyan
2022-10-11 16:31:57 +02:00
parent 9d45d505d5
commit 945bd17701
205 changed files with 3130 additions and 3441 deletions

View File

@ -1,16 +1,8 @@
// 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.
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once

View File

@ -1,16 +1,8 @@
// 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.
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
@ -22,15 +14,15 @@ namespace esp_modem {
*/
struct unique_buffer {
explicit unique_buffer(size_t size);
unique_buffer (unique_buffer const&) = delete;
unique_buffer& operator=(unique_buffer const&) = delete;
unique_buffer(unique_buffer&& other) noexcept
unique_buffer (unique_buffer const &) = delete;
unique_buffer &operator=(unique_buffer const &) = delete;
unique_buffer(unique_buffer &&other) noexcept
{
data = std::move(other.data);
size = other.size;
consumed = 0;
}
unique_buffer& operator=(unique_buffer&& other) noexcept
unique_buffer &operator=(unique_buffer &&other) noexcept
{
if (&other == this) {
return *this;
@ -40,7 +32,10 @@ struct unique_buffer {
consumed = 0;
return *this;
}
[[nodiscard]] uint8_t *get() const { return data.get(); }
[[nodiscard]] uint8_t *get() const
{
return data.get();
}
std::unique_ptr<uint8_t[]> data;
size_t size{};

View File

@ -1,16 +1,8 @@
// 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.
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
@ -55,7 +47,7 @@ class CMuxInstance;
*/
class CMux {
public:
explicit CMux(std::shared_ptr<Terminal> t, unique_buffer&& b):
explicit CMux(std::shared_ptr<Terminal> t, unique_buffer &&b):
term(std::move(t)), payload_start(nullptr), total_payload_size(0), buffer(std::move(b)) {}
~CMux() = default;

View File

@ -1,16 +1,8 @@
// 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.
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
@ -47,7 +39,7 @@ command_result get_battery_status_sim7xxx(CommandableIf *t, int &voltage, int &b
command_result set_gnss_power_mode_sim76xx(CommandableIf *t, int mode);
command_result power_down_sim76xx(CommandableIf *t);
command_result power_down_sim70xx(CommandableIf *t);
command_result set_network_bands_sim76xx(CommandableIf *t, const std::string& mode, const int* bands, int size);
command_result set_network_bands_sim76xx(CommandableIf *t, const std::string &mode, const int *bands, int size);
command_result power_down_sim8xx(CommandableIf *t);
command_result set_data_mode_sim8xx(CommandableIf *t);

View File

@ -1,16 +1,8 @@
// 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.
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once

View File

@ -1,16 +1,8 @@
// 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.
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "esp_log.h"

View File

@ -1,16 +1,8 @@
// 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.
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
@ -82,11 +74,13 @@ public:
Task::Delay(1000); // Mandatory 1s pause before
int retry = 0;
while (retry++ < 3) {
if (set_command_mode() == command_result::OK)
if (set_command_mode() == command_result::OK) {
return true;
}
Task::Delay(1000); // Mandatory 1s pause after escape
if (sync() == command_result::OK)
if (sync() == command_result::OK) {
return true;
}
Task::Delay(1000); // Mandatory 1s pause before escape
}
return false;
@ -107,7 +101,7 @@ public:
/**
* @brief Simplified version of operator name (without the ACT, which is included in the command library)
*/
command_result get_operator_name(std::string& name)
command_result get_operator_name(std::string &name)
{
int dummy_act;
return get_operator_name(name, dummy_act);
@ -140,7 +134,7 @@ public:
command_result get_battery_status(int &voltage, int &bcs, int &bcl) override;
command_result power_down() override;
command_result set_gnss_power_mode(int mode) override;
command_result set_network_bands(const std::string& mode, const int* bands, int size) override;
command_result set_network_bands(const std::string &mode, const int *bands, int size) override;
};
/**

View File

@ -1,16 +1,8 @@
// 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.
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
@ -106,8 +98,14 @@ protected:
/**
* @brief Allows for locking the DTE
*/
void lock() { internal_lock.lock(); }
void unlock() { internal_lock.unlock(); }
void lock()
{
internal_lock.lock();
}
void unlock()
{
internal_lock.unlock();
}
friend class Scoped<DTE>; /*!< Declaring "Scoped<DTE> lock(dte)" locks this instance */
private:
static const size_t GOT_LINE = SignalGroup::bit0; /*!< Bit indicating response available */

View File

@ -1,16 +1,8 @@
// 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.
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
@ -51,35 +43,44 @@ private:
#define ESP_MODEM_THROW(exception) do { exception; abort(); } while(0)
class esp_err_exception {
void print(std::string msg) { ESP_LOGE("ESP_MODEM_THROW", "%s\n", msg.c_str()); }
void print(std::string msg)
{
ESP_LOGE("ESP_MODEM_THROW", "%s\n", msg.c_str());
}
public:
explicit esp_err_exception(std::string msg) { print(std::move(msg)); }
explicit esp_err_exception(std::string msg, esp_err_t err) { print(std::move(msg)); }
explicit esp_err_exception(std::string msg)
{
print(std::move(msg));
}
explicit esp_err_exception(std::string msg, esp_err_t err)
{
print(std::move(msg));
}
};
#endif
static inline std::string make_message(const std::string& filename, int line, const std::string& message = "ERROR")
static inline std::string make_message(const std::string &filename, int line, const std::string &message = "ERROR")
{
std::string text = filename + ":" + std::to_string(line) + " " + message;
return text;
}
static inline void throw_if_false(const std::string& filename, int line, bool condition, const std::string& message)
static inline void throw_if_false(const std::string &filename, int line, bool condition, const std::string &message)
{
if (!condition) {
ESP_MODEM_THROW(esp_err_exception(make_message(filename, line, message)));
}
}
static inline void throw_if_error(const std::string& filename, int line, esp_err_t err, const std::string& message)
static inline void throw_if_error(const std::string &filename, int line, esp_err_t err, const std::string &message)
{
if (err != ESP_OK) {
ESP_MODEM_THROW(esp_err_exception(make_message(filename, line, message), err));
}
}
static inline void throw_if_error(const std::string& filename, int line, esp_err_t err)
static inline void throw_if_error(const std::string &filename, int line, esp_err_t err)
{
if (err != ESP_OK) {
ESP_MODEM_THROW(esp_err_exception(make_message(filename, line), err));

View File

@ -1,16 +1,8 @@
// 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.
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once

View File

@ -1,16 +1,8 @@
// 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.
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once

View File

@ -1,16 +1,8 @@
// 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.
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once

View File

@ -1,16 +1,8 @@
// 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.
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
@ -68,10 +60,10 @@ struct PdpContext {
class CommandableIf {
public:
CommandableIf() = default;
CommandableIf(const CommandableIf&) = delete;
CommandableIf& operator=(const CommandableIf&) = delete;
CommandableIf(CommandableIf&&) = delete;
CommandableIf& operator=(CommandableIf&&) = delete;
CommandableIf(const CommandableIf &) = delete;
CommandableIf &operator=(const CommandableIf &) = delete;
CommandableIf(CommandableIf &&) = delete;
CommandableIf &operator=(CommandableIf &&) = delete;
virtual ~CommandableIf() = default;
/**
* @brief Sends custom AT command
@ -90,10 +82,10 @@ public:
class ModuleIf {
public:
ModuleIf() = default;
ModuleIf(const ModuleIf&) = delete;
ModuleIf& operator=(const ModuleIf&) = delete;
ModuleIf(ModuleIf&&) = delete;
ModuleIf& operator=(ModuleIf&&) = delete;
ModuleIf(const ModuleIf &) = delete;
ModuleIf &operator=(const ModuleIf &) = delete;
ModuleIf(ModuleIf &&) = delete;
ModuleIf &operator=(ModuleIf &&) = delete;
virtual ~ModuleIf() = default;
/**
* @brief Sets the data mode up (provides the necessary configuration to connect to the cellular network)

View File

@ -1,16 +1,8 @@
// 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.
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
@ -26,7 +18,7 @@ extern "C" {
#define ESP_MODEM_DECLARE_DCE_COMMAND(name, return_type, num, ...) \
esp_err_t esp_modem_ ## name(esp_modem_dce_t *dce, ##__VA_ARGS__);
DECLARE_ALL_COMMAND_APIS(declares esp_modem_<API>(esp_modem_t * dce, ...);)
DECLARE_ALL_COMMAND_APIS(declares esp_modem_<API>(esp_modem_t *dce, ...);)
#undef ESP_MODEM_DECLARE_DCE_COMMAND

View File

@ -1,16 +1,8 @@
// 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.
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
@ -40,8 +32,7 @@ typedef struct esp_modem_PdpContext_t {
/**
* @brief DCE mode: This enum is used to set desired operation mode of the DCE
*/
typedef enum esp_modem_dce_mode
{
typedef enum esp_modem_dce_mode {
ESP_MODEM_MODE_COMMAND, /**< Default mode after modem startup, used for sending AT commands */
ESP_MODEM_MODE_DATA, /**< Used for switching to PPP mode for the modem to connect to a network */
ESP_MODEM_MODE_CMUX, /**< Multiplexed terminal mode */
@ -50,8 +41,7 @@ typedef enum esp_modem_dce_mode
/**
* @brief DCE devices: Enum list of supported devices
*/
typedef enum esp_modem_dce_device
{
typedef enum esp_modem_dce_device {
ESP_MODEM_DCE_GENETIC, /**< The most generic device */
ESP_MODEM_DCE_SIM7600,
ESP_MODEM_DCE_SIM7070,
@ -63,8 +53,7 @@ typedef enum esp_modem_dce_device
/**
* @brief Terminal errors
*/
typedef enum esp_modem_terminal_error
{
typedef enum esp_modem_terminal_error {
ESP_MODEM_TERMINAL_BUFFER_OVERFLOW,
ESP_MODEM_TERMINAL_CHECKSUM_ERROR,
ESP_MODEM_TERMINAL_UNEXPECTED_CONTROL_FLOW,
@ -105,16 +94,16 @@ esp_modem_dce_t *esp_modem_new_dev(esp_modem_dce_device_t module, const esp_mode
*
* @param dce DCE to destroy
*/
void esp_modem_destroy(esp_modem_dce_t * dce);
void esp_modem_destroy(esp_modem_dce_t *dce);
/**
* @brief Set DTE's error callback
*
*
* @param dce Modem DCE handle
* @param[in] err_cb Error callback
* @return ESP_OK on success, ESP_FAIL on failure
*/
esp_err_t esp_modem_set_error_cb(esp_modem_dce_t * dce, esp_modem_terminal_error_cbt err_cb);
esp_err_t esp_modem_set_error_cb(esp_modem_dce_t *dce, esp_modem_terminal_error_cbt err_cb);
/**
* @brief Set operation mode for this DCE
@ -122,7 +111,7 @@ esp_err_t esp_modem_set_error_cb(esp_modem_dce_t * dce, esp_modem_terminal_error
* @param mode Desired MODE
* @return ESP_OK on success, ESP_FAIL on failure
*/
esp_err_t esp_modem_set_mode(esp_modem_dce_t * dce, esp_modem_dce_mode_t mode);
esp_err_t esp_modem_set_mode(esp_modem_dce_t *dce, esp_modem_dce_mode_t mode);
/**
* @}

View File

@ -1,16 +1,8 @@
// 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.
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
@ -70,7 +62,7 @@ struct esp_modem_vfs_resource;
*/
struct esp_modem_vfs_term_config {
int fd; /*!< Already created file descriptor */
void (*deleter)(int, struct esp_modem_vfs_resource*); /*!< Custom close function for the fd */
void (*deleter)(int, struct esp_modem_vfs_resource *); /*!< Custom close function for the fd */
struct esp_modem_vfs_resource *resource; /*!< Resource attached to the VFS (need for clenaup) */
};

View File

@ -1,16 +1,8 @@
// 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.
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
@ -37,7 +29,7 @@ typedef struct esp_modem_dce_config esp_modem_dce_config_t;
* @brief DCE configuration structure
*/
struct esp_modem_dce_config {
const char* apn; /*!< APN: Logical name of the Access point */
const char *apn; /*!< APN: Logical name of the Access point */
};
/**

View File

@ -1,87 +1,79 @@
// 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.
/**
* @file c_api_wrapper.hpp
* @brief Collection of C API wrappers
*
* This file is located in include/esp_private because it is not intended for users,
* but rather for esp_modem C extension developers.
*
* The C extension API must provide a 'factory function' that returns initialized pointer to esp_modem_dce_wrap.
* Helper functions provided below, can be used for conversion between C++ enum classes and standard C enums.
*/
#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;
std::shared_ptr<DTE> dte;
esp_modem_dce_wrap() : dce(nullptr), dte(nullptr) {}
};
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;
}
}
inline esp_modem_terminal_error_t convert_terminal_error_enum(terminal_error err)
{
switch (err) {
case terminal_error::BUFFER_OVERFLOW:
return ESP_MODEM_TERMINAL_BUFFER_OVERFLOW;
case terminal_error::CHECKSUM_ERROR:
return ESP_MODEM_TERMINAL_CHECKSUM_ERROR;
case terminal_error::UNEXPECTED_CONTROL_FLOW:
return ESP_MODEM_TERMINAL_UNEXPECTED_CONTROL_FLOW;
case terminal_error::DEVICE_GONE:
return ESP_MODEM_TERMINAL_DEVICE_GONE;
default:
return ESP_MODEM_TERMINAL_UNKNOWN_ERROR;
}
}
inline esp_err_t command_response_to_esp_err(command_result res)
{
switch (res) {
case command_result::OK:
return ESP_OK;
case command_result::FAIL:
return ESP_FAIL;
case command_result::TIMEOUT:
return ESP_ERR_TIMEOUT;
}
return ESP_ERR_INVALID_ARG;
}
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file c_api_wrapper.hpp
* @brief Collection of C API wrappers
*
* This file is located in include/esp_private because it is not intended for users,
* but rather for esp_modem C extension developers.
*
* The C extension API must provide a 'factory function' that returns initialized pointer to esp_modem_dce_wrap.
* Helper functions provided below, can be used for conversion between C++ enum classes and standard C enums.
*/
#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;
std::shared_ptr<DTE> dte;
esp_modem_dce_wrap() : dce(nullptr), dte(nullptr) {}
};
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;
}
}
inline esp_modem_terminal_error_t convert_terminal_error_enum(terminal_error err)
{
switch (err) {
case terminal_error::BUFFER_OVERFLOW:
return ESP_MODEM_TERMINAL_BUFFER_OVERFLOW;
case terminal_error::CHECKSUM_ERROR:
return ESP_MODEM_TERMINAL_CHECKSUM_ERROR;
case terminal_error::UNEXPECTED_CONTROL_FLOW:
return ESP_MODEM_TERMINAL_UNEXPECTED_CONTROL_FLOW;
case terminal_error::DEVICE_GONE:
return ESP_MODEM_TERMINAL_DEVICE_GONE;
default:
return ESP_MODEM_TERMINAL_UNKNOWN_ERROR;
}
}
inline esp_err_t command_response_to_esp_err(command_result res)
{
switch (res) {
case command_result::OK:
return ESP_OK;
case command_result::FAIL:
return ESP_FAIL;
case command_result::TIMEOUT:
return ESP_ERR_TIMEOUT;
}
return ESP_ERR_INVALID_ARG;
}

View File

@ -324,7 +324,7 @@ public:
#define ESP_MODEM_DECLARE_DCE_COMMAND(name, return_type, TEMPLATE_ARG, ...) return_type esp_modem_ ## name (__VA_ARGS__);
#endif
DECLARE_ALL_COMMAND_APIS()
DECLARE_ALL_COMMAND_APIS()
#ifdef __cplusplus
};

View File

@ -1,16 +1,8 @@
// 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.
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once