Ignore:
Timestamp:
Nov 19, 2012, 2:08:02 PM (12 years ago)
Author:
chronos
Message:
  • Přidáno: Základní čtení logů z přístupového terminálu.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/ChiyuAccessControlers/UTerminalBF630.pas

    r24 r25  
    8181    function ReadDateTime: TDateTime;
    8282    function GetUserCount: Integer; override;
    83     function GetUser(Id: Integer; User: TUser): Boolean; override;
     83    function GetUser(Index: Integer; User: TUser): Boolean; override;
     84    function GetPassageCount: Integer; override;
     85    function GetPassage(Index: Integer; Passage: TUserPassage): Boolean; override;
    8486    constructor Create; override;
    8587    destructor Destroy; override;
     
    106108  end;
    107109
     110  TVirtualTerminalBF630Passage = class
     111    Id: Integer;
     112    Time: TDateTime;
     113    User: Integer;
     114    Key: Integer;
     115  end;
     116
    108117  { TVirtualTerminalBF630 }
    109118
     
    116125    function CommandGetUserIDList(Request: TListByte; Response: TListByte): Byte;
    117126    function CommandGetUserData(Request: TListByte; Response: TListByte): Byte;
     127    function CommandLogGet(Request: TListByte; Response: TListByte): Byte;
     128    function CommandLogGetCount(Request: TListByte; Response: TListByte): Byte;
    118129    procedure SetActive(AValue: Boolean);
    119130    procedure NewConnection(Sender: TCommTCPServer; Pin: TCommPin);
     
    121132  public
    122133    Users: TListObject; // TListObject<TVirtualTerminalBF630User>
     134    Passages: TListObject; // TListObject<TVirtualTerminalBF630Passage>
    123135    Sessions: TListObject; // TListObject<TVirtualTerminalBF630Session>
    124136    AccessKey: array[0..5] of Byte;
     
    198210        else if Command = Byte(toGetDate) then ResultCode := CommandReadDate(Request, Response)
    199211        else if Command = Byte(toUserDataGet) then ResultCode := CommandGetUserData(Request, Response)
     212        else if Command = Byte(toLogGet) then ResultCode := CommandLogGet(Request, Response)
     213        else if Command = Byte(toLogGetCount) then ResultCode := CommandLogGetCount(Request, Response)
    200214        else ResultCode := ResultCodeUnknownCommand;
    201215
     
    314328end;
    315329
     330function TVirtualTerminalBF630.CommandLogGet(Request: TListByte;
     331  Response: TListByte): Byte;
     332var
     333  UserId: Integer;
     334  RequestSerializer: TBinarySerializer;
     335  ResponseSerializer: TBinarySerializer;
     336  I: Integer;
     337  Day, Month, Year: Word;
     338  MSec, Sec, Min, Hour: Word;
     339  FunctionKey: Integer;
     340begin
     341  try
     342    RequestSerializer := TBinarySerializer.Create;
     343    RequestSerializer.List := Request;
     344    //UserId := RequestSerializer.ReadInteger;
     345
     346    ResponseSerializer := TBinarySerializer.Create;
     347    ResponseSerializer.List := Response;
     348    DecodeDateTime(TVirtualTerminalBF630Passage(Passages[0]).Time,
     349      Year, Month, Day, Hour, Min, Sec, MSec);
     350    with ResponseSerializer do begin
     351      WriteByte(Sec);
     352      WriteByte(Min);
     353      WriteByte(Hour);
     354      WriteByte(Day);
     355      WriteByte(Month);
     356      WriteByte(Year mod 100);
     357      WriteByte(0);
     358      WriteByte(0);
     359      WriteByte(0);
     360      WriteByte(TVirtualTerminalBF630Passage(Passages[0]).Key);
     361      WriteInteger(TVirtualTerminalBF630Passage(Passages[0]).User);
     362      WriteByte(0);
     363      WriteByte(0);
     364    end;
     365  finally
     366    RequestSerializer.Free;
     367    ResponseSerializer.Free;
     368  end;
     369end;
     370
     371function TVirtualTerminalBF630.CommandLogGetCount(Request: TListByte;
     372  Response: TListByte): Byte;
     373var
     374  ResponseSerializer: TBinarySerializer;
     375begin
     376  try
     377    ResponseSerializer := TBinarySerializer.Create;
     378    ResponseSerializer.List := Response;
     379    ResponseSerializer.WriteInteger(Passages.Count);
     380    Result := ResultCodeSuccess;
     381  finally
     382    ResponseSerializer.Free;
     383  end;
     384end;
     385
    316386procedure TVirtualTerminalBF630.SetActive(AValue: Boolean);
    317387begin
     
    356426    SecondName := 'Second ' + IntToStr(Id);
    357427  end;
     428  with TVirtualTerminalBF630Passage(Passages.AddNew(TVirtualTerminalBF630Passage.Create)) do begin
     429    Id := Passages.Count;
     430    Time := Now;
     431    User := 1;
     432    Key := 2;
     433  end;
    358434end;
    359435
     
    362438  Sessions := TListObject.Create;
    363439  Users := TListObject.Create;
     440  Passages := TListObject.Create;
    364441  CommSocket := TCommTCPServer.Create(nil);
    365442  CommSocket.Address := 'localhost';
     
    374451  FreeAndNil(CommSocket);
    375452  FreeAndNil(Users);
     453  FreeAndNil(Passages);
    376454  FreeAndNil(Sessions);
    377455  inherited Destroy;
     
    550628end;
    551629
    552 function TTerminalBF630.GetUser(Id: Integer; User: TUser): Boolean;
     630function TTerminalBF630.GetUser(Index: Integer; User: TUser): Boolean;
    553631var
    554632  Request: TListByte;
     
    564642    RequestSerializer := TBinarySerializer.Create;
    565643    RequestSerializer.List := Request;
    566     RequestSerializer.WriteInteger(Id);
     644    RequestSerializer.WriteInteger(Index);
    567645    SendPacket(toUserDataGet, Request, Response);
    568646    if Response[0] <> Id then raise Exception.Create(SWrongId);
     
    581659
    582660  finally
     661    Request.Free;
     662    RequestSerializer.Free;
     663    Response.Free;
     664  end;
     665end;
     666
     667function TTerminalBF630.GetPassageCount: Integer;
     668var
     669  Response: TListByte;
     670  ResponseSerializer: TBinarySerializer;
     671begin
     672  try
     673    Response := TListByte.Create;
     674    ResponseSerializer := TBinarySerializer.Create;
     675    ResponseSerializer.List := Response;
     676    SendPacket(toLogGetCount, nil, Response);
     677    Result := ResponseSerializer.ReadInteger;
     678  finally
     679    Response.Free;
     680  end;
     681end;
     682
     683function TTerminalBF630.GetPassage(Index: Integer; Passage: TUserPassage): Boolean;
     684var
     685  Request: TListByte;
     686  RequestSerializer: TBinarySerializer;
     687  Response: TListByte;
     688  ResponseSerializer: TBinarySerializer;
     689  I: Integer;
     690  Title: Integer;
     691  Department: Integer;
     692  Sec, Min, Hour: Byte;
     693  Day, Month, Year: Byte;
     694  FunctionKey: BYte;
     695  Verify: Byte;
     696  UserId: Integer;
     697  InOutIndication: Byte;
     698  VerificationSource: Byte;
     699begin
     700  try
     701    Response := TListByte.Create;
     702    ResponseSerializer := TBinarySerializer.Create;
     703    ResponseSerializer.List := Response;
     704    Request := TListByte.Create;
     705    RequestSerializer := TBinarySerializer.Create;
     706    RequestSerializer.List := Request;
     707    //RequestSerializer.WriteInteger(Id);
     708    SendPacket(toLogGet, Request, Response);
     709    with ResponseSerializer do begin
     710      Sec := ReadByte;
     711      Min := ReadByte;
     712      Hour := ReadByte;
     713      Day := ReadByte;
     714      Month := ReadByte;
     715      Year := ReadByte;
     716      InOutIndication := ReadByte;
     717      VerificationSource := ReadByte;
     718      Verify := ReadByte;
     719      FunctionKey := ReadByte;
     720      UserId := ReadInteger;
     721    end;
     722
     723    Passage.Terminal := Id;
     724    Passage.Time := EncodeDateTime(2000 + Year, Month, Day, Hour, Min, Sec, 0);
     725    Passage.Operation := FunctionKey;
     726    Passage.User := UserId;
     727  finally
     728    ResponseSerializer.Free;
    583729    Request.Free;
    584730    RequestSerializer.Free;
Note: See TracChangeset for help on using the changeset viewer.