port_microrl.c 8.5 KB

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