aboutsummaryrefslogtreecommitdiffstats
path: root/dvb-t/auto-Taiwan
blob: 3b2fb9ff6443e1532282226a61679cf5d0f342b5 (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
# for ($freq = 527000000; $freq <= 599000000; $freq += 6000000) {
# 	print "T $freq 6MHz AUTO NONE AUTO AUTO AUTO NONE\n";
# }
#
[CHANNEL]
	DELIVERY_SYSTEM = DVBT
	FREQUENCY = 527000000
	BANDWIDTH_HZ = 6000000
	CODE_RATE_HP = AUTO
	CODE_RATE_LP = NONE
	MODULATION = QAM/AUTO
	TRANSMISSION_MODE = AUTO
	GUARD_INTERVAL = AUTO
	HIERARCHY = NONE
	INVERSION = AUTO

[CHANNEL]
	DELIVERY_SYSTEM = DVBT
	FREQUENCY = 533000000
	BANDWIDTH_HZ = 6000000
	CODE_RATE_HP = AUTO
	CODE_RATE_LP = NONE
	MODULATION = QAM/AUTO
	TRANSMISSION_MODE = AUTO
	GUARD_INTERVAL = AUTO
	HIERARCHY = NONE
	INVERSION = AUTO

[CHANNEL]
	DELIVERY_SYSTEM = DVBT
	FREQUENCY = 539000000
	BANDWIDTH_HZ = 6000000
	CODE_RATE_HP = AUTO
	CODE_RATE_LP = NONE
	MODULATION = QAM/AUTO
	TRANSMISSION_MODE = AUTO
	GUARD_INTERVAL = AUTO
	HIERARCHY = NONE
	INVERSION = AUTO

[CHANNEL]
	DELIVERY_SYSTEM = DVBT
	FREQUENCY = 545000000
	BANDWIDTH_HZ = 6000000
	CODE_RATE_HP = AUTO
	CODE_RATE_LP = NONE
	MODULATION = QAM/AUTO
	TRANSMISSION_MODE = AUTO
	GUARD_INTERVAL = AUTO
	HIERARCHY = NONE
	INVERSION = AUTO

[CHANNEL]
	DELIVERY_SYSTEM = DVBT
	FREQUENCY = 551000000
	BANDWIDTH_HZ = 6000000
	CODE_RATE_HP = AUTO
	CODE_RATE_LP = NONE
	MODULATION = QAM/AUTO
	TRANSMISSION_MODE = AUTO
	GUARD_INTERVAL = AUTO
	HIERARCHY = NONE
	INVERSION = AUTO

[CHANNEL]
	DELIVERY_SYSTEM = DVBT
	FREQUENCY = 557000000
	BANDWIDTH_HZ = 6000000
	CODE_RATE_HP = AUTO
	CODE_RATE_LP = NONE
	MODULATION = QAM/AUTO
	TRANSMISSION_MODE = AUTO
	GUARD_INTERVAL = AUTO
	HIERARCHY = NONE
	INVERSION = AUTO

[CHANNEL]
	DELIVERY_SYSTEM = DVBT
	FREQUENCY = 563000000
	BANDWIDTH_HZ = 6000000
	CODE_RATE_HP = AUTO
	CODE_RATE_LP = NONE
	MODULATION = QAM/AUTO
	TRANSMISSION_MODE = AUTO
	GUARD_INTERVAL = AUTO
	HIERARCHY = NONE
	INVERSION = AUTO

[CHANNEL]
	DELIVERY_SYSTEM = DVBT
	FREQUENCY = 569000000
	BANDWIDTH_HZ = 6000000
	CODE_RATE_HP = AUTO
	CODE_RATE_LP = NONE
	MODULATION = QAM/AUTO
	TRANSMISSION_MODE = AUTO
	GUARD_INTERVAL = AUTO
	HIERARCHY = NONE
	INVERSION = AUTO

[CHANNEL]
	DELIVERY_SYSTEM = DVBT
	FREQUENCY = 575000000
	BANDWIDTH_HZ = 6000000
	CODE_RATE_HP = AUTO
	CODE_RATE_LP = NONE
	MODULATION = QAM/AUTO
	TRANSMISSION_MODE = AUTO
	GUARD_INTERVAL = AUTO
	HIERARCHY = NONE
	INVERSION = AUTO

[CHANNEL]
	DELIVERY_SYSTEM = DVBT
	FREQUENCY = 581000000
	BANDWIDTH_HZ = 6000000
	CODE_RATE_HP = AUTO
	CODE_RATE_LP = NONE
	MODULATION = QAM/AUTO
	TRANSMISSION_MODE = AUTO
	GUARD_INTERVAL = AUTO
	HIERARCHY = NONE
	INVERSION = AUTO

[CHANNEL]
	DELIVERY_SYSTEM = DVBT
	FREQUENCY = 587000000
	BANDWIDTH_HZ = 6000000
	CODE_RATE_HP = AUTO
	CODE_RATE_LP = NONE
	MODULATION = QAM/AUTO
	TRANSMISSION_MODE = AUTO
	GUARD_INTERVAL = AUTO
	HIERARCHY = NONE
	INVERSION = AUTO

[CHANNEL]
	DELIVERY_SYSTEM = DVBT
	FREQUENCY = 593000000
	BANDWIDTH_HZ = 6000000
	CODE_RATE_HP = AUTO
	CODE_RATE_LP = NONE
	MODULATION = QAM/AUTO
	TRANSMISSION_MODE = AUTO
	GUARD_INTERVAL = AUTO
	HIERARCHY = NONE
	INVERSION = AUTO

[CHANNEL]
	DELIVERY_SYSTEM = DVBT
	FREQUENCY = 599000000
	BANDWIDTH_HZ = 6000000
	CODE_RATE_HP = AUTO
	CODE_RATE_LP = NONE
	MODULATION = QAM/AUTO
	TRANSMISSION_MODE = AUTO
	GUARD_INTERVAL = AUTO
	HIERARCHY = NONE
	INVERSION = AUTO
.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 */
/* $Id: plugin_fifo.c 1112 2010-02-14 02:47:49Z michael $
 * $URL: https://ssl.bulix.org/svn/lcd4linux/trunk/plugin_fifo.c $
 *
 * Fifo plugin
 *
 * Copyright (C) 2008 Michael Vogt <michu@neophob.com>
 * Copyright (C) 2010 Mattia Jona-Lasinio <mjona@users.sourceforge.net>
 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
 *
 * This file is part of LCD4Linux.
 *
 * LCD4Linux 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, or (at your option)
 * any later version.
 *
 * LCD4Linux 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.
 *
 */

/*
 * Configuration parameters:
 *
 * - FifoPath 'string'	: use <string> as the fifo complete file path
 *			  If absent use  /tmp/lcd4linux.fifo)
 *
 * - FifoBufSize num	: if the plugin is unable to determine the display size then
 *			  set the size of the internal buffer to <num> characters
 *			  otherwise use the display size (number of columns).
 *			  If no display size is available and no FifoBufSize parameter
  *			  is specified then arbitrarily set the internal buffer size
 *			  to 80 characters.
 */

#include "config.h"

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <signal.h>

#include "debug.h"
#include "plugin.h"
#include "cfg.h"

#ifdef WITH_DMALLOC
#include <dmalloc.h>
#endif

#define FIFO_MAXPATH		256
#define FIFO_DEFAULT_PATH	/tmp/lcd4linux.fifo
#define FIFO_DEFAULT_BUFSIZE	80
#define str(s) #s
#define string(s) str(s)

struct FifoData {
    char *path;
    char *msg;
    int msglen;
    int input;
    int created;
};

static struct FifoData fd = {
    .path = NULL,
    .msg = NULL,
    .msglen = -1,
    .input = -1,
    .created = -1,
};


static int confFifo(struct FifoData *p)
{
    char *path, *disp, *sect, *fifosect = "Plugin:FIFO";
    unsigned int pathlen;

    info("[FIFO] Reading config file '%s'", cfg_source());

    path = cfg_get(fifosect, "FifoPath", string(FIFO_DEFAULT_PATH));
    pathlen = strlen(path);
    if (pathlen == 0) {
	info("[FIFO] Invalid '%s.FifoPath' entry from '%s'. "
	     "Assuming " string(FIFO_DEFAULT_PATH), fifosect, cfg_source());
	free(path);
	path = strdup(string(FIFO_DEFAULT_PATH));
	pathlen = strlen(path);
    }
    if (pathlen > FIFO_MAXPATH) {
	error("[FIFO] Error: Too long '%s.FifoPath' entry from '%s'. "
	      "(MAX " string(FIFO_MAXPATH) " chars)", fifosect, cfg_source());
	free(path);
	return (-1);
    }
    info("[FIFO] Read '%s.FifoPath' value is '%s'", fifosect, path);

    disp = cfg_get(NULL, "Display", NULL);
    if (disp == NULL) {
	error("[FIFO] Error: Could not get the Display name from '%s'", cfg_source());
	free(path);
	return (-1);
    }
    if ((sect = malloc(1 + strlen("Display:") + strlen(disp))) == NULL) {
	error("[FIFO] Error: Memory allocation failed");
	free(disp);
	free(path);
	return (-1);
    }
    strcpy(sect, "Display:");
    strcat(sect, disp);
    info("[FIFO] Using display '%s'.", disp);
    free(disp);

    disp = cfg_get(sect, "Size", NULL);
    if (disp != NULL) {
	info("[FIFO] Getting the buffer size from '%s.Size'", sect);
	if (sscanf(disp, "%dx%*d", &p->msglen) != 1) {
	    info("[FIFO] Could not determine the display size. " "Assuming " string(FIFO_DEFAULT_BUFSIZE));
	    p->msglen = FIFO_DEFAULT_BUFSIZE;
	}
	free(disp);
    } else {
	info("[FIFO] Could not find a '%s.Size' entry.", sect);
	if (cfg_number(fifosect, "FifoBufSize", FIFO_DEFAULT_BUFSIZE, 0, -1, &p->msglen) > 0) {
	    info("[FIFO] Getting the buffer size from '%s.FifoBufSize'", fifosect);
	} else {
	    info("[FIFO] Could not find a valid '%s.FifoBufSize' entry. "
		 "Assuming " string(FIFO_DEFAULT_BUFSIZE), fifosect);
	    p->msglen = FIFO_DEFAULT_BUFSIZE;
	}
    }
    info("[FIFO] Read buffer size is '%d'", p->msglen);
    free(sect);

    if ((p->msg = malloc(2 + pathlen + p->msglen)) == NULL) {
	error("[FIFO] Error: Memory allocation failed");
	free(path);
	return (-1);
    }
    p->msg[0] = 0;
    p->path = p->msg + p->msglen + 1;
    strcpy(p->path, path);
    free(path);

    return (0);
}


static int makeFifo(struct FifoData *p)
{
    struct stat st;

    if (stat(p->path, &st) < 0) {
	if (errno == ENOENT) {
	    if (mkfifo(p->path, 0666) == 0) {
		p->created = 1;

		return (0);
	    }
	    error("Couldn't create FIFO \"%s\": %s\n", p->path, strerror(errno));

	    return (-1);
	}
	error("Failed to stat FIFO \"%s\": %s\n", p->path, strerror(errno));

	return (-1);
    }

    if (!S_ISFIFO(st.st_mode)) {
	error("\"%s\" already exists, but is not a FIFO", p->path);

	return (-1);
    }

    return (0);
}


static void closeFifo(struct FifoData *p)
{
    struct stat st;

    if (p->input >= 0) {
	close(p->input);
	p->input = -1;
    }

    if ((p->created >= 0) && (stat(p->path, &st) == 0)) {
	debug("Removing FIFO \"%s\"\n", p->path);
	if (unlink(p->path) < 0) {
	    error("Could not remove FIFO \"%s\": %s\n", p->path, strerror(errno));

	    return;
	}
	p->created = -1;
    }

    if (p->msg) {
	free(p->msg);
	p->msg = p->path = NULL;
	p->msglen = -1;
    }
}


static int openFifo(struct FifoData *p)
{
    if (p->created < 0) {
	error("Error: FIFO \"%s\" does not exist: %s\n", p->path, strerror(errno));

	return (-1);
    }

    if ((p->input = open(p->path, O_RDONLY | O_NONBLOCK)) < 0) {
	error("Could not open FIFO \"%s\" for reading: %s\n", p->path, strerror(errno));
	closeFifo(p);

	return (-1);
    }

    return (0);
}


static int startFifo(struct FifoData *p)
{
    int res;

    if ((res = confFifo(p)))
	return (res);

    if ((res = makeFifo(p)))
	return (res);

    if ((res = openFifo(p)))
	return (res);

    /* ignore broken pipe */
    signal(SIGPIPE, SIG_IGN);

    return (res);
}


static void readFifo(struct FifoData *p)
{
    int bytes;

    bytes = read(p->input, p->msg, p->msglen);
    if (bytes == 0)
	return;

    if (bytes > 0) {
	p->msg[bytes] = 0;
	while (bytes--)
	    if (p->msg[bytes] < 0x20)
		p->msg[bytes] = ' ';
    } else {
	error("[FIFO] Error %i: %s", errno, strerror(errno));
	strcpy(p->msg, "ERROR");
    }
}


static void runFifo(RESULT * result)
{
    static int state = 1;
    struct FifoData *p = &fd;
    char *s;

    switch (state) {
    case 1:
	/* Called for the first time. Set up everything. */
	state = startFifo(p);
	s = "";
	break;

    case 0:
	/* Init went fine. Now run in normal operation mode. */
	readFifo(p);
	s = p->msg;
	break;

    default:
	/* There was an error somewhere in init. Do nothing. */
	s = "ERROR";
	break;
    }

    /* Store the result */
    SetResult(&result, R_STRING, s);
}


/* plugin initialization */
int plugin_init_fifo(void)
{
    AddFunction("fifo::read", 0, runFifo);

    return (0);
}


void plugin_exit_fifo(void)
{
    closeFifo(&fd);
}