Changeset 296 for PinConnection
- Timestamp:
- Nov 16, 2011, 7:24:09 AM (13 years ago)
- Location:
- PinConnection
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
PinConnection/PinConnection.lpk
r289 r296 7 7 <Author Value="Chronos"/> 8 8 <CompilerOptions> 9 <Version Value="1 0"/>9 <Version Value="11"/> 10 10 <PathDelim Value="\"/> 11 11 <SearchPaths> 12 12 <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> 13 13 </SearchPaths> 14 <Linking>15 <Debugging>16 <GenerateDebugInfo Value="True"/>17 <DebugInfoType Value="dsAuto"/>18 </Debugging>19 </Linking>20 14 <Other> 21 15 <CompilerMessages> … … 42 36 </Item3> 43 37 <Item4> 44 <Filename Value="UComm Protocol.pas"/>45 <UnitName Value="UComm Protocol"/>38 <Filename Value="UCommSerialPort.pas"/> 39 <UnitName Value="UCommSerialPort"/> 46 40 </Item4> 47 41 <Item5> 48 <Filename Value="UCommS erialPort.pas"/>49 <UnitName Value="UCommS erialPort"/>42 <Filename Value="UCommSocket.pas"/> 43 <UnitName Value="UCommSocket"/> 50 44 </Item5> 51 45 <Item6> 52 <Filename Value="UComm Socket.pas"/>53 <UnitName Value="UComm Socket"/>46 <Filename Value="UCommThread.pas"/> 47 <UnitName Value="UCommThread"/> 54 48 </Item6> 55 49 <Item7> 56 <Filename Value="U CommThread.pas"/>57 <UnitName Value="U CommThread"/>50 <Filename Value="UPacketBurst.pas"/> 51 <UnitName Value="UPacketBurst"/> 58 52 </Item7> 59 53 <Item8> 60 <Filename Value="U PacketBurst.pas"/>61 <UnitName Value="U PacketBurst"/>54 <Filename Value="USerialPort.pas"/> 55 <UnitName Value="USerialPort"/> 62 56 </Item8> 63 57 <Item9> 64 <Filename Value="U SerialPort.pas"/>65 <UnitName Value="U SerialPort"/>58 <Filename Value="UCommConcentrator.pas"/> 59 <UnitName Value="UCommConcentrator"/> 66 60 </Item9> 67 61 <Item10> 68 <Filename Value="UComm Concentrator.pas"/>69 <UnitName Value="UComm Concentrator"/>62 <Filename Value="UCommDelay.pas"/> 63 <UnitName Value="UCommDelay"/> 70 64 </Item10> 71 65 </Files> -
PinConnection/PinConnection.pas
r289 r296 8 8 9 9 uses 10 UCommFrame, UCommHub, UCommPin, UComm Protocol, UCommSerialPort, UCommSocket,11 U CommThread, UPacketBurst, USerialPort, UCommConcentrator, LazarusPackageIntf;10 UCommFrame, UCommHub, UCommPin, UCommSerialPort, UCommSocket, UCommThread, 11 UPacketBurst, USerialPort, UCommConcentrator, UCommDelay, LazarusPackageIntf; 12 12 13 13 implementation -
PinConnection/UCommFrame.pas
r288 r296 8 8 Classes, UStreamHelper, Dialogs, SysUtils, 9 9 UCommPin; 10 11 const12 SpecialChar = $fe;13 ControlCodeFrameStart = $fd;14 ControlCodeFrameEnd = $fc;15 ControlCodeSpecialChar = $fb;16 TimeoutRepeatCount = 3;17 10 18 11 type … … 33 26 FrameDataPin: TCommPin; 34 27 PacketLoss: Real; 28 SpecialChar: Byte; 29 ControlCodeFrameStart: Byte; 30 ControlCodeFrameEnd: Byte; 31 ControlCodeSpecialChar: Byte; 35 32 procedure RawDataReceive(Sender: TCommPin; Stream: TStream); 36 33 procedure RawSetStatus(Sender: TCommPin; Status: Integer); 37 34 procedure FrameDataReceive(Sender: TCommPin; Stream: TStream); 38 35 procedure FrameSetStatus(Sender: TCommPin; Status: Integer); 36 function ComputeRawSize(DataStream: TStream): Integer; 39 37 constructor Create; 40 38 destructor Destroy; override; … … 56 54 FrameDataPin.OnReceive := FrameDataReceive; 57 55 PacketLoss := 0.005; 56 SpecialChar := $fe; 57 ControlCodeFrameStart := $fd; 58 ControlCodeFrameEnd := $fc; 59 ControlCodeSpecialChar := $fb; 58 60 end; 59 61 … … 99 101 RawData.WriteByte(SpecialChar); 100 102 RawData.WriteByte(ControlCodeFrameEnd); 101 //if Random >= PacketLoss then103 if Random >= PacketLoss then 102 104 RawDataPin.Send(RawData); 103 105 … … 110 112 begin 111 113 RawDataPin.Status := Status; 114 end; 115 116 function TCommFrame.ComputeRawSize(DataStream: TStream): Integer; 117 begin 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); 112 123 end; 113 124 … … 170 181 Polynom: Byte = $18; 171 182 begin 183 Pom := 0; 172 184 Stream.Position := 0; 173 185 Result := 0; -
PinConnection/UCommThread.pas
r293 r296 16 16 { TCommThreadReceiveThread } 17 17 18 TCommThreadReceiveThread = class(T ListedThread)18 TCommThreadReceiveThread = class(TTermThread) 19 19 public 20 20 Parent: TCommThread; … … 103 103 FReceiveThread.Start; 104 104 end else begin 105 FReceiveThread.Terminate;106 FReceiveThread.WaitFor;107 105 FreeAndNil(FReceiveThread); 108 106 end; … … 139 137 140 138 procedure TCommThreadReceiveThread.Execute; 139 var 140 TempStatus: Integer; 141 141 begin 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 147 146 try 148 147 FInputBufferLock.Acquire; 149 148 Stream.Size := 0; 150 149 Stream.WriteStream(FInputBuffer, FInputBuffer.Size); 151 Pin.Send(Stream);152 finally153 150 FDataAvailable.ResetEvent; 154 151 FInputBuffer.Clear; 152 finally 155 153 FInputBufferLock.Release; 156 154 end; // else Yield; 155 Pin.Send(Stream); 156 end; 157 157 158 159 if FStatusEvent.WaitFor(0) = wrSignaled then158 // Check if state changed 159 if FStatusEvent.WaitFor(0) = wrSignaled then begin 160 160 try 161 161 FInputBufferLock.Acquire; 162 Pin.Status := FStatusValue;162 TempStatus := FStatusValue; 163 163 finally 164 164 FStatusEvent.ResetEvent; 165 165 FInputBufferLock.Release; 166 166 end; 167 until Terminated;168 finally169 end;167 Pin.Status := TempStatus; 168 end; 169 until Terminated; 170 170 end; 171 171
Note:
See TracChangeset
for help on using the changeset viewer.