{****************************************************************************}
{ Generator a monitor signalu                                                }
{                                                                            }
{ uEcpGen.pas                                                                }
{                                                                            }
{ Spolecne deklarace prekladace a generatoru pro potreby komunikace          }
{                                                                            }
{ SofCon s.r.o.,  Petr Cernin, 2002                                          }
{****************************************************************************}

unit uEcpGen;

interface

{$IFDEF DELPHI32}
  {$MINENUMSIZE 1}
  {$ALIGN 2}
{$ELSE}
  {$A+}
{$ENDIF}

uses
  uEcpDef,
  uGenIntf;

type

{$IFDEF DELPHI32}
  TInteger = SmallInt;
  TReal    = Real48;
{$ELSE}
  TInteger = Integer;
  TReal    = Real;
{$ENDIF}


{ Komunikace protokolem UDP }

const { Identifikatory komunikujicich procesu }

  ECP_PROC_GENERATOR = $8000;

const { Identifikatory zprav }

  ECPGEN_CMD_RESETKIT   = $20;  { Reset komunikacniho automatu            }
  ECPGEN_CMD_SET_ADDR   = $21;
  ECPGEN_CMD_GET_ADDR   = $22;

  ECPGEN_CMD_STATE      = $30;
  ECPGEN_CMD_START      = $31;  { Spusteni generatoru/monitoru/citace     }
  ECPGEN_CMD_STOP       = $32;  { Zastaveni generatoru/monitoru/citace    }
  ECPGEN_CMD_START_ALL  = $33;
  ECPGEN_CMD_STOP_ALL   = $34;
  ECPGEN_CMD_RESET      = $35;  { Reset bloku generatoru/monitoru/citace  }

  ECPGEN_CMD_LOCK       = $40;
  ECPGEN_CMD_UNLOCK     = $41;
  ECPGEN_CMD_DELETE     = $42;  { Smazani generatoru/monitoru             }
  ECPGEN_CMD_DELETE_ALL = $43;  { Smazani vsech generatoru/monitoru       }
  ECPGEN_CMD_WRITE_DESC = $44;  { Zapis deskriptoru generatoru/monitoru   }
  ECPGEN_CMD_READ_DESC  = $45;  { Cteni deskriptoru generatoru/monitoru   }
  ECPGEN_CMD_WRITE_DATA = $46;  { Zapis zaznamu monitoru                  }
  ECPGEN_CMD_READ_DATA  = $47;  { Cteni zaznamu monitoru/generatoru       }
  ECPGEN_CMD_READ_OPT   = $48;  { Cteni nastaveni kitu                    }
  ECPGEN_CMD_WRITE_OPT  = $49;  { Zapis nastaveni kitu                    }


const { Chybove kody }

  ECPGEN_ERR_IndexOutOfRange = 32; { Index mimo rozsah  }
  ECPGEN_ERR_BlockIsLocked   = 33; { Pozadovany blok je jiz zamceny }
  ECPGEN_ERR_LockFailed      = 34; { Zamknuti selhalo }
  ECPGEN_ERR_NoMemory        = 35; {nedostatek pameti}
  ECPGEN_ERR_GeneralError    = 36; {obecna chyba}
  ECPGEN_ERR_Invalid         = 37; {blok je invalid}
  ECPGEN_ERR_Unknown         = 38; {nedefikovana chyba}
  ECPGEN_ERR_UnknownBlock    = 39; {neznamy blok}
  ECPGEN_ERR_NotSupported    = 40; {funkce nepodporovana}
  ECPGEN_ERR_TimeOutOfRng    = 41; {timer mimo rozsah}

type
  { _RS ... RESPONSE, _RQ ... REQUEST }

  TECPGEN_DIGGEN_STATE  = array[0..cMaxDigGen - 1] of TBlockState;
  TECPGEN_DIGMON_STATE  = array[0..cMaxDigMon - 1] of TBlockState;
  TECPGEN_ANAGEN_STATE  = array[0..cMaxAnaGen - 1] of TBlockState;
  TECPGEN_ANAMON_STATE  = array[0..cMaxAnaMon - 1] of TBlockState;
  TECPGEN_COUNTER_STATE = array[0..cMaxCounter - 1] of TBlockState;

  TECPGEN_STATE_RS = packed
  record
    CpuLoad : TInteger;
    DigGen  : TECPGEN_DIGGEN_STATE;
    DigMon  : TECPGEN_DIGMON_STATE;
    AnaGen  : TECPGEN_ANAGEN_STATE;
    AnaMon  : TECPGEN_ANAMON_STATE;
    Counter : TECPGEN_COUNTER_STATE;
  end;


  TECPGEN_START_RQ = packed
  record
    Id : TBlockId;   { Identifikator bloku }
  end;

  TECPGEN_STOP_RQ = packed
  record
    Id : TBlockId;   { Identifikator bloku }
  end;

  TECPGEN_LOCK_RQ = packed
  record
    Id : TBlockId;
  end;

  TECPGEN_UNLOCK_RQ = packed
  record
    Id : TBlockId;
  end;

  { Odstraneni generatoru/monitoru z pameti }

  TECPGEN_DELETE_RQ = packed
  record
    Id : TBlockId;
  end;

  { Reset generatoru/monitoru/citace }

  TECPGEN_RESET_RQ = packed
  record
    Id : TBlockId;
  end;

  { Zapis deskriptoru
    Deskriptor lze zapisovat pouze na volnou pozici }

  TECPGEN_WRITE_DESC_RQ = packed
  record
    Id       : TBlockId;
    Descr    : TBlockDescriptor;
    DataSize : Word;
  end;

  { Cteni deskriptoru (zadost) }

  TECPGEN_READ_DESC_RQ = packed
  record
    Id : TBlockId;
  end;

  { Cteni deskriptoru (odpoved) }

  TECPGEN_READ_DESC_RS = packed
  record
    Id       : TBlockId;
    Descr    : TBlockDescriptor;        { Deskriptor }
    DataSize : Word;                    { Delka dat (ktere je nasledne mozne precist) }
    AbsTime  : Longint;                 { Absolutni cas startu monitoru }
                                        {  !@# ...kam to dat????? tady je to dost blbe }
  end;

  TECPGEN_RW_CONTROL = packed
  record
    Id     : TBlockId;
    Offset : Word;
    Size   : Word;
  end;

  { Zapis dat
    Data lze zapisovat do generatoru, ktery byl prave vytvoren
    zpravou WRITE_DESC_RQ
    Po odeslani vsech dat je generator aktivovan }

const

  ECPGEN_MSG_DATA_SIZE = 1024;

type

  TECPGen_WRITE_DATA_RQ = packed
  record
    Ctrl   : TECPGEN_RW_CONTROL;
    Data   : array[0..ECPGEN_MSG_DATA_SIZE - 1] of Byte;
  end;

  { Cteni dat
    Data lze cist pouze z existujiciho generatoru/monitoru
    Pri cteni dat z monitoru je monitor zastaven, po
    ukonceni cteni je potreba poslat zpravu START_RQ }

  TECPGEN_READ_DATA_RQ = packed
  record
    Ctrl   : TECPGEN_RW_CONTROL;
  end;

  TECPGEN_READ_DATA_RS = packed
  record
    Ctrl   : TECPGEN_RW_CONTROL;
    Data   : array[0..ECPGEN_MSG_DATA_SIZE - 1] of Byte;
  end;

  TECPGEN_SET_ADDR_RQ = packed
  record
    IpAddr   : Longint;
    NetMask  : Longint;
    Port     : Word;
  end;

  TECPGEN_GET_ADDR_RS = TECPGEN_SET_ADDR_RQ;

  TECPGEN_WRITE_OPT_RQ = packed
  record
    Options : TKitOptions;
  end;

  TECPGEN_READ_OPT_RS = TECPGEN_WRITE_OPT_RQ;


type

  PECPGenData = ^TECPGenData;
  TECPGenData = record
    case Integer of
  { Standardni datove struktury }
      0: ( ERROR_RS        : TECP_ERROR_RS );
      1: ( PROC_ID_RS      : TECP_PROC_ID_RS );
      2: ( PROC_VER_RS     : TECP_PROC_VER_RS );
  { Nove datove struktury }
      3: ( STATE_RS        : TECPGEN_STATE_RS );
      4: ( START_RQ        : TECPGEN_START_RQ );
      5: ( STOP_RQ         : TECPGEN_STOP_RQ );
      6: ( DELETE_RQ       : TECPGEN_DELETE_RQ );
      7: ( RESET_RQ        : TECPGEN_RESET_RQ );
      8: ( WRITE_DESC_RQ   : TECPGEN_WRITE_DESC_RQ );
      9: ( READ_DESC_RQ    : TECPGEN_READ_DESC_RQ );
     10: ( READ_DESC_RS    : TECPGEN_READ_DESC_RS );
     11: ( WRITE_DATA_RQ   : TECPGEN_WRITE_DATA_RQ );
     12: ( READ_DATA_RQ    : TECPGEN_READ_DATA_RQ );
     13: ( READ_DATA_RS    : TECPGEN_READ_DATA_RS );
     14: ( LOCK_RQ         : TECPGEN_LOCK_RQ );
     15: ( UNLOCK_RQ       : TECPGEN_UNLOCK_RQ );
     16: ( SET_ADDR_RQ     : TECPGEN_SET_ADDR_RQ );
     17: ( GET_ADDR_RS     : TECPGEN_GET_ADDR_RS );
     18: ( WRITE_OPT_RQ    : TECPGEN_WRITE_OPT_RQ );
     19: ( READ_OPT_RS     : TECPGEN_READ_OPT_RS );
  end;


implementation

end.
