File: eppdiag.c

package info (click to toggle)
baycomepp 0.10-15
  • links: PTS
  • area: main
  • in suites: bullseye, buster
  • size: 2,896 kB
  • ctags: 3,195
  • sloc: ansic: 32,213; sh: 3,795; makefile: 482; sed: 93; perl: 31; asm: 18
file content (341 lines) | stat: -rw-r--r-- 9,172 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
/*****************************************************************************/

/*
 *      eppdiag.c  -- HDLC packet radio modem for EPP using FPGA GUI tool.
 *
 *      Copyright (C) 1998, 2000  Thomas Sailer (sailer@ife.ee.ethz.ch)
 *
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *  Please note that the GPL allows you to use the driver, NOT the radio.
 *  In order to use the radio, you need a license from the communications
 *  authority of your country.
 *
 */

/*****************************************************************************/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdarg.h>
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>

#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif

#include "fpga.h"

#include <gtk/gtk.h>
#include <glib.h>
#include "gladesrc.h"
#include "gladesig.h"

/* ---------------------------------------------------------------------- */

static unsigned verboselevel = 0;
static int quit = 0;
static GtkWidget *diag;

/* ---------------------------------------------------------------------- */

int lprintf(unsigned vl, const char *format, ...)
{
	char buf[256];
        va_list ap;
        int r;
	char *cp;

#if 0
        if (vl > verboselevel)
                return 0;
#endif
	va_start(ap, format);
	r = vsnprintf(buf, sizeof(buf), format, ap);
	va_end(ap);
	while (cp = strchr(buf, '\r'))
		*cp = '\n';
	gtk_text_insert(GTK_TEXT(gtk_object_get_data(GTK_OBJECT(diag), "textl")), NULL, NULL, NULL, buf, r);
        return r;
}

int tprintf(const char *format, ...)
{
	char buf[256];
	va_list ap;
	int r;
	char *cp;

        va_start(ap, format);
	r = vsnprintf(buf, sizeof(buf), format, ap);
        va_end(ap);
	while (cp = strchr(buf, '\r'))
		*cp = '\n';
	gtk_text_insert(GTK_TEXT(gtk_object_get_data(GTK_OBJECT(diag), "textt")), NULL, NULL, NULL, buf, r);
	return r;
}

int idle_callback(unsigned us_delay)
{
	while (gtk_events_pending())
		gtk_main_iteration();
	if (us_delay)
		usleep(us_delay);
	return quit;
}

void epp_error(const char *msg)
{
	lprintf(0, msg);
	reset_modem();
	exit(1);
}

/* ---------------------------------------------------------------------- */

void on_bquit_clicked(GtkButton *button, gpointer user_data)
{
	quit = 1;
	gtk_main_quit();
}

void on_btest_clicked(GtkButton *button, gpointer user_data)
{
	static int test_run = 0;
	const struct eppfpgatests *tst;
	struct adapter_config cfg;
	gchar *cp;

	if (test_run) {
		quit = 1;
		return;
	}
	cp = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(gtk_object_get_data(GTK_OBJECT(diag), "partest"))->entry));
	for (tst = eppfpgatests; tst->name && strcmp(cp, tst->name); tst++);
	if (!tst->name) {
		g_error("Internal Error: test %s not found\n", cp);
		return;
	}
	/*iobase = strtoul(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(gtk_object_get_data(GTK_OBJECT(diag), "paraddress"))->entry)), NULL, 0);*/
	cfg.intclk = GTK_TOGGLE_BUTTON(gtk_object_get_data(GTK_OBJECT(diag), "parclk"))->active;
	cfg.bitrate = strtoul(gtk_entry_get_text(GTK_ENTRY(gtk_object_get_data(GTK_OBJECT(diag), "parbitrate"))), NULL, 0);
	cfg.fclk = strtoul(gtk_entry_get_text(GTK_ENTRY(gtk_object_get_data(GTK_OBJECT(diag), "parfclk"))), NULL, 0);
	cfg.extmodem = !GTK_TOGGLE_BUTTON(gtk_object_get_data(GTK_OBJECT(diag), "parmodem"))->active;
	cfg.loopback = GTK_TOGGLE_BUTTON(gtk_object_get_data(GTK_OBJECT(diag), "parloopback"))->active;
	cfg.extstat = GTK_TOGGLE_BUTTON(gtk_object_get_data(GTK_OBJECT(diag), "parstat"))->active;
	cp = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(gtk_object_get_data(GTK_OBJECT(diag), "parfilter"))->entry));
	switch(cp[0]) {
	default:
		cfg.filtmode = 0;
		break;
	case 'A':
		cfg.filtmode = 1;
		break;
	case 'L':
		cfg.filtmode = 2;
		break;
	}
	cfg.gain = 1;
	test_run = 1;
	quit = 0;
	tst->func(&cfg);
	test_run = 0;
}

/* ---------------------------------------------------------------------- */

static void initdiag(void)
{
	GList *items = NULL;
	const struct eppfpgatests *tst;

	diag = create_diag();
	for (tst = eppfpgatests; tst->name; tst++)
		items = g_list_append(items, tst->name);
	gtk_combo_set_popdown_strings(GTK_COMBO(gtk_object_get_data(GTK_OBJECT(diag), "partest")), items);
	g_list_free(items);

	gtk_widget_show(diag);
}

/* ---------------------------------------------------------------------- */

int main(int argc, char *argv[])
{
        static const struct option long_options[] = {
#ifdef HAVE_PPUSER
                { "ppuser", 1, 0, 0x400 },
                { "ppdev", 1, 0, 0x402 },
#endif
#ifdef HAVE_PPKDRV
                { "ppkdrv", 1, 0, 0x401 },
#endif
#ifdef WIN32
                { "ppgenport", 0, 0, 0x403 },
                { "ppwin", 1, 0, 0x404 },
                { "pplpt", 1, 0, 0x404 },
                { "ppring0", 0, 0, 0x405 },
#endif
		{ "ppforcehwepp", 0, 0, 0x410 },
		{ "ppswemulepp", 0, 0, 0x411 },
		{ "ppswemulecp", 0, 0, 0x412 },
		{ 0, 0, 0, 0 }
        };
	int c, err = 0;
	unsigned int iobase = 0x378, ntddkgenport = 0, ntdrv = 0, w9xring0 = 0, ppflags = 0;
	const char *ppuser = NULL, *ppkdrv = NULL, *ppdev = NULL;

	gtk_set_locale();
	gtk_init(&argc, &argv);
	while ((c = getopt_long(argc, argv, "vp:", long_options, NULL)) != EOF) {
		switch (c) {
		case 0x400:
			ppuser = optarg;
			ppkdrv = NULL;
			ppdev = NULL;
			ntddkgenport = 0;
                        ntdrv = 0;
                        w9xring0 = 0;
			break;

		case 0x401:
			ppkdrv = optarg;
			ppuser = NULL;
			ppdev = NULL;
			ntddkgenport = 0;
                        ntdrv = 0;
                        w9xring0 = 0;
			break;

		case 0x402:
			ppkdrv = NULL;
			ppuser = NULL;
			ppdev = optarg;
			ntddkgenport = 0;
                        ntdrv = 0;
                        w9xring0 = 0;
			break;

		case 0x403:
			ppkdrv = NULL;
			ppuser = NULL;
			ppdev = NULL;
			ntddkgenport = 1;
                        ntdrv = 0;
                        w9xring0 = 0;
                        break;

		case 0x404:
			ppkdrv = NULL;
			ppuser = NULL;
			ppdev = NULL;
			ntddkgenport = 0;
                        ntdrv = strtoul(optarg, NULL, 0);
                        w9xring0 = 0;
			break;

		case 0x405:
			ppkdrv = NULL;
			ppuser = NULL;
			ppdev = NULL;
			ntddkgenport = 0;
                        ntdrv = 0;
                        w9xring0 = 1;
			break;

		case 0x410:
			ppflags |= PPFLAG_FORCEHWEPP;
			break;

		case 0x411:
			ppflags |= PPFLAG_SWEMULEPP;
			break;

		case 0x412:
			ppflags |= PPFLAG_SWEMULECP;
			break;

		case 'v':
			verboselevel++;
			break;

		case 'p': 
			iobase = strtoul(optarg, NULL, 0);
			if (iobase <= 0 || iobase >= 0x3f8)
				err++;
			break;

		default:
			err++;
			break;
		}
	}
	if (err) {
		lprintf(0, "usage: %s [-v] [-p <portaddr>]\n", argv[0]);
		exit(1);
	}
#ifdef HAVE_PPUSER
	if (ppkdrv) {
		if (parport_init_ppkdrv(ppkdrv)) {
			fprintf(stderr, "no kernel interface %s driver found\n", ppkdrv);
			exit(1);
		}
	} else
#endif
#ifdef HAVE_PPUSER
		if (ppdev) {
			if (parport_init_ppdev(ppdev)) {
				fprintf(stderr, "no ppdev driver found at %s\n", ppdev);
				exit(1);
			}
		} else if (ppuser) {
			if (parport_init_ppuser(ppuser)) {
				fprintf(stderr, "no ppuser driver found at %s\n", ppuser);
				exit(1);
			}
		} else
#endif
#ifdef WIN32
                        if (ntdrv) {
                                if (parport_init_win_flags(ntdrv-1, ppflags)) {
                                        fprintf(stderr, "no eppflex.sys/vxd driver found\n");
                                        exit(1);
                                }
                        } else if (ntddkgenport) {
                                if (parport_init_ntddkgenport()) {
                                        fprintf(stderr, "no NTDDK genport.sys driver found\n");
                                        exit(1);
                                }
                        } else if (w9xring0) {
                                if (parport_init_w9xring0_flags(iobase, ppflags)) {
                                        fprintf(stderr, "no parport found at 0x%x\n", iobase);
                                        exit(1);
                                }
                        } else
#endif
                                if (parport_init_direct_flags(iobase, ppflags)) {
                                        fprintf(stderr, "no parport found at 0x%x\n", iobase);
                                        exit(1);
                                }
	initdiag();
	gtk_main();
	exit(0);
}