/*
 * diseqc.h: DiSEqC handling
 *
 * See the main source file 'vdr.c' for copyright information and
 * how to reach the author.
 *
 * $Id: diseqc.h 1.2 2002/12/07 13:54:02 kls Exp $
 */

#ifndef __DISEQC_H
#define __DISEQC_H

#define  SINGLE 0
#define  MINI  1
#define  COMB  2
#define  OPTIM 3

#define DISEQCMOD_NONE 0
#define DISEQCMOD_FILE 1
#define DISEQCMOD_USER 2

#define DISEQCSMOD_NONE 0

#define MINLNBS 1
#define MAXLNBS 4

#include "config.h"


class cDiseqc : public cListObject {
friend class cMenuSetupLNB;
public:
  enum eDiseqcActions {
    daNone,
    daToneOff,
    daToneOn,
    daVoltage13,
    daVoltage18,
    daMiniA,
    daMiniB,
    daCodes,
  };
  enum { MaxDiseqcCodes = 6 };
private:
  static cString ToText(const cDiseqc *Diseqc);
  enum ID {A=65, B, C, D, E, F, G, H} lnbID;
  int line;
  int type;
  char *satName;
  int source;
  char polarization;
  int slof;
  int lof;
  char *commands;
  bool parsing;
  cString ToText(const cDiseqc diseqc);
  uchar codes[MaxDiseqcCodes];
  int numCodes;
  char *Wait(char *s);
  char *Codes(char *s);
  int repeat;
public:
  cDiseqc(void);
  cDiseqc(const cDiseqc &diseqc);
  ~cDiseqc();
  cDiseqc &operator=(const cDiseqc &diseqc);
  cString ToText(void);
  bool Save(FILE *f);
  bool Parse(const char *s);
  eDiseqcActions Execute(char **CurrentAction);
      // Parses the DiSEqC commands and returns the appropriate action code
      // with every call. CurrentAction must be the address of a character pointer,
      // which is initialized to NULL. This pointer is used internally while parsing
      // the commands and shall not be modified once Execute() has been called with
      // it. Call Execute() repeatedly (always providing the same CurrentAction pointer)
      // until it returns daNone. After a successful execution of all commands
      // *CurrentAction points to the value 0x00.
  char *SatName(void) const { return satName; }
  int NumCodes(void) const { return numCodes; }
  int Line(void) const { return line; };
  int Type(void) const { return type;   };
  int LnbID(void) const { return lnbID; }
  int Source(void) const { return source; }
  int Slof(void) const { return slof; }
  char Polarization(void) const { return polarization; }
  int Lof(void) const { return lof; }
  const char *Commands(void) const { return commands; }

  uchar *Codes(int &NumCodes) { NumCodes = numCodes; return numCodes ? codes : NULL; }
  void SetID(int lnbID);
  void SetLine(int Line)  { line = Line; };
  void SetCommands(int type, char *satName, int p, int id, int line);
  void NewDiseqc(const char *satName, int *source, int type, int pol, int id, int line);
  };


// --- cDiseqcs -----------------------------------------------
class cDiseqcs : public cConfig<cDiseqc> {

  int lines; // total numbers of lines
  int modified;
  int waitMs;
  int repeatCmd;

  int lofTbl[2][2];

public:

  bool Load(const char *FileName, bool AllowComments = false, bool MustExist = false);
  void ReNumber(void);
  cDiseqc *Get(int Source, int Frequency, char Polarization);
  cDiseqc *Get(const char *satName);
  cDiseqc *Get(int line);
  cDiseqc *Get(void);
  int WaitMs(void) { return waitMs; }
  void SetWaitMs(int ms) { waitMs = ms; }
  int RepeatCmd(void) { return repeatCmd; }
  void SetRepeatCmd(int rep) { repeatCmd = rep; }
  int Modified(void);
  void SetModified(bool);
  bool IsUnique(int *src, int lnbs);
  bool cDiseqcs::ConfigLocked(void);
  void SetOszilatorFrequenzies(int LofStat);
  int OszilatorFrequenzies(void);
  };

extern cDiseqcs Diseqcs;

#endif //__DISEQC_H
