Changeset 25 for trunk/Modules/ChiyuAccessControlers
- Timestamp:
- Nov 19, 2012, 2:08:02 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/ChiyuAccessControlers/UTerminalBF630.pas
r24 r25 81 81 function ReadDateTime: TDateTime; 82 82 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; 84 86 constructor Create; override; 85 87 destructor Destroy; override; … … 106 108 end; 107 109 110 TVirtualTerminalBF630Passage = class 111 Id: Integer; 112 Time: TDateTime; 113 User: Integer; 114 Key: Integer; 115 end; 116 108 117 { TVirtualTerminalBF630 } 109 118 … … 116 125 function CommandGetUserIDList(Request: TListByte; Response: TListByte): Byte; 117 126 function CommandGetUserData(Request: TListByte; Response: TListByte): Byte; 127 function CommandLogGet(Request: TListByte; Response: TListByte): Byte; 128 function CommandLogGetCount(Request: TListByte; Response: TListByte): Byte; 118 129 procedure SetActive(AValue: Boolean); 119 130 procedure NewConnection(Sender: TCommTCPServer; Pin: TCommPin); … … 121 132 public 122 133 Users: TListObject; // TListObject<TVirtualTerminalBF630User> 134 Passages: TListObject; // TListObject<TVirtualTerminalBF630Passage> 123 135 Sessions: TListObject; // TListObject<TVirtualTerminalBF630Session> 124 136 AccessKey: array[0..5] of Byte; … … 198 210 else if Command = Byte(toGetDate) then ResultCode := CommandReadDate(Request, Response) 199 211 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) 200 214 else ResultCode := ResultCodeUnknownCommand; 201 215 … … 314 328 end; 315 329 330 function TVirtualTerminalBF630.CommandLogGet(Request: TListByte; 331 Response: TListByte): Byte; 332 var 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; 340 begin 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; 369 end; 370 371 function TVirtualTerminalBF630.CommandLogGetCount(Request: TListByte; 372 Response: TListByte): Byte; 373 var 374 ResponseSerializer: TBinarySerializer; 375 begin 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; 384 end; 385 316 386 procedure TVirtualTerminalBF630.SetActive(AValue: Boolean); 317 387 begin … … 356 426 SecondName := 'Second ' + IntToStr(Id); 357 427 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; 358 434 end; 359 435 … … 362 438 Sessions := TListObject.Create; 363 439 Users := TListObject.Create; 440 Passages := TListObject.Create; 364 441 CommSocket := TCommTCPServer.Create(nil); 365 442 CommSocket.Address := 'localhost'; … … 374 451 FreeAndNil(CommSocket); 375 452 FreeAndNil(Users); 453 FreeAndNil(Passages); 376 454 FreeAndNil(Sessions); 377 455 inherited Destroy; … … 550 628 end; 551 629 552 function TTerminalBF630.GetUser(I d: Integer; User: TUser): Boolean;630 function TTerminalBF630.GetUser(Index: Integer; User: TUser): Boolean; 553 631 var 554 632 Request: TListByte; … … 564 642 RequestSerializer := TBinarySerializer.Create; 565 643 RequestSerializer.List := Request; 566 RequestSerializer.WriteInteger(I d);644 RequestSerializer.WriteInteger(Index); 567 645 SendPacket(toUserDataGet, Request, Response); 568 646 if Response[0] <> Id then raise Exception.Create(SWrongId); … … 581 659 582 660 finally 661 Request.Free; 662 RequestSerializer.Free; 663 Response.Free; 664 end; 665 end; 666 667 function TTerminalBF630.GetPassageCount: Integer; 668 var 669 Response: TListByte; 670 ResponseSerializer: TBinarySerializer; 671 begin 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; 681 end; 682 683 function TTerminalBF630.GetPassage(Index: Integer; Passage: TUserPassage): Boolean; 684 var 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; 699 begin 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; 583 729 Request.Free; 584 730 RequestSerializer.Free;
Note:
See TracChangeset
for help on using the changeset viewer.