cli.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. /* Delete cli command
  25. * @param cli - pointer to cli instance
  26. * @param name - command name
  27. */
  28. void cli_delete_command(Cli* cli, const char* name);
  29. /* Read from terminal
  30. * Do it only from inside of cli call.
  31. * @param cli - Cli instance
  32. * @param buffer - pointer to buffer
  33. * @param size - size of buffer in bytes
  34. * @return bytes written
  35. */
  36. size_t cli_read(Cli* cli, uint8_t* buffer, size_t size);
  37. /* Not blocking check for interrupt command received
  38. * @param cli - Cli instance
  39. */
  40. bool cli_cmd_interrupt_received(Cli* cli);
  41. /* Write to terminal
  42. * Do it only from inside of cli call.
  43. * @param cli - Cli instance
  44. * @param buffer - pointer to buffer
  45. * @param size - size of buffer in bytes
  46. * @return bytes written
  47. */
  48. void cli_write(Cli* cli, uint8_t* buffer, size_t size);
  49. /* Read character
  50. * @param cli - Cli instance
  51. * @return char
  52. */
  53. char cli_getc(Cli* cli);
  54. /* New line
  55. * Send new ine sequence
  56. */
  57. void cli_nl();
  58. #ifdef __cplusplus
  59. }
  60. #endif