terminal_sbs.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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], "lstate") == 0) {
  102. if (argc > 1)
  103. log_log_state(atoi(argv[1]));
  104. return 0;
  105. }
  106. //
  107. if (strcmp(argv[0], "astate") == 0) {
  108. log_archive_state(atoi(argv[1]));
  109. return 0;
  110. }
  111. // ---------------------------------------------------------------------- //
  112. if (strcmp(argv[0], "mstime") == 0) {
  113. TM_RTC_PrintTime();
  114. printf("\r\n%" PRId64 " [ms]\r\n", rtc_get_ms());
  115. return 0;
  116. }
  117. //
  118. if (strcmp(argv[0], "settings") == 0) {
  119. settings_print();
  120. return 0;
  121. }
  122. // ---------------------------------------------------------------------- //
  123. else {
  124. printeol();
  125. printll("Uncknown command [oO]");
  126. return -1;
  127. }
  128. }
  129. void SbsTerminal::sigint() {
  130. }
  131. //Колбэк, который может быть вызван при подключении
  132. void SbsTerminal::connectCallback()
  133. {
  134. clearScreen();
  135. printll("SBS terminal.");
  136. //Тут выводим полезную при подключении информацию
  137. printeol();
  138. printll("For help type 'help'.");
  139. insert('\r');
  140. }
  141. //
  142. int SbsTerminal::help(int argc, const char * const *argv)
  143. {
  144. printeol();
  145. printeol();
  146. printl ("You can use the following commands:");
  147. printl (" version Print software version");
  148. printl (" reset Reset");
  149. printl (" add_lentry Add N log entries");
  150. printl (" add_aentry Add N archive entries");
  151. printl (" linfo Print log info");
  152. printl (" ainfo Print archive info");
  153. printl (" afetch Fetch archive entry");
  154. printl (" aentry Get archive entry [position] [sector] [slot]");
  155. printl (" lformat Format log partition");
  156. printl (" aformat Format archive partition");
  157. printl (" lstate log enable/disable");
  158. printl (" astate archive enable/disable");
  159. printl (" mstime gurrnet rtc in ms");
  160. printl (" settings Print settings structure");
  161. printeol();
  162. return 0;
  163. }
  164. //
  165. int SbsTerminal::version(int argc, const char * const *argv)
  166. {
  167. printeol();
  168. print(FW_VERSION);
  169. printeol();
  170. return 0;
  171. }
  172. //
  173. int SbsTerminal::clear(int argc, const char * const *argv)
  174. {
  175. if ((argc > 1) && (strcmp(argv[1], "help") == 0))
  176. {
  177. printeol();
  178. printl("Clear terminal screen");
  179. printeol();
  180. printeol();
  181. return 0;
  182. }
  183. clearScreen();
  184. return 0;
  185. }
  186. //
  187. void SbsTerminal::put_byte(char byte)
  188. {
  189. portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
  190. xQueueSendFromISR(m_dataQueue, &byte, &xHigherPriorityTaskWoken);
  191. }
  192. //
  193. void vTerminal(void *params)
  194. {
  195. char val;
  196. for (;;)
  197. {
  198. if (xQueueReceive(sbsTerminal.m_dataQueue, &val, 1000 ) == pdPASS)
  199. {
  200. sbsTerminal.insert(val);
  201. }
  202. }
  203. }