mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-08 00:39:50 +03:00
updated console based on latest uuid::console
This commit is contained in:
919
src/console.cpp
919
src/console.cpp
File diff suppressed because it is too large
Load Diff
@@ -26,85 +26,52 @@
|
||||
#include "system.h"
|
||||
#include "mqtt.h"
|
||||
|
||||
using uuid::console::Commands;
|
||||
using uuid::console::Shell;
|
||||
|
||||
static constexpr uint32_t INVALID_PASSWORD_DELAY_MS = 2000;
|
||||
|
||||
namespace emsesp {
|
||||
|
||||
using LogLevel = ::uuid::log::Level;
|
||||
using LogFacility = ::uuid::log::Facility;
|
||||
|
||||
#ifdef LOCAL
|
||||
#undef LOCAL
|
||||
#endif
|
||||
|
||||
namespace emsesp {
|
||||
|
||||
enum CommandFlags : uint8_t { USER = 0, ADMIN = (1 << 0), LOCAL = (1 << 1) };
|
||||
|
||||
enum ShellContext : uint8_t {
|
||||
MAIN = 0,
|
||||
SYSTEM,
|
||||
};
|
||||
enum ShellContext : uint8_t { MAIN = 0, SYSTEM, END };
|
||||
|
||||
class EMSESPShell : virtual public uuid::console::Shell {
|
||||
class EMSESP;
|
||||
|
||||
class EMSESPShell : public uuid::console::Shell {
|
||||
public:
|
||||
~EMSESPShell() override = default;
|
||||
|
||||
virtual std::string console_name() = 0;
|
||||
|
||||
static std::shared_ptr<uuid::console::Commands> commands;
|
||||
static std::shared_ptr<EMSESPShell> shell;
|
||||
static void generic_exit_context_function(Shell & shell, const std::vector<std::string> & arguments);
|
||||
static void main_help_function(Shell & shell, const std::vector<std::string> & arguments);
|
||||
static void main_exit_function(Shell & shell, const std::vector<std::string> & arguments);
|
||||
static void main_logout_function(Shell & shell, const std::vector<std::string> & arguments);
|
||||
|
||||
EMSESP & emsesp_;
|
||||
|
||||
protected:
|
||||
EMSESPShell();
|
||||
EMSESPShell(EMSESP & emsesp, Stream & stream, unsigned int context, unsigned int flags);
|
||||
|
||||
static std::shared_ptr<uuid::console::Commands> commands_;
|
||||
|
||||
// our custom functions for Shell
|
||||
void started() override;
|
||||
void stopped() override;
|
||||
void display_banner() override;
|
||||
std::string hostname_text() override;
|
||||
std::string context_text() override;
|
||||
std::string prompt_suffix() override;
|
||||
void end_of_transmission() override;
|
||||
|
||||
|
||||
private:
|
||||
void add_console_commands();
|
||||
bool console_commands_loaded_ = false; // set to true when the initial commands are loaded
|
||||
static void main_exit_user_function(Shell & shell, const std::vector<std::string> & arguments);
|
||||
static void main_exit_admin_function(Shell & shell, const std::vector<std::string> & arguments);
|
||||
|
||||
std::string console_hostname_;
|
||||
};
|
||||
|
||||
class EMSESPStreamConsole : public uuid::console::StreamConsole, public EMSESPShell {
|
||||
public:
|
||||
EMSESPStreamConsole(Stream & stream, bool local);
|
||||
EMSESPStreamConsole(Stream & stream, const IPAddress & addr, uint16_t port);
|
||||
~EMSESPStreamConsole() override;
|
||||
|
||||
std::string console_name() override;
|
||||
|
||||
private:
|
||||
static std::vector<bool> ptys_;
|
||||
|
||||
std::string name_;
|
||||
size_t pty_;
|
||||
IPAddress addr_;
|
||||
uint16_t port_;
|
||||
};
|
||||
|
||||
class Console {
|
||||
public:
|
||||
void loop();
|
||||
void start_serial();
|
||||
void start_telnet();
|
||||
|
||||
uuid::log::Level log_level();
|
||||
|
||||
static void load_standard_commands(unsigned int context);
|
||||
static void load_system_commands(unsigned int context);
|
||||
|
||||
private:
|
||||
bool telnet_enabled_ = false; // telnet is default off
|
||||
};
|
||||
|
||||
} // namespace emsesp
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user