Also set the serial port as blocking

This commit is contained in:
Pierre Pronchery 2017-12-13 22:21:13 +01:00
parent feb1bf4184
commit bf1c94092d
4 changed files with 13 additions and 2 deletions

View File

@ -72,7 +72,7 @@ void CloseProxmark() {
int OpenProxmark(size_t i) {
sp = uart_open(serial_port_name);
if (sp == INVALID_SERIAL_PORT || sp == CLAIMED_SERIAL_PORT) {
if (sp == INVALID_SERIAL_PORT || sp == CLAIMED_SERIAL_PORT || sp == NONBLOCKING_SERIAL_PORT) {
//poll once a second
return 0;
}

View File

@ -362,7 +362,7 @@ int main(int argc, char* argv[]) {
msleep(1000);
printf(".");
fflush(stdout);
} while(++openCount < 20 && (sp == INVALID_SERIAL_PORT || sp == CLAIMED_SERIAL_PORT));
} while(++openCount < 20 && (sp == INVALID_SERIAL_PORT || sp == CLAIMED_SERIAL_PORT || sp == NONBLOCKING_SERIAL_PORT));
printf("\n");
}

View File

@ -56,6 +56,10 @@ typedef void* serial_port;
*/
#define CLAIMED_SERIAL_PORT (void*)(~2)
/* Returned by uart_open if the serial port specified is in non-blocking mode.
*/
#define NONBLOCKING_SERIAL_PORT (void*)(~4)
/* Given a user-specified port name, connect to the port and return a structure
* used for future references to that port.
*

View File

@ -86,6 +86,13 @@ serial_port uart_open(const char* pcPortName)
return CLAIMED_SERIAL_PORT;
}
int i;
i = fcntl(sp->fd, F_GETFL, 0);
if((i & ~O_NONBLOCK) != i && fcntl(sp->fd, F_SETFL, i & ~O_NONBLOCK) != 0) {
free(sp);
return NONBLOCKING_SERIAL_PORT;
}
// Try to retrieve the old (current) terminal info struct
if(tcgetattr(sp->fd,&sp->tiOld) == -1) {
uart_close(sp);