Changeset 296 for PinConnection


Ignore:
Timestamp:
Nov 16, 2011, 7:24:09 AM (13 years ago)
Author:
george
Message:
  • Added: New TCommDelay interconnection block for creating time delay in route.
  • Fixed: In TCommThread do not obtain lock during sending data in thread.
  • Modified: TCommFrame have ability to change special control symbols.
Location:
PinConnection
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • PinConnection/PinConnection.lpk

    r289 r296  
    77    <Author Value="Chronos"/>
    88    <CompilerOptions>
    9       <Version Value="10"/>
     9      <Version Value="11"/>
    1010      <PathDelim Value="\"/>
    1111      <SearchPaths>
    1212        <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
    1313      </SearchPaths>
    14       <Linking>
    15         <Debugging>
    16           <GenerateDebugInfo Value="True"/>
    17           <DebugInfoType Value="dsAuto"/>
    18         </Debugging>
    19       </Linking>
    2014      <Other>
    2115        <CompilerMessages>
     
    4236      </Item3>
    4337      <Item4>
    44         <Filename Value="UCommProtocol.pas"/>
    45         <UnitName Value="UCommProtocol"/>
     38        <Filename Value="UCommSerialPort.pas"/>
     39        <UnitName Value="UCommSerialPort"/>
    4640      </Item4>
    4741      <Item5>
    48         <Filename Value="UCommSerialPort.pas"/>
    49         <UnitName Value="UCommSerialPort"/>
     42        <Filename Value="UCommSocket.pas"/>
     43        <UnitName Value="UCommSocket"/>
    5044      </Item5>
    5145      <Item6>
    52         <Filename Value="UCommSocket.pas"/>
    53         <UnitName Value="UCommSocket"/>
     46        <Filename Value="UCommThread.pas"/>
     47        <UnitName Value="UCommThread"/>
    5448      </Item6>
    5549      <Item7>
    56         <Filename Value="UCommThread.pas"/>
    57         <UnitName Value="UCommThread"/>
     50        <Filename Value="UPacketBurst.pas"/>
     51        <UnitName Value="UPacketBurst"/>
    5852      </Item7>
    5953      <Item8>
    60         <Filename Value="UPacketBurst.pas"/>
    61         <UnitName Value="UPacketBurst"/>
     54        <Filename Value="USerialPort.pas"/>
     55        <UnitName Value="USerialPort"/>
    6256      </Item8>
    6357      <Item9>
    64         <Filename Value="USerialPort.pas"/>
    65         <UnitName Value="USerialPort"/>
     58        <Filename Value="UCommConcentrator.pas"/>
     59        <UnitName Value="UCommConcentrator"/>
    6660      </Item9>
    6761      <Item10>
    68         <Filename Value="UCommConcentrator.pas"/>
    69         <UnitName Value="UCommConcentrator"/>
     62        <Filename Value="UCommDelay.pas"/>
     63        <UnitName Value="UCommDelay"/>
    7064      </Item10>
    7165    </Files>
  • PinConnection/PinConnection.pas

    r289 r296  
    88
    99uses
    10   UCommFrame, UCommHub, UCommPin, UCommProtocol, UCommSerialPort, UCommSocket,
    11   UCommThread, UPacketBurst, USerialPort, UCommConcentrator, LazarusPackageIntf;
     10  UCommFrame, UCommHub, UCommPin, UCommSerialPort, UCommSocket, UCommThread,
     11  UPacketBurst, USerialPort, UCommConcentrator, UCommDelay, LazarusPackageIntf;
    1212
    1313implementation
  • PinConnection/UCommFrame.pas

    r288 r296  
    88  Classes, UStreamHelper, Dialogs, SysUtils,
    99  UCommPin;
    10 
    11 const
    12   SpecialChar = $fe;
    13   ControlCodeFrameStart = $fd;
    14   ControlCodeFrameEnd = $fc;
    15   ControlCodeSpecialChar = $fb;
    16   TimeoutRepeatCount = 3;
    1710
    1811type
     
    3326    FrameDataPin: TCommPin;
    3427    PacketLoss: Real;
     28    SpecialChar: Byte;
     29    ControlCodeFrameStart: Byte;
     30    ControlCodeFrameEnd: Byte;
     31    ControlCodeSpecialChar: Byte;
    3532    procedure RawDataReceive(Sender: TCommPin; Stream: TStream);
    3633    procedure RawSetStatus(Sender: TCommPin; Status: Integer);
    3734    procedure FrameDataReceive(Sender: TCommPin; Stream: TStream);
    3835    procedure FrameSetStatus(Sender: TCommPin; Status: Integer);
     36    function ComputeRawSize(DataStream: TStream): Integer;
    3937    constructor Create;
    4038    destructor Destroy; override;
     
    5654  FrameDataPin.OnReceive := FrameDataReceive;
    5755  PacketLoss := 0.005;
     56  SpecialChar := $fe;
     57  ControlCodeFrameStart := $fd;
     58  ControlCodeFrameEnd := $fc;
     59  ControlCodeSpecialChar := $fb;
    5860end;
    5961
     
    99101    RawData.WriteByte(SpecialChar);
    100102    RawData.WriteByte(ControlCodeFrameEnd);
    101     //if Random >= PacketLoss then
     103    if Random >= PacketLoss then
    102104      RawDataPin.Send(RawData);
    103105
     
    110112begin
    111113  RawDataPin.Status := Status;
     114end;
     115
     116function TCommFrame.ComputeRawSize(DataStream: TStream): Integer;
     117begin
     118  Result := 5; // FrameStart + CRC + FrameEnd
     119  DataStream.Position := 0;
     120  while DataStream.Position < DataStream.Size do
     121    if DataStream.ReadByte = SpecialChar then Inc(Result, 2)
     122      else Inc(Result, 1);
    112123end;
    113124
     
    170181  Polynom: Byte = $18;
    171182begin
     183  Pom := 0;
    172184  Stream.Position := 0;
    173185  Result := 0;
  • PinConnection/UCommThread.pas

    r293 r296  
    1616  { TCommThreadReceiveThread }
    1717
    18   TCommThreadReceiveThread = class(TListedThread)
     18  TCommThreadReceiveThread = class(TTermThread)
    1919  public
    2020    Parent: TCommThread;
     
    103103    FReceiveThread.Start;
    104104  end else begin
    105     FReceiveThread.Terminate;
    106     FReceiveThread.WaitFor;
    107105    FreeAndNil(FReceiveThread);
    108106  end;
     
    139137
    140138procedure TCommThreadReceiveThread.Execute;
     139var
     140  TempStatus: Integer;
    141141begin
    142   try
    143     with Parent do
    144     repeat
    145       // Check if new data arrived
    146       if FDataAvailable.WaitFor(1) = wrSignaled then
     142  with Parent do
     143  repeat
     144    // Check if new data arrived
     145    if FDataAvailable.WaitFor(1) = wrSignaled then begin
    147146      try
    148147        FInputBufferLock.Acquire;
    149148        Stream.Size := 0;
    150149        Stream.WriteStream(FInputBuffer, FInputBuffer.Size);
    151         Pin.Send(Stream);
    152       finally
    153150        FDataAvailable.ResetEvent;
    154151        FInputBuffer.Clear;
     152      finally
    155153        FInputBufferLock.Release;
    156154      end; // else Yield;
     155      Pin.Send(Stream);
     156    end;
    157157
    158       // Check if state changed
    159       if FStatusEvent.WaitFor(0) = wrSignaled then
     158    // Check if state changed
     159    if FStatusEvent.WaitFor(0) = wrSignaled then begin
    160160      try
    161161        FInputBufferLock.Acquire;
    162         Pin.Status := FStatusValue;
     162        TempStatus := FStatusValue;
    163163      finally
    164164        FStatusEvent.ResetEvent;
    165165        FInputBufferLock.Release;
    166166      end;
    167     until Terminated;
    168   finally
    169   end;
     167      Pin.Status := TempStatus;
     168    end;
     169  until Terminated;
    170170end;
    171171
Note: See TracChangeset for help on using the changeset viewer.