1 /*
2  * test_front.c - Test program for new API
3  *
4  * Copyright (C) 2000 Ralph  Metzler <ralph@convergence.de>
5  *                  & Marcus Metzler <marcus@convergence.de>
6                       for convergence integrated media GmbH
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation; either version 2.1
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21  *
22  */
23 
24 #include <sys/ioctl.h>
25 #include <stdio.h>
26 #include <stdint.h>
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 #include <fcntl.h>
30 #include <time.h>
31 #include <unistd.h>
32 
33 #include <ost/dmx.h>
34 #include <ost/frontend_old.h>
35 #include <ost/sec.h>
36 #include <ost/audio.h>
37 #include <sys/poll.h>
38 
OSTSelftest(int fd)39 int OSTSelftest(int fd)
40 {
41 	int ans;
42 
43 	if ((ans = ioctl(fd,OST_SELFTEST,0)) < 0) {
44 		perror("OST SELF TEST: ");
45 		return -1;
46 	}
47 
48 	return 0;
49 }
50 
OSTSetPowerState(int fd,uint32_t state)51 int OSTSetPowerState(int fd, uint32_t state)
52 {
53 	int ans;
54 
55 	if ((ans = ioctl(fd,OST_SET_POWER_STATE,state)) < 0) {
56 		perror("OST SET POWER STATE: ");
57 		return -1;
58 	}
59 
60 	return 0;
61 }
62 
OSTGetPowerState(int fd,uint32_t * state)63 int OSTGetPowerState(int fd, uint32_t *state)
64 {
65 	int ans;
66 
67 	if ((ans = ioctl(fd,OST_GET_POWER_STATE,state)) < 0) {
68 		perror("OST GET POWER STATE: ");
69 		return -1;
70 	}
71 
72 	switch(*state){
73 	case OST_POWER_ON:
74 		printf("POWER ON (%d)\n",*state);
75 		break;
76 	case OST_POWER_STANDBY:
77 		printf("POWER STANDBY (%d)\n",*state);
78 		break;
79 	case OST_POWER_SUSPEND:
80 		printf("POWER SUSPEND (%d)\n",*state);
81 		break;
82 	case OST_POWER_OFF:
83 		printf("POWER OFF (%d)\n",*state);
84 		break;
85 	default:
86 		printf("unknown (%d)\n",*state);
87 		break;
88 	}
89 
90 	return 0;
91 }
92 
FEReadStatus(int fd)93 int FEReadStatus(int fd)
94 {
95 	int ans;
96 	feStatus stat;
97 
98 	if ((ans = ioctl(fd,FE_READ_STATUS,&stat)) < 0) {
99 		perror("FE READ STATUS: ");
100 		return -1;
101 	}
102 
103 	if (stat & FE_HAS_POWER)
104 		printf("FE HAS POWER\n");
105 
106 	if (stat & FE_HAS_SIGNAL)
107 		printf("FE HAS SIGNAL\n");
108 
109 	if (stat & QPSK_SPECTRUM_INV)
110 		printf("QPSK SPEKTRUM INV\n");
111 
112 	return 0;
113 }
114 
FEReadBER(int fd,uint32_t * ber)115 int FEReadBER(int fd, uint32_t *ber)
116 {
117 	int ans;
118 
119 	if ((ans = ioctl(fd,FE_READ_BER, ber)) < 0) {
120 		perror("FE READ_BER: ");
121 		return -1;
122 	}
123 	printf("BER: %d\n",*ber);
124 
125 	return 0;
126 }
127 
FEReadSignalStrength(int fd,int32_t * strength)128 int FEReadSignalStrength(int fd, int32_t *strength)
129 {
130 	int ans;
131 
132 	if ((ans = ioctl(fd,FE_READ_SIGNAL_STRENGTH, strength)) < 0) {
133 		perror("FE READ SIGNAL STRENGTH: ");
134 		return -1;
135 	}
136 	printf("SIGNAL STRENGTH: %d\n",*strength);
137 
138 	return 0;
139 }
140 
FEReadSNR(int fd,int32_t * snr)141 int FEReadSNR(int fd, int32_t *snr)
142 {
143 	int ans;
144 
145 	if ((ans = ioctl(fd,FE_READ_SNR, snr)) < 0) {
146 		perror("FE READ_SNR: ");
147 		return -1;
148 	}
149 	printf("SNR: %d\n",*snr);
150 
151 	return 0;
152 }
153 
154 
FEReadUncorrectedBlocks(int fd,uint32_t * ucb)155 int FEReadUncorrectedBlocks(int fd, uint32_t *ucb)
156 {
157 	int ans;
158 
159 	if ((ans = ioctl(fd,FE_READ_UNCORRECTED_BLOCKS, ucb)) < 0) {
160 		perror("FE READ UNCORRECTED BLOCKS: ");
161 		return -1;
162 	}
163 	printf("UBLOCKS: %d\n",*ucb);
164 
165 	return 0;
166 }
167 
FEGetNextFrequency(int fd,uint32_t * nfr)168 int FEGetNextFrequency(int fd, uint32_t *nfr)
169 {
170 	int ans;
171 
172 	if ((ans = ioctl(fd,FE_GET_NEXT_FREQUENCY, nfr)) < 0) {
173 		perror("FE GET NEXT FREQUENCY: ");
174 		return -1;
175 	}
176 	printf("Next Frequency: %d\n",*nfr);
177 
178 	return 0;
179 }
180 
FEGetNextSymbolRate(int fd,uint32_t * nsr)181 int FEGetNextSymbolRate(int fd, uint32_t *nsr)
182 {
183 	int ans;
184 
185 	if ((ans = ioctl(fd,FE_GET_NEXT_SYMBOL_RATE, nsr)) < 0) {
186 		perror("FE GET NEXT SYMBOL RATE: ");
187 		return -1;
188 	}
189 	printf("Next Symbol Rate: %d\n",*nsr);
190 
191 	return 0;
192 }
193 
QPSKTune(int fd,struct qpskParameters * param)194 int QPSKTune(int fd, struct qpskParameters *param)
195 {
196 	int ans;
197 
198 	if ((ans = ioctl(fd,QPSK_TUNE, param)) < 0) {
199 		perror("QPSK TUNE: ");
200 		return -1;
201 	}
202 
203 	return 0;
204 }
205 
QPSKGetEvent(int fd,struct qpskEvent * event)206 int QPSKGetEvent (int fd, struct qpskEvent *event)
207 {
208 	int ans;
209 
210 	if ((ans = ioctl(fd,QPSK_GET_EVENT, event)) < 0) {
211 		perror("QPSK GET EVENT: ");
212 		return -1;
213 	}
214 
215 	return 0;
216 }
217 
QPSKFEInfo(int fd,struct qpskFrontendInfo * info)218 int QPSKFEInfo (int fd, struct qpskFrontendInfo *info)
219 {
220 	int ans;
221 
222 	if ((ans = ioctl(fd,QPSK_FE_INFO, info)) < 0) {
223 		perror("QPSK FE INFO: ");
224 		return -1;
225 	}
226 
227 	printf("min Frequency   : %d\n", info->minFrequency);
228 	printf("max Frequency   : %d\n", info->maxFrequency);
229 	printf("min Symbol Rate : %d\n", info->minSymbolRate);
230 	printf("max Symbol Rate : %d\n", info->maxSymbolRate);
231 	printf("Hardware Type   : %d\n", info->hwType);
232 	printf("Hardware Version: %d\n", info->hwVersion);
233 
234 	return 0;
235 }
236 
SecGetStatus(int fd,struct secStatus * state)237 int SecGetStatus (int fd, struct secStatus *state)
238 {
239 	int ans;
240 
241 	if ((ans = ioctl(fd,SEC_GET_STATUS, state)) < 0) {
242 		perror("QPSK GET EVENT: ");
243 		return -1;
244 	}
245 
246 	switch (state->busMode){
247 	case SEC_BUS_IDLE:
248 		printf("SEC BUS MODE:  IDLE (%d)\n",state->busMode);
249 		break;
250 	case SEC_BUS_BUSY:
251 		printf("SEC BUS MODE:  BUSY (%d)\n",state->busMode);
252 		break;
253 	case SEC_BUS_OFF:
254 		printf("SEC BUS MODE:  OFF  (%d)\n",state->busMode);
255 		break;
256 	case SEC_BUS_OVERLOAD:
257 		printf("SEC BUS MODE:  OVERLOAD (%d)\n",state->busMode);
258 		break;
259 	default:
260 		printf("SEC BUS MODE:  unknown  (%d)\n",state->busMode);
261 		break;
262 	}
263 
264 
265 	switch (state->selVolt){
266 	case SEC_VOLTAGE_OFF:
267 		printf("SEC VOLTAGE:  OFF (%d)\n",state->selVolt);
268 		break;
269 	case SEC_VOLTAGE_LT:
270 		printf("SEC VOLTAGE:  LT  (%d)\n",state->selVolt);
271 		break;
272 	case SEC_VOLTAGE_13:
273 		printf("SEC VOLTAGE:  13  (%d)\n",state->selVolt);
274 		break;
275 	case SEC_VOLTAGE_13_5:
276 		printf("SEC VOLTAGE:  13.5 (%d)\n",state->selVolt);
277 		break;
278 	case SEC_VOLTAGE_18:
279 		printf("SEC VOLTAGE:  18 (%d)\n",state->selVolt);
280 		break;
281 	case SEC_VOLTAGE_18_5:
282 		printf("SEC VOLTAGE:  18.5 (%d)\n",state->selVolt);
283 		break;
284 	default:
285 		printf("SEC VOLTAGE:  unknown (%d)\n",state->selVolt);
286 		break;
287 	}
288 
289 	printf("SEC CONT TONE: %s\n", (state->contTone ? "ON" : "OFF"));
290 	return 0;
291 }
292 
293 
main(int argc,char ** argv)294 main(int argc, char **argv)
295 {
296 	int fd,fd_sec;
297 	uint32_t state;
298 	int32_t strength;
299 	struct qpskFrontendInfo info;
300 	struct secStatus sec_state;
301 
302 	if ((fd = open("/dev/ost/qpskfe",O_RDWR)) < 0){
303 		perror("FRONTEND DEVICE: ");
304 		return -1;
305 	}
306 	if ((fd_sec = open("/dev/ost/sec",O_RDWR)) < 0){
307 		perror("SEC DEVICE: ");
308 		return -1;
309 	}
310 
311 	OSTSelftest(fd);
312 	OSTSetPowerState(fd, OST_POWER_ON);
313 	OSTGetPowerState(fd, &state);
314 	FEReadStatus(fd);
315 	FEReadBER(fd, &state);
316 	FEReadSignalStrength(fd, &strength);
317 	FEReadSNR(fd, &state);
318 	FEReadUncorrectedBlocks(fd, &state);
319 	state = 12567000;
320 	FEGetNextFrequency(fd, &state);
321 	FEGetNextSymbolRate(fd, &state);
322 	QPSKFEInfo (fd, &info);
323 	SecGetStatus (fd_sec, &sec_state);
324 
325 	close(fd);
326 	close(fd_sec);
327 }
328