terminal_sbs.cpp 4.0 KB

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