terminal_sbs.cpp 6.2 KB

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