Subversion Repositories public

Compare Revisions

Ignore whitespace Rev 213 → Rev 214

/sportwatcher/trunk/libgarmin/usb_comm.c
106,6 → 106,7
garmin_packet p;
struct sigaction saio;
char hv0[1024];
struct termios tp;
 
if (method && garmin->usb.fd == -1)
{
116,40 → 117,31
return 0;
}
*/
if ((garmin->usb.fd = open(USBdevice, O_RDWR | O_NOCTTY | O_NONBLOCK)) == -1)
if ((garmin->usb.fd = open(USBdevice, O_RDWR)) == -1)
return 0;
 
if (isatty(garmin->usb.fd))
{
/* install the signal handler before making the device asynchronous */
memset (&saio, 0, sizeof(struct sigaction));
saio.sa_handler = signal_handler_IO;
/* saio.sa_mask = 0;
saio.sa_flags = 0;
saio.sa_restorer = NULL; */
sigaction(SIGIO, &saio, NULL);
if (tcgetattr(garmin->usb.fd, &tp) == -1)
return 0;
 
/* allow the process to receive SIGIO */
fcntl(garmin->usb.fd, F_SETOWN, getpid());
/* Make the file descriptor asynchronous (the manual page says only
O_APPEND and O_NONBLOCK, will work with F_SETFL...) */
fcntl(garmin->usb.fd, F_SETFL, FASYNC);
tcgetattr(garmin->usb.fd, &ttyset_old); /* save current port settings */
ttyset.c_cflag &= ~(PARENB | CRTSCTS);
ttyset.c_cflag |= CREAD | CLOCAL | B9600;
ttyset.c_iflag = ttyset.c_oflag = ttyset.c_lflag = (tcflag_t) 0;
ttyset.c_oflag = (ONLCR);
tp.c_iflag &=
~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON|IXOFF|IXANY|INPCK|IUCLC);
tp.c_oflag &= ~OPOST;
tp.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN|ECHOE);
tp.c_cflag &= ~(CSIZE|PARENB);
tp.c_cflag |= CS8 | CLOCAL | CREAD | CRTSCTS;
 
tcflush(garmin->usb.fd, TCIFLUSH);
tcsetattr(garmin->usb.fd, TCSANOW, &ttyset);
}
else
{
close(garmin->usb.fd);
garmin->usb.fd = -1;
if (cfsetispeed(&tp, B115200) == -1)
return 0;
}
 
if (cfsetospeed(&tp, B115200) == -1)
return 0;
tp.c_cc[VMIN] = 1;
tp.c_cc[VTIME] = 0;
 
if (tcsetattr(garmin->usb.fd, TCSANOW, &tp) == -1)
return 0;
 
return 1;
}
else if (!method && garmin->usb.handle == NULL)
/sportwatcher/trunk/libgarmin/garmin.h
2141,9 → 2141,9
/* ------------------------------------------------------------------------- */
 
void garmin_queue_error(char *str, err_type type);
void garmin_clear_errors();
void garmin_clear_errors(void);
char *garmin_get_first_error(int *key);
char *garmin_get_next_error(int *key);
int garmin_count_error();
int garmin_count_error(void);
 
#endif /* __GARMIN_GARMIN_H__ */