-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSatControlPanel.cs
406 lines (336 loc) · 13 KB
/
SatControlPanel.cs
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Collections;
using SDRSharp.Common;
namespace SDRSharp.Plugin.SatControl
{
public partial class SatControlPanel : UserControl
{
private RigControlProcess _radio;
private SatControlProcess _satellite;
private ISharpControl _control;
private RotControlProcess _rotor;
private bool ShowTransmitter = false;
private bool TransmitterReset = false;
private bool SatelliteFrequencyReset = false;
// Satellite Control Free RX Tune
private long prevSdrRxFreq = 0;
private long startRxFreq = 0;
private long rxDoppler = 0;
private long txDoppler = 0;
private long startTxFreq = 0;
public SatControlPanel(RigControlProcess radio, SatControlProcess satellite, ISharpControl control, RotControlProcess rottor)
{
InitializeComponent();
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
lblVersion.Text = "v" + fvi.FileMajorPart + "." + fvi.FileMinorPart + " dev by E29AHU";
_radio = radio;
_radio.rigStatus += _process_rigStatus;
_satellite = satellite;
_satellite.satRefresh += _satellite_satRefresh;
_control = control;
_rotor = rottor;
_rotor.rotorUpdate += _rotor_rotorUpdate;
// Prepare list Radio;
cbRig.Items.Add("Rig1");
cbRig.Items.Add("Rig2");
cbRig.SelectedIndex = 0;
resetGui();
// load satellite list
ArrayList satnames = _satellite.getSatelliteList();
foreach(string satname in satnames)
{
cbSateList.Items.Add(satname);
}
cbSateList.SelectedIndex = 0;
// get TxOffset from config
nudTxOffset.Text = _radio.getTxOffsetFromConfig();
}
private void resetGui()
{
lblRigName.Text = "";
lblStatus.Text = "";
lblFrequency.Text = "";
lblMode.Text = "";
lblSpeed.Text = "";
lblAos.Text = "";
lblMaxEl.Text = "";
lblAzimuth.Text = "";
lblElevation.Text = "";
lblDistance.Text = "";
lblRx.Text = "";
lblTx.Text = "";
lblSatMode.Text = "";
lblDoppler.Text = "";
lblRxDoppler.Text = "";
lblTxDoppler.Text = "";
lblRotorAz.Text = "";
lblRotorEl.Text = "";
}
// ##################################################################################
// Satellite Control
private void _satellite_satRefresh()
{
double Az = _satellite.observation.Azimuth.Degrees;
double El = _satellite.observation.Elevation.Degrees;
double range = _satellite.observation.Range;
double rangeRate = _satellite.observation.RangeRate;
lblAzimuth.Text = Az.ToString("#0.##0°");
lblElevation.Text = El.ToString("#0.##0°"); ;
lblDistance.Text = range.ToString("#0.##0 km");
lblSpeed.Text = rangeRate.ToString("#0.##0 km/s");
lblAos.Text = _satellite.satInfo.deltaTime.ToString(@"hh\:mm\:ss");
lblMaxEl.Text = _satellite.satInfo.MaxEl.ToString("0.0°");
if (ShowTransmitter == true)
{
int i = cbTransmitter.SelectedIndex;
long rxFreqHigh = Convert.ToInt64(_satellite.transmitterSelected.ElementAt(i).Value.downlink_high);
long rxFreqLow = Convert.ToInt64(_satellite.transmitterSelected.ElementAt(i).Value.downlink_low);
long txFreqHigh = Convert.ToInt64(_satellite.transmitterSelected.ElementAt(i).Value.uplink_high);
long txFreqLow = Convert.ToInt64(_satellite.transmitterSelected.ElementAt(i).Value.uplink_low);
string upMode = Convert.ToString(_satellite.transmitterSelected.ElementAt(i).Value.uplink_mode);
string dnMode = Convert.ToString(_satellite.transmitterSelected.ElementAt(i).Value.mode);
bool invert = _satellite.transmitterSelected.ElementAt(i).Value.invert;
long rxFreq = 0;
long txFreq = 0;
lblRx.Text = "";
if (rxFreqHigh != 0)
{
lblRx.Text = rxFreqLow / 1000 + " - " + rxFreqHigh / 1000 + " kHz";
rxFreq = rxFreqHigh - ((rxFreqHigh - rxFreqLow) / 2);
}
else
{
lblRx.Text = rxFreqLow / 1000 + " kHz";
rxFreq = rxFreqLow;
}
lblTx.Text = "";
if (txFreqHigh != 0)
{
lblTx.Text = txFreqLow / 1000 + " - " + txFreqHigh + " kHz";
txFreq = txFreqHigh - ((txFreqHigh - txFreqLow) / 2);
}
else if (txFreqLow != 0)
{
lblTx.Text = txFreqLow / 1000 + " kHz";
txFreq = txFreqLow;
}
else
{
lblTx.Text = "n/a";
}
lblSatMode.Text = "";
if (upMode != null)
{
lblSatMode.Text = "Up:" + upMode + " / Dn:" + dnMode;
}
else
{
lblSatMode.Text = dnMode;
}
if (TransmitterReset == true || SatelliteFrequencyReset == true) // Set SDR and Radio frequency to Satellite RX frequency
{
startTxFreq = txFreq;
startRxFreq = rxFreq;
prevSdrRxFreq = rxFreq;
_control.Frequency = rxFreq;
_control.CenterFrequency = rxFreq;
switch (dnMode)
{
case "LSB":
_control.DetectorType = Radio.DetectorType.LSB; break;
case "USB":
_control.DetectorType = Radio.DetectorType.USB; break;
case "CW":
_control.DetectorType = Radio.DetectorType.CW; break;
case "FM":
_control.DetectorType = Radio.DetectorType.NFM; break;
default:
_control.DetectorType = Radio.DetectorType.NFM; break;
}
}
if (_control.Frequency != prevSdrRxFreq) // Free Tune Option
{
startRxFreq = _control.Frequency - rxDoppler;
}
// RX Doppler
lblDoppler.Text = "";
rxDoppler = (long)_satellite.observation.GetDopplerShift((double)startRxFreq);
lblDoppler.Text = rxDoppler + " Hz";
_control.Frequency = startRxFreq + rxDoppler;
lblRxDoppler.Text = ((double)_control.Frequency / 1000).ToString("#0.#0 kHz");
prevSdrRxFreq = _control.Frequency;
// TX Doppler
if (txFreq != 0)
{
txDoppler = -(long)_satellite.observation.GetDopplerShift((double)startTxFreq);
lblDoppler.Text += " / " + txDoppler + " Hz";
long rigTxFreq = startTxFreq + txDoppler;
if (invert == true)
{
rigTxFreq += (rxFreq - startRxFreq);
}
lblTxDoppler.Text = ((double)rigTxFreq / 1000).ToString("#0.#0 kHz");
// send to radio control
if (chkRigEnable.Checked)
{
_radio.satInfo.frequency = rigTxFreq + Convert.ToInt64(nudTxOffset.Value);
//_radio.rigInfo.mode = upMode;
}
}
else
{
lblTxDoppler.Text = "n/a";
}
// Update RotorData
if (chkRotorEnable.Checked)
{
if(Az>0 && El>0) // If Satellite Available. send command to rotor
//if(true)
{
_rotor.setPosition(Az, El);
//_rotor.setPosition(90, 0);
}
}
TransmitterReset = false;
SatelliteFrequencyReset = false;
}
}
private void cbSateList_SelectedIndexChanged(object sender, EventArgs e)
{
_satellite.connectSatellite(cbSateList.SelectedIndex);
// Update Satellite Mode
cbTransmitter.Items.Clear();
foreach (string txDetail in _satellite.transmitterSelectedDisplay)
{
cbTransmitter.Items.Add(txDetail);
}
cbTransmitter.SelectedIndex = 0;
}
private void cbTransmitter_SelectedIndexChanged(object sender, EventArgs e)
{
ShowTransmitter = true;
TransmitterReset = true;
}
private void chkSatEnable_CheckedChanged(object sender, EventArgs e)
{
if (chkSatEnable.Checked)
{
_satellite.serviceStart();
}
else
{
_satellite.serviceStop();
resetGui();
}
}
// ###########################################################################
// Radio Control
private void bb_omniRigConfig_Click(object sender, EventArgs e)
{
_radio.OmniRigConfig();
}
private void _process_rigStatus()
{
lblStatus.Text = _radio.rigInfo.status;
lblFrequency.Text = ((_radio.rigInfo.frequency - nudTxOffset.Value)/1000).ToString("#0.#0 kHz");
lblMode.Text = _radio.rigInfo.mode;
lblRigName.Text = _radio.rigInfo.rigName;
}
private void chkRigEnable_CheckedChanged(object sender, EventArgs e)
{
if (chkRigEnable.Checked)
{
_radio.connectRig(cbRig.Text);
}
else
{
_radio.disConnectRig();
lblStatus.Text = "";
lblFrequency.Text = "";
lblMode.Text = "";
lblRigName.Text = "";
}
}
private void bb_satReset_Click(object sender, EventArgs e)
{
SatelliteFrequencyReset = true;
}
private void bb_rigFM_Click(object sender, EventArgs e)
{
_radio.setModeFM();
}
private void bb_rigLSB_Click(object sender, EventArgs e)
{
_radio.setModeLSB();
}
private void bb_rigUSB_Click(object sender, EventArgs e)
{
_radio.setModeUSB();
}
private void bb_rigCW_Click(object sender, EventArgs e)
{
_radio.setModeCW();
}
// ###########################################################################
// Rotor Control
private void chkRotorEnable_CheckedChanged(object sender, EventArgs e)
{
if (chkRotorEnable.Checked)
{
lblRotMsg.Text = _rotor.connect();
}
else
{
lblRotMsg.Text = "";
_rotor.disconnect();
}
}
private void _rotor_rotorUpdate()
{
lblRotorAz.Text = Convert.ToString(_rotor.rotInfo.Az);
lblRotorEl.Text = Convert.ToString(_rotor.rotInfo.El);
}
private void bbRotorUp_MouseDown(object sender, MouseEventArgs e)
{
_rotor.rotateUp();
}
private void bbRotorDn_MouseDown(object sender, MouseEventArgs e)
{
_rotor.rotateDn();
}
private void bbRotorLeft_MouseDown(object sender, MouseEventArgs e)
{
_rotor.rotateLeft();
}
private void bbRotorRight_MouseDown(object sender, MouseEventArgs e)
{
_rotor.rotateRight();
}
private void bbRotorDn_MouseUp(object sender, MouseEventArgs e)
{
_rotor.rotateStop();
}
private void bbRotorUp_MouseUp(object sender, MouseEventArgs e)
{
_rotor.rotateStop();
}
private void bbRotorLeft_MouseUp(object sender, MouseEventArgs e)
{
_rotor.rotateStop();
}
private void bbRotorRight_MouseUp(object sender, MouseEventArgs e)
{
_rotor.rotateStop();
}
}
}