updated console based on latest uuid::console

This commit is contained in:
Proddy
2023-01-05 15:11:15 +01:00
parent cd807cd035
commit 132acaf758
2 changed files with 467 additions and 525 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -26,85 +26,52 @@
#include "system.h" #include "system.h"
#include "mqtt.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 #ifdef LOCAL
#undef LOCAL #undef LOCAL
#endif #endif
namespace emsesp {
enum CommandFlags : uint8_t { USER = 0, ADMIN = (1 << 0), LOCAL = (1 << 1) }; enum CommandFlags : uint8_t { USER = 0, ADMIN = (1 << 0), LOCAL = (1 << 1) };
enum ShellContext : uint8_t { enum ShellContext : uint8_t { MAIN = 0, SYSTEM, END };
MAIN = 0,
SYSTEM,
};
class EMSESPShell : virtual public uuid::console::Shell { class EMSESP;
class EMSESPShell : public uuid::console::Shell {
public: public:
~EMSESPShell() override = default; ~EMSESPShell() override = default;
virtual std::string console_name() = 0; virtual std::string console_name() = 0;
static std::shared_ptr<uuid::console::Commands> commands; static void generic_exit_context_function(Shell & shell, const std::vector<std::string> & arguments);
static std::shared_ptr<EMSESPShell> shell; 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: 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 // our custom functions for Shell
void started() override; void started() override;
void stopped() override; void stopped() override;
void display_banner() override; void display_banner() override;
std::string hostname_text() override; std::string hostname_text() override;
std::string context_text() override;
std::string prompt_suffix() override; std::string prompt_suffix() override;
void end_of_transmission() override; void end_of_transmission() override;
private: private:
void add_console_commands(); static void main_exit_user_function(Shell & shell, const std::vector<std::string> & arguments);
bool console_commands_loaded_ = false; // set to true when the initial commands are loaded static void main_exit_admin_function(Shell & shell, const std::vector<std::string> & arguments);
std::string console_hostname_; 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 } // namespace emsesp
#endif #endif