1.sdk里tty usb读取调整

This commit is contained in:
payton 2024-02-19 14:32:55 +08:00
parent 9dbb3e2617
commit 26fdab3f19

View File

@ -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) static SINT32 hal_ttyusb_read(SINT32 fd, SF_CHAR *recvBuf, SINT32 waitTime)
{ {
//SF_PDT_PARAM_CFG_S *sfParam = sf_customer_param_get(); //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; fd_set read_fds;
struct timeval TimeoutVal; struct timeval TimeoutVal;
//if(waitTime > 0) if(waitTime > 0)
// sf_sleep_ms(waitTime); {
sf_sleep_ms(waitTime);
// waitTime = 10;//200ms*10=2s
}
if(fd < 0) if(fd < 0)
{ {
MLOGE(" fd read fail!\n"); MLOGE(" fd read fail!\n");
return SF_FAILURE; return SF_FAILURE;
} }
//while(waitTime--) // while(waitTime--)
{ {
FD_ZERO(&read_fds); FD_ZERO(&read_fds);
FD_SET(fd, &read_fds); FD_SET(fd, &read_fds);
TimeoutVal.tv_sec = 0; TimeoutVal.tv_sec = 0;
TimeoutVal.tv_usec = 200000; TimeoutVal.tv_usec = 10000;
s32ret = select(fd + 1, &read_fds, NULL, NULL, &TimeoutVal); s32ret = select(fd + 1, &read_fds, NULL, NULL, &TimeoutVal);
if (s32ret > 0) { if (s32ret > 0) {
@ -287,17 +298,18 @@ static SINT32 hal_ttyusb_read(SINT32 fd, SF_CHAR *recvBuf, SINT32 waitTime)
else if (s32ret < 0) { else if (s32ret < 0) {
//MLOGE(" select failed\n"); //MLOGE(" select failed\n");
return SF_FAILURE; return SF_FAILURE;
//continue; // continue;
} }
else if (0 == s32ret) { else if (0 == s32ret) {
//MLOGW("FIFO select timeout [%d]\n",waitTime); //MLOGW("FIFO select timeout [%d]\n",waitTime);
return SF_FAILURE; return SF_FAILURE;
//continue; // continue;
} }
} }
return SF_SUCCESS; return SF_SUCCESS;
#endif
} }
#endif #endif