summaryrefslogtreecommitdiffstats
path: root/hdlcutil/fl/xfhdlcst_main.cxx
blob: bf54292ebd7dfaecd155f1123fce233cb80ab3c6 (plain)
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
/*****************************************************************************/

/*
 *	xfhdlcst_main.C  -- kernel hdlc radio modem driver status display utility.
 *
 *	Copyright (C) 1996,1997,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.
 *
 *
 * History:
 *   0.1  14.12.1996  Started
 *   0.2  11.05.1997  introduced hdrvcomm.h
 *   0.3  05.01.2000  upgraded to fltk 1.0.7
 */

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

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <net/if.h>
#include "hdrvcomm.h"
#include "xfhdlcst.h"

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

static char *progname;
static bool update = true;

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

void cb_quit(Fl_Button *, long)
{
	exit(0);
}

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

void cb_timer(void *)
{
	update = true;
}

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

static const char *usage_str = 
"[-i smif]\n"
"  -i: specify the name of the baycom kernel driver interface\n\n";

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

int main(int argc, char *argv[])
{
        int c, i;
	int ret;
	struct hdrvc_channel_state cs;
#ifdef HDRVC_KERNEL
	struct sm_ioctl smi;
#endif /* HDRVC_KERNEL */
	char buf[32];
	char name[64];

	progname = *argv;
	printf("%s: Version 0.3; (C) 1996,1997,2000 by Thomas Sailer HB9JNX/AE4WA\n", *argv);
	hdrvc_args(&argc, argv, "bc0");
	for (i = 1; i < argc; ) {
		c = i;
		Fl::arg(argc, argv, c);
		if (c <= 0) {
			i++;
			continue;
		}
		memmove(&argv[i], &argv[i+c], (argc-i) * sizeof(char *));
		argc -= c;
	}
#if 0
	while ((ret = getopt(argc, argv, "")) != -1) {
		switch (ret) {
		default:
			printf("usage: %s %s", *argv, usage_str);
			exit(-1);
		}
	}
#endif
	hdrvc_init();

	create_the_forms();
	Fl::add_timeout(0.1, cb_timer);
	/*
	 * set driver and modem name
	 */
	ret = hdrvc_get_mode_name(name, sizeof(name));
	if (ret < 0) {
		perror("hdrvc_get_mode_name");
		modename->hide();
	} else 
		modename->value(name);
	ret = hdrvc_get_driver_name(name, sizeof(name));
	if (ret < 0) {
		perror("hdrvc_get_driver_name");
		drivername->hide();
	} else 
		drivername->value(name);
	/*
	 * check for soundmodem driver
	 */
#ifdef HDRVC_KERNEL
	ret = hdrvc_sm_ioctl(SMCTL_GETDEBUG, &smi);
	if (ret < 0) {
#endif /* HDRVC_KERNEL */
		tdemodcyc->hide();
		tmodcyc->hide();
		tintfreq->hide();
		tdmares->hide();
		demodcyc->hide();
		modcyc->hide();
		intfreq->hide();
		dmares->hide();
#ifdef HDRVC_KERNEL
	}
#endif /* HDRVC_KERNEL */
	hdlcst->show();
	for (;;) {
		Fl::wait();
		if (!update)
			continue;
		update = false;
		Fl::add_timeout(0.5, cb_timer);
		/*
		 * display state
		 */
		ret = hdrvc_get_channel_state(&cs);
		if (ret >= 0) {
			ptt->value(cs.ptt);
			dcd->value(cs.dcd);
			sprintf(buf, "%ld", cs.tx_packets);
			txpacket->value(buf);
			sprintf(buf, "%ld", cs.tx_errors);
			txerror->value(buf);
			sprintf(buf, "%ld", cs.rx_packets);
			rxpacket->value(buf);
			sprintf(buf, "%ld", cs.rx_errors);
			rxerror->value(buf);
		}
		ret = hdrvc_sm_ioctl(SMCTL_GETDEBUG, &smi);
		if (ret >= 0) {
			sprintf(buf, "%d", smi.data.dbg.int_rate);
			intfreq->value(buf);
			sprintf(buf, "%d", smi.data.dbg.mod_cycles);
			modcyc->value(buf);
			sprintf(buf, "%d", smi.data.dbg.demod_cycles);
			demodcyc->value(buf);
			sprintf(buf, "%d", smi.data.dbg.dma_residue);
			dmares->value(buf);
		} 
	}
	exit (0);
}