cli.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. /* Read from terminal
  25. * Do it only from inside of cli call.
  26. * @param cli - Cli instance
  27. * @param buffer - pointer to buffer
  28. * @param size - size of buffer in bytes
  29. * @return bytes written
  30. */
  31. size_t cli_read(Cli* cli, uint8_t* buffer, size_t size);
  32. /* Write to terminal
  33. * Do it only from inside of cli call.
  34. * @param cli - Cli instance
  35. * @param buffer - pointer to buffer
  36. * @param size - size of buffer in bytes
  37. * @return bytes written
  38. */
  39. void cli_write(Cli* cli, uint8_t* buffer, size_t size);
  40. /* Read character
  41. * @param cli - Cli instance
  42. * @return char
  43. */
  44. char cli_getc(Cli* cli);
  45. /* New line
  46. * Send new ine sequence
  47. */
  48. void cli_nl();
  49. #ifdef __cplusplus
  50. }
  51. #endif