(*
*******************************************************************************
*         Copyright (C) SofCon 2002 All Rights Reserved                       *
*******************************************************************************
*
*    project:     priklad generatoru online parametru
*
*    title:       xAppVzor.pas
*
*******************************************************************************
*
*    description: popis online parametru
*                 - slouzi pri generaci CSV souboru a je sdilen s aplikaci
*
*    version:     1.01
*    language:    Borland Pascal
*
*    author:      Hvozdovic
*    history:     date      sign   remark
*                10.02      hv     zacatek vyvoje
*                11.02      hv     prvni release
*****************************************************************************
*)
{$I sets.inc}

unit xAppVzor;
interface

uses
  XTKing_1  { Zakladni typy invariantni vuci verzi firmware ridiciho systemu }
  ;

const
  cName = 'xApp';               { jmeno jednotky }
  cVer  = 'v1.01, 8.11.2002';   { verze jednotky }

const
(*
    ===============================================================
    Tato jednotka je pro konkretni verzi firmware ridiciho systemu!
    ===============================================================

    Jednotka obsahuje nezbytne nutne spolecne typy a konstanty pro aplikaci TheKing

    - deklarace typu parametru pouzitych v konkretni verzi firmware ridiciho systemu
    - deklarace logickych adres komunikovanych parametru LA_xxx

*)
(* ===============================================================================
    Parametry s LA_XXXX < BaseLA_Firmware jsou povinne pro vsechny verze firmware
    a nesmi se v dalsich verzich menit !!!
   ===============================================================================
 vyznam jednotlivych konstant:
    LA_Xxx - jedinecny kod parametru pro komunikace
    Le_Xxx - uroven pristupu k parametru
    Im_Xxx - implicitni hodnota parametru pri nacteni z receptury
    Lo_Xxx - spodni mez hodnoty parametru
    Hi_Xxx - horni mez hodnoty parametru
    k nekterym parametrum existuji i implicitni hodnoty Im_Xxx, ty vsak z duvodu
    moznosti ruznych hodnot pro ruzne verze aplikace jsou u sebe v extra sekci CONST
*)
{=== Parametry ridiciho systemu ve vsech verzich firmware - LA_xxx ========================}

{=== Parametry ridiciho systemu v dane verzi firmware - LA_xxx ============================}
LA_VersionGlb_Ver   =BaseLA_Firmware+ 1; NA_VersionGlb_Ver ='VersionGlb_Ver';
                                         Le_VersionGlb_Ver = LeReadOnly;
                                         Im_VersionGlb_Ver =    0;
                                         Lo_VersionGlb_Ver = 0.00;
                                         Hi_VersionGlb_Ver =99.99;
                                         Dm_VersionGlb_Ver =    2;

LA_DemoByte1        =BaseLA_Firmware+ 2; NA_DemoByte1      ='DemoByte1';
                                         Le_DemoByte1      = LeUser1;
                                         Im_DemoByte1      =  1;
                                         Lo_DemoByte1      =  1;
                                         Hi_DemoByte1      =255;

LA_DemoByte2        =BaseLA_Firmware+ 3; NA_DemoByte2      ='DemoByte2';
                                         Le_DemoByte2      = LeUser1;
                                         Im_DemoByte2      =$01;
                                         Lo_DemoByte2      =$01;
                                         Hi_DemoByte2      =$F0;

LA_DemoEnum1        =BaseLA_Firmware+ 4; NA_DemoEnum1      ='DemoEnum1';
                                         Le_DemoEnum1      = LeUser1;
                                         Im_DemoEnum1      =  1;
                                         Lo_DemoEnum1      =  0;
                                         Hi_DemoEnum1      =255;

LA_DemoEnum2        =BaseLA_Firmware+ 5; NA_DemoEnum2      ='DemoEnum2';
                                         Le_DemoEnum2      = LeUser1;
                                         Im_DemoEnum2      =  1;
                                         Lo_DemoEnum2      =  0;
                                         Hi_DemoEnum2      =255;

LA_DemoWord1        =BaseLA_Firmware+ 6; NA_DemoWord1      ='DemoWord1';
                                         Le_DemoWord1      = LeUser1;
                                         Im_DemoWord1      =    1;
                                         Lo_DemoWord1      =    1;
                                         Hi_DemoWord1      =$FFF0;

LA_DemoSmallInt1    =BaseLA_Firmware+ 7; NA_DemoSmallInt1  ='DemoSmallInt1';
                                         Le_DemoSmallInt1  = LeUser1;
                                         Im_DemoSmallInt1  =   -1;
                                         Lo_DemoSmallInt1  =-27000;
                                         Hi_DemoSmallInt1  =+27000;

LA_DemoInteger1     =BaseLA_Firmware+ 8; NA_DemoInteger1   ='DemoInteger1';
                                         Le_DemoInteger1   = LeUser1;
                                         Im_DemoInteger1   =   -1;
                                         Lo_DemoInteger1   =-6700;
                                         Hi_DemoInteger1   =+6700;

LA_DemoLongint1     =BaseLA_Firmware+ 9; NA_DemoLongint1   ='DemoLongint1';
                                         Le_DemoLongint1   = LeUser1;
                                         Im_DemoLongint1   =   -1;
                                         Lo_DemoLongint1   =-67000;
                                         Hi_DemoLongint1   =+67000;

LA_DemoLongword1    =BaseLA_Firmware+10; NA_DemoLongword1  ='DemoLongword1';
                                         Le_DemoLongword1  = LeUser1;
                                         Im_DemoLongword1  =        0;
                                         Lo_DemoLongword1  =$00000001;
                                         Hi_DemoLongword1  =$FFFFFFF0;

LA_DemoRealp1       =BaseLA_Firmware+11; NA_DemoRealp1     ='DemoRealp1';
                                         Le_DemoRealp1     = LeUser1;
                                         Im_DemoRealp1     =   -1.5;
                                         Lo_DemoRealp1     =-1.5e10;
                                         Hi_DemoRealp1     =+1.5e10;
                                         Dm_DemoRealp1     = 1;

LA_DemoRealp2       =BaseLA_Firmware+12; NA_DemoRealp2     ='DemoRealp2';
                                         Le_DemoRealp2     = LeUser1;
                                         Im_DemoRealp2     =   -1.5;
                                         Lo_DemoRealp2     =-1.5e10;
                                         Hi_DemoRealp2     =+1.5e10;
                                         Dm_DemoRealp2     = 1;

LA_DemoRealp3       =BaseLA_Firmware+13; NA_DemoRealp3     ='DemoRealp3';
                                         Le_DemoRealp3     = LeUser1;
                                         Im_DemoRealp3     =   -1.5;
                                         Lo_DemoRealp3     =-1.5e10;
                                         Hi_DemoRealp3     =+1.5e10;
                                         Dm_DemoRealp3     = 1;

LA_DemoString1      =BaseLA_Firmware+14; NA_DemoString1    ='DemoString1';
                                         Le_DemoString1    = LeUser1;
                                         Im_DemoString1    = 's1';

LA_DemoSpecWord1    =BaseLA_Firmware+15; NA_DemoSpecWord1  ='DemoSpecWord1';
                                         Le_DemoSpecWord1  = LeUser1;
                                         Im_DemoSpecWord1  =    1;
                                         Lo_DemoSpecWord1  =    1;
                                         Hi_DemoSpecWord1  =$FFF0;

LA_DemoSpecWord2    =BaseLA_Firmware+16; NA_DemoSpecWord2  ='DemoSpecWord2';
                                         Le_DemoSpecWord2  = LeUser1;
                                         Im_DemoSpecWord2  =    1;
                                         Lo_DemoSpecWord2  =    1;
                                         Hi_DemoSpecWord2  =$FFF0;


LA_CFTemperature1   =BaseLA_Firmware+20; NA_CFTemperature1 ='CFTemperature1';
                                         Le_CFTemperature1 = LeUser2;
                                         Im_CFTemperature1 = 20;
                                         Lo_CFTemperature1 =-22;
                                         Hi_CFTemperature1 =+80;

LA_CFTemperature2   =BaseLA_Firmware+21; NA_CFTemperature2 ='CFTemperature2';
                                         Le_CFTemperature2 = LeUser2;
                                         Im_CFTemperature2 =   0;
                                         Lo_CFTemperature2 = -10;
                                         Hi_CFTemperature2 =+100;


{ vypocet rozmeru datove struktury parametru v programu TKingCon }
Max_LA_Online  =BaseLA_Firmware+700;{!Bu-zatim}


{=======================================================================================}
function GetOnLineParSize     (ALA:word)    :word;
function GetSizeGetParamVal   (pRec:pointer):Word; { vrati velikost hlavicky (LA) zpravy pro cteni parametru }
function GetSizePutParamVal   (pRec:pointer):Word; { vrati velikost hlavicky (LA) zpravy pro zapis parametru }
function GetSizePutParamValBlk(pRec:pointer):Word; { vrati velikost hlavicky (LA) zpravy pro zapis bloku parametru }
function GetSizeGetParamValBlk(pRec:pointer):Word; { vrati velikost hlavicky (LA) zpravy pro cteni bloku parametru }

{#######################################################################################}
implementation

type
  { typ tabulky pro ziskani delky OnLine parametru z jeho logicke adresy LA_xxxx }
  tPutParSizeTab=array[0..Max_LA_Online] of Word;

const
  { Dynamicky alokovana tabulka v maximalni mozne delce }
  PutParSizeTab:^tPutParSizeTab = nil;

{---------------------}
function GetOnLineParSize(ALA:word):word;
begin
  if (ALA<=Max_LA_Online) and Assigned(PutParSizeTab)
  then GetOnLineParSize:=PutParSizeTab^[ALA]
  else GetOnLineParSize:=0;
end;

{---------------------}
function GetSizePutParamVal(pRec:pointer):Word;
var Len:Word;
begin
  with tgcmd_ParamValue(pRec^) do
  begin
    Len:=SizeOf(LA);
    if LA<=Max_LA_Online then Len:=Len+PutParSizeTab^[LA];
  end;
  GetSizePutParamVal:=Len;
end;

{---------------------}
function GetSizeGetParamVal(pRec:pointer):Word;
var Len:Word;
begin
  with Tgcmd_GetParamVal(pRec^) do
  begin
    Len:=SizeOf(LA);
  end;
  GetSizeGetParamVal:=Len;
end;

{---------------------}
function GetSizePutParamValBlk(pRec:pointer):Word;
var Len:Word;
    I  :word;
begin
  with tgcmd_ParamValueBlk(pRec^) do
  begin
    Len:=SizeOf(LACnt)+LACnt*SizeOf(LAArr[0]);
    for I:=0 to LACnt-1 do
    begin
      if LAArr[I]<=Max_LA_Online then Len:=Len+PutParSizeTab^[LAArr[I]];
    end;
  end;
  GetSizePutParamValBlk:=Len;
end;

{---------------------}
function GetSizeGetParamValBlk(pRec:pointer):Word;
var Len:Word;
begin
  with Tgcmd_GetParamValBlk(pRec^) do
  begin
    Len:=SizeOf(LACnt)+LACnt*SizeOf(LAArr[0]);
  end;
  GetSizeGetParamValBlk:=Len;
end;

{=======================================================================================}
const
  SaveExit:Pointer=nil;

procedure ExitXTKing_LA;far;
begin
  if SaveExit<>nil then
  begin
    ExitProc:=SaveExit;
    if PutParSizeTab<>nil then Dispose(PutParSizeTab);
    PutParSizeTab:=nil;
  end;
end;

{---------------------}
procedure InitXTKing_LA;
begin
  SaveExit:=ExitProc;
  ExitProc:=@ExitXTKing_LA;
  New(PutParSizeTab);
  if PutParSizeTab=nil then RunError(255);
  FillChar(PutParSizeTab^,SizeOf(PutParSizeTab^),0);
  {--------------------------------------------------------}
  { Naplneni tabulky delkou datovych typu OnLine parametru }
  {--------------------------------------------------------}
  PutParSizeTab^[LA_RstStruct      ]:=SizeOf(tRstStruct  );
  PutParSizeTab^[LA_VersionGlb_Ver ]:=SizeOf(TReal       );
  PutParSizeTab^[LA_DemoByte1]      :=sizeOf(Byte        );
  PutParSizeTab^[LA_DemoByte2]      :=sizeOf(Byte        );
  PutParSizeTab^[LA_DemoWord1]      :=sizeOf(Word        );
  PutParSizeTab^[LA_DemoSmallInt1]  :=sizeOf(Word        );
  PutParSizeTab^[LA_DemoLongInt1]   :=sizeOf(LongInt     );
  PutParSizeTab^[LA_DemoRealp1]     :=sizeOf(Real        );
end;

Begin
  InitXTKing_LA;
End.
