port_microrl.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. /******************************* (C) LiteMesh **********************************
  2. * @module Console
  3. * @file portConsole.c
  4. * @version 1.0.0
  5. * @date XX.XX.XXXX
  6. * $brief Port functions console lib
  7. *******************************************************************************
  8. * @history Version Author Comment
  9. * XX.XX.XXXX 1.0.0 Telenkov D.A. First release.
  10. *******************************************************************************
  11. */
  12. #include "stm32f4xx.h"
  13. #include "port_microrl.h"
  14. #include "microrl.h"
  15. #include "config.h"
  16. #include "sntp.h"
  17. #include "gpio.h"
  18. #include "bt_6701_settings.h"
  19. #include "commands_api.h"
  20. #ifdef PRINTF_STDLIB
  21. #include <stdio.h>
  22. #endif
  23. #ifdef PRINTF_CUSTOM
  24. #include "tinystdio.h"
  25. #endif
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include <stdbool.h>
  29. #define _AVR_DEMO_VER "1.0"
  30. // definition commands word
  31. #define _CMD_HELP "help"
  32. #define _CMD_CLEAR "clear"
  33. #define _CMD_CLR "clear_port"
  34. #define _CMD_LED "led"
  35. #define _CMD_ETH "ETH"
  36. #define _CMD_PSVOLT "PSVOLT"
  37. #define _CMD_LOADVOLT "LOADVOLT"
  38. #define _CMD_BATVOLT "BATVOLT"
  39. #define _CMD_BATVOLTK "BATVOLTK"
  40. #define _CMD_BATVOLTR "BATVOLTR"
  41. #define _CMD_BAT1VOLT "BAT1VOLT"
  42. #define _CMD_BAT2VOLT "BAT2VOLT"
  43. #define _CMD_BAT3VOLT "BAT3VOLT"
  44. #define _CMD_BAT4VOLT "BAT4VOLT"
  45. #define _CMD_BATCUR "BATCUR"
  46. #define _CMD_LOADCUR "LOADCUR"
  47. #define _CMD_LOADCURK "LOADCURK"
  48. #define _CMD_DIDOOR "DIDOOR"
  49. #define _CMD_DIRV "DIRV"
  50. #define _CMD_LOW150 "LOW150"
  51. #define _CMD_HILOW230 "HILOW230"
  52. #define _CMD_HIGH264 "HIGH264"
  53. #define _CMD_MPSOFF "MPSOFF"
  54. #define _CMD_CANTX "CANTX"
  55. #define _CMD_CANRX "CANRX"
  56. #define _CMD_DAC "DAC"
  57. #define _CMD_SD "SD"
  58. #define _CMD_ONEWIRE "OW"
  59. #define _CMD_SET "SET"
  60. #define _CMD_DEF "DEF"
  61. #define _CMD_RTC "RTC"
  62. #define _CMD_SERNO "SERNO"
  63. #define _CMD_STATUS "STATUS"
  64. #define _CMD_FREQ "FREQ"
  65. #define _CMD_50HZ "50HZ"
  66. #define _CMD_LOW "LOW"
  67. #define _CMD_HILOW "HILOW"
  68. #define _CMD_HI "HI"
  69. #define _CMD_T2READY "T2READY"
  70. #define _CMD_U232U485 "U232U485"
  71. #define _CMD_DRY "DRY"
  72. #define _CMD_U232F "U232F"
  73. #define _CMD_RST "reset"
  74. #define _CMD_SPIFLASH "SPIFLASH"
  75. // arguments for set/clear
  76. #define _SCMD_PB "port_b"
  77. #define _SCMD_PD "port_d"
  78. #define _NUM_OF_CMD
  79. #define _NUM_OF_SETCLEAR_SCMD 2
  80. //available commands
  81. char * keyworld [] = {
  82. _CMD_HELP,
  83. _CMD_CLEAR,
  84. _CMD_LED,
  85. _CMD_ETH,
  86. _CMD_PSVOLT,
  87. _CMD_LOADVOLT,
  88. _CMD_BATVOLT,
  89. _CMD_BATVOLTK,
  90. _CMD_BATVOLTR,
  91. _CMD_BAT1VOLT,
  92. _CMD_BAT2VOLT,
  93. _CMD_BAT3VOLT,
  94. _CMD_BAT4VOLT,
  95. _CMD_BATCUR,
  96. _CMD_LOADCUR,
  97. _CMD_LOADCURK,
  98. _CMD_DIDOOR,
  99. _CMD_DIRV,
  100. _CMD_LOW150,
  101. _CMD_HILOW230,
  102. _CMD_HIGH264,
  103. _CMD_MPSOFF,
  104. _CMD_CANTX,
  105. _CMD_CANRX,
  106. _CMD_DAC,
  107. _CMD_SD,
  108. _CMD_ONEWIRE,
  109. _CMD_SET,
  110. _CMD_DEF,
  111. _CMD_RTC,
  112. _CMD_SERNO,
  113. _CMD_STATUS,
  114. _CMD_FREQ,
  115. _CMD_50HZ,
  116. _CMD_LOW,
  117. _CMD_HILOW,
  118. _CMD_HI,
  119. _CMD_T2READY,
  120. _CMD_U232U485,
  121. _CMD_DRY,
  122. _CMD_U232F,
  123. _CMD_RST,
  124. _CMD_SPIFLASH
  125. };
  126. // 'set/clear' command argements
  127. char * set_clear_key [] = {_SCMD_PB, _SCMD_PD};
  128. // array for comletion
  129. char * compl_world [_NUM_OF_CMD + 1];
  130. microrl_t rl;
  131. microrl_t *prl = &rl;
  132. // параметр команды
  133. #define PARAM_LEN 20
  134. char param[PARAM_LEN];
  135. float value = 0.0;
  136. extern bool testLed;
  137. extern bool testEthernet;
  138. extern bool testDef;
  139. extern bool testSet;
  140. extern bool testRtc;
  141. extern bool testSerno;
  142. extern bool testT2Ready;
  143. /**
  144. * @brief
  145. * @retval
  146. */
  147. void MICRORL_Init(void)
  148. {
  149. microrl_init(prl, print);
  150. microrl_set_execute_callback (prl, execute);
  151. }
  152. /**
  153. * @brief Print callback for microrl library
  154. * @retval
  155. */
  156. void print (const char *str)
  157. {
  158. //printf(str);
  159. }
  160. /**
  161. * @brief
  162. * @retval
  163. */
  164. void MICRORL_GetChar(uint8_t ch)
  165. {
  166. microrl_insert_char(prl, ch);
  167. }
  168. //*****************************************************************************
  169. // execute callback for microrl library
  170. // do what you want here, but don't write to argv!!! read only!!
  171. int execute (int argc, const char * const * argv)
  172. {
  173. int i = 0;
  174. uint16_t len = 0;
  175. // just iterate through argv word and compare it with your commands
  176. while (i < argc)
  177. {
  178. memset(param, 0, PARAM_LEN);
  179. if (strcmp (argv[i], _CMD_HELP) == 0)
  180. {
  181. print ("microrl library v");
  182. print (MICRORL_LIB_VER);
  183. print ("\n\r");
  184. print_help (); // print help
  185. }
  186. else if (strcmp (argv[i], _CMD_CLEAR) == 0)
  187. {
  188. print ("\033[2J"); // ESC seq for clear entire screen
  189. print ("\033[H"); // ESC seq for move cursor at left-top corner
  190. }
  191. /* Тестовая команда */
  192. else if (strcmp (argv[i], _CMD_LED) == 0)
  193. {
  194. //testLed = true;
  195. // TODO Убрать затычку
  196. printf("STATUS T1OK\r");
  197. return 0;
  198. }
  199. /* Тест Ethernet */
  200. else if (strcmp (argv[i], _CMD_ETH) == 0)
  201. {
  202. COM_SetMAC();
  203. //testEthernet = true;
  204. TEST_SetTest(TEST_ETHERNET);
  205. print ("\n\r");
  206. return 0;
  207. }
  208. /* Тест кнопки SET */
  209. else if (strcmp (argv[i], _CMD_SET) == 0)
  210. {
  211. //testSet = true;
  212. TEST_SetTest(TEST_SET);
  213. print ("\n\r");
  214. return 0;
  215. }
  216. /* Тест кнопки DEF */
  217. else if (strcmp (argv[i], _CMD_DEF) == 0)
  218. {
  219. //testDef = true;
  220. TEST_SetTest(TEST_DEF);
  221. print ("\n\r");
  222. return 0;
  223. }
  224. /* Тест RTC */
  225. else if (strcmp (argv[i], _CMD_RTC) == 0)
  226. {
  227. if (++i < argc)
  228. {
  229. len = strlen(argv[i]);
  230. strncpy(param, argv[i], len);
  231. SNTP_SetServerAddr(param);
  232. TEST_SetTest(TEST_RTC);
  233. // testRtc = true;
  234. print ("\n\r");
  235. return 0;
  236. }
  237. print ("\n\r");
  238. }
  239. /* Установка SERNO */
  240. else if (strcmp (argv[i], _CMD_SERNO) == 0)
  241. {
  242. if (++i < argc)
  243. {
  244. len = strlen(argv[i]);
  245. strncpy(param, argv[i], len);
  246. SETTINGS_SetSerno(param);
  247. //testSerno = true;
  248. TEST_SetTest(TEST_SERNO);
  249. print ("\n\r");
  250. return 0;
  251. }
  252. print ("\n\r");
  253. }
  254. /* -------------------------------------------------------------------- */
  255. /* Тесты для SmartUPS */
  256. /* Тест сухих контактов */
  257. else if (strcmp (argv[i], _CMD_DRY) == 0)
  258. {
  259. //testSet = true;
  260. TEST_SetTest(TEST_DRY);
  261. print ("\n\r");
  262. return 0;
  263. }
  264. /* Тест дополнительных пинов RS232 */
  265. else if (strcmp (argv[i], _CMD_U232F) == 0)
  266. {
  267. //testSet = true;
  268. TEST_SetTest(TEST_U232F);
  269. print ("\n\r");
  270. return 0;
  271. }
  272. /* Тест spi flash */
  273. else if (strcmp (argv[i], _CMD_SPIFLASH) == 0)
  274. {
  275. //testSet = true;
  276. TEST_SetTest(TEST_SPIFLASH);
  277. print ("\n\r");
  278. return 0;
  279. }
  280. /* -------------------------------------------------------------------- */
  281. /* Тесты этапа Т2 */
  282. /* Статус тестера */
  283. else if (strcmp (argv[i], _CMD_STATUS) == 0)
  284. {
  285. //printf("STATUS %s\r", sSettings.sFlags.testState);
  286. printf("STATUS %s\r", SETTINGS_GetTestState());
  287. return 0;
  288. }
  289. /* T2READY */
  290. else if (strcmp (argv[i], _CMD_T2READY) == 0)
  291. {
  292. testT2Ready = true;
  293. return 0;
  294. }
  295. /* Перезагрузить контроллер */
  296. else if (strcmp (argv[i], _CMD_RST) == 0)
  297. {
  298. NVIC_SystemReset();
  299. }
  300. else
  301. {
  302. print ("command: '");
  303. print ((char*)argv[i]);
  304. print ("' Not found.\n\r");
  305. }
  306. i++;
  307. }
  308. return 0;
  309. }
  310. void print_help (void)
  311. {
  312. print ("Use TAB key for completion\n\rCommand:\n\r");
  313. print ("\tclear - clear screen\n\r");
  314. print ("\tdac - send test value\n\r");
  315. }
  316. /******************************* (C) LiteMesh *********************************/