Changeset 231
- Timestamp:
- Apr 14, 2011, 12:47:57 PM (14 years ago)
- Location:
- PinConnection
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
PinConnection/PinConnection.lpk
r163 r231 6 6 <Author Value="Chronos"/> 7 7 <CompilerOptions> 8 <Version Value=" 10"/>8 <Version Value="9"/> 9 9 <PathDelim Value="\"/> 10 10 <SearchPaths> … … 57 57 </Files> 58 58 <Type Value="RunAndDesignTime"/> 59 <RequiredPkgs Count=" 5">59 <RequiredPkgs Count="4"> 60 60 <Item1> 61 <PackageName Value=" MicroThreading"/>61 <PackageName Value="synapse"/> 62 62 </Item1> 63 63 <Item2> 64 <PackageName Value=" synapse"/>64 <PackageName Value="Common"/> 65 65 </Item2> 66 66 <Item3> 67 <PackageName Value="Co mmon"/>67 <PackageName Value="CoolStreaming"/> 68 68 </Item3> 69 69 <Item4> 70 <PackageName Value="CoolStreaming"/>71 </Item4>72 <Item5>73 70 <PackageName Value="FCL"/> 74 71 <MinVersion Major="1" Valid="True"/> 75 </Item 5>72 </Item4> 76 73 </RequiredPkgs> 77 74 <UsageOptions> -
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; -
PinConnection/UCommSerialPort.pas
r171 r231 6 6 7 7 uses 8 Classes, USerialPort, UCommPin, SysUtils, UMicroThreading,DateUtils,8 Classes, USerialPort, UCommPin, SysUtils, DateUtils, 9 9 SyncObjs; 10 10 … … 15 15 procedure ReceiveData(Stream: TMemoryStream); 16 16 public 17 Lock: T MicroThreadCriticalSection;17 Lock: TCriticalSection; 18 18 Pin: TCommPin; 19 19 destructor Destroy; override; … … 35 35 begin 36 36 inherited; 37 Lock := T MicroThreadCriticalSection.Create;37 Lock := TCriticalSection.Create; 38 38 Pin := TCommPin.Create; 39 39 Pin.OnReceive := Receive; … … 60 60 end; 61 61 if Stream.Position <> Stream.Size then 62 MTSleep(1 * OneMillisecond);62 Sleep(1); 63 63 until Stream.Position = Stream.Size; 64 64 end; -
PinConnection/UCommSocket.pas
r163 r231 6 6 7 7 uses 8 Classes, SysUtils, blcksock, UCommPin, UCommon, U MicroThreading,8 Classes, SysUtils, blcksock, UCommPin, UCommon, UThreading, 9 9 DateUtils; 10 10 … … 16 16 { TCommSocketReceiveThread } 17 17 18 TCommSocketReceiveThread = class(T MicroThread)18 TCommSocketReceiveThread = class(TListedThread) 19 19 public 20 20 Parent: TCommSocket; … … 94 94 InBufferUsed := 0; 95 95 with Parent do repeat 96 if InBufferUsed = 0 then MTSleep(1 * OneMillisecond)97 else Yield;96 if InBufferUsed = 0 then Sleep(1); 97 //else Yield; 98 98 if Assigned(Socket) then 99 99 with Socket do -
PinConnection/UCommThread.pas
r222 r231 7 7 uses 8 8 Classes, SysUtils, blcksock, UCommPin, SyncObjs, UStreamHelper, UCommon, 9 UMicroThreading, DateUtils;9 DateUtils, UThreading; 10 10 11 11 type … … 16 16 { TCommThreadReceiveThread } 17 17 18 TCommThreadReceiveThread = class(T MicroThread)18 TCommThreadReceiveThread = class(TListedThread) 19 19 public 20 20 Parent: TCommThread; … … 34 34 FReceiveThread: TCommThreadReceiveThread; 35 35 FInputBuffer: TMemoryStream; 36 FInputBufferLock: T MicroThreadCriticalSection;37 FDataAvailable: T MicroThreadEvent;36 FInputBufferLock: TCriticalSection; 37 FDataAvailable: TEvent; 38 38 procedure ReceiveData(Sender: TCommPin; Stream: TStream); 39 39 procedure ExtReceiveData(Sender: TCommPin; Stream: TStream); … … 93 93 inherited Create; 94 94 FInputBuffer := TMemoryStream.Create; 95 FInputBufferLock := T MicroThreadCriticalSection.Create;95 FInputBufferLock := TCriticalSection.Create; 96 96 Ext := TCommPin.Create; 97 97 Ext.OnReceive := ExtReceiveData; 98 98 Pin := TCommPin.Create; 99 99 Pin.OnReceive := ReceiveData; 100 FDataAvailable := T MicroThreadEvent.Create;100 FDataAvailable := TSimpleEvent.Create; 101 101 end; 102 102 … … 122 122 with Parent do 123 123 repeat 124 if FDataAvailable.WaitFor(1 * OneMillisecond) = wrSignaled then begin124 if FDataAvailable.WaitFor(1) = wrSignaled then begin 125 125 try 126 126 FInputBufferLock.Acquire; … … 132 132 FInputBufferLock.Release; 133 133 end; 134 end else Yield;134 end; // else Yield; 135 135 until Terminated; 136 136 finally -
PinConnection/UPacketBurst.pas
r171 r231 7 7 uses 8 8 Classes, UCommPin, SyncObjs, UStreamHelper, UCommon, SysUtils, 9 UMicroThreading,DateUtils;9 DateUtils; 10 10 11 11 type 12 12 TPacketBurst = class; 13 13 14 TPacketBurstSendThread = class(T MicroThread)14 TPacketBurstSendThread = class(TThread) 15 15 PacketBurst: TPacketBurst; 16 16 procedure Execute; override; … … 22 22 private 23 23 FActive: Boolean; 24 SendThreadEvent: T MicroThreadEvent;24 SendThreadEvent: TEvent; 25 25 SendThread: TPacketBurstSendThread; 26 26 SendStreamLock: TCriticalSection; … … 31 31 procedure SetActive(const AValue: Boolean); 32 32 public 33 SendPeriod: TDateTime;33 SendPeriod: Integer; 34 34 SendBurstSize: Integer; 35 35 PacketSinglePin: TCommPin; … … 50 50 PacketBurstPin := TCommPin.Create; 51 51 PacketBurstPin.OnReceive := PacketBurstReceive; 52 SendThreadEvent := T MicroThreadEvent.Create;53 SendPeriod := OneMillisecond;52 SendThreadEvent := TSimpleEvent.Create; 53 SendPeriod := 1; 54 54 end; 55 55 … … 93 93 SendThread.FreeOnTerminate := False; 94 94 SendThread.PacketBurst := Self; 95 SendThread.Name := 'PacketBurst';95 //SendThread.Name := 'PacketBurst'; 96 96 SendThread.Start; 97 97 end else begin -
PinConnection/USerialPort.pas
r163 r231 6 6 7 7 uses 8 Classes, SysUtils, SynaSer, StdCtrls, Dialogs, UCommon, U MicroThreading,8 Classes, SysUtils, SynaSer, StdCtrls, Dialogs, UCommon, UThreading, 9 9 DateUtils; 10 10 … … 23 23 { TSerialPortReceiveThread } 24 24 25 TSerialPortReceiveThread = class(T MicroThread)25 TSerialPortReceiveThread = class(TListedThread) 26 26 public 27 27 Parent: TSerialPort; … … 292 292 InBufferUsed := 0; 293 293 with Parent do repeat 294 if InBufferUsed = 0 then MTSleep(1 * OneMillisecond)295 else Yield;294 if InBufferUsed = 0 then Sleep(1); 295 //else Yield; 296 296 if Active then begin 297 297 InBufferUsed := WaitingData;
Note:
See TracChangeset
for help on using the changeset viewer.