port_microrl.c 7.9 KB

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