Avionics
Core avionics package for CURE flight computers
Loading...
Searching...
No Matches
UARTCommandHandler.h
Go to the documentation of this file.
1#ifndef UARTCOMMANDHANDLER_H
2#define UARTCOMMANDHANDLER_H
3
4#include <functional>
5#include <queue>
6#include <string>
7#include <vector>
8
9#include "ArduinoHAL.h"
10
11#define SHELL_PROMPT "AS> " // AS = Avionics Shell
12
13enum class AsciiKey : uint8_t {
14 Escape = 27,
15 UpArrow = 65,
18 Delete = 127
19};
20
21constexpr int UART_BUFFER_SIZE = 128;
22constexpr int MAX_ARGUMENTS = 5;
23constexpr int MAX_ROW_LENGTH = 40;
24
31
32public:
33 CommandLine(Stream * UART); // Constructor
34 void addCommand(const std::string& longName, const std::string& shortName, std::function<void(std::queue<std::string> argumentQueue ,std::string&)> funcPtr);
35 void executeCommand(const std::string& command, std::queue<std::string> arugments);
36 void readInput();
37 void processCommand(const std::string& command);
38 void begin();
39
40 // Pass-through functions for the UART object
41 void println(const std::string& message){
42 UART->println(message.c_str());
43 }
44 void print(const std::string& message){
45 UART->print(message.c_str());
46 }
47
48private:
49 Stream * UART; // Pointer to the UART object
50 struct Command {
51 std::string longName;
52 std::string shortName;
53 std::function<void(std::queue<std::string>, std::string&)> funcPtr; // Function pointer to the command handler
54 };
55 std::vector<Command> commands{}; // Vector to store the list of commands
56
57 // Class member variables for buffering and history
58 std::string fullLine = {""};
59
60
61 void help();
62 void trimSpaces(std::string& str);
63
64 void handleBackspace_();
65 void handleNewline_();
66 void handleChar_(char receivedChar);
67
68 bool lastWasCR_ = false; // Track if the last character was a carriage return for proper newline handling
69};
70
71#endif
constexpr int MAX_ARGUMENTS
constexpr int UART_BUFFER_SIZE
constexpr int MAX_ROW_LENGTH
void print(const std::string &message)
void executeCommand(const std::string &command, std::queue< std::string > arugments)
void addCommand(const std::string &longName, const std::string &shortName, std::function< void(std::queue< std::string > argumentQueue, std::string &)> funcPtr)
CommandLine(Stream *UART)
void println(const std::string &message)
void processCommand(const std::string &command)