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

61 lines
1.6 KiB
C++
Raw Normal View History

2021-03-29 19:34:45 +02:00
// Copyright 2021 Espressif Systems (Shanghai) PTE LTD
//
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
2021-03-29 19:34:45 +02:00
// 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.
2021-03-29 19:34:45 +02:00
#ifndef _ESP_MODEM_TERMINAL_HPP_
#define _ESP_MODEM_TERMINAL_HPP_
#include <memory>
#include <functional>
#include <exception>
#include <cstddef>
#include <cstdint>
#include <utility>
#include "esp_err.h"
#include "esp_modem_primitives.hpp"
2021-03-29 19:34:45 +02:00
namespace esp_modem {
enum class terminal_error {
BUFFER_OVERFLOW,
CHECKSUM_ERROR,
UNEXPECTED_CONTROL_FLOW,
};
class Terminal {
public:
virtual ~Terminal() = default;
2021-03-29 19:34:45 +02:00
virtual void set_data_cb(std::function<bool(size_t len)> f) { on_data = std::move(f); }
2021-03-29 19:34:45 +02:00
void set_error_cb(std::function<void(terminal_error)> f) { on_error = std::move(f); }
2021-03-29 19:34:45 +02:00
virtual int write(uint8_t *data, size_t len) = 0;
2021-03-29 19:34:45 +02:00
virtual int read(uint8_t *data, size_t len) = 0;
2021-03-29 19:34:45 +02:00
virtual void start() = 0;
2021-03-29 19:34:45 +02:00
virtual void stop() = 0;
2021-03-29 19:34:45 +02:00
virtual size_t max_virtual_terms() { return 1; }
protected:
std::function<bool(size_t len)> on_data;
std::function<void(terminal_error)> on_error;
};
2021-03-29 19:34:45 +02:00
} // namespace esp_modem
2021-03-29 19:34:45 +02:00
#endif // _ESP_MODEM_TERMINAL_HPP_