terminal_sbs.cpp 6.2 KB

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