terminal_sbs.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. archive_entry_t entry;
  73. log_get_entry(atoi(argv[1]), &fs_archive, &entry);
  74. return 0;
  75. }
  76. // ---------------------------------------------------------------------- //
  77. if (strcmp(argv[0], "mstime") == 0) {
  78. printf("\r\n%" PRId64 " [ms]\r\n", rtc_get_ms());
  79. return 0;
  80. }
  81. // ---------------------------------------------------------------------- //
  82. else {
  83. printeol();
  84. printll("Uncknown command [oO]");
  85. return -1;
  86. }
  87. }
  88. void SbsTerminal::sigint() {
  89. }
  90. //Колбэк, который может быть вызван при подключении
  91. void SbsTerminal::connectCallback()
  92. {
  93. clearScreen();
  94. printll("SBS terminal.");
  95. //Тут выводим полезную при подключении информацию
  96. printeol();
  97. printll("For help type 'help'.");
  98. insert('\r');
  99. }
  100. //
  101. int SbsTerminal::help(int argc, const char * const *argv)
  102. {
  103. printeol();
  104. printeol();
  105. printl ("You can use the following commands:");
  106. printl (" version Print software version");
  107. printl (" reset Reset");
  108. printl (" add_aentry Add N archive entries");
  109. printl (" ainfo Print archive info");
  110. printl (" afetch Fetch archive entry");
  111. printl (" aentry Get archive entry [position] [sector] [slot]");
  112. printll(" aformat Format archive partition");
  113. printeol();
  114. return 0;
  115. }
  116. //
  117. int SbsTerminal::version(int argc, const char * const *argv)
  118. {
  119. printeol();
  120. print(VERSION);
  121. printeol();
  122. return 0;
  123. }
  124. //
  125. int SbsTerminal::clear(int argc, const char * const *argv)
  126. {
  127. if ((argc > 1) && (strcmp(argv[1], "help") == 0))
  128. {
  129. printeol();
  130. printl("Clear terminal screen");
  131. printeol();
  132. printeol();
  133. return 0;
  134. }
  135. clearScreen();
  136. return 0;
  137. }
  138. //
  139. void SbsTerminal::put_byte(char byte)
  140. {
  141. portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
  142. xQueueSendFromISR(m_dataQueue, &byte, &xHigherPriorityTaskWoken);
  143. }
  144. //
  145. void vTerminal(void *params)
  146. {
  147. char val;
  148. for (;;)
  149. {
  150. if (xQueueReceive(sbsTerminal.m_dataQueue, &val, 1000 ) == pdPASS)
  151. {
  152. sbsTerminal.insert(val);
  153. }
  154. }
  155. }