-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathCmdQue.pas
More file actions
144 lines (104 loc) · 3.23 KB
/
CmdQue.pas
File metadata and controls
144 lines (104 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//------------------------------------------------------------------------------
//This Source Code Form is subject to the terms of the Mozilla Public
//License, v. 2.0. If a copy of the MPL was not distributed with this
//file, You can obtain one at http://mozilla.org/MPL/2.0/.
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Omni-Rig
//
// Copyright (c) 2003 Alex Shovkoplyas, VE3NEA
//
// ve3nea@dxatlas.com
//------------------------------------------------------------------------------
unit CmdQue;
interface
uses
SysUtils, Classes, RigCmds, ByteFuns;
type
TCommandKind = (ckInit, ckWrite, ckStatus, ckCustom);
TExchangePhase = (phSending, phReceiving, phIdle);
TQueueItem = class(TCollectionItem)
public
Code: TByteArray;
Kind: TCommandKind;
Param: TRigParam; //param of Set comand
Number: integer; //ordinal number of Init or Status command
CustSender: Pointer; //COM object that sent custom command
ReplyLength: integer;
ReplyEnd: AnsiString;
function NeedsReply: boolean;
end;
TCommandQueue = class(TCollection)
private
function GetItem(Index: Integer): TQueueItem;
procedure SetItem(Index: Integer; Value: TQueueItem);
public
Phase:TExchangePhase;
constructor Create;
function Add: TQueueItem;
function AddBeforeStatusCommands: TQueueItem;
function HasStatusCommands: boolean;
function CurrentCmd: TQueueItem;
property Items[index: integer]: TQueueItem read GetItem write SetItem; default;
end;
implementation
{ TQueueItem }
function TQueueItem.NeedsReply: boolean;
begin
Result := (ReplyLength > 0) or (ReplyEnd <> '');
end;
{ TCommandQueue }
constructor TCommandQueue.Create;
begin
inherited Create(TQueueItem);
end;
function TCommandQueue.GetItem(Index: Integer): TQueueItem;
begin
Result := TQueueItem(inherited GetItem(Index));
end;
procedure TCommandQueue.SetItem(Index: Integer; Value: TQueueItem);
begin
inherited SetItem(Index, Value);
end;
function TCommandQueue.Add: TQueueItem;
begin
Result := TQueueItem(inherited Add);
end;
function TCommandQueue.AddBeforeStatusCommands: TQueueItem;
var
i, Idx: integer;
begin
Idx := Count;
//Items[0] is being worked on, start with [1]
for i:=1 to Count-1 do if Items[i].Kind = ckStatus
then begin Idx := i; Break; end;
Result := TQueueItem(Insert(Idx));
end;
function TCommandQueue.HasStatusCommands: boolean;
var
i: integer;
begin
Result := true;
for i:=0 to Count-1 do if Items[i].Kind = ckStatus then Exit;
Result := false;
end;
{
procedure TCommandQueue.AddCommand(ACode: TByteArray; ALen: integer;
AEnd: TByteArray; AKind: TCommandKind);
begin
with Add do
begin
Code := ACode;
Param := AParam;
ReplyLength := ALen;
SetLength(ReplyEnd, Length(AEnd));
Move(AEnd[0], ReplyEnd[1], Length(AEnd));
Kind := AKind;
end;
end;
}
function TCommandQueue.CurrentCmd: TQueueItem;
begin
Result := Items[0];
end;
end.