HomeAut
CommandHandler.h
1 /*
2  * CommandHandler.h
3  *
4  * Created on 2013.10.08.
5  * Author: Vizi Gábor
6  * E-mail: vizi.gabor90@gmail.com
7  * Function: Command Handler: communication with UART, execute commands
8  * Target: STM32Fx
9  * Version: v4
10  * Last modified: 2016. dec. 13
11  */
12 
13 #ifndef COMMANDHANDLER_H_
14 #define COMMANDHANDLER_H_
15 
16 
17 #include "include.h"
18 #include "escapesequence.h"
19 #include "communication.h"
20 #include "board.h"
21 #include "version.h"
22 
23 
25 
26 
28 // DEFINES
29 // TYPEDEFS
30 // EXTERNED GLOBAL VARIABLES
31 // EXTERNED PROTOTYPES
33 
34 
35 
36 /*------------------------------------------------------------------------------
37  * Macros & definitions
38  *----------------------------------------------------------------------------*/
39 
40 
41 // Config defines
42 
43 
44 #define MONITOR_MAX_COMMAND_LENGTH (255U)
45 #define MONITOR_COMMAND_ARG_MAX_COUNT (3)
46 #define MONITOR_COMMAND_ARG_MAX_NUM_BITS (0x07) // 0b111 <-- warning: "binary constants are a GCC extension
47 
48 #define MONITOR_HISTORY_MAX_COUNT (5)
49 
50 
51 #define MONITOR_DUMMY_STRING "____________________________________________\r\n"
52 
53 
54 #define MONITOR_SEND_WELCOME() \
55  MONITOR_SendMessage( \
56  "\r\n" \
57  "Welcome in Monitor program!\r\n" \
58  "Version: " VERSION_DEFINE "\r\n" \
59  "Date: " DATE_VERSION "\r\n" \
60  "Time: "TIME_VERSION "\r\n" \
61  "Used panel: " BOARD_NAME "\r\n" \
62  "(c) Copyright, Vizi Gabor\r\n" \
63  "\r\n" \
64  "Try \"help\" command for help!\r\n")
65 
66 
67 #define MONITOR_SEND_PROMT_NEW_LINE() \
68  MONITOR_SendMessage("\r\n# ")
69 
70 #define MONITOR_SEND_PROMT() \
71  MONITOR_SendMessage("# ")
72 
73 
74 #define USART_SEND_DUMMYSTRING() MONITOR_SendMessage(MONITOR_DUMMY_STRING)
75 
76 
77 #define MONITOR_SEND_NEW_LINE() \
78  MONITOR_SendMessage("\r\n")
79 
80 
81 // DEFINES FOR CHARACTERS
82 
83 CONFIG_USE_TERMINAL_ZOC
84 #if defined(CONFIG_USE_TERMINAL_ZOC) || defined(CONFIG_USE_TERMINAL_PUTTY)
85 #define USART_KEY_DELETE (0x08)
86 #define USART_KEY_BACKSPACE (0x7F)
87 #else
88 #define USART_KEY_DELETE (0x7F)
89 #define USART_KEY_BACKSPACE (0x08)
90 #endif
91 
92 
93 #define USART_KEY_ENTER ('\r')
94 #define USART_KEY_SPACE (' ')
95 #define USART_KEY_ESCAPE ('\x1B')
96 #define USART_KEY_BELL ('\a')
97 
98 
99 // NOTE: Changed \e to \x1B
100 #define USART_ESCAPESEQUENCE_1 ('\x1B')
101 #define USART_ESCAPESEQUENCE_2 ('[')
102 
103 
104 // BUTTONS
105 
106 
107 // 8 = BS = Backspace
108 #define USART_SEND_KEY_BACKSPACE() \
109  MONITOR_SendChar(8)
110 
111 // 127 = DEL = Delete
112 #define USART_SEND_KEY_DEL() \
113  MONITOR_SendChar(127)
114 
115 
116 
117 /*------------------------------------------------------------------------------
118  * Type definitions
119  *----------------------------------------------------------------------------*/
120 
121 
123 typedef enum
124 {
125  CommandResult_Unknown = 0,
126  CommandResult_Ok,
127  CommandResult_Ok_SendSuccessful,
128  CommandResult_Error_WrongArgument1,
129  CommandResult_Error_WrongArgument2,
130  CommandResult_Error_TooFewArgument,
131  CommandResult_Error_WrongArgumentNum,
132  CommandResult_Error_TooManyArgument,
133  CommandResult_Error_CommandArgNumIsWrong,
134  CommandResult_Error_CommandNotFound,
135  CommandResult_Error_Unknown
136 } CommandResult_t;
137 
138 
140 typedef CommandResult_t ( *FunctionPointer )( uint32_t argc, char** COMMAND_Arguments );
141 
142 
144 typedef uint8_t CommandID_t;
145 
146 
148 typedef enum
149 {
150  CommandArgument_0 = (1 << 0),
151  CommandArgument_1 = (1 << 1),
152  CommandArgument_2 = (1 << 2)
153 } CommandArgNum_t;
154 
155 
157 typedef struct
158 {
159  const char *name;
160  const FunctionPointer *commandFunctionPointer;
161  const char *description;
162  const char *syntax;
163  const CommandArgNum_t commandArgNum;
164 } CommandStruct;
165 
166 
167 
168 /*------------------------------------------------------------------------------
169  * Global variables
170  *----------------------------------------------------------------------------*/
171 
172 extern volatile char MONITOR_CommandActual[MONITOR_MAX_COMMAND_LENGTH];
173 extern volatile CommProtocol_t MONITOR_CommandSource;
174 
175 extern const bool MONITOR_CommandReceiveEnable;
176 
177 
178 #ifdef CONFIG_USE_FREERTOS
179 extern xSemaphoreHandle DEBUG_USART_Rx_Semaphore;
180 extern xSemaphoreHandle DEBUG_USART_Tx_Semaphore;
181 #endif
182 
183 
184 
185 /*------------------------------------------------------------------------------
186  * Global function declarations
187  *----------------------------------------------------------------------------*/
188 
189 void MONITOR_Init(void);
190 void MONITOR_SendWelcome(void);
191 
192 void MONITOR_CheckCommand(void);
193 
194 void MONITOR_WriteCommandHelp(CommandID_t commandID);
195 void MONITOR_SendCls(void);
196 
197 void MONITOR_SendMessage(const char *message);
198 void MONITOR_SendLine(const char *message);
199 void MONITOR_SendChar(char c);
200 void MONITOR_Printf(const char *format, ...);
201 
202 void MONITOR_PrintAllCommands(void);
203 void MONITOR_SearchCommandAndPrintHelp(const char *command);
204 
205 
206 #endif /* COMMANDHANDLER_H_ */
const FunctionPointer * commandFunctionPointer
Function pointer (which called)
Definition: CommandHandler.h:160
const char * syntax
Command syntax.
Definition: CommandHandler.h:162
const CommandArgNum_t commandArgNum
Required command argument num.
Definition: CommandHandler.h:163
const char * description
Command description (for help)
Definition: CommandHandler.h:161
Command structure.
Definition: CommandHandler.h:157
const char * name
Name of command (which need type) [string].
Definition: CommandHandler.h:159