forked from curlyboi/WinTelive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wtl-structures.cs
1704 lines (1457 loc) · 52.3 KB
/
wtl-structures.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
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using System.Net;
using System.IO;
using System.Xml;
using System.Runtime.InteropServices;
using System.Net.Sockets;
using System.Threading;
using System.Timers;
using NAudio.Wave;
using NAudio.Wave.SampleProviders;
using System.Windows.Forms;
namespace wintelive
{
public static class tetraRx
{
// interface to listen for UDP packets from tetra-rx instances
public static UdpClient udpCli = new UdpClient(7379);
public static void Recv(IAsyncResult ar)
{
IPEndPoint e = new IPEndPoint(IPAddress.Any, 0);
byte[] prebuf = udpCli.EndReceive(ar, ref e);
telive.parseUdp(prebuf);
if (udpCli.Client!=null)
{
Start();
}
}
public static void Start()
{
udpCli.BeginReceive(new AsyncCallback(Recv), null);
}
public static void Stop()
{
udpCli.Close();
}
}
public class acelp
{
BufferedWaveProvider wp;
FileStream fs;
int fpass = 1;
public bool listenOpen = false;
public bool recordOpen = false;
DateTime lastData;
private telive.receiver parentRx;
object listenLock, recordLock;
[DllImport("libtetradec.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void tetra_decode_init();
[DllImport("libtetradec.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int tetra_cdec(int fp, short[] inp, short[] outp);
[DllImport("libtetradec.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int tetra_sdec(short[] inp, short[] outp);
public acelp(telive.receiver myParent)
{
listenLock = new object();
recordLock = new object();
parentRx = myParent;
initDll();
}
public void initDll()
{
fpass = 1;
tetra_decode_init();
}
public static byte[] s2b(short[] shorts)
{
int len = shorts.Length * 2;
byte[] nbytes = new byte[len];
Buffer.BlockCopy(shorts, 0, nbytes, 0, len);
return nbytes;
}
public static short[] b2s(byte[] bytes)
{
int len = (int)Math.Ceiling((double)(bytes.Length / 2));
short[] nshorts = new short[len];
Buffer.BlockCopy(bytes, 0, nshorts, 0, bytes.Length);
return nshorts;
}
public byte[] acelp2pcm(byte[] acdata)
{
short[] sh = b2s(acdata);
short[] cdc = new short[276];
tetra_cdec(fpass, sh, cdc);
fpass = 0;
short[] sdc = new short[480];
tetra_sdec(cdc, sdc);
return s2b(sdc);
}
public void processAcelp(byte[] audio)
{
byte[] pcmaudio = acelp2pcm(audio);
if (pcmaudio.Any(w => w != 0))
{
lastData = DateTime.Now;
listenInit();
listen(pcmaudio);
recordInit();
record(pcmaudio);
}
}
public void listenInit()
{
lock (listenLock)
{
if (listenOpen) return;
wp = new BufferedWaveProvider(new WaveFormat(8000, 16, 1));
// i know, i know... but the discard effectively prevents crashing on full buffer forever...
wp.DiscardOnBufferOverflow = true;
telive.msp.AddMixerInput(wp);
listenOpen = true;
}
}
public void listen(byte[] pcm)
{
if (wp.BufferedBytes + pcm.Length >= wp.BufferLength || telive.wout.PlaybackState != PlaybackState.Playing)
telive.wout.Play();
wp.AddSamples(pcm, 0, pcm.Length);
}
public void listenClose()
{
lock (listenLock)
{
if (!listenOpen) return;
telive.msp.RemoveMixerInput(wp.ToSampleProvider());
wp = null;
listenOpen = false;
}
}
public void timeout()
{
TimeSpan kdy = DateTime.Now - lastData;
if (kdy.TotalMilliseconds > settings.timeoutUsiPlay)
{
listenClose();
}
if (kdy.TotalMilliseconds > settings.timeoutUsiActive)
{
recordClose();
}
}
public void recordInit()
{
lock (recordLock)
{
if (recordOpen) return;
string recpath = string.Format(@"tetra_{0:yyyyMMdd}_{0:HHmmss}_{1}.wav", DateTime.Now, parentRx.freq);
bool writeHead = true;
if (File.Exists(recpath))
{
writeHead = false;
}
fs = new FileStream(recpath, FileMode.Append);
if (writeHead)
{
byte[] wavhead = new byte[] { 0x52, 0x49, 0x46, 0x46, 0xFF, 0xFF, 0xFF, 0xFF, 0x57, 0x41, 0x56, 0x45, 0x66, 0x6D, 0x74, 0x20, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x40, 0x1F, 0x00, 0x00, 0x80, 0x3E, 0x00, 0x00, 0x02, 0x00, 0x10, 0x00, 0x64, 0x61, 0x74, 0x61, 0xFF, 0xFF, 0xFF, 0xFF };
fs.Write(wavhead, 0, wavhead.Length);
}
recordOpen = true;
}
}
public void record(byte[] pcm)
{
fs.Write(pcm, 0, pcm.Length);
}
public void recordClose()
{
lock (recordLock)
{
if (!recordOpen) return;
fs.Close();
recordOpen = false;
}
}
}
public static class gnuradio
{
public static string addr;
public static double basefreq;
public static double ppm_corr;
public static double samp_rate;
public static double sdr_gain;
public static double sdr_ifgain;
public static int receivers;
public static string title;
public static double cbw = 12500;
public static bool baselock = false;
private static object sendreq(bool method, string varname, object value = null)
{
// send XML RPC request
string kver;
if (method)
{
string typ;
switch (Type.GetTypeCode(value.GetType()))
{
case TypeCode.Int16:
case TypeCode.Int32:
case TypeCode.Int64:
case TypeCode.UInt16:
case TypeCode.UInt32:
case TypeCode.UInt64:
typ = "int";
break;
case TypeCode.Double:
typ = "double";
break;
case TypeCode.Boolean:
typ = "boolean";
break;
default:
typ = "string";
value = value.ToString();
break;
}
kver = string.Format("<?xml version=\"1.0\"?><methodCall> <methodName>set_{0}</methodName><params><param><value><{1}>{2}</{1}></value></param></params></methodCall>\n", varname, typ, value);
}
else
{
kver = string.Format("<?xml version=\"1.0\"?><methodCall> <methodName>get_{0}</methodName></methodCall>\n", varname);
}
WebClient wc = new WebClient();
wc.Headers.Add("Content-Type", "text/xml");
string vystup = Encoding.ASCII.GetString(wc.UploadData(addr, Encoding.ASCII.GetBytes(kver)));
XmlDocument xd = new XmlDocument();
xd.LoadXml(vystup);
XmlNode chyba = xd.SelectSingleNode("/methodResponse/fault");
object oval = null;
if (chyba == null)
{
// no problem
if (method)
return true;
XmlNode respn = xd.SelectSingleNode("/methodResponse/params/param/value");
XmlNode respt = respn.FirstChild;
string otyp = respt.Name;
string cont = respt.InnerText;
switch (otyp)
{
case "string":
oval = cont;
break;
case "int":
oval = int.Parse(cont);
break;
case "double":
oval = double.Parse(cont, CultureInfo.InvariantCulture);
break;
case "boolean":
oval = bool.Parse(cont);
break;
}
}
else
{
if (method)
return false;
}
return oval;
}
public static bool setval(string varname, object varvalue)
{
// set GNU Radio value
return (bool)sendreq(true, varname, varvalue);
}
public static object getval(string varname)
{
// Read GNU Radio value
return sendreq(false, varname);
}
public static bool baseSet(double nfreq)
{
// Set baseband frequency
bool vysl = setval("freq", nfreq);
if (vysl)
{
basefreq = nfreq;
}
return vysl;
}
public static bool getSampRate()
{
// Get tuner sample rate
object srate = getval("samp_rate");
if (srate != null)
{
samp_rate = Convert.ToDouble(srate);
return true;
}
else
{
return false;
}
}
public static bool getBaseFreq()
{
// Get tuner baseband frequency
object freqval = getval("freq");
if (freqval != null)
{
basefreq = Convert.ToDouble(freqval);
return true;
}
else
{
return false;
}
}
public static bool getReceivers()
{
// Get receiver count
object rxcount = getval("telive_receiver_channels");
if (rxcount != null)
{
receivers = (int)rxcount;
return true;
}
else
{
return false;
}
}
public static bool getTitle()
{
// Get project title
object titl = getval("telive_receiver_name");
if (titl != null)
{
title = (string)titl;
return true;
}
else
{
return false;
}
}
public static void init(string naddr, ushort nport)
{
// Initialize GNU Radio URL and some data structures
addr = string.Format("http://{0}:{1}/", naddr, nport);
getTitle();
getBaseFreq();
getSampRate();
getReceivers();
}
public static bool freqIsOver(double qfreq, IEnumerable<double> oldfreqs)
{
return (qfreq > oldfreqs.Max());
}
public static bool freqIsUnder(double qfreq, IEnumerable<double> oldfreqs)
{
return (qfreq < oldfreqs.Min());
}
public static bool freqFitsToBase(double nfreq)
{
// Does frequency fit into currently tuned baseband?
// (i.e. can we listen to it without changing the base frequency?)
double noff = nfreq - basefreq;
double maxdiff = (samp_rate / 2) - cbw;
return (Math.Abs(noff) <= maxdiff);
}
public static bool freqsFitToBandwidth(IEnumerable<double> freqs)
{
// Are all specified frequencies within single bandwidth?
// (i.e. can we tune them all together?)
bool fits = false;
if (freqs.Count() > 0)
{
double min = freqs.Min();
double max = freqs.Max();
double range = max - min;
fits = range <= samp_rate - 2 * cbw;
}
return fits;
}
public static double freqsCenter(IEnumerable<double> freqs)
{
// Return exact center of specified frequencies
if (freqs.Count() > 0)
{
return (freqs.Max() + freqs.Min()) / 2;
}
// Or nothing if there are none
return -1;
}
public static double baseCalc(double nfreq, IEnumerable<double> neededfreqs, bool allowRxLoss)
{
// Calculate new baseband frequency that covers all specified frequencies optimally
// Will return -1 if that's not possible (all freqs don't fit bandwidth)
double nbase = 0;
if (neededfreqs.Count() > 0)
{
sbyte newpos = 0;
if (freqIsOver(nfreq, neededfreqs))
newpos = 1;
if (freqIsUnder(nfreq, neededfreqs))
newpos = -1;
neededfreqs = neededfreqs.Concat(new double[] { nfreq });
// check the list
if (freqsFitToBandwidth(neededfreqs))
{
// it fits
nbase = freqsCenter(neededfreqs);
// this also means that newpos = 0, just sayin... :D
}
else
{
// not possible without losing some channels
if (allowRxLoss)
{
// this will cut the currently used freuqencies list until
// the list + the new freq fit within one baseband
do
{
if (newpos == 1)
{
double fmin = neededfreqs.Min();
neededfreqs = neededfreqs.Where(w => w != fmin);
}
else
if (newpos == -1)
{
double fmax = neededfreqs.Max();
neededfreqs = neededfreqs.Where(w => w != fmax);
}
} while (!freqsFitToBandwidth(neededfreqs));
// ok, now we have a frequency list that was stripped of some border freqencies
// and contains the rest AND the new frequency
nbase = freqsCenter(neededfreqs);
}
else
{
// just return that it's impossible
nbase = -1;
}
}
}
else
{
// spot on the new freq
nbase = nfreq;
}
return nbase;
}
public static double lowestValidFreq()
{
// gets the lower tunable frequency of current baseband
// (with proper rounding to 100KHz's)
double lvf = basefreq - (samp_rate / 2);
int roundbase = 100000;
long rnd = (long)lvf / roundbase;
lvf = rnd * roundbase;
while (!freqFitsToBase(lvf))
{
lvf += cbw;
}
return lvf;
}
public static double lowRange()
{
return basefreq - samp_rate / 2;
}
public static double HighRange()
{
return basefreq + samp_rate / 2;
}
}
public static class settings
{
public static double allScanLow = 424000000;
public static double allScanHigh = 428000000;
public static int allScanTime = 500;
public static int bandScanTime = 1000;
public static int timeoutUsiExist = 30000;
public static int timeoutUsiActive = 10000;
public static int timeoutUsiPlay = 2000;
public static int timeoutSsiExist = 20000;
public static int timeoutRxTuned = 60000;
}
public static class telive
{
public enum addr_type : ushort
{
NULL = 0,
SSI = 1,
EVENT_LABEL = 2,
USSI = 3,
SMI = 4,
SSI_EVENT = 5,
SSI_USAGE = 6,
SMI_EVENT = 7,
};
public enum freq_reason : ushort
{
NETINFO = 0,
FREQINFO = 1,
DLFREQ = 2,
SCANNED = 3,
UNKNOWN = 99
}
public enum rx_mode : ushort
{
OFF = 0, // receiver is considered disabled
TUNED = 1, // receiver is tunned to a channel
ALLSCAN = 2, // ALL receivers are progressively scanning defined range
BANDSCAN = 3 // receiver is loop-scanning within currently tuned baseband
}
public class receiver
{
public ushort id { get; }
public int afc { get; set; }
public double freq { get { return gnuradio.basefreq + offset; } }
public double freqFix;
public double offset;
public DateTime lastseen { get; set; }
public DateTime lastburst { get; set; }
public DateTime firstTuned;
public rx_mode mode;
public string state
{
get
{
switch (mode)
{
case rx_mode.OFF:
return "OFF";
case rx_mode.TUNED:
return "tuned";
case rx_mode.ALLSCAN:
return "scan";
case rx_mode.BANDSCAN:
return "band scan";
default:
return "unknown";
}
}
}
public uint master;
public acelp spl;
public receiver(ushort newid)
{
id = newid;
mode = rx_mode.OFF;
spl = new acelp(this);
}
public bool getOffset()
{
// get current offset against baseband
object offval = gnuradio.getval(string.Format("xlate_offset{0}", id));
if (offval != null)
{
double boffs = Convert.ToDouble(offval);
offset = boffs;
return true;
}
else
{
return false;
}
}
public bool setOffset(double noff)
{
// set current offset against baseband
bool vysl = gnuradio.setval(string.Format("xlate_offset{0}", id), noff);
if (vysl)
{
offset = noff;
freqRefDel();
if (mode == rx_mode.TUNED)
{
firstTuned = DateTime.Now;
freqRefAdd();
}
}
return vysl;
}
public void setAfc(int newafc)
{
// just log AFC value
afc = newafc;
}
public void seenBurst()
{
// a burst has been received on the receiver
lastburst = DateTime.Now;
}
public void seen()
{
// receiver is seen alive (whether tuned to a signal or not)
lastseen = DateTime.Now;
}
public bool tuneOOR()
{
// make the receiver quiet by tuning it out of receiving range
return setOffset(gnuradio.samp_rate);
}
public void setMode(rx_mode nmode)
{
// set mode of receiver
mode = nmode;
switch (mode)
{
case rx_mode.OFF:
firstTuned = default(DateTime);
freqRefDel();
break;
case rx_mode.TUNED:
firstTuned = DateTime.Now;
freqRefAdd();
break;
}
}
public void freqRefAdd()
{
foreach (frequency fr in freqs.Where(w => w.dl_freq == freq))
{
fr.tuned(id);
}
}
public void freqRefDel()
{
lastburst = default(DateTime);
foreach (frequency fr in freqs.Where(w => w.tunedrx == id).ToList())
{
fr.detuned();
}
}
public bool setFreq(double nfreq)
{
// just overlay method for setting offset
double noff = nfreq - gnuradio.basefreq;
bool vysledek = setOffset(noff);
if (vysledek)
{
updateFix();
}
return vysledek;
}
public void updateFix()
{
// what we have is what we want
freqFix = freq;
}
public bool applyFix()
{
// tune receiver to what we want
bool vysledek = true;
if (freq != freqFix)
{
vysledek = setFreq(freqFix);
}
return vysledek;
}
}
public class usi
{
public ushort id { get; }
public List<ssi> ssis;
public string ssilist { get { return string.Join(", ", ssis.Select(w => w.id).ToArray()); } }
public bool encr { get; set; }
public bool active { get; set; }
public bool playing { get; set; }
public DateTime lastseen { get; set; }
public DateTime lastplay { get; set; }
public ushort cid { get; set; }
public ushort lastrx { get; set; }
public usi(ushort newid)
{
id = newid;
ssis = new List<ssi>();
encr = false;
active = false;
playing = false;
}
public void seen(ushort rx)
{
// this USI has been seen on receiver rx
lastseen = DateTime.Now;
lastrx = rx;
activate();
}
public void addssi(uint nssi)
{
// a SSI has been seen
if (nssi == 0) return;
if (!ssis.Any(w => w.id == nssi))
{
ssi nsio = new ssi(nssi);
nsio.seen();
ssis.Add(nsio);
}
}
public void removessi(uint ossi)
{
// ssi is being forgotten
ssis.RemoveAll(w => w.id == ossi);
}
public void addcid(ushort ncid)
{
// calledid has been seen
if (ncid == 0) return;
cid = ncid;
}
public void activate()
{
// there is an activity on this USI
active = true;
}
public void play(ushort rxid)
{
// there is a voice comming from this USI
playing = true;
lastplay = DateTime.Now;
}
public void stop()
{
// voice ceased
playing = false;
}
public void deactivate()
{
// USI forgotten
active = false;
}
}
public class ssi
{
public uint id;
public DateTime lastseen;
public ssi(uint nid)
{
id = nid;
}
public void seen()
{
// SSI activity
lastseen = DateTime.Now;
}
}
public class frequency
{
public uint mcc { get; set; }
public uint mnc { get; set; }
public double dl_freq { get; }
public double ul_freq { get; }
public List<uint> la;
public string lalist { get { return string.Join(", ", la.ToArray()); } }
public List<ushort> ccode;
public string cclist { get { return string.Join(", ", ccode.ToArray()); } }
public freq_reason reason;
public ushort tunedrx { get; set; }
public DateTime lastuned;
public frequency(uint nmcc, uint nmnc, double dlf, double ulf, uint nla, ushort ncc, freq_reason nreason)
{
mcc = nmcc;
mnc = nmnc;
dl_freq = dlf;
ul_freq = ulf;
la = new List<uint> { nla };
ccode = new List<ushort> { ncc };
reason = nreason;
tunedrx = 0;
}
public void tuned(ushort rx)
{
// frequency has been tuned on receiver
tunedrx = rx;
lastuned = DateTime.Now;
}
public void detuned()
{
// frequency has been detuned form receiver
tunedrx = 0;
}
public void addla(uint nla)
{
// detected new LA for this frequency
if (!la.Contains(nla))
la.Add(nla);
}
public void addcc(ushort ncc)
{
// detected new CCODE for this frequency
if (!ccode.Contains(ncc))
ccode.Add(ncc);
}
}
public class allScanner
{
// all receivers scanning defined range
public double startfreq;
public double stopfreq;
private System.Timers.Timer tmrScan = new System.Timers.Timer(settings.allScanTime);
private object scanLock;
public allScanner(double lf, double uf)
{
startfreq = lf;
stopfreq = uf;
scanLock = new object();
}
public void start()
{
lock (scanLock)
{
for (ushort i = 1; i <= gnuradio.receivers; i++)
{
receiver rx = rxs.FirstOrDefault(w => w.id == i);
rx.setMode(rx_mode.OFF);
}
double nbase = startfreq + (gnuradio.receivers / 2) * gnuradio.cbw;
baseSetSafe(nbase);
for (ushort i = 1; i <= gnuradio.receivers; i++)
{
if (rxTune(i, nbase + (i - 6) * gnuradio.cbw))
rxs.FirstOrDefault(w => w.id == i).setMode(rx_mode.ALLSCAN);
}
}
tmrScan.Elapsed += new ElapsedEventHandler(tmrScan_tick);
tmrScan.Enabled = true;
}
public void step()
{
double nbase;
lock (scanLock)
{
nbase = gnuradio.basefreq + gnuradio.receivers * gnuradio.cbw;
baseSetSafe(nbase);
}
if (nbase + (gnuradio.receivers / 2) * gnuradio.cbw > stopfreq)
{
stop();
}
}
public void stop()
{
lock (scanLock)
{
tmrScan.Enabled = false;
foreach (receiver rx in rxs.Where(w => w.mode == rx_mode.ALLSCAN))
{
rx.setMode(rx_mode.OFF);
}
}
}
public void tmrScan_tick(object source, ElapsedEventArgs e)
{
step();
}
}
public class bandScanner
{
public ushort scanRx;
private System.Timers.Timer tmrScan = new System.Timers.Timer(settings.bandScanTime);
private object scanLock;
public bandScanner(ushort rx)
{
scanRx = rx;
scanLock = new object();
}