Skip to content

A Hardware Hacking Tool with Web-Based CLI That Speaks Every Protocol

2.7 KB
Raw Blame
#pragma once

#include <vector>
#include <Arduino.h>
#include <string>
#include <sstream>
#include <algorithm>
#include "Models/TerminalCommand.h"
#include "Interfaces/ITerminalView.h"
#include "Interfaces/IInput.h"
#include "Interfaces/IDeviceView.h"
#include "States/GlobalState.h"
#include "Enums/ModeEnum.h"
#include "Services/PinService.h"
#include "Managers/UserInputManager.h"
#include "Managers/PinAnalyzeManager.h"
#include "Transformers/ArgTransformer.h"
#include "Shells/SysInfoShell.h"
#include "Shells/GuideShell.h"
#include "Shells/HelpShell.h"
#include "Shells/ProfileShell.h"

class UtilityController {
public:
    // Constructor
    UtilityController(
        ITerminalView& terminalView, 
        IDeviceView& deviceView, 
        IInput& terminalInput, 
        PinService& pinService, 
        UserInputManager& userInputManager,
        PinAnalyzeManager& pinAnalyzeManager,
        ArgTransformer& argTransformer,
        SysInfoShell& sysInfoShell,
        GuideShell& guideShell,
        HelpShell& helpShell,
        ProfileShell& profileShell
    );

    // Entry point for global utility commands
    void handleCommand(const TerminalCommand& cmd);

    // Process mode change command and return new mode
    ModeEnum handleModeChangeCommand(const TerminalCommand& cmd);

    // Logic Analyzer on device screen
    void handleLogicAnalyzer(const TerminalCommand& cmd);

    // Analogic plotter on device screen
    void handleAnalogic(const TerminalCommand& cmd);

    // Save or load profile with pin states and settings
    void handleProfile();

    // Check if a command is a global utility command
    bool isGlobalCommand(const TerminalCommand& cmd);

    // Check if a command is related to screen operations
    bool isScreenCommand(const TerminalCommand& cmd);

private:
    // Display help for utility commands
    void handleHelp();

    // Ask user to select a mode
    ModeEnum handleModeSelect();

    // Enable internal pull-up resistors
    void handleEnablePullups();

    // Disable internal pull-up resistors
    void handleDisablePullups();

    // System information
    void handleSystem();

    // Firmware guide
    void handleGuide();

    // Pin diagnostic with periodic report
    void handleWizard(const TerminalCommand& cmd);

    // Hexadecimal converter
    void handleHex(const TerminalCommand& cmd);

    ITerminalView& terminalView;
    IDeviceView& deviceView;
    IInput& terminalInput;
    PinService& pinService;
    UserInputManager& userInputManager;
    PinAnalyzeManager& pinAnalyzeManager;
    ArgTransformer& argTransformer;
    SysInfoShell& sysInfoShell;
    GuideShell& guideShell;
    HelpShell& helpShell;
    ProfileShell& profileShell;
    GlobalState& state = GlobalState::getInstance();
};