From 26fdab3f19bd8572e42b87747475ffc8eadf654e Mon Sep 17 00:00:00 2001 From: payton Date: Mon, 19 Feb 2024 14:32:55 +0800 Subject: [PATCH] =?UTF-8?q?1.sdk=E9=87=8Ctty=20usb=E8=AF=BB=E5=8F=96?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sf_app/code/source/ttyusb/sf_hal_ttyusb.c | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/code/application/source/sf_app/code/source/ttyusb/sf_hal_ttyusb.c b/code/application/source/sf_app/code/source/ttyusb/sf_hal_ttyusb.c index 44714cea7..0f41aeb39 100755 --- a/code/application/source/sf_app/code/source/ttyusb/sf_hal_ttyusb.c +++ b/code/application/source/sf_app/code/source/ttyusb/sf_hal_ttyusb.c @@ -252,26 +252,37 @@ static SINT32 hal_ttyusb_read(SINT32 fd, SF_CHAR *recvBuf, SINT32 waitTime) static SINT32 hal_ttyusb_read(SINT32 fd, SF_CHAR *recvBuf, SINT32 waitTime) { //SF_PDT_PARAM_CFG_S *sfParam = sf_customer_param_get(); - SINT32 s32ret = 0; + SF_TTY_DATA_TYPE_S ttyData = { .waitMs = 1000, .len = 255/*Must wait for OK or error.*/, .lenMax = (GPRS_INFO_LINE_MAX-1), .cmp = "OK", .cmperr = "ERROR", .data = recvBuf}; + if(fd < 0) + { + MLOGE(" fd read fail!\n"); + return SF_FAILURE; + } + sf_hal_ttyusb2_read_buf(&ttyData); + return SF_SUCCESS; + #if 0 + SINT32 s32ret = 0; fd_set read_fds; struct timeval TimeoutVal; - //if(waitTime > 0) - // sf_sleep_ms(waitTime); + if(waitTime > 0) + { + sf_sleep_ms(waitTime); + // waitTime = 10;//200ms*10=2s + } if(fd < 0) { MLOGE(" fd read fail!\n"); return SF_FAILURE; } - //while(waitTime--) + // while(waitTime--) { - FD_ZERO(&read_fds); FD_SET(fd, &read_fds); TimeoutVal.tv_sec = 0; - TimeoutVal.tv_usec = 200000; + TimeoutVal.tv_usec = 10000; s32ret = select(fd + 1, &read_fds, NULL, NULL, &TimeoutVal); if (s32ret > 0) { @@ -287,17 +298,18 @@ static SINT32 hal_ttyusb_read(SINT32 fd, SF_CHAR *recvBuf, SINT32 waitTime) else if (s32ret < 0) { //MLOGE(" select failed\n"); return SF_FAILURE; - //continue; + // continue; } else if (0 == s32ret) { //MLOGW("FIFO select timeout [%d]\n",waitTime); return SF_FAILURE; - //continue; + // continue; } } return SF_SUCCESS; + #endif } #endif