cli.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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)(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. /* Write to terminal
  38. * Do it only from inside of cli call.
  39. * @param cli - Cli instance
  40. * @param buffer - pointer to buffer
  41. * @param size - size of buffer in bytes
  42. * @return bytes written
  43. */
  44. void cli_write(Cli* cli, uint8_t* buffer, size_t size);
  45. /* Read character
  46. * @param cli - Cli instance
  47. * @return char
  48. */
  49. char cli_getc(Cli* cli);
  50. /* New line
  51. * Send new ine sequence
  52. */
  53. void cli_nl();
  54. #ifdef __cplusplus
  55. }
  56. #endif