cli.h 1.9 KB

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