aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_front.c
blob: 72acbb69907f582120fad05ed0d7d46d95ec2af9 (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
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
/*
 * test_front.c - Test program for new API
 *
 * Copyright (C) 2000 Ralph  Metzler <ralph@convergence.de>
 *                  & Marcus Metzler <marcus@convergence.de>
                      for convergence integrated media GmbH
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1
 * 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 Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */

#include <sys/ioctl.h>
#include <stdio.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <time.h>
#include <unistd.h>

#include <ost/dmx.h>
#include <ost/frontend_old.h>
#include <ost/sec.h>
#include <ost/audio.h>
#include <sys/poll.h>

int OSTSelftest(int fd)
{
	int ans;

	if ((ans = ioctl(fd,OST_SELFTEST,0)) < 0) {
		perror("OST SELF TEST: ");
		return -1;
	}

	return 0;
}

int OSTSetPowerState(int fd, uint32_t state)
{
	int ans;

	if ((ans = ioctl(fd,OST_SET_POWER_STATE,state)) < 0) {
		perror("OST SET POWER STATE: ");
		return -1;
	}

	return 0;
}

int OSTGetPowerState(int fd, uint32_t *state)
{
	int ans;

	if ((ans = ioctl(fd,OST_GET_POWER_STATE,state)) < 0) {
		perror("OST GET POWER STATE: ");
		return -1;
	}

	switch(*state){
	case OST_POWER_ON:
		printf("POWER ON (%d)\n",*state);
		break;
	case OST_POWER_STANDBY:
		printf("POWER STANDBY (%d)\n",*state);
		break;
	case OST_POWER_SUSPEND:
		printf("POWER SUSPEND (%d)\n",*state);
		break;
	case OST_POWER_OFF:
		printf("POWER OFF (%d)\n",*state);
		break;
	default:
		printf("unknown (%d)\n",*state);
		break;
	}

	return 0;
}

int FEReadStatus(int fd)
{
	int ans;
	feStatus stat;

	if ((ans = ioctl(fd,FE_READ_STATUS,&stat)) < 0) {
		perror("FE READ STATUS: ");
		return -1;
	}

	if (stat & FE_HAS_POWER)
		printf("FE HAS POWER\n");

	if (stat & FE_HAS_SIGNAL)
		printf("FE HAS SIGNAL\n");

	if (stat & QPSK_SPECTRUM_INV)
		printf("QPSK SPEKTRUM INV\n");

	return 0;
}

int FEReadBER(int fd, uint32_t *ber)
{
	int ans;

	if ((ans = ioctl(fd,FE_READ_BER, ber)) < 0) {
		perror("FE READ_BER: ");
		return -1;
	}
	printf("BER: %d\n",*ber);

	return 0;
}

int FEReadSignalStrength(int fd, int32_t *strength)
{
	int ans;

	if ((ans = ioctl(fd,FE_READ_SIGNAL_STRENGTH, strength)) < 0) {
		perror("FE READ SIGNAL STRENGTH: ");
		return -1;
	}
	printf("SIGNAL STRENGTH: %d\n",*strength);

	return 0;
}

int FEReadSNR(int fd, int32_t *snr)
{
	int ans;

	if ((ans = ioctl(fd,FE_READ_SNR, snr)) < 0) {
		perror("FE READ_SNR: ");
		return -1;
	}
	printf("SNR: %d\n",*snr);

	return 0;
}


int FEReadUncorrectedBlocks(int fd, uint32_t *ucb)
{
	int ans;

	if ((ans = ioctl(fd,FE_READ_UNCORRECTED_BLOCKS, ucb)) < 0) {
		perror("FE READ UNCORRECTED BLOCKS: ");
		return -1;
	}
	printf("UBLOCKS: %d\n",*ucb);

	return 0;
}

int FEGetNextFrequency(int fd, uint32_t *nfr)
{
	int ans;

	if ((ans = ioctl(fd,FE_GET_NEXT_FREQUENCY, nfr)) < 0) {
		perror("FE GET NEXT FREQUENCY: ");
		return -1;
	}
	printf("Next Frequency: %d\n",*nfr);

	return 0;
}

int FEGetNextSymbolRate(int fd, uint32_t *nsr)
{
	int ans;

	if ((ans = ioctl(fd,FE_GET_NEXT_SYMBOL_RATE, nsr)) < 0) {
		perror("FE GET NEXT SYMBOL RATE: ");
		return -1;
	}
	printf("Next Symbol Rate: %d\n",*nsr);

	return 0;
}

int QPSKTune(int fd, struct qpskParameters *param)
{
	int ans;

	if ((ans = ioctl(fd,QPSK_TUNE, param)) < 0) {
		perror("QPSK TUNE: ");
		return -1;
	}

	return 0;
}

int QPSKGetEvent (int fd, struct qpskEvent *event)
{
	int ans;

	if ((ans = ioctl(fd,QPSK_GET_EVENT, event)) < 0) {
		perror("QPSK GET EVENT: ");
		return -1;
	}

	return 0;
}

int QPSKFEInfo (int fd, struct qpskFrontendInfo *info)
{
	int ans;

	if ((ans = ioctl(fd,QPSK_FE_INFO, info)) < 0) {
		perror("QPSK FE INFO: ");
		return -1;
	}

	printf("min Frequency   : %d\n", info->minFrequency);
	printf("max Frequency   : %d\n", info->maxFrequency);
	printf("min Symbol Rate : %d\n", info->minSymbolRate);
	printf("max Symbol Rate : %d\n", info->maxSymbolRate);
	printf("Hardware Type   : %d\n", info->hwType);
	printf("Hardware Version: %d\n", info->hwVersion);

	return 0;
}

int SecGetStatus (int fd, struct secStatus *state)
{
	int ans;

	if ((ans = ioctl(fd,SEC_GET_STATUS, state)) < 0) {
		perror("QPSK GET EVENT: ");
		return -1;
	}

	switch (state->busMode){
	case SEC_BUS_IDLE:
		printf("SEC BUS MODE:  IDLE (%d)\n",state->busMode);
		break;
	case SEC_BUS_BUSY:
		printf("SEC BUS MODE:  BUSY (%d)\n",state->busMode);
		break;
	case SEC_BUS_OFF:
		printf("SEC BUS MODE:  OFF  (%d)\n",state->busMode);
		break;
	case SEC_BUS_OVERLOAD:
		printf("SEC BUS MODE:  OVERLOAD (%d)\n",state->busMode);
		break;
	default:
		printf("SEC BUS MODE:  unknown  (%d)\n",state->busMode);
		break;
	}


	switch (state->selVolt){
	case SEC_VOLTAGE_OFF:
		printf("SEC VOLTAGE:  OFF (%d)\n",state->selVolt);
		break;
	case SEC_VOLTAGE_LT:
		printf("SEC VOLTAGE:  LT  (%d)\n",state->selVolt);
		break;
	case SEC_VOLTAGE_13:
		printf("SEC VOLTAGE:  13  (%d)\n",state->selVolt);
		break;
	case SEC_VOLTAGE_13_5:
		printf("SEC VOLTAGE:  13.5 (%d)\n",state->selVolt);
		break;
	case SEC_VOLTAGE_18:
		printf("SEC VOLTAGE:  18 (%d)\n",state->selVolt);
		break;
	case SEC_VOLTAGE_18_5:
		printf("SEC VOLTAGE:  18.5 (%d)\n",state->selVolt);
		break;
	default:
		printf("SEC VOLTAGE:  unknown (%d)\n",state->selVolt);
		break;
	}

	printf("SEC CONT TONE: %s\n", (state->contTone ? "ON" : "OFF"));
	return 0;
}


main(int argc, char **argv)
{
	int fd,fd_sec;
	uint32_t state;
	int32_t strength;
	struct qpskFrontendInfo info;
	struct secStatus sec_state;

	if ((fd = open("/dev/ost/qpskfe",O_RDWR)) < 0){
		perror("FRONTEND DEVICE: ");
		return -1;
	}
	if ((fd_sec = open("/dev/ost/sec",O_RDWR)) < 0){
		perror("SEC DEVICE: ");
		return -1;
	}

	OSTSelftest(fd);
	OSTSetPowerState(fd, OST_POWER_ON);
	OSTGetPowerState(fd, &state);
	FEReadStatus(fd);
	FEReadBER(fd, &state);
	FEReadSignalStrength(fd, &strength);
	FEReadSNR(fd, &state);
	FEReadUncorrectedBlocks(fd, &state);
	state = 12567000;
	FEGetNextFrequency(fd, &state);
	FEGetNextSymbolRate(fd, &state);
	QPSKFEInfo (fd, &info);
	SecGetStatus (fd_sec, &sec_state);

	close(fd);
	close(fd_sec);
}