This class can map strings(commands) and functions receiving no arguments returning an int value.
Dependents: Interference_Simple StrCommandHandler_Demo
StrCommandHandler.h@4:59a5e39e3e91, 2020-08-10 (annotated)
- Committer:
- aktk
- Date:
- Mon Aug 10 10:35:29 2020 +0000
- Revision:
- 4:59a5e39e3e91
- Parent:
- 3:049a5f083f32
Modify the callbacks which are to be received and registered to those which receive the command str received as an argument.;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aktk | 0:024213917a9f | 1 | #ifndef STR_COMMAND_HANDLER_H |
aktk | 0:024213917a9f | 2 | #define STR_COMMAND_HANDLER_H |
aktk | 0:024213917a9f | 3 | #include "mbed.h" |
aktk | 0:024213917a9f | 4 | #include <string> |
aktk | 0:024213917a9f | 5 | |
aktk | 0:024213917a9f | 6 | /** Maps strings and functions |
aktk | 0:024213917a9f | 7 | * |
aktk | 0:024213917a9f | 8 | * This class can map strings(commands) and functions receiving no arguments |
aktk | 0:024213917a9f | 9 | * returning int. |
aktk | 0:024213917a9f | 10 | */ |
aktk | 0:024213917a9f | 11 | class StrCommandHandler |
aktk | 0:024213917a9f | 12 | { |
aktk | 0:024213917a9f | 13 | public: |
aktk | 0:024213917a9f | 14 | StrCommandHandler( |
aktk | 0:024213917a9f | 15 | int const arg_num_ofcommand = 10 |
aktk | 0:024213917a9f | 16 | ); |
aktk | 0:024213917a9f | 17 | |
aktk | 1:1d46d90eb7bf | 18 | /** Maps strings and functions |
aktk | 1:1d46d90eb7bf | 19 | * |
aktk | 4:59a5e39e3e91 | 20 | * This maps strings(commands) and functions receiving own command, |
aktk | 2:a4873d38a32c | 21 | * returning something of pointer. |
aktk | 1:1d46d90eb7bf | 22 | */ |
aktk | 2:a4873d38a32c | 23 | void map( |
aktk | 0:024213917a9f | 24 | const char * const arg_command, |
aktk | 4:59a5e39e3e91 | 25 | void * (*arg_pfunc)(const char * const) |
aktk | 0:024213917a9f | 26 | ); |
aktk | 0:024213917a9f | 27 | |
aktk | 1:1d46d90eb7bf | 28 | /** Analyzes a command input and executs a function corresponding to it. |
aktk | 1:1d46d90eb7bf | 29 | * |
aktk | 2:a4873d38a32c | 30 | * This analyzes a string(commands) and executs a corresponding function. |
aktk | 1:1d46d90eb7bf | 31 | * If an error occur, the function returns an error code |
aktk | 1:1d46d90eb7bf | 32 | * Error code: |
aktk | 1:1d46d90eb7bf | 33 | * - Exception of NULL pointer returns 0xFFFFFFFF |
aktk | 1:1d46d90eb7bf | 34 | * - Exception of Null character returna 0xFFFFFFFE |
aktk | 1:1d46d90eb7bf | 35 | * - Exception of Over length returns 0xFFFFFFFD |
aktk | 1:1d46d90eb7bf | 36 | * - Exception of Not registered Command returns 0xFFFFFFFC; |
aktk | 1:1d46d90eb7bf | 37 | */ |
aktk | 2:a4873d38a32c | 38 | void * exe( |
aktk | 0:024213917a9f | 39 | const char* const arg_command |
aktk | 0:024213917a9f | 40 | ); |
aktk | 0:024213917a9f | 41 | |
aktk | 1:1d46d90eb7bf | 42 | /** Lists commands registered |
aktk | 1:1d46d90eb7bf | 43 | * |
aktk | 1:1d46d90eb7bf | 44 | * This lists commands registered by users. |
aktk | 1:1d46d90eb7bf | 45 | */ |
aktk | 0:024213917a9f | 46 | void list(); |
aktk | 3:049a5f083f32 | 47 | |
aktk | 3:049a5f083f32 | 48 | |
aktk | 3:049a5f083f32 | 49 | static char const * const ARROW_UP; /// ascii code series arrow-up symbol 0x1b 0x5b, 0x41 |
aktk | 3:049a5f083f32 | 50 | static char const * const ARROW_DOWN; /// ascii code series arrow-up symbol 0x1b 0x5b, 0x42 |
aktk | 3:049a5f083f32 | 51 | static char const * const ARROW_RIGHT; /// ascii code series arrow-up symbol 0x1b 0x5b, 0x43 |
aktk | 3:049a5f083f32 | 52 | static char const * const ARROW_LEFT; /// ascii code series arrow-up symbol 0x1b 0x5b, 0x44 |
aktk | 0:024213917a9f | 53 | |
aktk | 0:024213917a9f | 54 | private: |
aktk | 0:024213917a9f | 55 | /** Array of commands' name |
aktk | 0:024213917a9f | 56 | * |
aktk | 4:59a5e39e3e91 | 57 | * The length should be within 15 without last '\0' |
aktk | 4:59a5e39e3e91 | 58 | * The number of the array is (int)m_numofcommands |
aktk | 0:024213917a9f | 59 | */ |
aktk | 0:024213917a9f | 60 | char (*m_command_name)[16]; |
aktk | 0:024213917a9f | 61 | |
aktk | 0:024213917a9f | 62 | /** Array of pointers to functions |
aktk | 4:59a5e39e3e91 | 63 | * |
aktk | 4:59a5e39e3e91 | 64 | * The number of the array is (int)m_numofcommands |
aktk | 0:024213917a9f | 65 | */ |
aktk | 4:59a5e39e3e91 | 66 | void * (**m_function)(const char * const); |
aktk | 4:59a5e39e3e91 | 67 | |
aktk | 0:024213917a9f | 68 | /** Numbers of commands registered in this. |
aktk | 0:024213917a9f | 69 | * |
aktk | 0:024213917a9f | 70 | * If commands are registered over this value, |
aktk | 0:024213917a9f | 71 | * this value increase by 5, and arrays get reallocated. |
aktk | 0:024213917a9f | 72 | */ |
aktk | 0:024213917a9f | 73 | int m_num_ofcommands; |
aktk | 2:a4873d38a32c | 74 | |
aktk | 2:a4873d38a32c | 75 | /** Result code of exe() |
aktk | 2:a4873d38a32c | 76 | * |
aktk | 2:a4873d38a32c | 77 | * This is supposed to be offered by pointer |
aktk | 2:a4873d38a32c | 78 | */ |
aktk | 2:a4873d38a32c | 79 | int m_rescode; |
aktk | 0:024213917a9f | 80 | }; |
aktk | 0:024213917a9f | 81 | #endif |