port_microrl.c 8.9 KB

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