Subversion Repositories public

Rev

Rev 150 | Rev 230 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 150 Rev 214
Line 104... Line 104...
104
int                  i;
104
int                  i;
105
static unsigned int rates[] = {0, 4800, 9600, 19200, 38400, 57600};
105
static unsigned int rates[] = {0, 4800, 9600, 19200, 38400, 57600};
106
garmin_packet p;
106
garmin_packet p;
107
struct sigaction saio;
107
struct sigaction saio;
108
char hv0[1024];
108
char hv0[1024];
-
 
109
struct termios tp;
109
 
110
 
110
	if (method && garmin->usb.fd == -1)
111
	if (method && garmin->usb.fd == -1)
111
	{
112
	{
112
	   /* check for USB serial drivers -- very Linux-specific */
113
	   /* check for USB serial drivers -- very Linux-specific */
113
/*	   if (access("/sys/module/garmin_gps", R_OK) != 0)
114
/*	   if (access("/sys/module/garmin_gps", R_OK) != 0)
114
	   {
115
	   {
115
	      garmin_queue_error("garmin_gps not active!", err_error);
116
	      garmin_queue_error("garmin_gps not active!", err_error);
116
	      return 0;
117
	      return 0;
117
	   }
118
	   }
118
*/
119
*/
119
	   if ((garmin->usb.fd = open(USBdevice, O_RDWR | O_NOCTTY | O_NONBLOCK)) == -1)
120
	   if ((garmin->usb.fd = open(USBdevice, O_RDWR)) == -1)
120
	      return 0;
121
	      return 0;
121
 
122
 
122
	   if (isatty(garmin->usb.fd))
123
	   if (tcgetattr(garmin->usb.fd, &tp) == -1)
123
	   {
-
 
124
	      /* install the signal handler before making the device asynchronous */
-
 
125
	      memset (&saio, 0, sizeof(struct sigaction));
-
 
126
	      saio.sa_handler = signal_handler_IO;
-
 
127
/*	      saio.sa_mask = 0;
-
 
128
	      saio.sa_flags = 0;
124
	      return 0;
129
	      saio.sa_restorer = NULL; */
-
 
130
	      sigaction(SIGIO, &saio, NULL);
-
 
131
 
-
 
132
	      /* allow the process to receive SIGIO */
-
 
133
	      fcntl(garmin->usb.fd, F_SETOWN, getpid());
-
 
134
	      /* Make the file descriptor asynchronous (the manual page says only
-
 
135
		 O_APPEND and O_NONBLOCK, will work with F_SETFL...) */
-
 
136
	      fcntl(garmin->usb.fd, F_SETFL, FASYNC);
-
 
137
	      tcgetattr(garmin->usb.fd, &ttyset_old);	/* save current port settings */
-
 
138
	      ttyset.c_cflag &= ~(PARENB | CRTSCTS);
-
 
139
	      ttyset.c_cflag |= CREAD | CLOCAL | B9600;
-
 
140
	      ttyset.c_iflag = ttyset.c_oflag = ttyset.c_lflag = (tcflag_t) 0;
-
 
141
	      ttyset.c_oflag = (ONLCR);
-
 
142
 
125
 
-
 
126
	   tp.c_iflag &=
-
 
127
	     ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON|IXOFF|IXANY|INPCK|IUCLC);
-
 
128
	   tp.c_oflag &= ~OPOST;
-
 
129
	   tp.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN|ECHOE);
143
	      tcflush(garmin->usb.fd, TCIFLUSH);
130
	   tp.c_cflag &= ~(CSIZE|PARENB);
-
 
131
	   tp.c_cflag |= CS8 | CLOCAL | CREAD | CRTSCTS;
-
 
132
 
144
	      tcsetattr(garmin->usb.fd, TCSANOW, &ttyset);
133
	   if (cfsetispeed(&tp, B115200) == -1)
145
	   }
134
	      return 0;
-
 
135
 
-
 
136
	   if (cfsetospeed(&tp, B115200) == -1)
146
	   else
137
	      return 0;
147
	   {
138
	
-
 
139
	   tp.c_cc[VMIN] = 1;
148
	      close(garmin->usb.fd);
140
	   tp.c_cc[VTIME] = 0;
-
 
141
 
149
	      garmin->usb.fd = -1;
142
	   if (tcsetattr(garmin->usb.fd, TCSANOW, &tp) == -1)
150
	      return 0;
143
	      return 0;
151
	   }
-
 
152
 
144
 
153
	   return 1;
145
	   return 1;
154
	}
146
	}
155
	else if (!method && garmin->usb.handle == NULL)
147
	else if (!method && garmin->usb.handle == NULL)
156
	{
148
	{