wm_demo_console.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. /*****************************************************************************
  2. *
  3. * File Name : wm_demo_cmd.h
  4. *
  5. * Description: demo command header
  6. *
  7. * Copyright (c) 2014 Winner Micro Electronic Design Co., Ltd.
  8. * All rights reserved.
  9. *****************************************************************************/
  10. #ifndef __WM_DEMO_CMD_H__
  11. #define __WM_DEMO_CMD_H__
  12. #include <string.h>
  13. #include "wm_include.h"
  14. #include "wm_watchdog.h"
  15. #include "wm_config.h"
  16. /*****************************************************************
  17. EXTERN FUNC
  18. *****************************************************************/
  19. extern int demo_connect_net(void *, ...);
  20. extern int demo_socket_client(void *, ...);
  21. extern int demo_socket_server(void *, ...);
  22. extern int demo_oneshot(void *, ...);
  23. extern int demo_socket_config(void *, ...);
  24. extern int demo_webserver_config(void *, ...);
  25. extern int demo_create_softap(void *, ...);
  26. extern int uart_demo(void *, ...);
  27. extern int ntp_demo(void *, ...);
  28. extern int ntp_set_server_demo(void *, ...);
  29. extern int ntp_query_cfg(void *, ...);
  30. extern int flash_demo(void *, ...);
  31. extern int Socket_Client_Demo(void *, ...);
  32. extern int sck_c_send_data_demo(void *, ...);
  33. extern int socket_server_demo(void *, ...);
  34. extern int sck_s_send_data_demo(void *, ...);
  35. extern int socket_udp_demo(void *, ...);
  36. extern int udp_send_data_demo(void *, ...);
  37. extern int apsta_demo(void *, ...);
  38. extern int apsta_socket_demo(void *, ...);
  39. extern int gpio_demo(void *, ...);
  40. extern int gpio_isr_test(void *, ...);
  41. extern int pwm_demo(void *, ...);
  42. extern int crypt_hard_demo(void *, ...);
  43. extern int wm_7816_demo(void *, ...);
  44. extern int rsa_demo(void *, ...);
  45. extern int slave_spi_demo(void *, ...);
  46. //extern int master_spi_demo(void *, ...);
  47. extern int master_spi_recv_data(void *, ...);
  48. extern int master_spi_send_data(void *, ...);
  49. extern int pmu_timer0_demo(void *, ...);
  50. extern int pmu_timer1_demo(void *, ...);
  51. extern int rtc_demo(void *, ...);
  52. extern int timer_demo(void *, ...);
  53. extern int http_fwup_demo(void *, ...);
  54. extern int http_get_demo(void *, ...);
  55. extern int http_post_demo(void *, ...);
  56. extern int http_put_demo(void *, ...);
  57. extern int socket_server_demo(void *, ...);
  58. extern int sck_s_send_data_demo(void *, ...);
  59. extern int CreateMCastDemoTask(void *, ...);
  60. extern int adc_input_voltage_demo(void *, ...);
  61. extern int adc_chip_temperature_demo(void*,...);
  62. extern int sd_card_test(void *, ...);
  63. extern int demo_wps_pbc(void *, ...);
  64. extern int demo_wps_pin(void *, ...);
  65. extern int demo_wps_get_pin(void *, ...);
  66. extern int demo_iperf_auto_test(void *, ...);
  67. extern int CreateSSLServerDemoTask(void *, ...);
  68. extern int lwsDemoTest(void *, ...);
  69. extern int tls_i2s_io_init(void);
  70. extern int tls_i2s_demo(void *, ...);
  71. extern int i2c_demo(void *, ...);
  72. extern int scan_demo(void *, ...);
  73. extern int https_demo(void *, ...);
  74. extern int mqtt_demo(void *, ...);
  75. extern int fatfs_test(void *, ...);
  76. extern int mbedtls_demo(void *, ...);
  77. extern int dsp_demo(void *,...);
  78. #if DEMO_BT
  79. extern int demo_bt_enable(void *, ...);
  80. extern int demo_bt_destroy(void *, ...);
  81. #if (TLS_CONFIG_BLE == CFG_ON)
  82. extern int demo_ble_server_on(void *, ...);
  83. extern int demo_ble_server_off(void *, ...);
  84. extern int demo_ble_client_on(void *, ...);
  85. extern int demo_ble_client_off(void *, ...);
  86. extern int demo_ble_scan(void *,...);
  87. extern int demo_ble_adv(void *,...);
  88. #endif
  89. #if (TLS_CONFIG_BR_EDR== CFG_ON)
  90. extern int demo_bt_app_on(void *, ...);
  91. extern int demo_bt_app_off(void *, ...);
  92. #endif
  93. #endif
  94. #if DEMO_TOUCHSENSOR
  95. extern int demo_touchsensor(void *, ...);
  96. #endif
  97. /*****************************************************************
  98. LOCAL FUNC
  99. *****************************************************************/
  100. static void demo_console_show_info(char *buf);
  101. static int demo_console_show_help(void *p, ...);
  102. static int demo_sys_reset(void *p, ...);
  103. /*****************************************************************
  104. LOCAL TYPE
  105. *****************************************************************/
  106. typedef struct demo_console_st
  107. {
  108. int rx_data_len;
  109. u8 *rx_buf; /*uart rx*/
  110. u16 rptr;
  111. u8 MsgNum;
  112. } Demo_Console;
  113. struct demo_console_info_t
  114. {
  115. char *cmd;
  116. int (*callfn)(void *, ...);
  117. short type;/* perbit: 0-string, 1-number */
  118. short param_cnt;
  119. char *info;
  120. };
  121. #define DEMO_CONSOLE_CMD 1 //��������cmd
  122. #define DEMO_CONSOLE_SHORT_CMD 2 //CMD��һ���֣�û�н�����
  123. #define DEMO_CONSOLE_WRONG_CMD 3
  124. #define DEMO_BUF_SIZE TLS_UART_RX_BUF_SIZE
  125. const char HTTP_POST[] = "t-httppost";
  126. const char HTTP_PUT[] = "t-httpput";
  127. struct demo_console_info_t console_tbl[] =
  128. {
  129. //To Do When Add New Demo
  130. #if DEMO_CONNECT_NET
  131. {"t-connect", demo_connect_net, 0, 2, "Test connecting ap;t-connect(\"ssid\",\"pwd\"); For open ap, pwd should be empty"},
  132. {"t-oneshot", demo_oneshot, 0, 0, "Test Oneshot configuration"},
  133. // {"t-socketcfg", demo_socket_config, 0, 0, "Test socket configuration"},
  134. {"t-webcfg", demo_webserver_config, 0, 0, "Test web server configuration"},
  135. #endif
  136. #if DEMO_APSTA
  137. {"t-apsta", apsta_demo, 0x0, 4, "Test connecting with AP by apsta mode;"},
  138. {"t-asskt", apsta_socket_demo, 0x0, 0, "Test socket communication in apsta mode;"},
  139. #endif
  140. #if DEMO_SOFT_AP
  141. {"t-softap", demo_create_softap, 0x1C, 5, "Test softap create & station join monitor;"},
  142. #endif
  143. #if DEMO_WPS
  144. {"t-wps-get-pin", demo_wps_get_pin, 0x0, 0, "Test WPS get pin"},
  145. {"t-wps-start-pin", demo_wps_pin, 0x0, 0, "Test WPS start pin"},
  146. {"t-wps-start-pbc", demo_wps_pbc, 0x0, 0, "Test WPS start pbc"},
  147. #endif
  148. #if DEMO_SCAN
  149. {"t-scan", scan_demo, 0x0, 0, "Test wifi scan"},
  150. #endif
  151. /************************************************************************/
  152. #if DEMO_UARTx
  153. {"t-uart", uart_demo, 0x7, 3, "Test uart tx/rx; For example t-uart=(9600,0,0),baudrate 9600 ,parity none and 1 stop bit"},
  154. #endif
  155. #if DEMO_GPIO
  156. {"t-gpioirq", gpio_isr_test, 0x0, 0, "Test gpio interrupt services"},
  157. {"t-gpio", gpio_demo, 0x0, 0, "Test gpio read and write"},
  158. #endif
  159. #if DEMO_FLASH
  160. {"t-flash", flash_demo, 0x0, 0, "Test Read/Write Flash "},
  161. #endif
  162. #if DEMO_ENCRYPT
  163. {"t-crypt", crypt_hard_demo, 0x0, 0, "Test Encryption/Decryption API"},
  164. #endif
  165. #if DEMO_RSA
  166. {"t-rsa", rsa_demo, 0x0, 0, "Test RSA Encryption/Decryption API"},
  167. #endif
  168. #if DEMO_RTC
  169. {"t-rtc", rtc_demo, 0x0, 0, "Test rtc"},
  170. #endif
  171. #if DEMO_TIMER
  172. {"t-timer", timer_demo, 0x0, 0, "Test timer"},
  173. #endif
  174. #if DEMO_PWM
  175. {"t-pwm", pwm_demo, 0x1F, 5, "Test PWM output, for example t-pwm=(0,20,99,1,0) to test ALLSYC mode."},
  176. #endif
  177. #if DEMO_PMU
  178. {"t-pmuT0", pmu_timer0_demo, 0x1, 1, "Test power management unit with timer0"},
  179. {"t-pmuT1", pmu_timer1_demo, 0x1, 1, "Test power management unit with timer1"},
  180. #endif
  181. #if DEMO_I2C
  182. {"t-i2c", i2c_demo, 0x1, 1, "Test I2C module, for example t-i2c to W&R AT24CXX."},
  183. #endif
  184. #if DEMO_I2S
  185. {"t-i2sioinit", tls_i2s_io_init, 0, 0, "Initialize I2S IO."},
  186. {"t-i2s", tls_i2s_demo, 0x3F, 6, "Test I2S module, for example t-i2s=(0,1,44100,16,0,0) to send data."},
  187. #endif
  188. #if DEMO_MASTER_SPI
  189. {"t-mspi-s", master_spi_send_data, 0x3, 2, "Test SPI Master sending data(Note: need another module acts as a client device)"},
  190. {"t-mspi-r", master_spi_recv_data, 0x3, 2, "Test SPI Master receiving data(Note: need another module acts as a client device)"},
  191. #endif
  192. #if DEMO_SLAVE_SPI
  193. {"t-sspi", slave_spi_demo, 0x1, 1, "Test slave HSPI,t-sspi=(0),(Note: need another module support as a master device)"},
  194. #endif
  195. #if DEMO_SDIO_HOST
  196. {"t-sdh", sd_card_test, 0x0, 0, "Test sdio host write & read sd card"},
  197. #endif
  198. #if DEMO_ADC
  199. {"t-adctemp", adc_chip_temperature_demo, 0x0, 0, "(ADC)Test chip temperature"},
  200. {"t-adcvolt", adc_input_voltage_demo, 0x1, 1, "(ADC)Test input voltage,0-PA1(chan0), 1-PA4(chan1),8-different"},
  201. #endif
  202. #if DEMO_7816
  203. {"t-7816", wm_7816_demo, 0x0, 0, "Test 7816 tx/rx function"},
  204. #endif
  205. /************************************************************************/
  206. #if DEMO_STD_SOCKET_CLIENT
  207. {"t-sockc", Socket_Client_Demo, 0x1, 2, "Test data stream as [STANDARD SOCKET] CLIENT(working after connecting with AP successfully)"},
  208. {"t-skcsnd", sck_c_send_data_demo, 0x3, 2, "Test socket client send data, len:send len, uart_trans: is or not use uart retransmission"},
  209. #endif
  210. #if DEMO_STD_SOCKET_SERVER
  211. {"t-socks", socket_server_demo, 0x1, 1, "Test data stream as [STANDARD SOCKET] SERVER(working after connecting with AP successfully)"},
  212. {"t-skssnd", sck_s_send_data_demo, 0x7, 3, "Test socket server send data skt_no:socket num, len:send len, uart_trans: is or not use uart retransmission"},
  213. #endif
  214. #if DEMO_SOCKET_CLIENT_SERVER
  215. {"t-client", demo_socket_client,0x4,4,"Test socket client; t-client(\"ssid\",\"pwd\",port,\"ip\")"},
  216. {"t-server", demo_socket_server,0x4,3,"Test socket server; t-server(\"ssid\",\"pwd\",port,)"},
  217. #endif
  218. #if DEMO_UDP
  219. {"t-udp", socket_udp_demo, 0x3, 3, "Test data stream as UDP(working after connecting with AP successfully)"},
  220. {"t-sndudp", udp_send_data_demo, 0x1, 1, "Test udp send data"},
  221. #endif
  222. #if DEMO_UDP_MULTI_CAST
  223. {"t-mcast", CreateMCastDemoTask, 0x0, 1, "Test Multicast data stream"},
  224. #endif
  225. #if DEMO_NTP
  226. {"t-ntp", ntp_demo, 0x0, 0, "Test NTP"},
  227. {"t-setntps", ntp_set_server_demo, 0x0, 3, "Set NTP server ip;For example:t-setntps(\"cn.ntp.org.cn\", \"ntp.sjtu.edu.cn\", \"192.168.1.101\"),max server num is 3"},
  228. {"t-queryntps", ntp_query_cfg, 0x0, 0, "Query the NTP server domain"},
  229. #endif
  230. #if DEMO_HTTP
  231. {"t-httpfwup", http_fwup_demo, 0x0, 1, "Test firmware update via HTTP, like this t-httpfwup=(http://192.168.1.100:8080/xt804_SEC.img)"},
  232. {"t-httpget", http_get_demo, 0x0, 1, "Test HTTP get method, like this t-httpget"},
  233. {(char *)HTTP_POST, http_post_demo, 0x0, 1, "Test HTTP post method, like this t-httppost=(user=winnermicro)"},
  234. {(char *)HTTP_PUT, http_put_demo, 0x0, 1, "Test HTTP put method, like this t-httpput=(user=winnermicro)"},
  235. #endif
  236. #if DEMO_SSL_SERVER
  237. {"t-ssl-server", CreateSSLServerDemoTask, 0x0, 1, "Test ssl server,remember to turn on TLS_CONFIG_SERVER_SIDE_SSL"},
  238. #endif
  239. #if DEMO_WEBSOCKETS
  240. {"t-websockets", lwsDemoTest, 0x0, 0, "websockets demo test"},
  241. #endif
  242. #if DEMO_HTTPS
  243. {"t-https", https_demo, 0x0, 0, "Test https request"},
  244. #endif
  245. #if DEMO_MBEDTLS
  246. {"t-mbedtls", mbedtls_demo, 0x0, 0, "Test mbedtls ssl"},
  247. #endif
  248. #if DEMO_MQTT
  249. {"t-mqtt", mqtt_demo, 0x0, 0, "Test mqtt"},
  250. #endif
  251. #if DEMO_FATFS
  252. {"t-fatfs", fatfs_test, 0x0, 0, "Test fatfs on sd card"},
  253. #endif
  254. #if DEMO_IPERF_AUTO_TEST
  255. {"t-iperf", demo_iperf_auto_test, 0x7E, 7, "Iperf auto test"},
  256. #endif
  257. #if DEMO_DSP
  258. {"t-dsp", dsp_demo, 0x1, 1, "DSP demo:0-fir,1-matrix,2-rfft,3-sin,4-variance"},
  259. #endif
  260. #if DEMO_BT
  261. {"t-bt-on", demo_bt_enable, 0x0, 0, "Test enable bt system"},
  262. {"t-bt-off", demo_bt_destroy, 0x0, 0, "Test destroy bt system"},
  263. #if (TLS_CONFIG_BLE == CFG_ON)
  264. {"t-ble-server-on", demo_ble_server_on, 0x0, 0, "Test enable ble server"},
  265. {"t-ble-server-off", demo_ble_server_off, 0x0, 0, "Test disable ble server"},
  266. {"t-ble-client-on", demo_ble_client_on, 0x0, 0, "Test enable ble client"},
  267. {"t-ble-client-off", demo_ble_client_off, 0x0, 0, "Test disable ble client"},
  268. {"t-ble-adv", demo_ble_adv, 0x01, 1, "Test start connectable/unconnectable/stop ble advertisement,eg: t-ble-adv=(1/2/0)"},
  269. {"t-ble-scan",demo_ble_scan, 0x01, 1, "Test start/stop ble scan,eg: t-ble-scan=(1/0)"},
  270. #endif
  271. #if (TLS_CONFIG_BR_EDR == CFG_ON)
  272. {"t-bt-demo-on", demo_bt_app_on, 0x0, 0, "Test enable bt app on"},
  273. {"t-bt-demo-off", demo_bt_app_off, 0x0, 0, "Test disable bt app off"},
  274. #endif
  275. #endif
  276. #if DEMO_TOUCHSENSOR
  277. {"t-touch", demo_touchsensor, 0x1, 1, "Test Touch sensor function,0:all, 1:touch sensor 1... 15:touch sensor 15"},
  278. #endif
  279. //����̨����ʾ�����һ��������Ҫ��������ʾ�ڿ���̨�ϣ���Ҫ���ڸ��е�����
  280. {"demohelp", demo_console_show_help, 0, 0, "Display Help information"},
  281. //��������������ڲ����ԣ�����ʾ�ڿ���̨��
  282. {"reset", demo_sys_reset, 0, 0, "Reset System"},
  283. //���һ�������������ʱ�жϽ�����ʶ
  284. {"lastcmd", NULL, 0, 0, "Table Terminal Flag; MUST BE THE LAST ONE"}
  285. };
  286. static void demo_console_show_info(char *buf)
  287. {
  288. char *p = NULL;
  289. char *p1 = NULL;
  290. p = buf;
  291. p1 = strchr(p, '\n');
  292. if(NULL == p1)
  293. {
  294. printf("%s\n", p);
  295. return;
  296. }
  297. while(p1 != NULL)
  298. {
  299. *p1 = '\0';
  300. printf("%s\n", p);
  301. printf("%-30s", " ");
  302. p = p1 + 1;
  303. p1 = strchr(p, '\n');
  304. }
  305. printf("%s\n", p);
  306. }
  307. static int demo_console_show_help(void *p, ...)
  308. {
  309. int i;
  310. printf("\n%-10s", "Sequence");
  311. printf("%-20s", "Command");
  312. printf("%s", "Description");
  313. printf("\n------------------------------------------------------------------------------------\n");
  314. for(i = 0; ; i ++)
  315. {
  316. printf("%-10d", i + 1);
  317. printf("%-20s", console_tbl[i].cmd);
  318. //printf("%s\n",console_tbl[i].info);
  319. demo_console_show_info(console_tbl[i].info);
  320. if(0 == strcmp(console_tbl[i].cmd, "demohelp"))
  321. break;
  322. }
  323. printf("------------------------------------------------------------------------------------\n");
  324. return WM_SUCCESS;
  325. }
  326. int demo_sys_reset(void *p, ...)
  327. {
  328. tls_sys_reset();
  329. return WM_SUCCESS;
  330. }
  331. #endif /*__WM_DEMO_CMD_H__*/