11 typedef char str[256];
14 str device="/dev/gps";
24 char *out_ptr=in_buff;
29 char *tracks[MAX_TRACKS];
33 FN void tty_puts(char *s);
34 FN void tty_close(void);
39 fprintf(dbf,"Debug: %s\n",s);
49 int receive(char *fname)
52 fprintf(stderr,"%c",7);
55 sprintf(command,"rx %s < %s > %s",fname,device,device);
56 return(system(command));
59 void exittelix(int retcode, int hangup)
68 /*******************************************************************
69 add a track to the set of current tracks
70 ********************************************************************/
71 FN int track(char *s,int tracknum)
75 for (i=0;i<num_tracks;i++)
78 tracks[i] = (char *)malloc(strlen(s)+1);
84 if (num_tracks == MAX_TRACKS)
86 dbg("no more tracks");
89 tracks[num_tracks] = (char *)malloc(strlen(s)+1);
90 strcpy(tracks[num_tracks],s);
95 return(num_tracks - 1);
98 /*******************************************************************
99 check the list of tracks and return the index of a found track from
101 ********************************************************************/
102 FN int track_hit(int tracknum)
113 int got = tty_gets(&s[count],1023-count);
115 if (got == 0) tries--;
117 for (i=0;i<num_tracks;i++)
120 if ((strstr(s,tracks[i])!=NULL))
122 fprintf(dbf,"Got: [%s]\n",s);
130 memcpy(s,s+(count-80),80);
132 memset(s+count,0,1024-count);
139 /*******************************************************************
141 ********************************************************************/
142 FN void track_free(int tracknum)
144 fprintf(dbf,"freeing track %d\n",tracknum);
145 if (tracks[tracknum]) free(tracks[tracknum]);
146 tracks[tracknum] = NULL;
152 void set_terminal(char *term)
156 void set_port(int port)
158 sprintf(device,"/dev/cua%d",port-1);
161 int tty_open(char *device)
168 sprintf(command,"stty 0:1805:cbb:0:3:1c:7f:15:4:0:1:0:11:13:1a:0:12:f:17:16:0 < %s",device);
171 fd = open(device,O_RDWR);
173 ioctl(fd,TCGETS,&tty);
174 tty.c_cflag &= ~CBAUD;
175 tty.c_cflag |= B19200;
176 ioctl(fd,TCSETS,&tty);
189 tty_fd = tty_open(device);
192 fprintf(stderr,"Couldn't open port %s\n",device);
200 fprintf(dbf,"Sending: [%s]\n",s);
208 /*******************************************************************
209 signal this fn if something times out
210 ********************************************************************/
211 FN void TimeOut(int sig)
219 /*******************************************************************
220 get a string from the terminal
221 ********************************************************************/
222 FN int tty_gets(char *s,int n)
229 oldsig = signal(SIGALRM, TimeOut);
230 (void) alarm(howlong);
233 while(!timeout && count<n) {
234 c = (char) tty_getc();
235 if (c == -1) continue;
241 (void) signal(SIGALRM, oldsig);
247 /*******************************************************************
248 Read one character (byte) from the TTY link.
249 ********************************************************************/
250 FN int tty_getc(void)
255 s = read(tty_fd, in_buff, in_size);
256 if (s < 0) return(-1);
262 dbg(" tty_getc: I/O error.\n");
275 /*******************************************************************
276 Write one character (byte) to the TTY link.
277 ********************************************************************/
278 FN int tty_putc(int c)
282 if ((out_cnt == out_size) || (c == -1)) {
283 s = write(tty_fd, out_buff, out_cnt);
286 if (s < 0) return(-1);
300 /*******************************************************************
301 Output a string of characters to the TTY link.
302 ********************************************************************/
303 FN void tty_puts(char *s)
305 while(*s != '\0') tty_putc((int) *s++);
306 tty_putc(-1); /* flush */
309 /*******************************************************************
311 ********************************************************************/
312 FN void tty_close(void)
314 if (tty_fd>=0) close(tty_fd);