-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.c
2183 lines (2114 loc) · 68.7 KB
/
menu.c
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
// Copyright (c) <2012> <Leif Asbrink>
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify,
// merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE.
#include <ctype.h>
#include <string.h>
#include "globdef.h"
#if(OSNUM == OSNUM_WINDOWS)
#include "wscreen.h"
#include <winsock.h>
#define INVSOCK INVALID_SOCKET
extern HANDLE savefile_handle;
#endif
#if(OSNUM == OSNUM_LINUX)
#define INVSOCK -1
#include "loadalsa.h"
#include "lscreen.h"
int alsa_get_native_samplerate(int n,int mode,int *line,unsigned int *new_sampling_rate);
#endif
#include "uidef.h"
#include "fft1def.h"
#include "fft2def.h"
#include "screendef.h"
#include "powtdef.h"
#include "vernr.h"
#include "sigdef.h"
#include "seldef.h"
#include "thrdef.h"
#include "sdrdef.h"
#include "caldef.h"
#include "keyboard_def.h"
#include "txdef.h"
#include "options.h"
#include "hwaredef.h"
#include "fft3def.h"
#include "padef.h"
char *parfilnam;
int uiparm_save[MAX_UIPARM];
int dirflag, iqflag;
int first_txproc_no;
int zzr;
void rx_adtest_routine(void)
{
usercontrol_mode=USR_ADTEST;
genparm[SECOND_FFT_ENABLE]=0;
get_wideband_sizes();
if(kill_all_flag)return;
get_buffers(1);
if(kill_all_flag || lir_status != LIR_OK)return;
init_semaphores();
linrad_thread_create(rx_input_thread);
lir_sleep(100000);
if(lir_status != LIR_OK) {
lir_join(rx_input_thread);
goto adtest_x;
}
if(kill_all_flag) goto adtest_x;
linrad_thread_create(THREAD_USER_COMMAND);
if(kill_all_flag) goto adtest_x;
linrad_thread_create(THREAD_RX_ADTEST);
lir_sleep(50000);
lir_refresh_screen();
all_threads_started=TRUE;
lir_join(THREAD_USER_COMMAND);
linrad_thread_stop_and_join(rx_input_thread);
linrad_thread_stop_and_join(THREAD_RX_ADTEST);
adtest_x:
;
free_semaphores();
}
void txtest_routine(void)
{
int i;
usercontrol_mode=USR_TXTEST;
if(diskread_flag != 0) {
lirerr(1158);
return;
}
if( (ui.rx_input_mode&IQ_DATA) != 0) {
ui.rx_ad_channels=2;
} else {
ui.rx_ad_channels=1;
}
ui.rx_input_mode&=-1-TWO_CHANNELS;
ui.rx_rf_channels=1;
genparm[AFC_ENABLE]=0;
genparm[SECOND_FFT_ENABLE]=0;
get_wideband_sizes();
if(kill_all_flag) return;
// Open the graph windows on the screen.
// Note that they must be opened in this order because
// Each window is placed outside the previous ones and the init
// routines assumes the order below and does not check for all possible
// conflicts.
get_buffers(1);
if(kill_all_flag)return;
if(lir_status != LIR_OK)return;
read_freq_control_data();
init_semaphores();
init_wide_graph();
if(kill_all_flag) goto txtest_x;
for(i=0; i<txtest_no_of_segs*wg.spek_avgnum; i++)txtest_power[i]=0;
if(lir_status != LIR_OK)goto txtest_x;
init_freq_control();
phasing_init_mode();
show_name_and_size();
settextcolor(7);
new_baseb_flag=-1;
ampinfo_flag=1;
linrad_thread_create(rx_input_thread);
lir_sleep(100000);
if(lir_status != LIR_OK) {
lir_join(rx_input_thread);
goto txtest_x;
}
if(kill_all_flag) goto txtest_x;
linrad_thread_create(THREAD_USER_COMMAND);
if(kill_all_flag) goto txtest_x;
linrad_thread_create(THREAD_TXTEST);
if(kill_all_flag) goto txtest_x;
linrad_thread_create(THREAD_WIDEBAND_DSP);
if(kill_all_flag) goto txtest_x;
linrad_thread_create(THREAD_SCREEN);
fft1_waterfall_flag=1;
lir_refresh_screen();
all_threads_started=TRUE;
lir_join(THREAD_USER_COMMAND);
linrad_thread_stop_and_join(rx_input_thread);
linrad_thread_stop_and_join(THREAD_WIDEBAND_DSP);
linrad_thread_stop_and_join(THREAD_TXTEST);
linrad_thread_stop_and_join(THREAD_SCREEN);
free_semaphores();
if(kill_all_flag)return;
if(lir_status == LIR_POWTIM) {
usercontrol_mode=USR_POWTIM;
free_buffers();
if(kill_all_flag)return;
clear_screen();
genparm[SECOND_FFT_ENABLE]=1;
genparm[FIRST_BCKFFT_VERNR]=0;
genparm[SECOND_FFT_VERNR]=0;
genparm[FIRST_FFT_SINPOW] = 2;
genparm[SECOND_FFT_SINPOW] = 2;
genparm[AFC_ENABLE]=0;
get_wideband_sizes();
if(kill_all_flag)return;
get_buffers(1);
if(kill_all_flag)return;
set_fft1_endpoints();
if(kill_all_flag)return;
if(lir_status != LIR_POWTIM)return;
genparm[SECOND_FFT_ENABLE]=0;
fft1_waterfall_flag=0;
init_semaphores();
linrad_thread_create(rx_input_thread);
i=0;
while(i<200 && lir_status != LIR_OK) {
i++;
lir_sleep(50000);
}
if(lir_status != LIR_OK) {
lir_join(rx_input_thread);
goto txtest_x;
}
if(kill_all_flag) goto txtest_x;
linrad_thread_create(THREAD_USER_COMMAND);
if(kill_all_flag) goto txtest_x;
linrad_thread_create(THREAD_POWTIM);
if(kill_all_flag) goto txtest_x;
linrad_thread_create(THREAD_WIDEBAND_DSP);
lir_sleep(50000);
fft1_waterfall_flag=0;
lir_refresh_screen();
all_threads_started=TRUE;
lir_join(THREAD_USER_COMMAND);
linrad_thread_stop_and_join(THREAD_POWTIM);
linrad_thread_stop_and_join(rx_input_thread);
linrad_thread_stop_and_join(THREAD_WIDEBAND_DSP);
clear_keyboard();
} else {
return;
}
txtest_x:
;
free_semaphores();
}
void normal_rx_routine(void)
{
char s[256];
int i, k, m;
int local_block_cnt;
int no_input_flag;
int wlcnt, wlcnt_max, local_workload_reset;
double total_time1, total_time2;
double cpu_time1, cpu_time2;
lir_set_title(rxmodes[rx_mode]);
workload_counter=0;
workload=-1;
computation_pause_flag=0;
usercontrol_mode=USR_NORMAL_RX;
#if OSNUM == OSNUM_LINUX
for (i = 0; i<THREAD_MAX; i++)
thread_pid[i] = 0;
#endif
init_semaphores();
if(kill_all_flag)
goto normal_rx_x;
get_wideband_sizes();
if(kill_all_flag)
goto normal_rx_x;
get_buffers(1);
if (kill_all_flag || lir_status != LIR_OK)
goto normal_rx_x;
if (! freq_from_file)
read_freq_control_data();
check_filtercorr_direction();
init_wide_graph();
if (genparm[SECOND_FFT_ENABLE] != 0)
init_blanker();
if (kill_all_flag || lir_status != LIR_OK)
goto normal_rx_x;
if (genparm[SECOND_FFT_ENABLE] != 0) {
init_hires_graph();
if(kill_all_flag || lir_status != LIR_OK)
goto normal_rx_x;
}
if(genparm[AFC_ENABLE] != 0) {
init_afc_graph();
if (kill_all_flag || lir_status != LIR_OK)
goto normal_rx_x;
}
if (ui.rx_rf_channels == 2) {
init_pol_graph();
if (kill_all_flag || lir_status != LIR_OK)
goto normal_rx_x;
}
init_baseband_graph();
if (kill_all_flag || lir_status != LIR_OK)
goto normal_rx_x;
init_coherent_graph();
if (kill_all_flag || lir_status != LIR_OK)
goto normal_rx_x;
if (ui.operator_skil != OPERATOR_SKIL_NEWCOMER && eme_flag != 0) {
init_eme_graph();
if (kill_all_flag || lir_status != LIR_OK)
goto normal_rx_x;
}
if (! freq_from_file) {
init_freq_control();
if (kill_all_flag || lir_status != LIR_OK)
goto normal_rx_x;
}
if (use_tx != 0)
init_tx_graph();
if (lir_status != LIR_OK) goto normal_rx_x;
phasing_init_mode();
if (kill_all_flag || lir_status != LIR_OK) goto normal_rx_x;
show_name_and_size();
lir_refresh_screen();
fft3_show_time=current_time();
fft1_show_time=fft3_show_time;
sys_func(THRFLAG_PORTAUDIO_STARTSTOP);
if(kill_all_flag) goto normal_rx_x;
linrad_thread_create(THREAD_USER_COMMAND);
if(kill_all_flag) goto normal_rx_x;
linrad_thread_create(THREAD_NARROWBAND_DSP);
if(kill_all_flag) goto normal_rx_x;
linrad_thread_create(THREAD_WIDEBAND_DSP);
if(kill_all_flag) goto normal_rx_x;
linrad_thread_create(THREAD_SCREEN);
if(kill_all_flag) goto normal_rx_x;
// Make sure that all the threads are running before
// opening inputs in order to avoid overrun errors.
// Some system calls they might do could cause overrun
// errors if the input were open.
while (thread_status_flag[THREAD_RX_OUTPUT]!=THRFLAG_SEMCLEAR &&
thread_status_flag[THREAD_USER_COMMAND]!=THRFLAG_ACTIVE &&
thread_status_flag[THREAD_NARROWBAND_DSP]!=THRFLAG_SEM_WAIT &&
thread_status_flag[THREAD_WIDEBAND_DSP]!=THRFLAG_ACTIVE ) {
if (kill_all_flag) goto normal_rx_x;
lir_sleep(3000);
}
mailbox[0]=0;
mailbox[1]=0;
mailbox[2]=0;
if(kill_all_flag) goto normal_rx_x;
linrad_thread_create(rx_input_thread);
i=0;
while (!kill_all_flag && thread_status_flag[rx_input_thread] != THRFLAG_ACTIVE) {
lir_sleep(10000);
if(++ i > 1000) {
lirerr(1450);
goto normal_rx_x;
}
}
if(kill_all_flag) goto normal_rx_x;
display_rx_input_source(s);
linrad_thread_create(THREAD_RX_OUTPUT);
i=0;
while (! kill_all_flag && thread_status_flag[THREAD_RX_OUTPUT] != THRFLAG_ACTIVE) {
lir_sleep(3000);
if(++ i > 1000)
lirerr(116711);
}
if(kill_all_flag) goto normal_rx_x;
thread_command_flag[THREAD_RX_OUTPUT]=THRFLAG_IDLE;
i=0;
while (! kill_all_flag && thread_status_flag[THREAD_RX_OUTPUT] != THRFLAG_IDLE) {
lir_sleep(20000);
if(++ i > 2000) {
lirerr(1167);
goto normal_rx_x;
}
}
if(kill_all_flag) goto normal_rx_x;
thread_command_flag[THREAD_RX_OUTPUT]=THRFLAG_SEMCLEAR;
while (thread_status_flag[THREAD_RX_OUTPUT] != THRFLAG_SEMCLEAR) {
if(kill_all_flag) goto normal_rx_x;
lir_sleep(3000);
}
#if SHOW_HARDWARE == TRUE
lir_text(25,screen_last_line,s);
#endif
lir_sleep(100000);
if (lir_status != LIR_OK) {
linrad_thread_stop_and_join(THREAD_USER_COMMAND);
goto normal_rx_join;
}
if(kill_all_flag) goto normal_rx_x;
if (use_tx) {
switch (rx_mode) {
case MODE_SSB:
init_txmem_spproc();
break;
case MODE_WCW:
case MODE_NCW:
case MODE_HSMS:
case MODE_QRSS:
init_txmem_cwproc();
break;
}
if(kill_all_flag)goto normal_rx_x;
linrad_thread_create(THREAD_TX_OUTPUT);
while (thread_status_flag[THREAD_TX_OUTPUT] != THRFLAG_ACTIVE) {
if(kill_all_flag) goto normal_rx_x;
lir_sleep(3000);
}
if(kill_all_flag) goto normal_rx_x;
lir_refresh_screen();
linrad_thread_create(THREAD_TX_INPUT);
while(thread_status_flag[THREAD_TX_INPUT]!=THRFLAG_ACTIVE) {
if(kill_all_flag) goto normal_rx_x;
lir_sleep(3000);
}
}
lir_refresh_screen();
lir_sched_yield();
#if OSNUM == OSNUM_WINDOWS
if(ui.timer_resolution > 0)timeBeginPeriod(ui.timer_resolution);
#endif
fft1_waterfall_flag=1;
setup_thread_affinities();
lir_sleep(50000);
if(kill_all_flag) goto normal_rx_x;
lir_refresh_screen();
all_threads_started=TRUE;
while (! kill_all_flag && thread_status_flag[rx_input_thread]!=THRFLAG_ACTIVE)
lir_sleep(3000);
rxin_block_counter=0;
i=0;
k=0;
wlcnt_max=1+snd[RXAD].interrupt_rate;
wlcnt=wlcnt_max;
local_workload_reset=workload_reset_flag;
lir_system_times(&cpu_time1, &total_time1);
#if OSNUM == OSNUM_LINUX
current_time();
for(i=0; i<THREAD_MAX; i++) {
thread_tottim1[i]=recent_time;
thread_cputim1[i]=0;
}
#endif
local_block_cnt=0;
no_input_flag=FALSE;
while(! kill_all_flag &&
thread_status_flag[THREAD_USER_COMMAND]==THRFLAG_ACTIVE &&
thread_status_flag[rx_input_thread] != THRFLAG_RETURNED) {
m=20;
lir_sleep(50000);
while(!kill_all_flag && m>0 && rxin_block_counter == local_block_cnt) {
m--;
if(local_workload_reset != workload_reset_flag)goto loadprt;
lir_sleep(50000);
}
if ((diskread_flag < 2 || diskread_pause_flag==0) && rxin_block_counter == local_block_cnt/* && local_block_cnt==0*/) {
wlcnt=wlcnt_max;
sprintf(s,"No input %d",k);
no_input_flag=TRUE;
lir_text(20,screen_last_line,s);
lir_refresh_screen();
}
if (diskwrite_flag)
lir_sync();
wlcnt-=rxin_block_counter-local_block_cnt;
if (wlcnt <= 0) {
if(no_input_flag) {
memset(s,' ',20);
s[20]=0;
lir_text(20,screen_last_line,s);
no_input_flag=FALSE;
}
loadprt:
;
fix_thread_affinities();
wlcnt=wlcnt_max;
// *******************************************************************
// Compute the workload. We should arrive here at a rate of about 1 Hz.
// Modern Linux kernels (2.6.8 or 2.6.9 and later) as well as Windows
// allow us to compute the work load from here.
current_time();
for (i=0; i<THREAD_MAX; i++) {
#if OSNUM == OSNUM_LINUX
if(thread_pid[i] != 0)
#endif
#if OSNUM == OSNUM_WINDOWS
if(thread_command_flag[i]!=THRFLAG_NOT_ACTIVE)
#endif
{
thread_tottim2[i]=recent_time;
thread_cputim2[i]=lir_get_thread_time(i);
thread_workload[i]=100*(thread_cputim2[i]-thread_cputim1[i])/
(thread_tottim2[i]-thread_tottim1[i]);
}
}
lir_system_times(&cpu_time2, &total_time2);
workload=100*(cpu_time2-cpu_time1)/(total_time2-total_time1);
#if OSNUM == OSNUM_LINUX
workload/=no_of_processors;
#endif
if(workload<0)workload=0;
#if OSNUM == OSNUM_LINUX
lir_fix_bug(1);
#endif
if(local_workload_reset != workload_reset_flag) {
local_workload_reset=workload_reset_flag;
total_time1=total_time2;
cpu_time1=cpu_time2;
for (i=0; i<THREAD_MAX; i++) {
if(thread_command_flag[i] != THRFLAG_NOT_ACTIVE) {
thread_tottim1[i]=thread_tottim2[i];
thread_cputim1[i]=thread_cputim2[i];
}
}
}
workload_counter++;
awake_screen();
}
if (++ k==10000)
k = 1;
local_block_cnt=rxin_block_counter;
}
lir_join(THREAD_USER_COMMAND);
if(diskwrite_flag != 0) disksave_stop();
#if OSNUM == OSNUM_WINDOWS
if(ui.timer_resolution > 0)timeEndPeriod(ui.timer_resolution);
#endif
if(use_tx != 0) {
linrad_thread_stop_and_join(THREAD_TX_INPUT);
linrad_thread_stop_and_join(THREAD_TX_OUTPUT);
close_tx_sndin();
close_tx_sndout();
if (txmem_handle != NULL)free(txmem_handle);
txmem_handle = NULL;
lir_close_event(EVENT_TX_INPUT);
}
normal_rx_join:
;
linrad_thread_stop_and_join(THREAD_RX_OUTPUT);
linrad_thread_stop_and_join(rx_input_thread);
linrad_thread_stop_and_join(THREAD_SCREEN);
linrad_thread_stop_and_join(THREAD_NARROWBAND_DSP);
linrad_thread_stop_and_join(THREAD_WIDEBAND_DSP);
normal_rx_x:
;
free_semaphores();
}
void prompt_reason(char *s)
{
clear_screen();
lir_text(5,8,"You are prompted to the parameter selection screens");
lir_text(15,10,"for the following reason:");
lir_text(5,13,s);
lir_text(20,16,press_any_key);
clear_keyboard();
await_keyboard();
}
void check_output_no_of_channels(void)
{
int i;
i=1+((genparm[OUTPUT_MODE]>>1)&1);
if(i<ui.rx_min_da_channels)i=ui.rx_min_da_channels;
if(i>ui.rx_max_da_channels)i=ui.rx_max_da_channels;
i--;
genparm[OUTPUT_MODE]&=-3;
genparm[OUTPUT_MODE]|=i<<1;
}
void fix_limits(int *out_max, int *out_min, int parnum)
{
int i;
*out_max = genparm_max[parnum];
*out_min = genparm_min[parnum];
switch (parnum) {
case FIRST_FFT_VERNR:
fft1mode=(ui.rx_input_mode&(TWO_CHANNELS+IQ_DATA))/2;
for (i = 0; fft1_version[fft1mode][i+1] >= 0 && i+1 < MAX_FFT1_VERNR; ++ i);
*out_max = i;
break;
case FIRST_BCKFFT_VERNR:
for (i=0; fft1_back_version[ui.rx_rf_channels-1][i+1] > 0 && i+1 < MAX_FFT1_BCKVERNR; ++ i);
*out_max = i;
break;
case FIRST_BCKFFT_ATT_N:
*out_max = (fft1_n-4) & 0xfffe;
break;
case SECOND_FFT_ATT_N:
*out_max = fft2_n - 2;
break;
case SECOND_FFT_VERNR:
for (i = 0; fft2_version[ui.rx_rf_channels-1][i+1] > 0 && i+1 < MAX_FFT2_VERNR; ++ i);
*out_max = i;
break;
case MIX1_BANDWIDTH_REDUCTION_N:
*out_max=(genparm[SECOND_FFT_ENABLE] ? fft2_n : fft1_n) - 3;
break;
case DA_OUTPUT_SPEED:
*out_min = ui.rx_min_da_speed;
*out_max = ui.rx_max_da_speed;
break;
case MAX_NO_OF_SPURS:
*out_max = genparm[AFC_ENABLE] ?
2 * (genparm[SECOND_FFT_ENABLE] ? fft2_size : fft1_size) / SPUR_WIDTH :
0;
break;
case SPUR_TIMECONSTANT:
*out_max = 5 * genparm[genparm[SECOND_FFT_ENABLE] ? FFT2_STORAGE_TIME : FFT1_STORAGE_TIME];
break;
}
// In case fft sizes are not set.
if(*out_max < *out_min || *out_min < genparm_min[parnum] || *out_max > genparm_max[parnum]) {
*out_max = genparm_max[parnum];
*out_min = genparm_min[parnum];
}
}
void modify_parms(char *line1, int first, int last)
{
unsigned int new_sample_rate;
char s[80];
int line1_len, line;
int i, j, k, m, no, mouse_line,parnum;
line1_len=strlen(line1)+8;
no=last-first+1;
start:
;
hide_mouse(0,screen_width,0,screen_height);
clear_screen();
settextcolor(14);
lir_text(5,1, line1);
// Make sure fft1_n and fft2_n are defined and
// in agreement with current parameters.
get_wideband_sizes();
if( first <= FIRST_FFT_SINPOW && last >= FIRST_FFT_SINPOW) {
sprintf(s,"fft1 size=%d (Bw=%fHz) %s",fft1_size,fft1_bandwidth,
fft_cntrl[FFT1_CURMODE].text);
lir_text(line1_len,1,s);
}
if( first <= SECOND_FFT_SINPOW && last >= SECOND_FFT_SINPOW) {
sprintf(s,"fft2 size=%d (Bw=%fHz)",fft2_size,fft2_bandwidth);
lir_text(line1_len,1,s);
}
if(kill_all_flag) return;
if( first <= DA_OUTPUT_SPEED && last >= DA_OUTPUT_SPEED) {
if(genparm[DA_OUTPUT_SPEED] < ui.rx_min_da_speed)
genparm[DA_OUTPUT_SPEED]=ui.rx_min_da_speed;
if(genparm[DA_OUTPUT_SPEED] > ui.rx_max_da_speed)
genparm[DA_OUTPUT_SPEED]=ui.rx_max_da_speed;
}
if( first <= CW_DECODE_ENABLE && last >= CW_DECODE_ENABLE) {
if(rx_mode==MODE_WCW || rx_mode==MODE_NCW || rx_mode==MODE_HSMS) {
if(genparm[CW_DECODE_ENABLE] != 0) {
settextcolor(12);
lir_text(1,14,"WARNING: The Morse decode routines are incomplete.");
lir_text(1,15,"They will not produce any useful output and may cause");
lir_text(1,16,"a program crasch. Use only for development and perhaps");
lir_text(1,17,"for some evaluation of chirp and other keying defects");
lir_text(1,18,"with the coherent graph oscilloscope.");
}
} else {
genparm[CW_DECODE_ENABLE]=0;
}
}
if( first <= FIRST_BCKFFT_ATT_N && last >= FIRST_BCKFFT_ATT_N) {
k=(fft1_n-4)&0xfffe;
if(genparm[FIRST_BCKFFT_ATT_N]>k)genparm[FIRST_BCKFFT_ATT_N]=k;
if(genparm[FIRST_BCKFFT_ATT_N]<0)genparm[FIRST_BCKFFT_ATT_N]=
genparm_min[FIRST_BCKFFT_ATT_N];
}
if( first <= SECOND_FFT_ATT_N && last >= SECOND_FFT_ATT_N) {
k=fft2_n-2;
if(genparm[SECOND_FFT_ATT_N]>k)genparm[SECOND_FFT_ATT_N]=k;
}
settextcolor(7);
line=0;
for(i=0; i<no; i++) {
j=i+first;
if(ui.operator_skil == OPERATOR_SKIL_NEWCOMER && newco_genparm[j] ==0) {
settextcolor(8);
} else {
settextcolor(7);
}
sprintf(s,"%s [%d] ",genparm_text[j],genparm[j]);
lir_text(1,3+i, s);
}
lir_text(1,5+no,"Use left mouse button to select line");
lir_text(1,3+no,"CONTINUE");
settextcolor(15);
show_mouse();
modloop:
;
if( new_mouse_x!=mouse_x || new_mouse_y!=mouse_y) {
lir_move_mouse_cursor();
show_mouse();
}
lir_refresh_screen();
lir_sleep(10000);
if(new_lbutton_state==1)lbutton_state=1;
if(new_lbutton_state==0 && lbutton_state==1) {
lbutton_state=0;
mouse_line=mouse_y/text_height-3;
if(mouse_line == no)goto loopx;
if(mouse_line >= 0 && mouse_line <no) {
parnum=mouse_line+first;
clear_screen();
settextcolor(14);
lir_text(5,1, line1);
line=3;
settextcolor(15);
sprintf(s,"Old value = %d",genparm[parnum]);
lir_text(1,line, s);
line++;
lir_text(1,line,"Enter new value for:");
line++;
fix_limits(&k, &m, parnum);
sprintf(s," %s (%d to %d)",genparm_text[parnum], m,k);
lir_text(1,line, s);
i=line+1;
line+=4;
msg_filename="help.lir";
write_from_msg_file(&line, 201+mouse_line+first, TRUE, HELP_VERNR);
if(parnum == DA_OUTPUT_SPEED && ui.rx_dadev_no != DISABLED_DEVICE_CODE) {
#if(OSNUM == OSNUM_LINUX)
if (( (ui.use_alsa&NATIVE_ALSA_USED) != 0) && ((ui.use_alsa&PORTAUDIO_RX_OUT)== 0) ) {
alsa_get_native_samplerate(ui.rx_dadev_no,SND_PCM_STREAM_PLAYBACK,&line,&new_sample_rate);
genparm[parnum]=new_sample_rate;
goto modify_parms_next;
} else
#endif
{
if( (ui.use_alsa&PORTAUDIO_RX_OUT) != 0 &&
ui.rx_dadev_no != DISABLED_DEVICE_CODE) {
pa_get_valid_samplerate(ui.rx_dadev_no,RXDA,&line,&new_sample_rate);
genparm[parnum]=new_sample_rate;
goto modify_parms_next;
}
}
}
lir_text(7,i,"=>");
genparm[parnum]=lir_get_integer(10, i, 8, m,k);
modify_parms_next:
;
if(kill_all_flag) return;
if(parnum == OUTPUT_MODE)check_output_no_of_channels();
goto start;
}
}
test_keyboard();
if(kill_all_flag) return;
if(lir_inkey != 0) {
process_current_lir_inkey();
if(kill_all_flag) return;
}
if(lir_inkey == F1_KEY || lir_inkey == '!') {
mouse_line=mouse_y/text_height-3;
if(mouse_line >= 0 && mouse_line <no) {
help_message(201+mouse_line+first);
} else {
help_message(200);
}
if(kill_all_flag) return;
goto start;
}
if(lir_inkey != 10 && lir_inkey!= 'X')goto modloop;
loopx:
;
}
void set_general_parms(char *mode)
{
char s[80];
sprintf(s,"%s: Rx channels=%d",mode,ui.rx_rf_channels);
if(lir_status < LIR_OK)goto bufreduce;
setfft1:
;
if(kill_all_flag) return;
modify_parms(s, 0, SECOND_FFT_ENABLE);
if(kill_all_flag) return;
if(lir_inkey == 'X')return;
// Make sure fft1_n and fft2_n are defined and that we can
// allocate memory.
get_wideband_sizes();
if(kill_all_flag) return;
get_buffers(0);
if(kill_all_flag) return;
if(fft1_handle != NULL)fft1_handle=chk_free(fft1_handle);
if(lir_status != LIR_OK)goto bufreduce;
if(genparm[SECOND_FFT_ENABLE]==1) {
modify_parms(s, FIRST_BCKFFT_VERNR, FFT2_STORAGE_TIME);
if(kill_all_flag) return;
if(lir_inkey == 'X')return;
get_wideband_sizes();
if(kill_all_flag) return;
get_buffers(0);
if(kill_all_flag) return;
if(fft1_handle != NULL)fft1_handle=chk_free(fft1_handle);
if(lir_status != LIR_OK) {
bufreduce:
;
clear_screen();
settextcolor(15);
switch (lir_status) {
case LIR_FFT1ERR:
lir_text(5,5,"Out of memory !!!");
lir_text(10,10,"Storage times are set to minimum.");
settextcolor(14);
lir_text(10,13,"Check memory allocations in waterfall window");
lir_text(10,14,"to decide how much you may increase storage times.");
genparm[FFT1_STORAGE_TIME]=genparm_min[FFT1_STORAGE_TIME];
genparm[FFT2_STORAGE_TIME]=genparm_min[FFT2_STORAGE_TIME];
genparm[BASEBAND_STORAGE_TIME]=genparm_min[BASEBAND_STORAGE_TIME];
lir_status=LIR_OK;
break;
case LIR_SPURERR:
sprintf(s,"fft1 storage time too short for spur removal");
if(genparm[SECOND_FFT_ENABLE] != 0)s[3]='2';
lir_text(7,7,s);
lir_text(7,8,"Spur removal disabled");
genparm[MAX_NO_OF_SPURS]=0;
lir_status=LIR_OK;
break;
case LIR_NEW_SETTINGS:
goto setfft1;
}
settextcolor(7);
lir_text(10,17,"Press ESC to quit, any other key to continue");
await_processed_keyboard();
if(kill_all_flag) return;
goto setfft1;
}
}
if(ui.operator_skil != OPERATOR_SKIL_NEWCOMER) {
modify_parms(s, AFC_ENABLE, AFC_ENABLE);
if(kill_all_flag) return;
if(lir_inkey == 'X')return;
if(genparm[AFC_ENABLE] != 0)modify_parms(s, AFC_ENABLE+1, SPUR_TIMECONSTANT);
if(kill_all_flag) return;
if(lir_inkey == 'X')return;
}
modify_parms(s, MIX1_BANDWIDTH_REDUCTION_N, MAX_GENPARM-1);
if(kill_all_flag) return;
if(lir_inkey == 'X')return;
clear_screen();
}
void cal_package(void)
{
char s[80], ss[80];
int single_run;
int i, ia, ib, ic;
float t1,t2;
calibrate_flag = 1;
// **************************************************************
// Set fft1_direction positive.
// The calibration routine does not want to know if the fft1 routine
// will invert the frequency scale.
fft1_direction=1;
single_run=0;
// Get normal buffers with minimum for all parameters.
// Everything selectable becomes deselected.
// Save fft1 version, window and bandwidth.
ia=genparm[FIRST_FFT_VERNR];
ib=genparm[FIRST_FFT_SINPOW];
ic=genparm[FIRST_FFT_BANDWIDTH];
for(i=0; i<MAX_GENPARM; i++)genparm[i]=genparm_min[i];
// Select the correct fft version for the current rx_mode
// This is not really needed for versions above Linrad-01.xx
// because the approximate fft has been removed. None of the
// fft implementations contains a filter any more.
genparm[FIRST_FFT_VERNR]=ia;
// Force fft1_size to be 4 times larger than specified for the current
// rx_mode by dividing bandwidth by 4.
t2=ic/4;
// Compensate for not using the specified window
// We use sin power 4 to suppress wideband noise that otherwise would
// be produced by discontinuities in matching between transform ends.
t1=pow(0.5,1.0/ib);
t2*=(1-2*asin(t1)/PI_L);
t1=pow(0.5,1.0/4);
t2/=(1-2*asin(t1)/PI_L);
genparm[FIRST_FFT_SINPOW]=4;
i=t2+0.5;
if(i < genparm_min[FIRST_FFT_BANDWIDTH])i=genparm_min[FIRST_FFT_BANDWIDTH];
genparm[FIRST_FFT_BANDWIDTH]=i;
clear_screen();
get_wideband_sizes();
if(kill_all_flag) return;
get_buffers(1);
if(kill_all_flag) return;
if(lir_status != LIR_OK)return;
wg.first_xpoint=0;
wg.xpoints=fft1_size;
set_fft1_endpoints();
if(fft1afc_flag == 0)fft1afc_flag=-1;
init_memalloc(calmem, MAX_CAL_ARRAYS);
mem( 1,&cal_graph,2*MAX_ADCHAN*screen_width*sizeof(short int),0);
mem( 2,&cal_table,fft1_size*sizeof(COSIN_TABLE )/2,0);
mem( 3,&cal_permute,fft1_size*sizeof(short int),0);
mem(22,&fft2_tab,fft1_size*sizeof(COSIN_TABLE )/2,0);
mem(23,&fft2_permute,fft1_size*sizeof(short int),0);
mem( 4,&cal_win,(1+fft1_size/2)*sizeof(float),0);
mem( 5,&cal_tmp,twice_rxchan*fft1_size*sizeof(float),0);
mem( 6,&cal_buf,twice_rxchan*fft1_size*sizeof(float),0);
mem( 7,&bal_flag,(BAL_MAX_SEG+1)*sizeof(int),0);
mem( 8,&bal_pos,BAL_AVGNUM*(BAL_MAX_SEG+1)*ui.rx_rf_channels*sizeof(int),0);
mem( 9,&bal_phsum,BAL_AVGNUM*(BAL_MAX_SEG+1)*ui.rx_rf_channels*sizeof(float),0);
mem(10,&bal_amprat,BAL_AVGNUM*(BAL_MAX_SEG+1)*ui.rx_rf_channels*sizeof(float),0);
mem(11,&contracted_iq_foldcorr,8*(BAL_MAX_SEG+1)*ui.rx_rf_channels*
sizeof(float),0);
mem(12,&cal_buf2,twice_rxchan*fft1_size*sizeof(float),0);
mem(13,&cal_buf3,twice_rxchan*fft1_size*sizeof(float),0);
mem(14,&cal_buf4,twice_rxchan*fft1_size*sizeof(float),0);
mem(15,&cal_buf5,twice_rxchan*fft1_size*sizeof(float),0);
mem(16,&cal_buf6,twice_rxchan*fft1_size*sizeof(float),0);
mem(17,&cal_buf7,twice_rxchan*fft1_size*sizeof(float),0);
mem(47,&cal_fft1_filtercorr,twice_rxchan*fft1_size*sizeof(float),0);
mem(48,&cal_fft1_desired,fft1_size*sizeof(float),0);
mem(49,&cal_fft1_sumsq,fft1_size*ui.rx_rf_channels*sizeof(float),0);
mem(50,&cal_fft1_slowsum,fft1_size*ui.rx_rf_channels*sizeof(float),0);
i=memalloc(&calmem_handle,"calmem");
if(i==0) {
lirerr(1188);
return;
}
if(ui.rx_rf_channels == 1) {
cal_ymax=.25;
cal_yzer=.65;
} else {
cal_ymax=.15;
cal_yzer=.5;
}
init_fft(0,fft1_n, fft1_size, cal_table, cal_permute);
make_window(2,fft1_size/2, 4, cal_win);
iqbeg:
;
single_run++;
if(single_run >=2)goto cal_skip;
fft1_pa=fft1_block;
fft1_na=1;
fft1_pb=0;
fft1_px=0;
fft1_nx=0;
timf1p_pa=snd[RXAD].block_bytes;
rxin_isho=(short int*)(&timf1_char[timf1p_pa]);
rxin_int=(int*)(&timf1_char[timf1p_pa]);
rxin_char=(char*)(&timf1_char[timf1p_pa]);
timf1p_px=0;
if(kill_all_flag) goto cal_skip;
cal_type=CAL_TYPE_MENU;
cal_initscreen();
if( (ui.rx_input_mode&IQ_DATA) != 0) {
if( (ui.rx_input_mode&DIGITAL_IQ) == 0) {
lir_text(1, 5,"Running in IQ mode (direct conversion receiver)");
lir_text(1, 6,"The I/Q phase and amplitude should be calibrated before");
lir_text(1, 7,"the total amplitude and phase response is calibrated");
lir_text(5, 9,"A=> Calibrate I/Q phase and amplitude.");
}
lir_text(5,10,"B=> Calibrate total amplitude and phase");
lir_text(5,11,"C=> Remove center discontinuity");
lir_text(5,12,"D=> Refine amplitude and phase correction");
lir_text(5,13,"X=> Skip");
lir_text(5,14,"F1 or !=> Help");
get_kbd:
;
await_processed_keyboard();
if(kill_all_flag) goto cal_skip;
switch (lir_inkey) {
case 'X':
goto cal_skip;
case 'A':
if( (ui.rx_input_mode&DIGITAL_IQ) != 0)break;
if( (fft1_calibrate_flag&CALAMP)==CALAMP) {
clear_screen();
lir_text(5,5,"The amplitudes are already calibrated.");
make_filfunc_filename(s);
sprintf(ss,"Exit from Linrad and remove the file %s",s);
lir_text(1,6,ss);
lir_text(5,8,press_any_key);
await_keyboard();
break;
}
usercontrol_mode=USR_IQ_BALANCE;
init_semaphores();
ampinfo_flag=1;
linrad_thread_create(rx_input_thread);
lir_sleep(100000);
if(lir_status != LIR_OK) {
lir_join(rx_input_thread);
goto cal_skip_freesem;
}
if(kill_all_flag) goto cal_skip_freesem;
linrad_thread_create(THREAD_USER_COMMAND);
if(kill_all_flag) goto iqbal;
linrad_thread_create(THREAD_CAL_IQBALANCE);
if(kill_all_flag) goto iqbal;
linrad_thread_create(THREAD_WIDEBAND_DSP);
iqbal:
;
lir_sleep(50000);
lir_refresh_screen();
lir_join(THREAD_USER_COMMAND);
linrad_thread_stop_and_join(rx_input_thread);
linrad_thread_stop_and_join(THREAD_CAL_IQBALANCE);
linrad_thread_stop_and_join(THREAD_WIDEBAND_DSP);
free_semaphores();
if(kill_all_flag) goto cal_skip;
break;
case 'B':
goto pulsecal;
case 'C':
if(remove_iq_notch() == 0)goto cal_skip;
break;
case 'D':
final_filtercorr_init();
goto cal_skip;
case F1_KEY:
case '!':
help_message(302);
break;