terminal_sbs.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #include "terminal_sbs.h"
  2. #include "common_config.h"
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <stdbool.h>
  7. #include <inttypes.h>
  8. extern "C" {
  9. #include "log.h"
  10. #include "rtc.h"
  11. }
  12. SbsTerminal sbsTerminal;
  13. Terminal* pTerminal; //Глобальный указатель на терминал
  14. void vTerminal(void *params);
  15. //
  16. SbsTerminal::SbsTerminal() :
  17. Terminal()
  18. {}
  19. //
  20. void SbsTerminal::configure()
  21. {
  22. Terminal::configure();
  23. pTerminal = &sbsTerminal;
  24. m_dataQueue = xQueueCreate(20, 1);
  25. xTaskCreate(vTerminal, "terminal", 2*configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL);
  26. }
  27. //
  28. int SbsTerminal::execute(int argc, const char * const *argv)
  29. {
  30. //char str[20];
  31. if (argc <= 0) {
  32. return -1;
  33. }
  34. if (strcmp(argv[0], "help") == 0) {
  35. return help(argc, argv);
  36. }
  37. if (strcmp(argv[0], "version") == 0) {
  38. return version(argc, argv);
  39. }
  40. if (strcmp(argv[0], "reset") == 0) {
  41. NVIC_SystemReset();
  42. }
  43. // ---------------------------------------------------------------------- //
  44. // Archive API
  45. // Добавить N новых записей в архив
  46. if (strcmp(argv[0], "add_aentry") == 0) {
  47. if (argc > 1)
  48. test_add_random_archive_entry(atoi(argv[1]));
  49. else
  50. printf("No record counter\r\n");
  51. return 0;
  52. }
  53. // Информация об архиве
  54. if (strcmp(argv[0], "ainfo") == 0) {
  55. test_archive_info();
  56. return 0;
  57. }
  58. // Fetch archive entry
  59. if (strcmp(argv[0], "afetch") == 0) {
  60. test_fetch();
  61. return 0;
  62. }
  63. // Format archive FS
  64. if (strcmp(argv[0], "aformat") == 0) {
  65. test_archive_format();
  66. return 0;
  67. }
  68. // ---------------------------------------------------------------------- //
  69. if (strcmp(argv[0], "mstime") == 0) {
  70. printf("\r\n%" PRId64 " [ms]\r\n", rtc_get_ms());
  71. return 0;
  72. }
  73. // ---------------------------------------------------------------------- //
  74. else {
  75. printeol();
  76. printll("Uncknown command [oO]");
  77. return -1;
  78. }
  79. }
  80. void SbsTerminal::sigint() {
  81. }
  82. //Колбэк, который может быть вызван при подключении
  83. void SbsTerminal::connectCallback()
  84. {
  85. clearScreen();
  86. printll("SBS terminal.");
  87. //Тут выводим полезную при подключении информацию
  88. printeol();
  89. printll("For help type 'help'.");
  90. insert('\r');
  91. }
  92. //
  93. int SbsTerminal::help(int argc, const char * const *argv)
  94. {
  95. printeol();
  96. printeol();
  97. printl ("You can use the following commands:");
  98. printl (" version Print software version");
  99. printl (" reset Reset");
  100. printl (" add_aentry Add N archive entrys");
  101. printl (" ainfo Print archive info");
  102. printl (" afetch Fetch archive entry");
  103. printll(" aformat Format archive partition");
  104. printeol();
  105. return 0;
  106. }
  107. //
  108. int SbsTerminal::version(int argc, const char * const *argv)
  109. {
  110. printeol();
  111. print(VERSION);
  112. printeol();
  113. return 0;
  114. }
  115. //
  116. int SbsTerminal::clear(int argc, const char * const *argv)
  117. {
  118. if ((argc > 1) && (strcmp(argv[1], "help") == 0))
  119. {
  120. printeol();
  121. printl("Clear terminal screen");
  122. printeol();
  123. printeol();
  124. return 0;
  125. }
  126. clearScreen();
  127. return 0;
  128. }
  129. //
  130. void SbsTerminal::put_byte(char byte)
  131. {
  132. portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
  133. xQueueSendFromISR(m_dataQueue, &byte, &xHigherPriorityTaskWoken);
  134. }
  135. //
  136. void vTerminal(void *params)
  137. {
  138. char val;
  139. for (;;)
  140. {
  141. if (xQueueReceive(sbsTerminal.m_dataQueue, &val, 1000 ) == pdPASS)
  142. {
  143. sbsTerminal.insert(val);
  144. }
  145. }
  146. }