aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_switch.c
blob: b2939add30dc15bc15dee7e1eb2c82a90ab06816 (plain)
1
2
3
4
5
6
7
pre { line-height: 125%; margin: 0; }
td.linenos pre { color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px; }
span.linenos { color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px; }
td.linenos pre.special { color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#channels.conf for DVB-T - Alpicat (Lleida) Transmitter

#C42
TV3:642000000:INVERSION_OFF:BANDWIDTH_8_MHZ:FEC_2_3:FEC_2_3:QAM_64:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:111:112:801
K3/33:642000000:INVERSION_OFF:BANDWIDTH_8_MHZ:FEC_2_3:FEC_2_3:QAM_64:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:121:122:802
3/24:642000000:INVERSION_OFF:BANDWIDTH_8_MHZ:FEC_2_3:FEC_2_3:QAM_64:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:131:132:803
Canal Pilot:642000000:INVERSION_OFF:BANDWIDTH_8_MHZ:FEC_2_3:FEC_2_3:QAM_64:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:141:142:804
3XL.net:642000000:INVERSION_OFF:BANDWIDTH_8_MHZ:FEC_2_3:FEC_2_3:QAM_64:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:151:152:805

#C58
TVE 1:770000000:INVERSION_OFF:BANDWIDTH_8_MHZ:FEC_2_3:FEC_NONE:QAM_64:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:101:103:1377
TVE 2:770000000:INVERSION_OFF:BANDWIDTH_8_MHZ:FEC_2_3:FEC_NONE:QAM_64:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:201:203:1441
ANTENA 3:770000000:INVERSION_OFF:BANDWIDTH_8_MHZ:FEC_2_3:FEC_NONE:QAM_64:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:301:303:1121
CANAL+:770000000:INVERSION_OFF:BANDWIDTH_8_MHZ:FEC_2_3:FEC_NONE:QAM_64:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:501:503:1057
TELECINCO:770000000:INVERSION_OFF:BANDWIDTH_8_MHZ:FEC_2_3:FEC_NONE:QAM_64:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:401:403:1185

#C66
Veo TV:834000000:INVERSION_OFF:BANDWIDTH_8_MHZ:FEC_2_3:FEC_1_2:QAM_64:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:301:302:1536
Net TV:834000000:INVERSION_OFF:BANDWIDTH_8_MHZ:FEC_2_3:FEC_1_2:QAM_64:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:401:402:1825
229'>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 342 343 344 345 346 347 348 349 350 351 352 353 354 355
/*
 * test_switch.c - Test program for new API
 *
 * Copyright (C) 2001 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 <sys/poll.h>

#include <linux/dvb/dmx.h>
#include <linux/dvb/frontend_old.h>
#include <linux/dvb/sec.h>
#include <linux/dvb/video.h>

int fd_frontend;
int fd_sec;
int fd_demuxa;
int fd_demuxv;
int fd_demuxtt;

struct dmx_sct_filter_params sctFilterParams;

struct secCommand scmd;
struct secCmdSequence scmds;
struct dmx_pes_filter_params pesFilterParams;
struct dmx_pes_filter_params pesFilterParamsV;
struct dmx_pes_filter_params pesFilterParamsA;
struct dmx_pes_filter_params pesFilterParamsTT;
FrontendParameters frp;
int front_type;


set_front(void)
{
	fe_status_t stat = 0;
	int i, freq;
	uint32_t soff;

	scmds.miniCommand = SEC_MINI_NONE;
	scmds.numCommands = 1;
	scmds.commands = &scmd;

	soff = frp.u.qpsk.SymbolRate/16000;

	if (ioctl(fd_sec, SEC_SEND_SEQUENCE, &scmds) < 0)
		perror("setfront sec");
	usleep(100000);

	freq = frp.Frequency;

	while(tune_it(&frp));
}

set_diseqc_nb(int nr)
{
	scmd.type=0;
	scmd.u.diseqc.addr = 0x10;
	scmd.u.diseqc.cmd = 0x38;
	scmd.u.diseqc.numParams = 1;
	scmd.u.diseqc.params[0] = 0xF0 | ((nr * 4) & 0x0F) |
	  (scmds.continuousTone == SEC_TONE_ON ? 1 : 0) |
	  (scmds.voltage==SEC_VOLTAGE_18 ? 2 : 0);
}

set_ttpid(ushort ttpid)
{
        if (ttpid==0 || ttpid==0xffff || ttpid==0x1fff) {
	        ioctl(fd_demuxtt, DMX_STOP, 0);
	        return;
	}

	pesFilterParamsTT.pid     = ttpid;
	pesFilterParamsTT.input   = DMX_IN_FRONTEND;
	pesFilterParamsTT.output  = DMX_OUT_DECODER;
	pesFilterParamsTT.pes_type = DMX_PES_TELETEXT;
	pesFilterParamsTT.flags   = DMX_IMMEDIATE_START;
	if (ioctl(fd_demuxtt, DMX_SET_PES_FILTER,
		  &pesFilterParamsTT) < 0) {
	  printf("PID=%04x\n", ttpid);
		perror("set_ttpid");
	}
}

set_vpid(ushort vpid)
{
        if (vpid==0 || vpid==0xffff || vpid==0x1fff) {
	        ioctl(fd_demuxv, DMX_STOP, 0);
	        return;
	}

	pesFilterParamsV.pid     = vpid;
	pesFilterParamsV.input   = DMX_IN_FRONTEND;
	pesFilterParamsV.output  = DMX_OUT_DECODER;
	pesFilterParamsV.pes_type = DMX_PES_VIDEO;
	pesFilterParamsV.flags   = DMX_IMMEDIATE_START;
	if (ioctl(fd_demuxv, DMX_SET_PES_FILTER,
		  &pesFilterParamsV) < 0)
		perror("set_vpid");
}

set_apid(ushort apid)
{
        if (apid==0 || apid==0xffff || apid==0x1fff) {
	        ioctl(fd_demuxa, DMX_STOP, apid);
	        return;
	}
	pesFilterParamsA.pid = apid;
	pesFilterParamsA.input = DMX_IN_FRONTEND;
	pesFilterParamsA.output = DMX_OUT_DECODER;
	pesFilterParamsA.pes_type = DMX_PES_AUDIO;
	pesFilterParamsA.flags = DMX_IMMEDIATE_START;
	if (ioctl(fd_demuxa, DMX_SET_PES_FILTER,
		  &pesFilterParamsA) < 0)
		perror("set_apid");
}

int tune_it(FrontendParameters *frp)
{
	fe_status_t stat = 0;
	int res;
	FrontendEvent event;
	int count = 0;
	struct pollfd pfd[1];

	if (ioctl(fd_frontend, FE_SET_FRONTEND, frp) <0)
		perror("setfront front");



	pfd[0].fd = fd_frontend;
	pfd[0].events = POLLIN;

	if (poll(pfd,1,3000)){
		if (pfd[0].revents & POLLIN){
			printf("Getting QPSK event\n");
			if ( ioctl(fd_frontend, FE_GET_EVENT, &event)

			     == -EOVERFLOW){
				perror("qpsk get event");
				return -1;
			}
			printf("Received ");
			switch(event.type){
			case FE_UNEXPECTED_EV:
				printf("unexpected event\n");
				return -1;
			case FE_FAILURE_EV:
				printf("failure event\n");
				return -1;

			case FE_COMPLETION_EV:
				printf("completion event\n");
			}
		}
	}
	return 0;
}

set_tp(uint *freq, int ttk, int pol, uint srate, int dis)
{
	if (*freq < 11700000) {
		frp.Frequency = (*freq - 9750000);
		scmds.continuousTone = SEC_TONE_OFF;
	} else {
		frp.Frequency = (*freq - 10600000);
		scmds.continuousTone = SEC_TONE_ON;
	}
	if (pol) scmds.voltage = SEC_VOLTAGE_18;
	else scmds.voltage = SEC_VOLTAGE_13;
	set_diseqc_nb(dis);
	frp.u.qpsk.SymbolRate = srate;
	frp.u.qpsk.FEC_inner = 0;
}

get_front(void)
{
	set_vpid(0);
	set_apid(0);
	set_ttpid(0);
	scmds.voltage = SEC_VOLTAGE_18;
	scmds.miniCommand = SEC_MINI_NONE;
	scmds.continuousTone = SEC_TONE_OFF;
	scmds.numCommands=1;
	scmds.commands=&scmd;

	frp.Frequency=(12073000-10600000);
	frp.u.qpsk.SymbolRate=25378000;
	frp.u.qpsk.FEC_inner=(fe_code_rate_t)5;
}


void get_sect(int fd)
{
        u_char sec[4096];
        int len, i;
        uint16_t cpid = 0;
        uint16_t length;
        struct pollfd pfd;

        pfd.fd = fd;
        pfd.events = POLLIN;

	while (1){
		if (poll(&pfd, 1, 5000) != POLLIN) {
			printf("not found\n");
			printf("Timeout\n");
		} else {
			len = read(fd, sec, 4096);

			length  = (sec[1]& 0x0F)<<8;
			length |= (sec[2]& 0xFF);


			for (i= 0; i < length+3; i++) {
				printf("0x%02x ",sec[i]);
				if ( !((i+1)%8))
					printf("\n");
			}
			printf("\n");
		}
	}
}

int FEReadStatus(int fd, fe_status_t *stat)
{
	int ans;

	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 & FE_SPECTRUM_INV)
		printf("QPSK SPEKTRUM INV\n");

	return 0;
}

int has_signal()
{
	fe_status_t stat;

	FEReadStatus(fd_frontend, &stat);
	if (stat & FE_HAS_SIGNAL)
		return 1;
	else {
		printf("Tuning failed\n");
		return 0;
	}
}

main()
{
	int freq;

	fd_demuxtt = open("/dev/ost/demux", O_RDWR|O_NONBLOCK);
	fd_frontend = open("/dev/ost/frontend", O_RDWR);
	fd_sec = open("/dev/ost/sec", O_RDWR);
	fd_demuxa = open("/dev/ost/demux", O_RDWR|O_NONBLOCK);
	fd_demuxv = open("/dev/ost/demux", O_RDWR|O_NONBLOCK);

//	get_front();
//        set_vpid(0x7d0);
//       set_apid(0x7d2);
//	set_ttpid(0);
//	freq = 12073000;
//	set_tp(&freq, 1, 1, 25378000, 3);
//	set_diseqc_nb(dis);

	scmds.voltage = SEC_VOLTAGE_18;
//	scmds.voltage = SEC_VOLTAGE_13;
	scmds.miniCommand = SEC_MINI_NONE;
	scmds.continuousTone = SEC_TONE_OFF;
	scmds.numCommands=1;
	scmds.commands=&scmd;
	frp.Frequency = (12073000 - 10600000);
//	frp.Frequency = (11975000 - 10600000);
	scmds.continuousTone = SEC_TONE_ON;
	frp.u.qpsk.SymbolRate = 25378000;
//	frp.u.qpsk.SymbolRate = 27500000;
//	frp.u.qpsk.FEC_inner = FEC_AUTO;
	frp.u.qpsk.FEC_inner = (fe_code_rate_t)5;
	scmd.type=0;
	scmd.u.diseqc.addr = 0x10;
	scmd.u.diseqc.cmd = 0x38;
	scmd.u.diseqc.numParams = 1;
	scmd.u.diseqc.params[0] = 0xF0 | ((3 * 4) & 0x0F) |
	  (scmds.continuousTone == SEC_TONE_ON ? 1 : 0) |
	  (scmds.voltage==SEC_VOLTAGE_18 ? 2 : 0);

	if (ioctl(fd_sec, SEC_SEND_SEQUENCE, &scmds) < 0)
		perror("setfront sec");

	while(tune_it(&frp));


/*
	if ((fd_demuxa=open("/dev/ost/demux", O_RDWR|O_NONBLOCK))
	    < 0){
		perror("DEMUX DEVICE: ");
		return -1;
	}
        memset(&sctFilterParams.filter, 0, sizeof(struct dmx_filter));
        sctFilterParams.pid                       = 0x1fff;
        sctFilterParams.filter.filter[0]          = 0x00;
        sctFilterParams.filter.mask[0]            = 0x00;
        sctFilterParams.timeout                   = 0;
        sctFilterParams.flags                     = DMX_IMMEDIATE_START;

        if (ioctl(fd_demuxa, DMX_SET_FILTER, &sctFilterParams) < 0)
                perror("DMX SET FILTER:");


	get_sect(fd_demuxa);
*/
	pesFilterParamsA.pid = 0x1fff;
	pesFilterParamsA.input = DMX_IN_FRONTEND;
	pesFilterParamsA.output = DMX_OUT_TS_TAP;
	pesFilterParamsA.pes_type = DMX_PES_OTHER;
	pesFilterParamsA.flags = DMX_IMMEDIATE_START;
	if (ioctl(fd_demuxa, DMX_SET_PES_FILTER,
		  &pesFilterParamsA) < 0)
		perror("set_apid");

	while(1);
}