1.tty usb打开关闭优化

This commit is contained in:
payton 2024-02-18 11:31:42 +08:00
parent 34cd4c1cf5
commit 02884fd430
2 changed files with 29 additions and 8 deletions

View File

@ -97,9 +97,8 @@ SINT32 app_ttyusb_IsOpen(void) {
int retryTime = 0; int retryTime = 0;
int retryFlag = 0; int retryFlag = 0;
static SINT32 s32ret = SF_SUCCESS; static SINT32 s32ret = SF_SUCCESS;
static int flag = 0;
if((flag) && (sf_get_ttyusb_flag())) if(sf_get_ttyusb_flag() >= 0)
{ {
return s32ret; return s32ret;
} }
@ -142,14 +141,25 @@ SINT32 app_ttyusb_IsOpen(void) {
break; break;
} }
} }
flag = 1;
MLOGD("e\n"); MLOGD("e\n");
return s32ret; return s32ret;
} }
SINT32 sf_ttyusb_restart(void) SINT32 sf_ttyusb_restart(void)
{ {
SINT32 ret = 0; SINT32 ret = -1;
UIMenuStoreInfo *puiPara = sf_app_ui_para_get();
if(strncmp(puiPara->ModuleVer, GPRS_MODULE_TYPE_EG915Q, 6) == 0)
{
//eg915q
}
else
{
system("killall quectel-CM-EG91");
}
ret = sf_hal_ttyusb2_deinit(); ret = sf_hal_ttyusb2_deinit();
if (ret != 0) if (ret != 0)
{ {

View File

@ -209,7 +209,13 @@ static SINT32 hal_ttyusb_config(SINT32 fd, SF_SERIAL_DATA_FRAME_TYPE_S *pSerialA
static SINT32 hal_ttyusb_write(SINT32 fd, SF_CHAR *sendBuf, SINT32 dataLen) static SINT32 hal_ttyusb_write(SINT32 fd, SF_CHAR *sendBuf, SINT32 dataLen)
{ {
SINT32 len = 0; SINT32 len = 0;
if(fd < 0)
{
MLOGE(" fd write fail!\n");
return SF_FAILURE;
}
len = write(fd,sendBuf,dataLen); len = write(fd,sendBuf,dataLen);
if (len == dataLen ) if (len == dataLen )
{ {
@ -252,6 +258,11 @@ 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);
if(fd < 0)
{
MLOGE(" fd read fail!\n");
return SF_FAILURE;
}
//while(waitTime--) //while(waitTime--)
{ {
@ -304,7 +315,7 @@ static SINT32 hal_ttyusb_create(SF_CHAR *ttyusbName,SF_SERIAL_DATA_FRAME_TYPE_S
usleep(100000);//100ms usleep(100000);//100ms
} }
if(*pttyfd <= 0) if(*pttyfd == -1)
return SF_FAILURE; return SF_FAILURE;
ret = hal_ttyusb_config(*pttyfd,pSerialAttr); ret = hal_ttyusb_config(*pttyfd,pSerialAttr);
@ -318,7 +329,7 @@ static SINT32 hal_ttyusb_create(SF_CHAR *ttyusbName,SF_SERIAL_DATA_FRAME_TYPE_S
} }
static SINT32 hal_ttyusb_destory(SINT32 fd) static SINT32 hal_ttyusb_destory(SINT32 fd)
{ {
int ret = 0; int ret = -1;
int count = 0; int count = 0;
while ((ret = close(fd)) < 0) while ((ret = close(fd)) < 0)
@ -366,7 +377,7 @@ SINT32 sf_hal_ttyusb2_read(SF_CHAR *recvBuf, SINT32 waitMs)
} }
SINT32 sf_hal_ttyusb2_deinit(void) SINT32 sf_hal_ttyusb2_deinit(void)
{ {
SINT32 ret = 0; SINT32 ret = -1;
if(TtyUSB2Fd < 0) if(TtyUSB2Fd < 0)
{ {