terminal_sbs.cpp 4.0 KB

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