1.ttyusb优化
This commit is contained in:
parent
878ee89221
commit
4e18af6e26
|
@ -61,6 +61,16 @@ typedef struct sf_SERIAL_DATA_FRAME_TYPE_S {
|
||||||
|
|
||||||
}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_init(void);
|
||||||
|
|
||||||
SINT32 sf_hal_ttyusb2_write(SF_CHAR *sendBuf, SINT32 dataLen);
|
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_uart_deinit(void);
|
||||||
|
|
||||||
|
SINT32 sf_hal_ttyusb2_read_buf(SF_TTY_DATA_TYPE_S *recv);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#if __cplusplus
|
#if __cplusplus
|
||||||
|
|
|
@ -249,10 +249,10 @@ static SINT32 hal_ttyusb_read(SINT32 fd, SF_CHAR *recvBuf, SINT32 waitTime)
|
||||||
SINT32 s32ret = 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);
|
||||||
|
|
||||||
while(waitTime--)
|
//while(waitTime--)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
@ -275,13 +275,13 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -415,6 +415,46 @@ SINT32 sf_hal_uart_deinit(void)
|
||||||
|
|
||||||
return hal_ttyusb_destory(UartFd);
|
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
|
#ifdef __cplusplus
|
||||||
#if __cplusplus
|
#if __cplusplus
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user