Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int readComData(const int toReadBytes, char *serDataBuf, const int stream_status){
- unsigned int idx=0; //index of the serDataBuf
- int remainingBytes=toReadBytes, readBytes=0, totalReadBytes=0;
- fd_set rfds; // File pointer set for select
- struct timeval serInWait; // Time to wait for serial input
- int selRetVal; // Return value of select
- //inits
- serInWait.tv_sec = SERIAL_TIMEOUT_SEC;
- serInWait.tv_usec = SERIAL_TIMEOUT_USEC;
- FD_ZERO(&rfds);
- FD_SET(fd, &rfds);
- //main fn
- while (remainingBytes>0){
- selRetVal = select(fd+1, &rfds, NULL, NULL, &serInWait);
- if (selRetVal==0){
- DEBUG_SERIAL(printf("SERIAL: DATA read timeout @ byte %d.\n",totalReadBytes));
- return SERIAL_TIMEOUT;
- } else if (selRetVal>0){
- readBytes=read(fd,&serDataBuf[totalReadBytes],remainingBytes);
- if (readBytes<remainingBytes){
- DEBUG_SERIAL(printf("SERIAL: last data read %d bytes. To a total of %d .\n",readBytes,totalReadBytes));
- remainingBytes-=readBytes;
- totalReadBytes+=readBytes;
- } else {
- DEBUG_SERIAL(printf("SERIAL: All remaining DATA have been read %d .\n",toReadBytes));
- }
- }// if selRetVal
- }//end while
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement