2002-10-06 10:25:42 +02:00
|
|
|
/*
|
|
|
|
* diseqc.c: DiSEqC handling
|
|
|
|
*
|
|
|
|
* See the main source file 'vdr.c' for copyright information and
|
|
|
|
* how to reach the author.
|
|
|
|
*
|
2005-12-30 15:43:21 +01:00
|
|
|
* $Id: diseqc.c 1.5 2005/12/30 15:41:48 kls Exp $
|
2002-10-06 10:25:42 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "diseqc.h"
|
|
|
|
#include <ctype.h>
|
|
|
|
#include "sources.h"
|
2004-10-24 11:12:05 +02:00
|
|
|
#include "thread.h"
|
2002-10-06 10:25:42 +02:00
|
|
|
|
|
|
|
// -- cDiseqc ----------------------------------------------------------------
|
|
|
|
|
|
|
|
cDiseqc::cDiseqc(void)
|
|
|
|
{
|
|
|
|
commands = NULL;
|
|
|
|
parsing = false;
|
|
|
|
numCodes = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cDiseqc::~cDiseqc()
|
|
|
|
{
|
|
|
|
free(commands);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cDiseqc::Parse(const char *s)
|
|
|
|
{
|
|
|
|
bool result = false;
|
|
|
|
char *sourcebuf = NULL;
|
|
|
|
int fields = sscanf(s, "%a[^ ] %d %c %d %a[^\n]", &sourcebuf, &slof, &polarization, &lof, &commands);
|
|
|
|
if (fields == 4)
|
|
|
|
commands = NULL; //XXX Apparently sscanf() doesn't work correctly if the last %a argument results in an empty string
|
|
|
|
if (4 <= fields && fields <= 5) {
|
|
|
|
source = cSource::FromString(sourcebuf);
|
|
|
|
if (Sources.Get(source)) {
|
|
|
|
polarization = toupper(polarization);
|
2005-01-09 13:18:15 +01:00
|
|
|
if (polarization == 'V' || polarization == 'H' || polarization == 'L' || polarization == 'R') {
|
2002-10-06 10:25:42 +02:00
|
|
|
parsing = true;
|
2002-12-08 09:55:26 +01:00
|
|
|
char *CurrentAction = NULL;
|
|
|
|
while (Execute(&CurrentAction) != daNone)
|
|
|
|
;
|
2002-10-06 10:25:42 +02:00
|
|
|
parsing = false;
|
2002-12-08 09:55:26 +01:00
|
|
|
result = !commands || !*CurrentAction;
|
2002-10-06 10:25:42 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
esyslog("ERROR: unknown polarization '%c'", polarization);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
esyslog("ERROR: unknown source '%s'", sourcebuf);
|
|
|
|
}
|
|
|
|
free(sourcebuf);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *cDiseqc::Wait(char *s)
|
|
|
|
{
|
|
|
|
char *p = NULL;
|
|
|
|
errno = 0;
|
|
|
|
int n = strtol(s, &p, 10);
|
|
|
|
if (!errno && p != s && n >= 0) {
|
|
|
|
if (!parsing)
|
2004-10-24 11:12:05 +02:00
|
|
|
cCondWait::SleepMs(n);
|
2002-10-06 10:25:42 +02:00
|
|
|
return p;
|
|
|
|
}
|
2005-12-30 15:43:21 +01:00
|
|
|
esyslog("ERROR: invalid value for wait time in '%s'", s - 1);
|
2002-10-06 10:25:42 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *cDiseqc::Codes(char *s)
|
|
|
|
{
|
|
|
|
char *e = strchr(s, ']');
|
|
|
|
if (e) {
|
|
|
|
numCodes = 0;
|
|
|
|
char *t = s;
|
|
|
|
char *p = s;
|
|
|
|
while (t < e) {
|
|
|
|
if (numCodes < MaxDiseqcCodes) {
|
|
|
|
errno = 0;
|
|
|
|
int n = strtol(t, &p, 16);
|
|
|
|
if (!errno && p != t && 0 <= n && n <= 255) {
|
|
|
|
codes[numCodes++] = n;
|
|
|
|
t = skipspace(p);
|
|
|
|
}
|
|
|
|
else {
|
2005-12-30 15:43:21 +01:00
|
|
|
esyslog("ERROR: invalid code at '%s'", t);
|
2002-10-06 10:25:42 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
esyslog("ERROR: too many codes in code sequence '%s'", s - 1);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return e + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
esyslog("ERROR: missing closing ']' in code sequence '%s'", s - 1);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-12-08 09:55:26 +01:00
|
|
|
cDiseqc::eDiseqcActions cDiseqc::Execute(char **CurrentAction)
|
2002-10-06 10:25:42 +02:00
|
|
|
{
|
2002-12-08 09:55:26 +01:00
|
|
|
if (!*CurrentAction)
|
|
|
|
*CurrentAction = commands;
|
|
|
|
while (*CurrentAction && **CurrentAction) {
|
|
|
|
switch (*(*CurrentAction)++) {
|
2002-10-06 10:25:42 +02:00
|
|
|
case ' ': break;
|
|
|
|
case 't': return daToneOff;
|
|
|
|
case 'T': return daToneOn;
|
|
|
|
case 'v': return daVoltage13;
|
|
|
|
case 'V': return daVoltage18;
|
|
|
|
case 'A': return daMiniA;
|
|
|
|
case 'B': return daMiniB;
|
2002-12-08 09:55:26 +01:00
|
|
|
case 'W': *CurrentAction = Wait(*CurrentAction); break;
|
|
|
|
case '[': *CurrentAction = Codes(*CurrentAction); return *CurrentAction ? daCodes : daNone;
|
2002-10-06 10:25:42 +02:00
|
|
|
default: return daNone;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return daNone;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -- cDiseqcs ---------------------------------------------------------------
|
|
|
|
|
|
|
|
cDiseqcs Diseqcs;
|
|
|
|
|
|
|
|
cDiseqc *cDiseqcs::Get(int Source, int Frequency, char Polarization)
|
|
|
|
{
|
|
|
|
for (cDiseqc *p = First(); p; p = Next(p)) {
|
|
|
|
if (p->Source() == Source && p->Slof() > Frequency && p->Polarization() == toupper(Polarization))
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|