terminal_sbs.cpp 5.1 KB

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