forked from VE3NEA/OmniRig
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAutoApp.pas
296 lines (213 loc) · 7.38 KB
/
AutoApp.pas
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
//------------------------------------------------------------------------------
//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
//
//------------------------------------------------------------------------------
unit AutoApp;
interface
uses
Windows, SysUtils, ComObj, ActiveX, AxCtrls, Classes, OmniRig_TLB, StdVcl,
AutoRig, CustRig, ByteFuns, RigObj, ScrFctry;
type
//TOmniRigX = class(TAutoObject, IConnectionPointContainer, IOmniRigX)
TOmniRigX = class(TScriptableAutoObject, IConnectionPointContainer, IOmniRigX)
private
FConnectionPoints: TConnectionPoints;
FConnectionPoint: TConnectionPoint;
FSinkList: TList;
FEvents: IOmniRigXEvents;
RigX1, RigX2: TRigX;
public
CustCommand, CustReply: TByteArray;
procedure Initialize; override;
destructor Destroy; override;
procedure CheckShutdown(var Shutdown: Boolean);
protected
property ConnectionPoints: TConnectionPoints read FConnectionPoints
implements IConnectionPointContainer;
procedure EventSinkChanged(const EventSink: IUnknown); override;
function Get_Rig1: IRigX; safecall;
function Get_Rig2: IRigX; safecall;
function Get_DialogVisible: WordBool; safecall;
procedure Set_DialogVisible(Value: WordBool); safecall;
function Get_InterfaceVersion: Integer; safecall;
function Get_SoftwareVersion: Integer; safecall;
end;
var
ObjList: TList;
//this event is fired immediately
procedure ComNotifyVisible;
procedure ComNotifyRigType(RigNumber: integer);
//send message to fire com event later
procedure ComNotifyStatus(RigNumber: integer);
procedure ComNotifyParams(RigNumber: integer; Params: integer);
procedure ComNotifyCustom(RigNumber: integer; Sender: Pointer);
//fire event in response to message
procedure DoComNotifyStatus(RigNumber: integer);
procedure DoComNotifyParams(RigNumber, Params: integer);
procedure DoComNotifyCustom(RigNumber: integer; Sender: Pointer);
implementation
uses
ComServ, Main;
//------------------------------------------------------------------------------
// init
//------------------------------------------------------------------------------
procedure TOmniRigX.CheckShutdown(var Shutdown: Boolean);
begin
//The [x] button hides main form instead of closing app
//if COM clients are connected. Now it's time to close.
Shutdown := Shutdown or not MainForm.Visible;
end;
procedure TOmniRigX.EventSinkChanged(const EventSink: IUnknown);
begin
FEvents := EventSink as IOmniRigXEvents;
if FConnectionPoint <> nil then FSinkList := FConnectionPoint.SinkList;
end;
procedure TOmniRigX.Initialize;
begin
//standard stuff
inherited Initialize;
FConnectionPoints := TConnectionPoints.Create(Self);
if AutoFactory.EventTypeInfo <> nil then
FConnectionPoint := FConnectionPoints.CreateConnectionPoint(
AutoFactory.EventIID, ckSingle, EventConnect)
else FConnectionPoint := nil;
//create COM object for Rig 1
RigX1 := TRigX.Create;
Get_Rig1._AddRef;
RigX1.FRig := MainForm.Rig1;
RigX1.Parent := Self;
RigX1.FPortBits.FPort := MainForm.Rig1.ComPort;
//create COM object for Rig 2
RigX2 := TRigX.Create;
Get_Rig2._AddRef;
RigX2.FRig := MainForm.Rig2;
RigX2.Parent := Self;
RigX2.FPortBits.FPort := MainForm.Rig2.ComPort;
ObjList.Add(Self);
ComServer.OnLastRelease := CheckShutdown;
end;
destructor TOmniRigX.Destroy;
begin
ObjList.Remove(Self);
FreeAndNil(FConnectionPoints);
RigX1.Free;
RigX2.Free;
inherited;
end;
//------------------------------------------------------------------------------
// interface methods
//------------------------------------------------------------------------------
//1.0 - initial release
//1.1 - PortBits added
//1.1+ - SentCustomCommand accepts strings
//1.1++ - SetSplitMode tries more commands
//1.1+++ - GetRxFreq, &GetTxFreeq corrected
function TOmniRigX.Get_InterfaceVersion: Integer;
begin
Result := $0101;
end;
function TOmniRigX.Get_SoftwareVersion: Integer;
begin
Result := MainForm.GetVersion;
end;
function TOmniRigX.Get_Rig1: IRigX;
begin
Result := RigX1;
end;
function TOmniRigX.Get_Rig2: IRigX;
begin
Result := RigX2;
end;
function TOmniRigX.Get_DialogVisible: WordBool;
begin
Result := MainForm.Visible;
end;
procedure TOmniRigX.Set_DialogVisible(Value: WordBool);
begin
if Value
then MainForm.ForceForeground
else MainForm.Hide;
end;
//------------------------------------------------------------------------------
// events
//------------------------------------------------------------------------------
//fire event immediately
procedure ComNotifyVisible;
var
i: integer;
begin
for i:=ObjList.Count-1 downto 0 do
with TOmniRigX(ObjList[i]) do
if FEvents <> nil then FEvents.VisibleChange;
end;
procedure ComNotifyRigType(RigNumber: integer);
var
i: integer;
begin
for i:=ObjList.Count-1 downto 0 do
with TOmniRigX(ObjList[i]) do
if FEvents <> nil then FEvents.RigTypeChange(RigNumber);
//rig type changed, client must re-read rig status
ComNotifyStatus(RigNumber);
end;
//send message to fire event later
procedure ComNotifyStatus(RigNumber: integer);
begin
PostMessage(MainForm.Handle, WM_COMSTATUS, RigNumber, 0);
end;
procedure ComNotifyParams(RigNumber, Params: integer);
begin
PostMessage(MainForm.Handle, WM_COMPARAMS, RigNumber, Params);
end;
procedure ComNotifyCustom(RigNumber: integer; Sender: Pointer);
begin
PostMessage(MainForm.Handle, WM_COMCUSTOM, RigNumber, Integer(Sender));
end;
//respond to message by firing an event
procedure DoComNotifyStatus(RigNumber: integer);
var
i: integer;
begin
for i:=ObjList.Count-1 downto 0 do
with TOmniRigX(ObjList[i]) do
if FEvents <> nil then FEvents.StatusChange(RigNumber);
end;
procedure DoComNotifyParams(RigNumber, Params: integer);
var
i: integer;
begin
for i:=ObjList.Count-1 downto 0 do
with TOmniRigX(ObjList[i]) do
if FEvents <> nil then FEvents.ParamsChange(RigNumber, Params);
end;
procedure DoComNotifyCustom(RigNumber: integer; Sender: Pointer);
var
Rig: TRig;
begin
if ObjList.IndexOf(Sender) < 0 then Exit;
with TOmniRigX(Sender) do
begin
if RigNumber = 1 then Rig := RigX1.FRig else Rig := RigX2.FRig;
Rig.Lock;
try
if FEvents <> nil then FEvents.CustomReply(RigNumber,
BytesToSafeArray(CustCommand), BytesToSafeArray(CustReply));
finally Rig.Unlock; end;
end;
end;
initialization
//TAutoObjectFactory.Create(ComServer, TOmniRigX, Class_OmniRigX,
TScriptableAutoObjectFactory.Create(ComServer, TOmniRigX, Class_OmniRigX,
ciMultiInstance, tmApartment);
ObjList := TList.Create;
finalization
ObjList.Free;
end.