CommandHandler.h
Go to the documentation of this file.
1 /*
2  * CommandHandler.h
3  *
4  * Created on: 2 jul. 2015
5  * Author: Herman
6  */
25 #pragma once
26 
27 #include "CommandDelegate.h"
28 #include <WHashMap.h>
29 #include <SystemClock.h>
30 #include <HardwareSerial.h>
31 
34 typedef enum {
37 } VerboseMode;
38 
41 {
42 public:
47 
54  bool registerCommand(CommandDelegate reqDelegate);
55 
59  bool unregisterCommand(CommandDelegate reqDelegate);
60 
71 
76  CommandDelegate getCommandDelegate(const String& commandString);
77 
82  {
83  return verboseMode;
84  }
85 
89  void setVerboseMode(VerboseMode reqVerboseMode)
90  {
91  verboseMode = reqVerboseMode;
92  }
93 
100  {
101  return currentPrompt;
102  }
103 
109  void setCommandPrompt(const String& reqPrompt)
110  {
111  currentPrompt = reqPrompt;
112  }
113 
119  {
120  return currentEOL;
121  }
122 
127  void setCommandEOL(char reqEOL)
128  {
129  currentEOL = reqEOL;
130  }
131 
137  {
138  return currentWelcomeMessage;
139  }
140 
145  void setCommandWelcomeMessage(const String& reqWelcomeMessage)
146  {
147  currentWelcomeMessage = reqWelcomeMessage;
148  }
149 
150  // int deleteGroup(String reqGroup);
151 
152 private:
153  HashMap<String, CommandDelegate>* registeredCommands;
154  void procesHelpCommand(String commandLine, CommandOutput* commandOutput);
155  void procesStatusCommand(String commandLine, CommandOutput* commandOutput);
156  void procesEchoCommand(String commandLine, CommandOutput* commandOutput);
157  void procesDebugOnCommand(String commandLine, CommandOutput* commandOutput);
158  void procesDebugOffCommand(String commandLine, CommandOutput* commandOutput);
159  void processCommandOptions(String commandLine, CommandOutput* commandOutput);
160 
161  VerboseMode verboseMode = VERBOSE;
162  String currentPrompt;
163  char currentEOL = '\r';
164  String currentWelcomeMessage;
165 };
166 
169 
CommandDelegate getCommandDelegate(const String &commandString)
Get the command delegate for a command.
CommandHandler()
Instantiate a CommandHandler.
String getCommandPrompt()
Get the command line prompt.
Definition: CommandHandler.h:99
void setCommandWelcomeMessage(const String &reqWelcomeMessage)
Set the welcome message.
Definition: CommandHandler.h:145
void setVerboseMode(VerboseMode reqVerboseMode)
Set the verbose mode.
Definition: CommandHandler.h:89
Silent mode.
Definition: CommandHandler.h:36
VerboseMode
Verbose mode.
Definition: CommandHandler.h:34
Verbose mode.
Definition: CommandHandler.h:35
The String class.
Definition: WString.h:136
char getCommandEOL()
Get the end of line character.
Definition: CommandHandler.h:118
void setCommandEOL(char reqEOL)
Set the end of line character.
Definition: CommandHandler.h:127
bool registerCommand(CommandDelegate reqDelegate)
Add a new command to the command handler.
bool unregisterCommand(CommandDelegate reqDelegate)
Remove a command from the command handler.
Definition: CommandOutput.h:15
void setCommandPrompt(const String &reqPrompt)
Set the command line prompt.
Definition: CommandHandler.h:109
Command handler class.
Definition: CommandHandler.h:40
CommandHandler commandHandler
Global instance of CommandHandler.
Command delegate class.
Definition: CommandDelegate.h:29
void registerSystemCommands()
Register default system commands.
VerboseMode getVerboseMode()
Get the verbose mode.
Definition: CommandHandler.h:81
String getCommandWelcomeMessage()
Get the welcome message.
Definition: CommandHandler.h:136