RT_Vterm_example_basic.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "rt_Vterm.h"
  2. #include <rtthread.h>
  3. /**
  4. * @brief Demonstrates basic Vterm read/write operations
  5. *
  6. * @note 1. Writes a message to the upstream buffer using RT_Vterm_Write
  7. * 2. Checks if there's data in the downstream buffer using RT_Vterm_HasData
  8. * 3. Reads data from downstream buffer if available
  9. * 4. Prints confirmation messages to the system console
  10. */
  11. void vterm_example_basic(void)
  12. {
  13. char msg[] = "Vterm Basic Example!"; // Message to send to upstream
  14. char buf[32] = {0}; // Buffer to store downstream data
  15. // Write message to upstream buffer (exclude null terminator)
  16. RT_Vterm_Write(msg, sizeof(msg) - 1);
  17. rt_kprintf("已写入上行: %s\n", msg);
  18. // Check if downstream buffer has data
  19. if (RT_Vterm_HasData())
  20. {
  21. // Read data from downstream buffer
  22. RT_Vterm_Read(buf, sizeof(buf));
  23. rt_kprintf("收到下行: %s\n", buf);
  24. }
  25. }
  26. MSH_CMD_EXPORT(vterm_example_basic, Vterm basic read / write example);
  27. /**
  28. * @brief Demonstrates various formatted output using RT_Vterm_printf
  29. *
  30. * @note 1. Shows different data types (integer, hexadecimal, string, float)
  31. * 2. Uses various format specifiers to illustrate RT_Vterm_printf capabilities
  32. * 3. Outputs results to Vterm upstream tunnel and confirms completion via system console
  33. */
  34. void vterm_example_printf(void)
  35. {
  36. int num = 123;
  37. unsigned hex = 0xABCD;
  38. const char *str = "hello";
  39. float fval = 3.1415f;
  40. RT_Vterm_printf("==== Vterm printf 示例 ====\n");
  41. RT_Vterm_printf("整数: %d\n", num);
  42. RT_Vterm_printf("十六进制: 0x%X\n", hex);
  43. RT_Vterm_printf("字符串: %s\n", str);
  44. RT_Vterm_printf("混合: num=%d, hex=0x%X, str=%s\n", num, hex, str);
  45. RT_Vterm_printf("请在调试器端查看输出\n");
  46. rt_kprintf("Vterm printf example done.\n");
  47. }
  48. MSH_CMD_EXPORT(vterm_example_printf, Vterm printf example);