1.优化tty读取
This commit is contained in:
parent
a3b4273c49
commit
455965e5f4
4
code/application/source/sf_app/code/include/sf_hal_ttyusb.h
Normal file → Executable file
4
code/application/source/sf_app/code/include/sf_hal_ttyusb.h
Normal file → Executable file
|
@ -65,7 +65,7 @@ SINT32 sf_hal_ttyusb2_init(void);
|
||||||
|
|
||||||
SINT32 sf_hal_ttyusb2_write(SF_CHAR *sendBuf, SINT32 dataLen);
|
SINT32 sf_hal_ttyusb2_write(SF_CHAR *sendBuf, SINT32 dataLen);
|
||||||
|
|
||||||
SINT32 sf_hal_ttyusb2_read(SF_CHAR *recvBuf, SINT32 dataLen);
|
SINT32 sf_hal_ttyusb2_read(SF_CHAR *recvBuf, SINT32 waitMs);
|
||||||
|
|
||||||
SINT32 sf_hal_ttyusb2_deinit(void);
|
SINT32 sf_hal_ttyusb2_deinit(void);
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ SINT32 sf_hal_uart_init(void);
|
||||||
|
|
||||||
SINT32 sf_hal_uart_write(SF_CHAR *sendBuf, SINT32 dataLen);
|
SINT32 sf_hal_uart_write(SF_CHAR *sendBuf, SINT32 dataLen);
|
||||||
|
|
||||||
SINT32 sf_hal_uart_read(SF_CHAR *recvBuf, SINT32 dataLen);
|
SINT32 sf_hal_uart_read(SF_CHAR *recvBuf, SINT32 waitMs);
|
||||||
|
|
||||||
SINT32 sf_hal_uart_deinit(void);
|
SINT32 sf_hal_uart_deinit(void);
|
||||||
|
|
||||||
|
|
24
code/application/source/sf_app/code/source/ttyusb/sf_hal_ttyusb.c
Normal file → Executable file
24
code/application/source/sf_app/code/source/ttyusb/sf_hal_ttyusb.c
Normal file → Executable file
|
@ -252,32 +252,36 @@ static SINT32 hal_ttyusb_read(SINT32 fd, SF_CHAR *recvBuf, SINT32 waitTime)
|
||||||
// if(waitTime > 0)
|
// if(waitTime > 0)
|
||||||
// sf_sleep_ms(waitTime);
|
// sf_sleep_ms(waitTime);
|
||||||
|
|
||||||
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 = 10000;
|
TimeoutVal.tv_usec = 200000;
|
||||||
|
|
||||||
s32ret = select(fd + 1, &read_fds, NULL, NULL, &TimeoutVal);
|
s32ret = select(fd + 1, &read_fds, NULL, NULL, &TimeoutVal);
|
||||||
if (s32ret > 0) {
|
if (s32ret > 0) {
|
||||||
if (FD_ISSET(fd, &read_fds)) {
|
if (FD_ISSET(fd, &read_fds)) {
|
||||||
s32ret = read(fd, recvBuf, 580);
|
s32ret = read(fd, recvBuf, (GPRS_INFO_LINE_MAX-1));
|
||||||
if (s32ret > 0) {
|
if (s32ret > 0) {
|
||||||
break;
|
//break;
|
||||||
|
return SF_SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FD_CLR(fd, &read_fds);
|
FD_CLR(fd, &read_fds);
|
||||||
}
|
}
|
||||||
else if (s32ret < 0) {
|
else if (s32ret < 0) {
|
||||||
//MLOGE(" select failed\n");
|
//MLOGE(" select failed\n");
|
||||||
continue;
|
return SF_FAILURE;
|
||||||
|
//continue;
|
||||||
}
|
}
|
||||||
else if (0 == s32ret) {
|
else if (0 == s32ret) {
|
||||||
//MLOGW("FIFO select timeout [%d]\n",waitTime);
|
//MLOGW("FIFO select timeout [%d]\n",waitTime);
|
||||||
continue;
|
return SF_FAILURE;
|
||||||
|
//continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -356,9 +360,9 @@ SINT32 sf_hal_ttyusb2_write(SF_CHAR *sendBuf, SINT32 dataLen)
|
||||||
{
|
{
|
||||||
return hal_ttyusb_write(TtyUSB2Fd,sendBuf,dataLen);
|
return hal_ttyusb_write(TtyUSB2Fd,sendBuf,dataLen);
|
||||||
}
|
}
|
||||||
SINT32 sf_hal_ttyusb2_read(SF_CHAR *recvBuf, SINT32 dataLen)
|
SINT32 sf_hal_ttyusb2_read(SF_CHAR *recvBuf, SINT32 waitMs)
|
||||||
{
|
{
|
||||||
return hal_ttyusb_read(TtyUSB2Fd,recvBuf,dataLen);
|
return hal_ttyusb_read(TtyUSB2Fd, recvBuf, waitMs);
|
||||||
}
|
}
|
||||||
SINT32 sf_hal_ttyusb2_deinit(void)
|
SINT32 sf_hal_ttyusb2_deinit(void)
|
||||||
{
|
{
|
||||||
|
@ -397,9 +401,9 @@ SINT32 sf_hal_uart_write(SF_CHAR *sendBuf, SINT32 dataLen)
|
||||||
{
|
{
|
||||||
return hal_ttyusb_write(UartFd,sendBuf,dataLen);
|
return hal_ttyusb_write(UartFd,sendBuf,dataLen);
|
||||||
}
|
}
|
||||||
SINT32 sf_hal_uart_read(SF_CHAR *recvBuf, SINT32 dataLen)
|
SINT32 sf_hal_uart_read(SF_CHAR *recvBuf, SINT32 waitMs)
|
||||||
{
|
{
|
||||||
return hal_ttyusb_read(UartFd,recvBuf,dataLen);
|
return hal_ttyusb_read(UartFd, recvBuf, waitMs);
|
||||||
}
|
}
|
||||||
SINT32 sf_hal_uart_deinit(void)
|
SINT32 sf_hal_uart_deinit(void)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user