port_microrl.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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_api.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. #define _CMD_U232 "U232"
  76. // arguments for set/clear
  77. #define _SCMD_PB "port_b"
  78. #define _SCMD_PD "port_d"
  79. #define _NUM_OF_CMD
  80. #define _NUM_OF_SETCLEAR_SCMD 2
  81. //available commands
  82. char * keyworld [] = {
  83. _CMD_HELP,
  84. _CMD_CLEAR,
  85. _CMD_LED,
  86. _CMD_ETH,
  87. _CMD_PSVOLT,
  88. _CMD_LOADVOLT,
  89. _CMD_BATVOLT,
  90. _CMD_BATVOLTK,
  91. _CMD_BATVOLTR,
  92. _CMD_BAT1VOLT,
  93. _CMD_BAT2VOLT,
  94. _CMD_BAT3VOLT,
  95. _CMD_BAT4VOLT,
  96. _CMD_BATCUR,
  97. _CMD_LOADCUR,
  98. _CMD_LOADCURK,
  99. _CMD_DIDOOR,
  100. _CMD_DIRV,
  101. _CMD_LOW150,
  102. _CMD_HILOW230,
  103. _CMD_HIGH264,
  104. _CMD_MPSOFF,
  105. _CMD_CANTX,
  106. _CMD_CANRX,
  107. _CMD_DAC,
  108. _CMD_SD,
  109. _CMD_ONEWIRE,
  110. _CMD_SET,
  111. _CMD_DEF,
  112. _CMD_RTC,
  113. _CMD_SERNO,
  114. _CMD_STATUS,
  115. _CMD_FREQ,
  116. _CMD_50HZ,
  117. _CMD_LOW,
  118. _CMD_HILOW,
  119. _CMD_HI,
  120. _CMD_T2READY,
  121. _CMD_U232U485,
  122. _CMD_DRY,
  123. _CMD_U232F,
  124. _CMD_RST,
  125. _CMD_SPIFLASH,
  126. _CMD_U232
  127. };
  128. // 'set/clear' command argements
  129. char * set_clear_key [] = {_SCMD_PB, _SCMD_PD};
  130. // array for comletion
  131. char * compl_world [_NUM_OF_CMD + 1];
  132. microrl_t rl;
  133. microrl_t *prl = &rl;
  134. // параметр команды
  135. #define PARAM_LEN 20
  136. char param[PARAM_LEN];
  137. float value = 0.0;
  138. extern bool testLed;
  139. extern bool testEthernet;
  140. extern bool testDef;
  141. extern bool testSet;
  142. extern bool testRtc;
  143. extern bool testSerno;
  144. extern bool testT2Ready;
  145. /**
  146. * @brief
  147. * @retval
  148. */
  149. void MICRORL_Init(void)
  150. {
  151. microrl_init(prl, print);
  152. microrl_set_execute_callback (prl, execute);
  153. }
  154. /**
  155. * @brief Print callback for microrl library
  156. * @retval
  157. */
  158. void print (const char *str)
  159. {
  160. //printf(str);
  161. }
  162. /**
  163. * @brief
  164. * @retval
  165. */
  166. void MICRORL_GetChar(uint8_t ch)
  167. {
  168. microrl_insert_char(prl, ch);
  169. }
  170. //*****************************************************************************
  171. // execute callback for microrl library
  172. // do what you want here, but don't write to argv!!! read only!!
  173. int execute (int argc, const char * const * argv)
  174. {
  175. int i = 0;
  176. uint16_t len = 0;
  177. // just iterate through argv word and compare it with your commands
  178. while (i < argc)
  179. {
  180. memset(param, 0, PARAM_LEN);
  181. if (strcmp (argv[i], _CMD_HELP) == 0)
  182. {
  183. print ("microrl library v");
  184. print (MICRORL_LIB_VER);
  185. print ("\n\r");
  186. print_help (); // print help
  187. }
  188. else if (strcmp (argv[i], _CMD_CLEAR) == 0)
  189. {
  190. print ("\033[2J"); // ESC seq for clear entire screen
  191. print ("\033[H"); // ESC seq for move cursor at left-top corner
  192. }
  193. /* Тестовая команда */
  194. else if (strcmp (argv[i], _CMD_LED) == 0)
  195. {
  196. //testLed = true;
  197. // TODO Убрать затычку
  198. printf("STATUS T1OK\r");
  199. return 0;
  200. }
  201. /* Тест Ethernet */
  202. else if (strcmp (argv[i], _CMD_ETH) == 0)
  203. {
  204. COM_SetMAC();
  205. //testEthernet = true;
  206. TEST_SetTest(TEST_ETHERNET);
  207. print ("\n\r");
  208. return 0;
  209. }
  210. /* Тест кнопки SET */
  211. else if (strcmp (argv[i], _CMD_SET) == 0)
  212. {
  213. //testSet = true;
  214. TEST_SetTest(TEST_SET);
  215. print ("\n\r");
  216. return 0;
  217. }
  218. /* Тест кнопки DEF */
  219. else if (strcmp (argv[i], _CMD_DEF) == 0)
  220. {
  221. //testDef = true;
  222. TEST_SetTest(TEST_DEF);
  223. print ("\n\r");
  224. return 0;
  225. }
  226. /* Тест RTC */
  227. else if (strcmp (argv[i], _CMD_RTC) == 0)
  228. {
  229. if (++i < argc)
  230. {
  231. len = strlen(argv[i]);
  232. strncpy(param, argv[i], len);
  233. SNTP_SetServerAddr(param);
  234. TEST_SetTest(TEST_RTC);
  235. // testRtc = true;
  236. print ("\n\r");
  237. return 0;
  238. }
  239. print ("\n\r");
  240. }
  241. /* Установка SERNO */
  242. else if (strcmp (argv[i], _CMD_SERNO) == 0)
  243. {
  244. if (++i < argc)
  245. {
  246. len = strlen(argv[i]);
  247. strncpy(param, argv[i], len);
  248. SETTINGS_SetSerno(param);
  249. //testSerno = true;
  250. TEST_SetTest(TEST_SERNO);
  251. print ("\n\r");
  252. return 0;
  253. }
  254. print ("\n\r");
  255. }
  256. /* -------------------------------------------------------------------- */
  257. /* Тесты для SmartUPS */
  258. /* Тест сухих контактов */
  259. else if (strcmp (argv[i], _CMD_DRY) == 0)
  260. {
  261. //testSet = true;
  262. TEST_SetTest(TEST_DRY);
  263. print ("\n\r");
  264. return 0;
  265. }
  266. /* Тест дополнительных пинов RS232 */
  267. else if (strcmp (argv[i], _CMD_U232) == 0)
  268. {
  269. //testSet = true;
  270. TEST_SetTest(TEST_U232);
  271. print ("\n\r");
  272. return 0;
  273. }
  274. /* Тест spi flash */
  275. else if (strcmp (argv[i], _CMD_SPIFLASH) == 0)
  276. {
  277. //testSet = true;
  278. TEST_SetTest(TEST_SPIFLASH);
  279. print ("\n\r");
  280. return 0;
  281. }
  282. /* -------------------------------------------------------------------- */
  283. /* Тесты этапа Т2 */
  284. /* Статус тестера */
  285. else if (strcmp (argv[i], _CMD_STATUS) == 0)
  286. {
  287. //printf("STATUS %s\r", sSettings.sFlags.testState);
  288. printf("STATUS %s\r", SETTINGS_GetTestState());
  289. return 0;
  290. }
  291. /* T2READY */
  292. else if (strcmp (argv[i], _CMD_T2READY) == 0)
  293. {
  294. testT2Ready = true;
  295. return 0;
  296. }
  297. /* Перезагрузить контроллер */
  298. else if (strcmp (argv[i], _CMD_RST) == 0)
  299. {
  300. NVIC_SystemReset();
  301. }
  302. else
  303. {
  304. print ("command: '");
  305. print ((char*)argv[i]);
  306. print ("' Not found.\n\r");
  307. }
  308. i++;
  309. }
  310. return 0;
  311. }
  312. void print_help (void)
  313. {
  314. print ("Use TAB key for completion\n\rCommand:\n\r");
  315. print ("\tclear - clear screen\n\r");
  316. print ("\tdac - send test value\n\r");
  317. }
  318. /******************************* (C) LiteMesh *********************************/