Changeset 288
- Timestamp:
- Oct 24, 2011, 9:01:08 AM (13 years ago)
- Location:
- PinConnection
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
PinConnection/UCommFrame.pas
r119 r288 19 19 TFrameState = (fsOutside, fsStart, fsInside, fsEnd); 20 20 21 { TCommFrame } 22 21 23 TCommFrame = class 22 24 private … … 32 34 PacketLoss: Real; 33 35 procedure RawDataReceive(Sender: TCommPin; Stream: TStream); 36 procedure RawSetStatus(Sender: TCommPin; Status: Integer); 34 37 procedure FrameDataReceive(Sender: TCommPin; Stream: TStream); 38 procedure FrameSetStatus(Sender: TCommPin; Status: Integer); 35 39 constructor Create; 36 40 destructor Destroy; override; … … 103 107 end; 104 108 109 procedure TCommFrame.FrameSetStatus(Sender: TCommPin; Status: Integer); 110 begin 111 RawDataPin.Status := Status; 112 end; 113 105 114 procedure TCommFrame.RawDataReceive(Sender: TCommPin; Stream: TStream); 106 115 var … … 148 157 end; 149 158 159 procedure TCommFrame.RawSetStatus(Sender: TCommPin; Status: Integer); 160 begin 161 FrameDataPin.Status := Status; 162 end; 163 150 164 function TCommFrame.GetStreamCRC8(Stream: TStream): Byte; 151 165 var -
PinConnection/UCommHub.pas
r272 r288 18 18 function GetPin(Index: Integer): TCommPin; 19 19 procedure Receive(Sender: TCommPin; Stream: TStream); 20 procedure SetStatus(Sender: TCommPin; Status: Integer); 20 21 public 21 22 constructor Create; … … 54 55 end; 55 56 57 procedure TCommHub.SetStatus(Sender: TCommPin; Status: Integer); 58 var 59 I: Integer; 60 begin 61 if FActive then begin 62 // Broadcast received packet to all other pins 63 for I := 0 to FPins.Count - 1 do 64 if Sender <> FPins[I] then 65 TCommPin(FPins[I]).Status := Status; 66 end; 67 end; 68 56 69 constructor TCommHub.Create; 57 70 begin … … 68 81 begin 69 82 Pin.OnReceive := Receive; 83 Pin.OnSetSatus := SetStatus; 70 84 Result := FPins.Add(Pin); 71 85 end; … … 74 88 begin 75 89 Pin.OnReceive := nil; 90 Pin.OnSetSatus := nil; 76 91 Result := TCommPin(FPins.Extract(Pin)); 77 92 end; … … 90 105 begin 91 106 Pin.OnReceive := Receive; 107 Pin.OnSetSatus := SetStatus; 92 108 FPins.Insert(Index, Pin); 93 109 end; … … 107 123 Result := TCommPin.Create; 108 124 Result.OnReceive := Receive; 125 Result.OnSetSatus := SetStatus; 109 126 FPins.Add(Result); 110 127 end; -
PinConnection/UCommPin.pas
r247 r288 14 14 TOnLogDataEvent = procedure (Stream: TStream; Direction: TDataDiretion) of object; 15 15 TOnStreamEvent = procedure (Sender: TCommPin; Stream: TStream) of object; 16 TOnSetStatus = procedure (Sender: TCommPin; Status: Integer) of object; 16 17 17 18 { TCommPin } … … 25 26 FFrameTxCount: Integer; 26 27 FFrameRxCount: Integer; 28 FOnSetStatus: TOnSetStatus; 29 FStatus: Integer; 27 30 function GetConnected: Boolean; 31 procedure SetStatus(AValue: Integer); 32 protected 33 procedure Receive(Stream: TStream); 34 procedure ReceiveStatus(AValue: Integer); 28 35 public 29 36 RemotePin: TCommPin; … … 33 40 procedure Disconnect; 34 41 procedure Send(Stream: TStream); 35 procedure Receive(Stream: TStream);36 42 procedure ResetCounters; 37 property OnReceive: TOnStreamEvent read FOnReceive write FOnReceive;38 43 property Connected: Boolean read GetConnected; 39 44 property OnLogData: TOnLogDataEvent read FOnLogData write FOnLogData; … … 42 47 property FrameTxCount: Integer read FFrameTxCount; 43 48 property FrameRxCount: Integer read FFrameRxCount; 49 property Status: Integer read FStatus write SetStatus; // Used for general status bits such as parity bit 50 property OnReceive: TOnStreamEvent read FOnReceive write FOnReceive; 51 property OnSetSatus: TOnSetStatus read FOnSetStatus write FOnSetStatus; 44 52 end; 45 53 … … 55 63 Disconnect; 56 64 Self.RemotePin := Pin; 57 Pin.RemotePin := Self; 65 if Assigned(Pin) then begin 66 Pin.RemotePin := Self; 67 RemotePin.ReceiveStatus(FStatus); 68 end; 58 69 end; 59 70 end; … … 78 89 end; 79 90 91 procedure TCommPin.SetStatus(AValue: Integer); 92 begin 93 FStatus := AValue; 94 if Assigned(RemotePin) then RemotePin.ReceiveStatus(AValue); 95 end; 96 80 97 constructor TCommPin.Create; 81 98 begin … … 90 107 Stream.Position := 0; 91 108 if Assigned(FOnReceive) then FOnReceive(Self, Stream); 109 end; 110 111 procedure TCommPin.ReceiveStatus(AValue: Integer); 112 begin 113 if Assigned(FOnSetStatus) then FOnSetStatus(Self, AValue); 92 114 end; 93 115 -
PinConnection/UCommSerialPort.pas
r272 r288 10 10 11 11 type 12 13 { TCommSerialPort } 14 12 15 TCommSerialPort = class(TSerialPort) 13 16 private 14 17 procedure Receive(Sender: TCommPin; Stream: TStream); 18 procedure SetStatus(Sender: TCommPin; AValue: Integer); 15 19 procedure ReceiveData(Stream: TMemoryStream); 16 20 public … … 32 36 end; 33 37 38 procedure TCommSerialPort.SetStatus(Sender: TCommPin; AValue: Integer); 39 begin 40 try 41 Lock.Acquire; 42 if (AValue and 1) = 1 then Parity := paMark else Parity := paSpace; 43 finally 44 Lock.Release; 45 end; 46 end; 47 34 48 constructor TCommSerialPort.Create; 35 49 begin … … 38 52 Pin := TCommPin.Create; 39 53 Pin.OnReceive := Receive; 54 Pin.OnSetSatus := SetStatus; 40 55 OnReceiveData := ReceiveData; 41 56 end; -
PinConnection/UCommThread.pas
r272 r288 36 36 FInputBufferLock: TCriticalSection; 37 37 FDataAvailable: TEvent; 38 procedure ReceiveData(Sender: TCommPin; Stream: TStream); 38 FStatusEvent: TEvent; 39 FStatusValue: Integer; 40 procedure PinReceiveData(Sender: TCommPin; Stream: TStream); 41 procedure PinSetStatus(Sender: TCommPin; Status: Integer); 39 42 procedure ExtReceiveData(Sender: TCommPin; Stream: TStream); 43 procedure ExtSetStatus(Sender: TCommPin; AStatus: Integer); 40 44 procedure SetActive(const AValue: Boolean); 41 45 public … … 51 55 { TCommThread } 52 56 53 procedure TCommThread. ReceiveData(Sender: TCommPin; Stream:TStream);57 procedure TCommThread.PinReceiveData(Sender: TCommPin; Stream:TStream); 54 58 begin 55 59 if FActive then Ext.Send(Stream); 60 end; 61 62 procedure TCommThread.PinSetStatus(Sender: TCommPin; Status: Integer); 63 begin 64 if FActive then Ext.Status := Status; 56 65 end; 57 66 … … 68 77 FInputBufferLock.Release; 69 78 StreamHelper.Free; 79 end; 80 end; 81 82 procedure TCommThread.ExtSetStatus(Sender: TCommPin; AStatus: Integer); 83 begin 84 try 85 FInputBufferLock.Acquire; 86 FStatusValue := AStatus; 87 FStatusEvent.SetEvent; 88 finally 89 FInputBufferLock.Release; 70 90 end; 71 91 end; … … 96 116 Ext := TCommPin.Create; 97 117 Ext.OnReceive := ExtReceiveData; 118 Ext.OnSetSatus := ExtSetStatus; 98 119 Pin := TCommPin.Create; 99 Pin.OnReceive := ReceiveData; 120 Pin.OnReceive := PinReceiveData; 121 Pin.OnSetSatus := PinSetStatus; 100 122 FDataAvailable := TSimpleEvent.Create; 123 FStatusEvent := TSimpleEvent.Create; 101 124 end; 102 125 … … 108 131 Ext.Free; 109 132 Pin.Free; 133 FStatusEvent.Free; 110 134 FDataAvailable.Free; 111 135 inherited Destroy; … … 119 143 with Parent do 120 144 repeat 145 // Check if new data arrived 121 146 if FDataAvailable.WaitFor(1) = wrSignaled then 122 147 try … … 130 155 FInputBufferLock.Release; 131 156 end; // else Yield; 157 158 // Check if state changed 159 if FStatusEvent.WaitFor(1) = wrSignaled then 160 try 161 FInputBufferLock.Acquire; 162 Pin.Status := FStatusValue; 163 finally 164 FStatusEvent.ResetEvent; 165 FInputBufferLock.Release; 166 end; 132 167 until Terminated; 133 168 finally
Note:
See TracChangeset
for help on using the changeset viewer.