diff --git a/src/lindbergh/baseboard.c b/src/lindbergh/baseboard.c index 700a1f5..cd2d3f8 100644 --- a/src/lindbergh/baseboard.c +++ b/src/lindbergh/baseboard.c @@ -205,22 +205,18 @@ int baseboardIoctl(int fd, unsigned int request, void *data) } else if (jvsFileDescriptor >= 0) { + write(jvsFileDescriptor, inputBuffer, jvsCommand.srcSize); - for (int i = 0; i < jvsCommand.srcSize; i++) - printf("%X ", inputBuffer[i]); - printf("\n"); for (int i = 0; i < jvsCommand.srcSize; i++) { if (inputBuffer[i] == 0xF0) { - printf("SENSE LINE 3\n"); setSenseLine(3); } else if (inputBuffer[i] == 0xF1) { setSenseLine(1); - printf("SENSE LINE 1\n"); } } } @@ -270,12 +266,13 @@ int baseboardIoctl(int fd, unsigned int request, void *data) } else if (jvsFileDescriptor >= 0) { - int count = read(jvsFileDescriptor, &sharedMemory[jvsCommand.destAddress], 255); + int count = readBytes(jvsFileDescriptor, &sharedMemory[jvsCommand.destAddress], 255); + + if (count == -1) + count = 0; + _data[2] = jvsCommand.destAddress; _data[3] = count; - for (int i = 0; i < count; i++) - printf("%X ", sharedMemory[jvsCommand.destAddress + i]); - printf("\n"); } } break; diff --git a/src/lindbergh/serial.c b/src/lindbergh/serial.c index 0eb0257..7ff8fb8 100644 --- a/src/lindbergh/serial.c +++ b/src/lindbergh/serial.c @@ -17,9 +17,10 @@ #include #include - #include "serial.h" +#define TIMEOUT_SELECT 200 + int setSerialAttributes(int fd, int myBaud) { struct termios options; @@ -38,8 +39,8 @@ int setSerialAttributes(int fd, int myBaud) options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); options.c_oflag &= ~OPOST; - options.c_cc[VMIN] = 10; - options.c_cc[VTIME] = 10; // One seconds (10 deciseconds) + options.c_cc[VMIN] = 0; + options.c_cc[VTIME] = 0; // One seconds (10 deciseconds) tcsetattr(fd, TCSANOW, &options); @@ -64,3 +65,25 @@ int setSerialAttributes(int fd, int myBaud) return 0; } + +int readBytes(int fd, unsigned char *buffer, int amount) +{ + fd_set fd_serial; + struct timeval tv; + + FD_ZERO(&fd_serial); + FD_SET(fd, &fd_serial); + + tv.tv_sec = 0; + tv.tv_usec = TIMEOUT_SELECT * 1000; + + int filesReadyToRead = select(fd + 1, &fd_serial, NULL, NULL, &tv); + + if (filesReadyToRead < 1) + return 0; + + if (!FD_ISSET(fd, &fd_serial)) + return 0; + + return read(fd, buffer, amount); +} diff --git a/src/lindbergh/serial.h b/src/lindbergh/serial.h index 9680c4f..b82e4b0 100644 --- a/src/lindbergh/serial.h +++ b/src/lindbergh/serial.h @@ -1,2 +1,3 @@ int setSerialAttributes(int fd, int myBaud); +int readBytes(int fd, unsigned char *buffer, int amount);