Changeset 231 for PinConnection/UCommProtocol.pas
- Timestamp:
- Apr 14, 2011, 12:47:57 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
PinConnection/UCommProtocol.pas
r222 r231 6 6 7 7 uses 8 Classes, SysUtils, UVarBlockSerializer, syncobjs, UCommPin, U MicroThreading,9 UDebugLog, UStreamHelper, StopWatch, SpecializedList, UCommon, UPlatform,8 Classes, SysUtils, UVarBlockSerializer, syncobjs, UCommPin, UThreading, 9 UDebugLog, UStreamHelper, StopWatch, SpecializedList, UCommon, 10 10 DateUtils; 11 11 … … 26 26 private 27 27 RepeatCounter: integer; 28 ReceiveEvent: T MicroThreadEvent;28 ReceiveEvent: TSimpleEvent; 29 29 Request: TStreamHelper; 30 30 ResponseParameters: TVarBlockIndexed; 31 31 TransmitTime: TDateTime; 32 32 public 33 Lock: T MicroThreadCriticalSection;33 Lock: TCriticalSection; 34 34 SequenceNumber: Integer; 35 35 ResponseCode: Integer; … … 51 51 SequenceNumber: integer; 52 52 Parent: TCommProtocol; 53 Lock: T MicroThreadCriticalSection;53 Lock: TCriticalSection; 54 54 procedure Add(Session: TDeviceProtocolSession); 55 55 function GetBySequence(Sequence: integer): TDeviceProtocolSession; … … 65 65 { TRetransmitCheckThread } 66 66 67 TRetransmitCheckThread = class(T MicroThread)67 TRetransmitCheckThread = class(TListedThread) 68 68 public 69 69 Parent: TCommProtocol; … … 82 82 OnAfterRequest: TAfterRequest; 83 83 RetransmitThread: TRetransmitCheckThread; 84 procedure DataReceive(Sender: TCommPin; Stream: TStream);85 84 procedure HandleRequest(Stream: TStream); 86 85 procedure SetActive(const AValue: Boolean); … … 98 97 LastCommandResponseTime: TDateTime; 99 98 LastLatency: TDateTime; 99 procedure DataReceive(Sender: TCommPin; Stream: TStream); virtual; 100 100 procedure SendCommand(Command: array of integer; 101 101 ResponseParameters: TVarBlockIndexed = nil; … … 153 153 if TestIndex(4) then CommandError := ReadVarUInt(4) 154 154 else CommandError := 0; 155 Latency := Now Precise- TransmitTime;155 Latency := Now - TransmitTime; 156 156 ReceiveEvent.SetEvent; 157 157 finally … … 254 254 RetransmitThread := TRetransmitCheckThread.Create(True); 255 255 with RetransmitThread do begin 256 CheckPeriod := 100; 256 CheckPeriod := 100; // ms 257 257 Parent := Self; 258 258 FreeOnTerminate := False; … … 296 296 // Wait for free remote buffer 297 297 while (RemoteBufferUsed + Request.Size) > RemoteBufferSize do 298 MTSleep(1 * OneMillisecond);298 Sleep(1); 299 299 300 300 //StopWatch.Start; 301 TransmitTime := Now Precise;301 TransmitTime := Now; 302 302 Pin.Send(Request); 303 303 finally … … 311 311 Sessions.Lock.Release; 312 312 end; 313 while ReceiveEvent.WaitFor(10 * OneMillisecond) = wrTimeout do begin313 while ReceiveEvent.WaitFor(10) = wrTimeout do begin 314 314 if Timeouted then 315 315 raise ECommTimeout.Create(SResponseTimeout); … … 320 320 raise ECommResponseCodeError.Create(Format(SResponseError, [CommandIndex.Implode('.', IntToStr), IntToStr(ResponseCode)])); 321 321 end; 322 LastCommandResponseTime := Now Precise;322 LastCommandResponseTime := Now; 323 323 LastLatency := Latency; 324 324 finally … … 365 365 begin 366 366 ResponseCode := 0; 367 Lock := T MicroThreadCriticalSection.Create;368 ReceiveEvent := T MicroThreadEvent.Create;369 ReceiveEvent.AutoReset := False;367 Lock := TCriticalSection.Create; 368 ReceiveEvent := TSimpleEvent.Create; 369 //ReceiveEvent.ManualReset := True; 370 370 Request := TStreamHelper.Create; 371 371 ResponseParameters := nil; … … 396 396 try 397 397 Lock.Release; 398 MTSleep(1 * OneMillisecond);398 Sleep(1); 399 399 finally 400 400 Lock.Acquire; … … 434 434 begin 435 435 inherited Create; 436 Lock := T MicroThreadCriticalSection.Create;436 Lock := TCriticalSection.Create; 437 437 end; 438 438 … … 478 478 try 479 479 Session.Lock.Acquire; 480 if (TransmitTime > 0) and (Now Precise> (TransmitTime + RetransmitTimeout)) then begin480 if (TransmitTime > 0) and (Now > (TransmitTime + RetransmitTimeout)) then begin 481 481 if RepeatCounter < RetransmitRepeatCount then begin 482 482 Pin.Send(Request); 483 TransmitTime := Now Precise;483 TransmitTime := Now; 484 484 Inc(RepeatCounter); 485 485 Inc(RetransmitTotalCount); … … 498 498 499 499 if not Terminated then 500 MTSleep(CheckPeriod * OneMillisecond);500 Sleep(CheckPeriod); 501 501 until Terminated; 502 502 end;
Note:
See TracChangeset
for help on using the changeset viewer.