cli.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #pragma once
  2. #ifdef __cplusplus
  3. extern "C" {
  4. #endif
  5. #include <m-string.h>
  6. typedef enum {
  7. CliSymbolAsciiSOH = 0x01,
  8. CliSymbolAsciiETX = 0x03,
  9. CliSymbolAsciiEOT = 0x04,
  10. CliSymbolAsciiBell = 0x07,
  11. CliSymbolAsciiBackspace = 0x08,
  12. CliSymbolAsciiTab = 0x09,
  13. CliSymbolAsciiCR = 0x0D,
  14. CliSymbolAsciiEsc = 0x1B,
  15. CliSymbolAsciiUS = 0x1F,
  16. CliSymbolAsciiSpace = 0x20,
  17. CliSymbolAsciiDel = 0x7F,
  18. } CliSymbols;
  19. /* Cli type
  20. * Anonymous structure. Use cli_i.h if you need to go deeper.
  21. */
  22. typedef struct Cli Cli;
  23. /* Cli callback function pointer.
  24. * Implement this interface and use add_cli_command
  25. * @param args - string with what was passed after command
  26. * @param context - pointer to whatever you gave us on cli_add_command
  27. */
  28. typedef void (*CliCallback)(Cli* cli, string_t args, void* context);
  29. /* Add cli command
  30. * Registers you command callback
  31. * @param cli - pointer to cli instance
  32. * @param name - command name
  33. * @param callback - callback function
  34. * @param context - pointer to whatever we need to pass to callback
  35. */
  36. void cli_add_command(Cli* cli, const char* name, CliCallback callback, void* context);
  37. /* Print unified cmd usage tip
  38. * @param cmd - cmd name
  39. * @param usage - usage tip
  40. * @param arg - arg passed by user
  41. */
  42. void cli_print_usage(const char* cmd, const char* usage, const char* arg);
  43. /* Delete cli command
  44. * @param cli - pointer to cli instance
  45. * @param name - command name
  46. */
  47. void cli_delete_command(Cli* cli, const char* name);
  48. /* Read from terminal
  49. * Do it only from inside of cli call.
  50. * @param cli - Cli instance
  51. * @param buffer - pointer to buffer
  52. * @param size - size of buffer in bytes
  53. * @return bytes written
  54. */
  55. size_t cli_read(Cli* cli, uint8_t* buffer, size_t size);
  56. /* Not blocking check for interrupt command received
  57. * @param cli - Cli instance
  58. */
  59. bool cli_cmd_interrupt_received(Cli* cli);
  60. /* Write to terminal
  61. * Do it only from inside of cli call.
  62. * @param cli - Cli instance
  63. * @param buffer - pointer to buffer
  64. * @param size - size of buffer in bytes
  65. * @return bytes written
  66. */
  67. void cli_write(Cli* cli, uint8_t* buffer, size_t size);
  68. /* Read character
  69. * @param cli - Cli instance
  70. * @return char
  71. */
  72. char cli_getc(Cli* cli);
  73. /* New line
  74. * Send new ine sequence
  75. */
  76. void cli_nl();
  77. #ifdef __cplusplus
  78. }
  79. #endif