source: PinConnection/CommMark.pas

Last change on this file was 575, checked in by chronos, 5 months ago
  • Modified: Remove U prefix from unit names of PinConnection package.
File size: 2.6 KB
Line 
1unit CommMark;
2
3interface
4
5uses
6 Classes, SysUtils, CommPin, SpecializedList;
7
8type
9
10 { TCommMark }
11
12 TCommMark = class(TCommNode)
13 private
14 FMarkIndex: Integer;
15 FFrameData: TListByte;
16 procedure RawDataReceive(Sender: TCommPin; Stream: TListByte);
17 procedure RawSetStatus(Sender: TCommPin; Status: Integer);
18 procedure FrameDataReceive(Sender: TCommPin; Stream: TListByte);
19 procedure FrameSetStatus(Sender: TCommPin; Status: Integer);
20 protected
21 procedure SetActive(const AValue: Boolean); override;
22 public
23 PinRaw: TCommPin;
24 PinFrame: TCommPin;
25 Mark: TListByte;
26 procedure Reset;
27 constructor Create(AOwner: TComponent); override;
28 destructor Destroy; override;
29 end;
30
31implementation
32
33{ TCommMark }
34
35procedure TCommMark.RawDataReceive(Sender: TCommPin; Stream: TListByte);
36var
37 I: Integer;
38begin
39 for I := 0 to Stream.Count - 1 do
40 if (Mark.Count > 0) and (Stream[I] = Mark[FMarkIndex]) then begin
41 Inc(FMarkIndex);
42 if FMarkIndex >= Mark.Count then begin
43 PinFrame.Send(FFrameData);
44 FFrameData.Count := 0;
45 FMarkIndex := 0;
46 end;
47 end else begin
48 FFrameData.Count := FFrameData.Count + 1;
49 FFrameData[FFrameData.Count - 1] := Stream[I];
50 FMarkIndex := 0;
51 if Mark.Count = 0 then begin
52 PinFrame.Send(FFrameData);
53 FFrameData.Count := 0;
54 end;
55 end;
56end;
57
58procedure TCommMark.RawSetStatus(Sender: TCommPin; Status: Integer);
59begin
60 PinFrame.Status := Status;
61end;
62
63procedure TCommMark.FrameDataReceive(Sender: TCommPin; Stream: TListByte);
64begin
65 PinRaw.Send(Stream);
66 PinRaw.Send(Mark);
67end;
68
69procedure TCommMark.FrameSetStatus(Sender: TCommPin; Status: Integer);
70begin
71 PinRaw.Status := Status;
72end;
73
74procedure TCommMark.SetActive(const AValue: Boolean);
75begin
76 if FActive = AValue then Exit;
77 FActive := AValue;
78 if FActive then Reset;
79 inherited;
80end;
81
82procedure TCommMark.Reset;
83begin
84 FMarkIndex := 0;
85 FFrameData.Clear;
86end;
87
88constructor TCommMark.Create(AOwner: TComponent);
89begin
90 inherited;
91 PinRaw := TCommPin.Create;
92 PinRaw.OnReceive := RawDataReceive;
93 PinRaw.OnSetSatus := RawSetStatus;
94 PinRaw.Node := Self;
95 PinFrame := TCommPin.Create;
96 PinFrame.OnReceive := FrameDataReceive;
97 PinFrame.OnSetSatus := FrameSetStatus;
98 PinFrame.Node := Self;
99 Mark := TListByte.Create;
100 FMarkIndex := 0;
101 FFrameData := TListByte.Create;
102end;
103
104destructor TCommMark.Destroy;
105begin
106 FreeAndNil(FFrameData);
107 FreeAndNil(Mark);
108 FreeAndNil(PinRaw);
109 FreeAndNil(PinFrame);
110 inherited;
111end;
112
113end.
114
Note: See TracBrowser for help on using the repository browser.