diff --git a/code/application/source/sf_app/code/include/sf_hal_ttyusb.h b/code/application/source/sf_app/code/include/sf_hal_ttyusb.h index 1a3d6c35d..03fddc650 100755 --- a/code/application/source/sf_app/code/include/sf_hal_ttyusb.h +++ b/code/application/source/sf_app/code/include/sf_hal_ttyusb.h @@ -61,6 +61,16 @@ typedef struct sf_SERIAL_DATA_FRAME_TYPE_S { }SF_SERIAL_DATA_FRAME_TYPE_S; +typedef struct sf_TTY_DATA_TYPE_S { + int waitMs; + unsigned int len; + unsigned int lenMax; + char *cmp; + char *cmperr; + char *data; +}SF_TTY_DATA_TYPE_S; + + SINT32 sf_hal_ttyusb2_init(void); SINT32 sf_hal_ttyusb2_write(SF_CHAR *sendBuf, SINT32 dataLen); @@ -77,7 +87,7 @@ SINT32 sf_hal_uart_read(SF_CHAR *recvBuf, SINT32 waitMs); SINT32 sf_hal_uart_deinit(void); - +SINT32 sf_hal_ttyusb2_read_buf(SF_TTY_DATA_TYPE_S *recv); #ifdef __cplusplus #if __cplusplus 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 732de229e..68274422b 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 @@ -249,10 +249,10 @@ static SINT32 hal_ttyusb_read(SINT32 fd, SF_CHAR *recvBuf, SINT32 waitTime) SINT32 s32ret = 0; fd_set read_fds; struct timeval TimeoutVal; - if(waitTime > 0) - sf_sleep_ms(waitTime); + //if(waitTime > 0) + // sf_sleep_ms(waitTime); - while(waitTime--) + //while(waitTime--) { @@ -275,13 +275,13 @@ static SINT32 hal_ttyusb_read(SINT32 fd, SF_CHAR *recvBuf, SINT32 waitTime) } else if (s32ret < 0) { //MLOGE(" select failed\n"); - //return SF_FAILURE; - continue; + return SF_FAILURE; + //continue; } else if (0 == s32ret) { //MLOGW("FIFO select timeout [%d]\n",waitTime); - //return SF_FAILURE; - continue; + return SF_FAILURE; + //continue; } } @@ -415,6 +415,46 @@ SINT32 sf_hal_uart_deinit(void) return hal_ttyusb_destory(UartFd); } + +SINT32 sf_hal_ttyusb2_read_buf(SF_TTY_DATA_TYPE_S *recv) +{ + //SF_PDT_PARAM_CFG_S *sfParam = sf_customer_param_get(); + SINT32 s32ret = 0; + fd_set read_fds; + struct timeval TimeoutVal; + int waitTime = 2; + unsigned int dataL = 0; + FD_ZERO(&read_fds); + FD_SET(TtyUSB2Fd, &read_fds); + + TimeoutVal.tv_sec = 0; + TimeoutVal.tv_usec = (recv->waitMs)*1000; + + while(waitTime--) + { + s32ret = select(TtyUSB2Fd + 1, &read_fds, NULL, NULL, &TimeoutVal); + if (s32ret > 0) { + if (FD_ISSET(TtyUSB2Fd, &read_fds)) { + s32ret = read(TtyUSB2Fd, recv->data+dataL, recv->lenMax); + dataL += strlen(recv->data); + if ((((dataL) >= (recv->len)) && (strstr(recv->data, recv->cmp))) || (strstr(recv->data, recv->cmperr))) { + break; + } + } + } + else if (s32ret < 0) { + MLOGE(" select failed\n"); + continue; + } + else if (0 == s32ret) { + MLOGW("FIFO select timeout [%d]\n",waitTime); + continue; + } + } + FD_CLR(TtyUSB2Fd, &read_fds); + return SF_SUCCESS; +} + #ifdef __cplusplus #if __cplusplus }