1 | unit CommMark;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, CommPin, SpecializedList;
|
---|
7 |
|
---|
8 | type
|
---|
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 |
|
---|
31 | implementation
|
---|
32 |
|
---|
33 | { TCommMark }
|
---|
34 |
|
---|
35 | procedure TCommMark.RawDataReceive(Sender: TCommPin; Stream: TListByte);
|
---|
36 | var
|
---|
37 | I: Integer;
|
---|
38 | begin
|
---|
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;
|
---|
56 | end;
|
---|
57 |
|
---|
58 | procedure TCommMark.RawSetStatus(Sender: TCommPin; Status: Integer);
|
---|
59 | begin
|
---|
60 | PinFrame.Status := Status;
|
---|
61 | end;
|
---|
62 |
|
---|
63 | procedure TCommMark.FrameDataReceive(Sender: TCommPin; Stream: TListByte);
|
---|
64 | begin
|
---|
65 | PinRaw.Send(Stream);
|
---|
66 | PinRaw.Send(Mark);
|
---|
67 | end;
|
---|
68 |
|
---|
69 | procedure TCommMark.FrameSetStatus(Sender: TCommPin; Status: Integer);
|
---|
70 | begin
|
---|
71 | PinRaw.Status := Status;
|
---|
72 | end;
|
---|
73 |
|
---|
74 | procedure TCommMark.SetActive(const AValue: Boolean);
|
---|
75 | begin
|
---|
76 | if FActive = AValue then Exit;
|
---|
77 | FActive := AValue;
|
---|
78 | if FActive then Reset;
|
---|
79 | inherited;
|
---|
80 | end;
|
---|
81 |
|
---|
82 | procedure TCommMark.Reset;
|
---|
83 | begin
|
---|
84 | FMarkIndex := 0;
|
---|
85 | FFrameData.Clear;
|
---|
86 | end;
|
---|
87 |
|
---|
88 | constructor TCommMark.Create(AOwner: TComponent);
|
---|
89 | begin
|
---|
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;
|
---|
102 | end;
|
---|
103 |
|
---|
104 | destructor TCommMark.Destroy;
|
---|
105 | begin
|
---|
106 | FreeAndNil(FFrameData);
|
---|
107 | FreeAndNil(Mark);
|
---|
108 | FreeAndNil(PinRaw);
|
---|
109 | FreeAndNil(PinFrame);
|
---|
110 | inherited;
|
---|
111 | end;
|
---|
112 |
|
---|
113 | end.
|
---|
114 |
|
---|