shellmatta.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * MIT License
  3. *
  4. * Copyright (c) 2019 Stefan Strobel <stefan.strobel@shimatta.net>
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"),
  8. * to deal in the Software without restriction, including without limitation
  9. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included
  14. * in all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  19. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  20. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  21. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
  22. * THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. */
  24. /**
  25. * @file shellmatta.h
  26. * @brief API definition of the Shellmatta terminal implementation
  27. * @author Stefan Strobel <stefan.strobel@shimatta.net>
  28. */
  29. /**
  30. * @addtogroup shellmatta
  31. * @{
  32. */
  33. #ifndef _SHELLMATTA_H_
  34. #define _SHELLMATTA_H_
  35. #include <stdint.h>
  36. /**
  37. * @brief definition of shellmatta return codes
  38. */
  39. typedef enum
  40. {
  41. SHELLMATTA_OK = 0u, /**< everything is OK */
  42. SHELLMATTA_ERROR , /**< error occured */
  43. SHELLMATTA_CONTINUE , /**< the function is not over */
  44. SHELLMATTA_USE_FAULT /**< parameter error - wrong usage */
  45. } shellmatta_retCode_t;
  46. /**
  47. * @brief shellmatta command function definition
  48. */
  49. typedef shellmatta_retCode_t (*shellmatta_cmdFct_t)(int argc, char *argv[]);
  50. /**
  51. * @brief structure of one shellmatta command
  52. */
  53. typedef struct shellmatta_cmd
  54. {
  55. char *cmd; /**< command name */
  56. char *cmdAlias; /**< command alias */
  57. char *helpText; /**< help text to print in "help" command */
  58. char *usageText; /**< usage text to print on parameter error */
  59. shellmatta_cmdFct_t cmdFct; /**< pointer to the cmd callack function */
  60. struct shellmatta_cmd *next; /**< pointer to next command or NULL */
  61. } shellmatta_cmd_t;
  62. /**
  63. * @brief structure of one shellmatta instance
  64. */
  65. typedef struct
  66. {
  67. uint8_t *buffer; /**< input buffer */
  68. uint32_t bufferSize; /**< size of the input buffer */
  69. uint32_t bufferWritePointer; /**< offset of the current write operation */
  70. uint32_t bufferReadPointer; /**< offset of the current read operation */
  71. uint8_t *historyBuffer; /**< buffer to store the last commands */
  72. uint32_t historyBufferSize; /**< size of the history buffer */
  73. shellmatta_cmd_t *cmdList; /**< pointer to the first command */
  74. } shellmatta_instance_t;
  75. void shellmatta_doInit(shellmatta_instance_t *inst, uint8_t *buffer, uint32_t bufferSize, uint8_t *historyBuffer, uint32_t historyBufferSize);
  76. void shellmatta_addCmd(shellmatta_instance_t *inst, shellmatta_cmd_t *cmd);
  77. void shellmatta_doTask(shellmatta_instance_t *inst, uint32_t time);
  78. void shellmatta_processData(shellmatta_instance_t *inst, char *data, uint32_t size);
  79. void shellmatta_printf(shellmatta_instance_t *inst, const char *fmt, ...);
  80. void shellmatta_getArg(uint32_t cnt, uint8_t *arg);
  81. #endif
  82. /** @} */