(*
*******************************************************************************
*         Copyright (C) SofCon 2002 All Rights Reserved                       *
*******************************************************************************
*
*    project:     priklad generatoru online parametru
*
*    title:       xCrExam2.pas
*
*******************************************************************************
*
*    description: popis online parametru
*                 - slouzi pri generaci CSV souboru a je sdilen s aplikaci
*
*    version:     1.02
*    language:    Borland Pascal
*
*    author:      Hvozdovic
*    history:     date      sign   remark
*                 9.02      bi     zacatek vyvoje
*                11.02      hv     prvni release
*                03.03      bi     doplnena velikost param. LA_FirmwareAppVer do tab.
*****************************************************************************
*)
{$I sets.inc}

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

const
  cName = 'xCrExam2';           { jmeno jednotky }
  cVer  = 'v1.02, 27.03.2003';  { 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_Byte1            =BaseLA_Firmware+ 2; NA_Byte1      ='Byte1';
                                         Le_Byte1      = LeUser1;
                                         Im_Byte1      =  1;
                                         Lo_Byte1      =  0;
                                         Hi_Byte1      =255;

LA_Byte2            =BaseLA_Firmware+ 3; NA_Byte2      ='Byte2';
                                         Le_Byte2      = LeUser1;
                                         Im_Byte2      =  1;
                                         Lo_Byte2      =$00;
                                         Hi_Byte2      =$FF;

LA_Byte3            =BaseLA_Firmware+ 4; NA_Byte3      ='Byte3';
                                         Le_Byte3      = LeUser1;
                                         Im_Byte3      =  1;
                                         Lo_Byte3      =  0;
                                         Hi_Byte3      =255;


{ 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);
  FillChar(PutParSizeTab^,SizeOf(PutParSizeTab^),0);
  {--------------------------------------------------------}
  { Naplneni tabulky delkou datovych typu OnLine parametru }
  {--------------------------------------------------------}
  PutParSizeTab^[LA_FirmwareAppVer ]:=SizeOf(tAppVerStr  );
  PutParSizeTab^[LA_RstStruct      ]:=SizeOf(tRstStruct  );
  PutParSizeTab^[LA_VersionGlb_Ver ]:=SizeOf(TReal       );
  PutParSizeTab^[LA_Byte1]          :=sizeOf(Byte        );
  PutParSizeTab^[LA_Byte2]          :=sizeOf(Byte        );
  PutParSizeTab^[LA_Byte3]          :=sizeOf(Byte        );
end;

Begin
  InitXTKing_LA;
End.
