FreeRTOS_CLI.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * FreeRTOS+CLI V1.0.4
  3. * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  6. * this software and associated documentation files (the "Software"), to deal in
  7. * the Software without restriction, including without limitation the rights to
  8. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  9. * the Software, and to permit persons to whom the Software is furnished to do so,
  10. * subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in all
  13. * copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  17. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  18. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  19. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  20. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * http://www.FreeRTOS.org
  23. * http://aws.amazon.com/freertos
  24. *
  25. * 1 tab == 4 spaces!
  26. */
  27. #ifndef COMMAND_INTERPRETER_H
  28. #define COMMAND_INTERPRETER_H
  29. /* The prototype to which callback functions used to process command line
  30. commands must comply. pcWriteBuffer is a buffer into which the output from
  31. executing the command can be written, xWriteBufferLen is the length, in bytes of
  32. the pcWriteBuffer buffer, and pcCommandString is the entire string as input by
  33. the user (from which parameters can be extracted).*/
  34. typedef BaseType_t (*pdCOMMAND_LINE_CALLBACK)( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
  35. /* The structure that defines command line commands. A command line command
  36. should be defined by declaring a const structure of this type. */
  37. typedef struct xCOMMAND_LINE_INPUT
  38. {
  39. const char * const pcCommand; /* The command that causes pxCommandInterpreter to be executed. For example "help". Must be all lower case. */
  40. const char * const pcHelpString; /* String that describes how to use the command. Should start with the command itself, and end with "\r\n". For example "help: Returns a list of all the commands\r\n". */
  41. const pdCOMMAND_LINE_CALLBACK pxCommandInterpreter; /* A pointer to the callback function that will return the output generated by the command. */
  42. int8_t cExpectedNumberOfParameters; /* Commands expect a fixed number of parameters, which may be zero. */
  43. } CLI_Command_Definition_t;
  44. /* For backward compatibility. */
  45. #define xCommandLineInput CLI_Command_Definition_t
  46. /*
  47. * Register the command passed in using the pxCommandToRegister parameter.
  48. * Registering a command adds the command to the list of commands that are
  49. * handled by the command interpreter. Once a command has been registered it
  50. * can be executed from the command line.
  51. */
  52. BaseType_t FreeRTOS_CLIRegisterCommand( const CLI_Command_Definition_t * const pxCommandToRegister );
  53. /*
  54. * Runs the command interpreter for the command string "pcCommandInput". Any
  55. * output generated by running the command will be placed into pcWriteBuffer.
  56. * xWriteBufferLen must indicate the size, in bytes, of the buffer pointed to
  57. * by pcWriteBuffer.
  58. *
  59. * FreeRTOS_CLIProcessCommand should be called repeatedly until it returns pdFALSE.
  60. *
  61. * pcCmdIntProcessCommand is not reentrant. It must not be called from more
  62. * than one task - or at least - by more than one task at a time.
  63. */
  64. BaseType_t FreeRTOS_CLIProcessCommand( const char * const pcCommandInput, char * pcWriteBuffer, size_t xWriteBufferLen );
  65. /*-----------------------------------------------------------*/
  66. /*
  67. * A buffer into which command outputs can be written is declared in the
  68. * main command interpreter, rather than in the command console implementation,
  69. * to allow application that provide access to the command console via multiple
  70. * interfaces to share a buffer, and therefore save RAM. Note, however, that
  71. * the command interpreter itself is not re-entrant, so only one command
  72. * console interface can be used at any one time. For that reason, no attempt
  73. * is made to provide any mutual exclusion mechanism on the output buffer.
  74. *
  75. * FreeRTOS_CLIGetOutputBuffer() returns the address of the output buffer.
  76. */
  77. char *FreeRTOS_CLIGetOutputBuffer( void );
  78. /*
  79. * Return a pointer to the xParameterNumber'th word in pcCommandString.
  80. */
  81. const char *FreeRTOS_CLIGetParameter( const char *pcCommandString, UBaseType_t uxWantedParameter, BaseType_t *pxParameterStringLength );
  82. #endif /* COMMAND_INTERPRETER_H */