Home

Dokumentation

Impressum

Dokumentation VDR
 

Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

diseqc.c

Go to the documentation of this file.
00001 /*
00002  * diseqc.c: DiSEqC handling
00003  *
00004  * See the main source file 'vdr.c' for copyright information and
00005  * how to reach the author.
00006  *
00007  * $Id: diseqc.c 1.2 2002/12/07 13:44:56 kls Exp $
00008  */
00009 
00010 #include "diseqc.h"
00011 #include <ctype.h>
00012 #include "sources.h"
00013 
00014 // -- cDiseqc ----------------------------------------------------------------
00015 
00016 cDiseqc::cDiseqc(void)
00017 {
00018   commands = NULL;
00019   parsing = false;
00020   numCodes = 0;
00021 }
00022 
00023 cDiseqc::~cDiseqc()
00024 {
00025   free(commands);
00026 }
00027 
00028 bool cDiseqc::Parse(const char *s)
00029 {
00030   bool result = false;
00031   char *sourcebuf = NULL;
00032   int fields = sscanf(s, "%a[^ ] %d %c %d %a[^\n]", &sourcebuf, &slof, &polarization, &lof, &commands);
00033   if (fields == 4)
00034      commands = NULL; //XXX Apparently sscanf() doesn't work correctly if the last %a argument results in an empty string
00035   if (4 <= fields && fields <= 5) {
00036      source = cSource::FromString(sourcebuf);
00037      if (Sources.Get(source)) {
00038         polarization = toupper(polarization);
00039         if (polarization == 'V' || polarization == 'H') {
00040            parsing = true;
00041            char *CurrentAction = NULL;
00042            while (Execute(&CurrentAction) != daNone)
00043                  ;
00044            parsing = false;
00045            result = !commands || !*CurrentAction;
00046            }
00047         else
00048            esyslog("ERROR: unknown polarization '%c'", polarization);
00049         }
00050      else
00051         esyslog("ERROR: unknown source '%s'", sourcebuf);
00052      }
00053   free(sourcebuf);
00054   return result;
00055 }
00056 
00057 char *cDiseqc::Wait(char *s)
00058 {
00059   char *p = NULL;
00060   errno = 0;
00061   int n = strtol(s, &p, 10);
00062   if (!errno && p != s && n >= 0) {
00063      if (!parsing)
00064         usleep(n * 1000);
00065      return p;
00066      }
00067   esyslog("ERROR: illegal value for wait time in '%s'", s - 1);
00068   return NULL;
00069 }
00070 
00071 char *cDiseqc::Codes(char *s)
00072 {
00073   char *e = strchr(s, ']');
00074   if (e) {
00075      numCodes = 0;
00076      char *t = s;
00077      char *p = s;
00078      while (t < e) {
00079            if (numCodes < MaxDiseqcCodes) {
00080               errno = 0;
00081               int n = strtol(t, &p, 16);
00082               if (!errno && p != t && 0 <= n && n <= 255) {
00083                  codes[numCodes++] = n;
00084                  t = skipspace(p);
00085                  }
00086               else {
00087                  esyslog("ERROR: illegal code at '%s'", t);
00088                  return NULL;
00089                  }
00090               }
00091            else {
00092               esyslog("ERROR: too many codes in code sequence '%s'", s - 1);
00093               return NULL;
00094               }
00095            }
00096      return e + 1;
00097      }
00098   else
00099      esyslog("ERROR: missing closing ']' in code sequence '%s'", s - 1);
00100   return NULL;
00101 }
00102 
00103 cDiseqc::eDiseqcActions cDiseqc::Execute(char **CurrentAction)
00104 {
00105   if (!*CurrentAction)
00106      *CurrentAction = commands;
00107   while (*CurrentAction && **CurrentAction) {
00108         switch (*(*CurrentAction)++) {
00109           case ' ': break;
00110           case 't': return daToneOff;
00111           case 'T': return daToneOn;
00112           case 'v': return daVoltage13;
00113           case 'V': return daVoltage18;
00114           case 'A': return daMiniA;
00115           case 'B': return daMiniB;
00116           case 'W': *CurrentAction = Wait(*CurrentAction); break;
00117           case '[': *CurrentAction = Codes(*CurrentAction); return *CurrentAction ? daCodes : daNone;
00118           default: return daNone;
00119           }
00120         }
00121   return daNone;
00122 }
00123 
00124 // -- cDiseqcs ---------------------------------------------------------------
00125 
00126 cDiseqcs Diseqcs;
00127 
00128 cDiseqc *cDiseqcs::Get(int Source, int Frequency, char Polarization)
00129 {
00130   for (cDiseqc *p = First(); p; p = Next(p)) {
00131       if (p->Source() == Source && p->Slof() > Frequency && p->Polarization() == toupper(Polarization))
00132         return p;
00133       }
00134   return NULL;
00135 }

Generated on Wed Feb 5 23:30:08 2003 for VDR by doxygen1.3-rc2