net_log.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. #include <stdlib.h>
  2. #include <unistd.h>
  3. #include "FreeRTOS.h"
  4. #include "task.h"
  5. #include "queue.h"
  6. #include "board.h"
  7. #include "chip.h"
  8. #include "animation.h"
  9. #include "sfud.h"
  10. #include "romfile.h"
  11. #include "sysinfo.h"
  12. #include "mmcsd_core.h"
  13. #include "ff_stdio.h"
  14. #include "ota_update.h"
  15. #include "md5.h"
  16. #include "unzip.h"
  17. #include "zip.h"
  18. #include "ulog.h"
  19. #include "easyflash.h"
  20. #include "include/crc.h"
  21. #include "ff_sfdisk.h"
  22. #include "ark_dwc2.h"
  23. #include "FreeRTOS_Sockets.h"
  24. #include "FreeRTOS_IP.h"
  25. #include "FreeRTOS_DHCP.h"
  26. #include "iperf_task.h"
  27. #include "iot_wifi.h"
  28. #include "FreeRTOS_DHCP_Server.h"
  29. #ifdef NCM_LOG_SUPPORT
  30. #define LOG_FRAME_HEADER_MAGIC 0xFF5AFFA5
  31. #define LOG_FRAME_TAIL_MAGIC 0xFFA5FF5A
  32. #define FILENAME_LEN 128
  33. #define MD5_LEN 32
  34. #define LOG_BUF_SIZE 0x100000
  35. #pragma pack(push, 1)
  36. typedef struct {
  37. uint32_t header;
  38. uint32_t type;
  39. uint32_t sub_type;
  40. uint32_t sub_type_1;
  41. uint32_t len;
  42. uint8_t checksum;
  43. } LogFrame;
  44. typedef struct {
  45. uint8_t request_type;
  46. uint32_t log_size;
  47. uint8_t log_md5[MD5_LEN];
  48. uint8_t log_filename[FILENAME_LEN];
  49. } LogTfrReq;
  50. #pragma pack(pop)
  51. static Socket_t log_req_socket;
  52. static Socket_t log_tfr_socket;
  53. #define FRAME_MAX_LEN 0x100000
  54. #define LOG_TFR_MAX_SIZE 128000
  55. #define OTA_LOG_FILENAME "log.zip"
  56. static int log_rev_state = 0;
  57. static int log_state_len = 0;
  58. static int log_rev_len = 0;
  59. static uint32_t log_frame_type = 0;
  60. static uint32_t log_frame_subtype = 0;
  61. static uint32_t log_frame_subtype_1 = 0;
  62. static uint32_t log_frame_len = 0;
  63. static uint8_t log_frame_checksum = 0;
  64. static uint8_t *log_frame_buf;
  65. static uint32_t log_file_size;
  66. static uint32_t log_file_offset;
  67. static uint32_t log_file_framenum;
  68. static uint8_t net_log_timeout_flag = 0;
  69. #define LOG_CHECKSUM(x) ((((x) >> 24) & 0xff) + (((x) >> 16) & 0xff) + (((x) >> 8) & 0xff) + ((x) & 0xff))
  70. static uint8_t calc_log_checksum(uint32_t type, uint32_t subtype, uint32_t subtype_1, uint32_t len)
  71. {
  72. uint32_t checksum = 0;
  73. checksum = LOG_CHECKSUM(type) + LOG_CHECKSUM(subtype) + LOG_CHECKSUM(subtype_1) + LOG_CHECKSUM(len);
  74. return 0x100 - (uint8_t)checksum;
  75. }
  76. static void logSendFrame(Socket_t socket, uint32_t type, uint32_t subtype,
  77. uint32_t subtype_1, void *data, uint32_t len)
  78. {
  79. LogFrame *frame = NULL;
  80. uint8_t *tmp;
  81. int32_t leftsize;
  82. BaseType_t ret;
  83. u32 errcnt = 0;
  84. printf("send frame type=0x%x, subtype=0x%x, len=%d.\n", type, subtype, len);
  85. frame = (LogFrame*)pvPortMalloc(sizeof(LogFrame) + len + 4);
  86. if (frame) {
  87. frame->header = LOG_FRAME_HEADER_MAGIC;
  88. frame->type = type;
  89. frame->sub_type = subtype;
  90. frame->sub_type_1 = subtype_1;
  91. frame->len = len;
  92. frame->checksum = calc_log_checksum(type, subtype, subtype_1, len);
  93. tmp = (uint8_t*)frame + sizeof(LogFrame);
  94. if (len) {
  95. memcpy(tmp, data, len);
  96. tmp += len;
  97. }
  98. *(uint32_t *)tmp = LOG_FRAME_TAIL_MAGIC;
  99. }
  100. leftsize = sizeof(LogFrame) + len + 4;
  101. tmp = (uint8_t *)frame;
  102. while (leftsize > 0) {
  103. ret = FreeRTOS_send(socket, tmp, leftsize, 0);
  104. if (ret > 0) {
  105. leftsize -= ret;
  106. tmp += ret;
  107. errcnt = 0;
  108. } else {
  109. //printf("FreeRTOS_send err %d.\n", ret);
  110. TRACE_INFO("FreeRTOS_send err %d.\n", ret);
  111. if (errcnt++ > 100) {
  112. //printf("FreeRTOS_send fail.\n");
  113. TRACE_INFO("FreeRTOS_send fail.\n");
  114. break;
  115. }
  116. vTaskDelay(pdMS_TO_TICKS(10));
  117. }
  118. }
  119. net_log_timeout_flag = 1;
  120. vPortFree(frame);
  121. }
  122. static int logTransferData(void)
  123. {
  124. char filename[FILENAME_LEN + 16] = OTA_MOUNT_PATH "/" OTA_LOG_FILENAME;
  125. FF_FILE *fp;
  126. uint32_t size;
  127. uint8_t *buf;
  128. fp = ff_fopen(filename, "rb");
  129. if (!fp) {
  130. printf("open log file fail.\n");
  131. return -1;
  132. }
  133. if (log_file_offset == 0) {
  134. log_file_framenum = 1;
  135. log_file_size = ff_filelength(fp);
  136. }
  137. size = log_file_size - log_file_offset;
  138. size = size > LOG_TFR_MAX_SIZE ? LOG_TFR_MAX_SIZE : size;
  139. ff_fseek(fp, log_file_offset, FF_SEEK_SET);
  140. log_file_offset += size;
  141. buf = pvPortMalloc(size + 6);
  142. if (!buf) {
  143. printf("tfrlog buf malloc fail.\n");
  144. ff_fclose(fp);
  145. return -1;
  146. }
  147. if (size > 0) {
  148. *(uint32_t*)buf = size;
  149. if (log_file_offset == log_file_size)
  150. *(uint16_t*)(buf + 4) = 0;
  151. else
  152. *(uint16_t*)(buf + 4) = log_file_framenum;
  153. log_file_framenum++;
  154. if (ff_fread(buf + 6, 1, size, fp) != size) {
  155. printf("read tfrlog fail.\n");
  156. vPortFree(buf);
  157. ff_fclose(fp);
  158. return -1;
  159. }
  160. } else {
  161. memset(buf, 0, 6);
  162. }
  163. logSendFrame(log_tfr_socket, 0x1f, 0x01, 0, buf, size + 6);
  164. vPortFree(buf);
  165. ff_fclose(fp);
  166. return 0;
  167. }
  168. static void RevLogFrameHandler(uint32_t type, uint32_t subtype, uint32_t subtype_1,
  169. uint8_t *data, uint32_t len)
  170. {
  171. printf("rev frame type=0x%x, subtype=0x%x, len=%d.\n", type, subtype, len);
  172. switch (type) {
  173. case 0x0a:
  174. if (subtype == 0x10) {
  175. if (data[0] == 0x01) {
  176. LogTfrReq req = {0};
  177. uint8_t *logbuf;
  178. size_t logsize;
  179. SystemTime_t tm;
  180. char filename[FILENAME_LEN + 16] = OTA_MOUNT_PATH "/" OTA_LOG_FILENAME;
  181. zipFile zf = {0};
  182. zip_fileinfo zi = {0};
  183. FF_FILE *fp;
  184. size_t filesize;
  185. size_t leftsize;
  186. size_t size;
  187. size_t logindex;
  188. unsigned char md5out[16];
  189. char md5string[MD5_LEN + 1];
  190. md5_context md5ctx;
  191. uint32_t logcrc;
  192. int i;
  193. logbuf = pvPortMalloc(LOG_BUF_SIZE);
  194. if (!logbuf) {
  195. printf("logbuf malloc fail.\n");
  196. logSendFrame(log_req_socket, 0x1b, 0x06, 0, &req, sizeof(req));
  197. break;
  198. }
  199. iGetLocalTime(&tm);
  200. snprintf((char*)req.log_filename, FILENAME_LEN, "IPLog%.4d%.2d%.2d%.2d%.2d%.2d.zip", tm.tm_year,
  201. tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  202. zf = zipOpen(filename, 0);
  203. if (!zf) {
  204. printf("create log file fail.\n");
  205. vPortFree(logbuf);
  206. logSendFrame(log_req_socket, 0x1b, 0x06, 0, &req, sizeof(req));
  207. break;
  208. }
  209. if (zipOpenNewFileInZip(zf, "log", &zi, NULL, 0, NULL, 0, NULL, Z_DEFLATED, 9)) {
  210. printf("zipOpenNewFileInZip fail.\n");
  211. zipClose(zf, NULL);
  212. vPortFree(logbuf);
  213. logSendFrame(log_req_socket, 0x1b, 0x06, 0, &req, sizeof(req));
  214. break;
  215. }
  216. leftsize = logsize = ef_log_get_used_size();
  217. logcrc = 0xffffffff;
  218. logindex = 0;
  219. while (leftsize > 0) {
  220. size = leftsize > LOG_BUF_SIZE ? LOG_BUF_SIZE : leftsize;
  221. read_flash_log(logbuf, logindex, size);
  222. if (zipWriteInFileInZip(zf, logbuf, size)) {
  223. printf("zipWriteInFileInZip fail.\n");
  224. break;
  225. }
  226. logcrc = xcrc32(logbuf, size, logcrc, HARD_CALC_CRC);
  227. leftsize -= size;
  228. logindex += size;
  229. }
  230. if (leftsize > 0) {
  231. zipClose(zf, NULL);
  232. vPortFree(logbuf);
  233. logSendFrame(log_req_socket, 0x1b, 0x06, 0, &req, sizeof(req));
  234. break;
  235. }
  236. sprintf((char*)logbuf, "\nlog size is 0x%x, crc is 0x%x.\n", logsize, logcrc);
  237. zipWriteInFileInZip(zf, logbuf, strlen((char*)logbuf));
  238. zipCloseFileInZip(zf);
  239. zipClose(zf, NULL);
  240. fp = ff_fopen(filename, "rb");
  241. if (!fp) {
  242. printf("open log zip file fail.\n");
  243. vPortFree(logbuf);
  244. logSendFrame(log_req_socket, 0x1b, 0x06, 0, &req, sizeof(req));
  245. break;
  246. }
  247. req.log_size = filesize = ff_filelength(fp);
  248. leftsize = filesize;
  249. memset(&md5ctx, 0, sizeof(md5_context));
  250. md5_starts(&md5ctx);
  251. while (leftsize > 0) {
  252. size = leftsize > LOG_BUF_SIZE ? LOG_BUF_SIZE : leftsize;
  253. size = ff_fread(logbuf, 1, size, fp);
  254. md5_update(&md5ctx, logbuf, size);
  255. leftsize -= size;
  256. }
  257. md5_finish(&md5ctx, md5out);
  258. ff_fclose(fp);
  259. vPortFree(logbuf);
  260. for (i = 0; i < 16; i++)
  261. sprintf(md5string + 2 * i, "%.2x", md5out[i]);
  262. memcpy(req.log_md5, md5string, MD5_LEN);
  263. req.request_type = 1;
  264. logSendFrame(log_req_socket, 0x1b, 0x06, 0, &req, sizeof(req));
  265. }
  266. }
  267. break;
  268. case 0x0b:
  269. if (subtype == 0x06) {
  270. if (data[0] == 0x01 && data[1] == 0x00) {
  271. uint8_t errdata[6] = {0};
  272. log_file_offset = 0;
  273. if (logTransferData())
  274. logSendFrame(log_tfr_socket, 0x1f, 0x01, 0, errdata, sizeof(errdata));
  275. }
  276. }
  277. break;
  278. case 0x0f:
  279. if (subtype == 0x02) {
  280. if (data[0] == 0x00) {
  281. uint8_t errdata[6] = {0};
  282. if (logTransferData())
  283. logSendFrame(log_tfr_socket, 0x1f, 0x01, 0, errdata, sizeof(errdata));
  284. }
  285. } else if (subtype == 0x03) {
  286. if (data[128] == 0x00) {
  287. printf("log transfer ok.\n");
  288. } else if (data[128] == 0x01 && data[129] == 0x01) {
  289. uint8_t errdata[6] = {0};
  290. printf("log transfer fail, resend.\n");
  291. log_file_offset = 0;
  292. if (logTransferData())
  293. logSendFrame(log_tfr_socket, 0x1f, 0x01, 0, errdata, sizeof(errdata));
  294. }
  295. }
  296. }
  297. }
  298. static void RevLogDataHandler(uint8_t *buf, int32_t len)
  299. {
  300. int i;
  301. for (i = 0; i < len; i++) {
  302. switch (log_rev_state) {
  303. case 0: //head receive
  304. if (log_state_len == 0 && buf[i] == 0xa5) {
  305. log_state_len++;
  306. } else if (log_state_len == 1 && buf[i] == 0xff) {
  307. log_state_len++;
  308. } else if (log_state_len == 2 && buf[i] == 0x5a) {
  309. log_state_len++;
  310. } else if (log_state_len == 3 && buf[i] == 0xff) {
  311. log_rev_state++;
  312. log_state_len = 0;
  313. log_frame_type = 0;
  314. log_frame_subtype = 0;
  315. log_frame_subtype_1 = 0;
  316. log_frame_len = 0;
  317. } else if (buf[i] == 0xff) {
  318. log_state_len = 1;
  319. } else {
  320. log_state_len = 0;
  321. }
  322. break;
  323. case 1: //type receive
  324. log_frame_type |= buf[i] << (8 * log_state_len);
  325. if (++log_state_len == 4) {
  326. log_rev_state++;
  327. log_state_len = 0;
  328. }
  329. break;
  330. case 2: //sub_type receive
  331. log_frame_subtype |= buf[i] << (8 * log_state_len);
  332. if (++log_state_len == 4) {
  333. log_rev_state++;
  334. log_state_len = 0;
  335. }
  336. break;
  337. case 3: //sub_type_1 receive
  338. log_frame_subtype_1 |= buf[i] << (8 * log_state_len);
  339. if (++log_state_len == 4) {
  340. log_rev_state++;
  341. log_state_len = 0;
  342. }
  343. break;
  344. case 4: //data len receive
  345. log_frame_len |= buf[i] << (8 * log_state_len);
  346. if (++log_state_len == 4) {
  347. if (log_frame_len > FRAME_MAX_LEN) {
  348. printf("Invalid NCM frame len 0x%x.\n", log_frame_len);
  349. }
  350. if (log_frame_len == 0)
  351. log_rev_state += 2;
  352. else
  353. log_rev_state++;
  354. log_rev_len = 0;
  355. log_state_len = 0;
  356. }
  357. break;
  358. case 5: //checksum receive
  359. log_frame_checksum = buf[i];
  360. if (log_frame_checksum != calc_log_checksum(log_frame_type, log_frame_subtype,
  361. log_frame_subtype_1, log_frame_len)) {
  362. printf("log frame checksum fail.\n");
  363. log_rev_state = 0;
  364. } else {
  365. log_rev_state++;
  366. }
  367. break;
  368. case 6: //data receive
  369. if (log_rev_len < FRAME_MAX_LEN)
  370. log_frame_buf[log_rev_len] = buf[i];
  371. if (++log_rev_len == log_frame_len)
  372. log_rev_state++;
  373. break;
  374. case 7: //tail receive
  375. if (log_state_len == 0 && buf[i] == 0x5a) {
  376. log_state_len++;
  377. } else if (log_state_len == 1 && buf[i] == 0xff) {
  378. log_state_len++;
  379. } else if (log_state_len == 2 && buf[i] == 0xa5) {
  380. log_state_len++;
  381. } else if (log_state_len == 3 && buf[i] == 0xff) {
  382. RevLogFrameHandler(log_frame_type, log_frame_subtype, log_frame_subtype_1,
  383. log_frame_buf, log_frame_len);
  384. log_rev_state = 0;
  385. log_state_len = 0;
  386. } else {
  387. log_state_len = 0;
  388. }
  389. break;
  390. default:
  391. break;
  392. }
  393. }
  394. }
  395. static void set_socket_win_net(Socket_t xSockets)
  396. {
  397. WinProperties_t xWinProperties;
  398. memset(&xWinProperties, '\0', sizeof xWinProperties);
  399. xWinProperties.lTxBufSize = ipconfigIPERF_TX_BUFSIZE; /* Units of bytes. */
  400. xWinProperties.lTxWinSize = ipconfigIPERF_TX_WINSIZE; /* Size in units of MSS */
  401. xWinProperties.lRxBufSize = ipconfigIPERF_RX_BUFSIZE; /* Units of bytes. */
  402. xWinProperties.lRxWinSize = ipconfigIPERF_RX_WINSIZE; /* Size in units of MSS */
  403. FreeRTOS_setsockopt( xSockets, 0, FREERTOS_SO_WIN_PROPERTIES, ( void * ) &xWinProperties, sizeof( xWinProperties ) );
  404. }
  405. static uint8_t ncm_data_buffer[65536] = {0};
  406. static int NCMLogConnectServer(Socket_t socket, int port)
  407. {
  408. struct freertos_sockaddr xAddress;
  409. int retries = 3;
  410. xAddress.sin_port = FreeRTOS_htons( port );
  411. xAddress.sin_addr = FreeRTOS_inet_addr_quick(192, 168, 2, 99);
  412. while (retries-- > 0) {
  413. if(!FreeRTOS_connect(socket, &xAddress, sizeof(xAddress)))
  414. return 0;
  415. vTaskDelay(pdMS_TO_TICKS(100));
  416. }
  417. return -1;
  418. }
  419. static int vCreateNCMLogClientSocket( void )
  420. {
  421. SocketSet_t xFD_Set;
  422. Socket_t xReqSockets = FREERTOS_INVALID_SOCKET, xTfrSockets = FREERTOS_INVALID_SOCKET;
  423. static const TickType_t xNoTimeOut = pdMS_TO_TICKS( 10000 );
  424. BaseType_t ret = -1;
  425. EventBits_t events;
  426. xFD_Set = FreeRTOS_CreateSocketSet();
  427. xReqSockets = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP );
  428. configASSERT( xReqSockets != FREERTOS_INVALID_SOCKET );
  429. FreeRTOS_setsockopt( xReqSockets,
  430. 0,
  431. FREERTOS_SO_RCVTIMEO,
  432. &xNoTimeOut,
  433. sizeof( xNoTimeOut ) );
  434. set_socket_win_net(xReqSockets);
  435. if (!NCMLogConnectServer(xReqSockets, 10001)) {
  436. printf("Connect to 192.168.2.99:10001 ok.\n");
  437. } else {
  438. printf("Connect to 192.168.2.99:10001 fail.\n");
  439. FreeRTOS_closesocket(xReqSockets);
  440. FreeRTOS_DeleteSocketSet(xFD_Set);
  441. return -1;
  442. }
  443. log_req_socket = xReqSockets;
  444. xTfrSockets = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP );
  445. configASSERT( xTfrSockets != FREERTOS_INVALID_SOCKET );
  446. FreeRTOS_setsockopt( xTfrSockets,
  447. 0,
  448. FREERTOS_SO_RCVTIMEO,
  449. &xNoTimeOut,
  450. sizeof( xNoTimeOut ) );
  451. set_socket_win_net(xTfrSockets);
  452. if (!NCMLogConnectServer(xTfrSockets, 10002)) {
  453. printf("Connect to 192.168.2.99:10002 ok.\n");
  454. } else {
  455. printf("Connect to 192.168.2.99:10002 fail.\n");
  456. FreeRTOS_closesocket(xReqSockets);
  457. FreeRTOS_closesocket(xTfrSockets);
  458. FreeRTOS_DeleteSocketSet(xFD_Set);
  459. return -1;
  460. }
  461. log_tfr_socket = xTfrSockets;
  462. while (1) {
  463. FreeRTOS_FD_CLR(xReqSockets, xFD_Set, eSELECT_ALL);
  464. FreeRTOS_FD_SET(xReqSockets, xFD_Set, eSELECT_READ | eSELECT_EXCEPT);
  465. FreeRTOS_FD_CLR(xTfrSockets, xFD_Set, eSELECT_ALL);
  466. FreeRTOS_FD_SET(xTfrSockets, xFD_Set, eSELECT_READ | eSELECT_EXCEPT);
  467. ret = FreeRTOS_select( xFD_Set, pdMS_TO_TICKS(3000));//portMAX_DELAY
  468. if (ret < 0) {
  469. break;
  470. } else if(ret == 0) {
  471. if(net_log_timeout_flag) {
  472. printf("%s, net_log timeout: %d\r\n", __func__, __LINE__);
  473. usb_dwc2_reset(0, 1);
  474. net_log_timeout_flag = 0;
  475. break;
  476. }
  477. continue;
  478. }
  479. net_log_timeout_flag = 0;
  480. if( events = FreeRTOS_FD_ISSET ( xReqSockets, xFD_Set ) ) {
  481. if (events & eSELECT_READ) {
  482. ret = FreeRTOS_recv(xReqSockets, ncm_data_buffer, sizeof(ncm_data_buffer), 0);
  483. if (ret > 0) {
  484. printf("@recv buf size:%d\r\n", ret);
  485. //print_hex(ncm_data_buffer, ret, NULL);
  486. RevLogDataHandler(ncm_data_buffer, ret);
  487. } else {
  488. printf("FreeRTOS_recv err:%d\r\n", ret);
  489. break;
  490. }
  491. }
  492. if (events & eSELECT_EXCEPT) {
  493. printf("xReqSockets exception\r\n");
  494. break;
  495. }
  496. }
  497. if( events = FreeRTOS_FD_ISSET ( xTfrSockets, xFD_Set ) ) {
  498. if (events & eSELECT_READ) {
  499. ret = FreeRTOS_recv(xTfrSockets, ncm_data_buffer, sizeof(ncm_data_buffer), 0);
  500. if (ret > 0) {
  501. printf("@@recv buf size:%d\r\n", ret);
  502. //print_hex(ncm_data_buffer, ret, NULL);
  503. RevLogDataHandler(ncm_data_buffer, ret);
  504. } else {
  505. printf("FreeRTOS_recv err:%d\r\n", ret);
  506. break;
  507. }
  508. }
  509. if (events & eSELECT_EXCEPT) {
  510. printf("xTfrSockets exception\r\n");
  511. break;
  512. }
  513. }
  514. }
  515. FreeRTOS_closesocket(xReqSockets);
  516. FreeRTOS_closesocket(xTfrSockets);
  517. FreeRTOS_DeleteSocketSet(xFD_Set);
  518. log_req_socket = NULL;
  519. log_tfr_socket = NULL;
  520. return 0;
  521. }
  522. void ncm_log_demo_thread(void *param)
  523. {
  524. #if DEVICE_TYPE_SELECT != EMMC_FLASH
  525. FF_Disk_t *sfdisk = FF_SFDiskInit(SF_MOUNT_PATH);
  526. if (!sfdisk) {
  527. printf("FF_SFDiskInit fail.\n");
  528. return;
  529. }
  530. #endif
  531. log_frame_buf = pvPortMalloc(FRAME_MAX_LEN);
  532. if (!log_frame_buf) {
  533. printf("log_frame_buf malloc fail.\n");
  534. return;
  535. }
  536. while(1) {
  537. vCreateNCMLogClientSocket();
  538. vTaskDelay(pdMS_TO_TICKS(3000));
  539. }
  540. }
  541. void ncm_log_demo(void)
  542. {
  543. if (xTaskCreate(ncm_log_demo_thread, "ncmlog", 32768, NULL,
  544. 1, NULL) != pdPASS) {
  545. printf("create ncm log demo task fail.\n");
  546. }
  547. }
  548. #endif