forked from ttrftech/NanoVNA
-
Notifications
You must be signed in to change notification settings - Fork 52
/
sa_cmd.c
1394 lines (1280 loc) · 31 KB
/
sa_cmd.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
/*
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* The software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Radio; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#pragma GCC push_options
#pragma GCC optimize ("Os")
uint32_t xtoi(char *t);
static int points = 101; // For 's' and 'm' commands
VNA_SHELL_FUNCTION(cmd_mode)
{
#ifdef TINYSA3
static const char cmd_low_high[] = "low|high";
#else
static const char cmd_low_high[] = "low";
#endif
static const char cmd_in_out[] = "input|output";
#ifdef TINYSA3
if (argc != 2) {
#else
if (argc != 1 && argc != 2) {
#endif
usage:
#ifdef TINYSA4
shell_printf("usage: mode [low] %s\r\n", cmd_in_out);
#else
shell_printf("usage: mode %s %s\r\n", cmd_low_high,cmd_in_out);
#endif
return;
}
int io = 0;
int lh = 0;
#ifdef TINYSA4
lh = get_str_index(argv[0], cmd_low_high);
if (lh != 0) {
lh = 0;
io = get_str_index(argv[0], cmd_in_out);
} else
io = get_str_index(argv[1], cmd_in_out);
#else
lh = get_str_index(argv[0], cmd_low_high);
io = get_str_index(argv[1], cmd_in_out);
#endif
if (lh < 0 || io<0)
goto usage;
menu_move_top();
switch(lh+io*2)
{
case 0:
set_mode(M_LOW);
ui_mode_normal();
break;
#ifdef TINYSA3
case 1:
set_mode(M_HIGH);
ui_mode_normal();
break;
#endif
case 2:
set_mode(M_GENLOW);
menu_push_lowoutput();
break;
#ifdef TINYSA3
case 3:
set_mode(M_GENHIGH);
menu_push_highoutput();
break;
#endif
}
}
VNA_SHELL_FUNCTION(cmd_modulation )
{
#ifdef TINYSA4
static const char cmd_mod[] = "off|am|fm|freq|depth|deviation";
#else
static const char cmd_mod[] = "off|am|nfm|wfm|extern|freq";
#endif
if (argc < 1) {
usage:
usage_printf("modulation %s 100..6000\r\n", cmd_mod);
return;
}
#ifdef TINYSA4
static const int cmd_mod_val[] = { MO_NONE, MO_AM, MO_WFM, -1, -1, -1};
#else
static const int cmd_mod_val[] = { MO_NONE, MO_AM, MO_NFM, MO_WFM, MO_EXTERNAL, -1};
#endif
int m = get_str_index(argv[0], cmd_mod);
if (m<0)
goto usage;
if (cmd_mod_val[m] >=0)
set_modulation(cmd_mod_val[m]);
else {
if (argc != 2)
goto usage;
int a = my_atoi(argv[1]);
#ifdef TINYSA4
switch(m) {
case 3: set_modulation_frequency(a); break;
case 4: set_depth(a); break;
case 5: set_deviation(a); break;
}
#else
set_modulation_frequency(a);
#endif
}
}
VNA_SHELL_FUNCTION(cmd_calc )
{
int t = 0;
#ifdef TINYSA4
static const char cmd_cal[] = "off|minh|maxh|maxd|aver4|aver16|aver|quasi|log|lin";
#else
static const char cmd_cal[] = "off|minh|maxh|maxd|aver4|aver16|aver|quasi";
#endif
if (argc < 1) {
usage:
usage_printf("calc [{trace#}] %s\r\n%s\r\n", cmd_cal,averageText[setting.average[t]]);
return;
}
int next_arg = 0;
if ('0' <= argv[0][0] && argv[0][0] <= '9') {
t = my_atoi(argv[0]) - 1;
next_arg++;
argc--;
if (t < 0 || t >= TRACES_MAX)
goto usage;
if (argc < 1)
goto usage;
}
int m = get_str_index(argv[next_arg], cmd_cal);
if (m<0)
goto usage;
#ifdef TINYSA4
if (m>=8) {
linear_averaging = (m == 9);
} else
#endif
set_average(t, m);
}
int generic_option_cmd( const char *cmd, const char *cmd_list, int argc, char *argv)
{
if (argc != 1) {
usage:
usage_printf("%s %s\r\n", cmd, cmd_list);
return -1;
}
int m = get_str_index(argv, cmd_list); // this will catch the ?
if (m < 0)
goto usage;
return m;
}
#ifdef __SPUR__
VNA_SHELL_FUNCTION(cmd_spur)
{
#ifdef TINYSA4
int m = generic_option_cmd("spur", "off|on|auto", argc, argv[0]);
#else
int m = generic_option_cmd("spur", "off|on", argc, argv[0]);
#endif
if (m>=0) {
set_spur(m);
redraw_request |= REDRAW_CAL_STATUS | REDRAW_AREA;
}
}
#endif
#ifdef TINYSA4
VNA_SHELL_FUNCTION(cmd_lna)
{
int m = generic_option_cmd("lna", "off|on", argc, argv[0]);
if (m>=0) {
set_extra_lna(m);
redraw_request |= REDRAW_CAL_STATUS | REDRAW_AREA;
}
}
#endif
#ifdef __ULTRA__
VNA_SHELL_FUNCTION(cmd_ultra)
{
const char *ultra_cmd = "off|on|auto|start|harm";
if (argc<1 || argc>2)
goto usage;
if (argv[0][0] == '?')
goto usage;
int m = get_str_index(argv[0], ultra_cmd);
freq_t a = ULTRA_AUTO;
switch(m) {
case 0:
case 1:
config.ultra = m;
update_min_max_freq();
break;
case 2:
goto auto_label;
case 3:
if (argc != 2)
goto usage;
if (get_str_index(argv[1], ultra_cmd)== 2)
goto auto_label;
a = my_atoui(argv[1]);
auto_label:
config.ultra_start = a;
ultra_start = a;
dirty = true;
break;
case 4:
if (argc != 2)
goto usage;
a = my_atoui(argv[1]);
config.harmonic_start = a;
dirty = true;
break;
default:
{
usage:
usage_printf("ultra %s {freq}\r\n", ultra_cmd);
}
}
}
/*
VNA_SHELL_FUNCTION(cmd_ultra_start)
{
if (argc != 1 || argv[0][0] == '?') {
usage_printf("ultra_start {0..4290M}\r\n%QHz\r\n", config.ultra_threshold);
return;
} else {
freq_t a = (freq_t)my_atoi(argv[0]);
config.ultra_threshold = a;
ultra_threshold = (config.ultra_threshold == 0 ? DEFAULT_ULTRA_THRESHOLD : config.ultra_threshold);
dirty = true;
config_save();
}
}
*/
#endif
VNA_SHELL_FUNCTION(cmd_output)
{
#ifdef TINYSA4
int m = generic_option_cmd("output", "on|off|normal|mixer", argc, argv[0]);
#else
int m = generic_option_cmd("output", "on|off", argc, argv[0]);
#endif
switch(m)
{
case 0:
case 1:
setting.mute = m;
break;
#ifdef TINYSA4
case 2:
case 3:
setting.mixer_output = m-2;
#endif
}
dirty = true;
}
VNA_SHELL_FUNCTION(cmd_load)
{
if (argc != 1 || argv[0][0] == '?') {
usage:
usage_printf("load 0..4\r\n");
return;
}
uint16_t a = my_atoui(argv[0]);
if (a > 4)
goto usage;
if (caldata_recall(a) == -1) {
if (a == 0)
reset_settings(setting.mode);
}
}
#ifdef TINYSA4
static uint8_t reg_agc_lna = 0;
VNA_SHELL_FUNCTION(cmd_lna2)
{
int a;
if (argc != 1 || argv[0][0] == '?') {
usage_printf("lna2 0..7|auto\r\n");
return;
}
if (get_str_index(argv[0],"auto") == 0) {
reg_agc_lna &= 0xf0;
} else {
a = my_atoi(argv[0]);
reg_agc_lna &= 0xf0;
reg_agc_lna |= 0x08 | a;
}
SI446x_set_AGC_LNA(reg_agc_lna);
}
VNA_SHELL_FUNCTION(cmd_agc)
{
int a;
if (argc != 1 || argv[0][0] == '?') {
usage_printf("agc 0..7|auto\r\n");
return;
}
if (get_str_index(argv[0],"auto") == 0) {
reg_agc_lna &= 0x0f;
} else {
a = my_atoi(argv[0]);
reg_agc_lna &= 0x0f;
reg_agc_lna |= 0x80 | (a << 4);
}
SI446x_set_AGC_LNA(reg_agc_lna);
}
#endif
VNA_SHELL_FUNCTION(cmd_attenuate)
{
if (argc != 1 || argv[0][0] == '?') {
usage_printf("attenuate 0..31|auto\r\n%4.2F\r\n", get_attenuation());
return;
}
if (get_str_index(argv[0],"auto") == 0) {
if (!setting.auto_attenuation)
set_auto_attenuation();
} else {
int a = my_atoi(argv[0]);
// if (a < 0 || a>31)
// goto usage;
if (get_attenuation() != a)
set_attenuation(a);
}
redraw_request |= REDRAW_CAL_STATUS | REDRAW_AREA;
}
VNA_SHELL_FUNCTION(cmd_level)
{
if (argc != 1 || argv[0][0] == '?') {
if (setting.mode==M_GENLOW)
usage_printf("level -76..-6\r\n");
if (setting.mode==M_GENHIGH)
usage_printf("level -38..13\r\n");
return;
}
float f = my_atof(argv[0]);
set_level(f);
}
VNA_SHELL_FUNCTION(cmd_sweeptime)
{
if (argc != 1 || argv[0][0] == '?') {
usage_printf("sweeptime 0.003..60\r\n%5.3Fs\r\n",((float)setting.actual_sweep_time_us)/ONE_SECOND_TIME);
return;
}
float f = my_atof(argv[0]);
set_sweep_time_us(f*ONE_SECOND_TIME);
}
VNA_SHELL_FUNCTION(cmd_ext_gain)
{
if (argc != 1 || argv[0][0] == '?') {
usage_printf("ext_gain -100.0..+100.0\r\n");
return;
}
float o = my_atof(argv[0]);
set_external_gain(o);
}
VNA_SHELL_FUNCTION(cmd_levelchange)
{
if (argc != 1) {
#ifdef TINYSA4
shell_printf("usage: levelchange -90..+90\r\n");
#else
shell_printf("usage: levelchange -70..+70\r\n");
#endif
return;
}
float f = my_atof(argv[0]);
set_level_sweep(f);
}
VNA_SHELL_FUNCTION(cmd_leveloffset)
{
// 0 1 2
#ifdef TINYSA4
static const char cmd_mode_list[] = "low|switch|receive_switch|out_switch|lna|harmonic|shift|shift1|shift2|shift3|drive1|drive2|drive3|direct|direct_lna|ultra|ultra_lna|harmonic_lna|adf";
#else
static const char cmd_mode_list[] = "low|high|switch|receive_switch";
#endif
if (argc == 0) {
const char *p = "leveloffset %s %.1f\r\n";
#ifdef TINYSA3
shell_printf(p, "low", config.low_level_offset);
shell_printf(p, "high", config.high_level_offset);
shell_printf(p, "low output", config.low_level_output_offset);
shell_printf(p, "high output", config.high_level_output_offset);
shell_printf(p, "switch", config.switch_offset);
shell_printf(p, "receive_switch",config.receive_switch_offset);
#endif
#ifdef TINYSA4
shell_printf(p, "low", config.low_level_offset);
shell_printf(p, "low output", config.low_level_output_offset);
shell_printf(p, "switch", config.switch_offset);
shell_printf(p, "receive_switch",config.receive_switch_offset);
shell_printf(p, "out_switch", config.out_switch_offset);
shell_printf(p, "lna", config.lna_level_offset);
shell_printf(p, "harmonic", config.harmonic_level_offset);
shell_printf(p, "harmonic_lna", config.harmonic_lna_level_offset);
shell_printf(p, "shift", config.shift_level_offset);
shell_printf(p, "shift1", config.shift1_level_offset);
shell_printf(p, "shift2", config.shift2_level_offset);
shell_printf(p, "shift3", config.shift3_level_offset);
shell_printf(p, "drive1", config.drive1_level_offset);
shell_printf(p, "drive2", config.drive2_level_offset);
shell_printf(p, "drive3", config.drive3_level_offset);
shell_printf(p, "direct", config.direct_level_offset);
shell_printf(p, "direct_lna", config.direct_lna_level_offset);
shell_printf(p, "ultra", config.ultra_level_offset);
shell_printf(p, "ultra_lna", config.ultra_lna_level_offset);
shell_printf(p, "adf", config.adf_level_offset);
shell_printf(p, "direct output",config.direct_level_output_offset);
#endif
return;
}
if (argv[0][0] == '?')
goto usage;
int mode = get_str_index(argv[0], cmd_mode_list);
if (mode < 0) goto usage;
float v;
if (argc == 2){
v = my_atof(argv[1]);
switch (mode){
#ifdef TINYSA3
case 0: config.low_level_offset = v; break;
case 1: config.high_level_offset = v; break;
case 2: config.switch_offset = v; break;
case 3: config.receive_switch_offset = v; break;
#endif
#ifdef TINYSA4
case 0: config.low_level_offset = v; config.input_is_calibrated = true; break;
case 1: config.switch_offset = v; break;
case 2: config.receive_switch_offset = v; break;
case 3: config.out_switch_offset = v; break;
case 4: config.lna_level_offset = v; break;
case 5: config.harmonic_level_offset = v; break;
case 6: config.shift_level_offset = v; break;
case 7: config.shift1_level_offset = v; break;
case 8: config.shift2_level_offset = v; break;
case 9: config.shift3_level_offset = v; break;
case 10: config.drive1_level_offset = v; break;
case 11: config.drive2_level_offset = v; break;
case 12: config.drive3_level_offset = v; break;
case 13: config.direct_level_offset = v; break;
case 14: config.direct_lna_level_offset = v; break;
case 15: config.ultra_level_offset = v; break;
case 16: config.ultra_lna_level_offset = v; break;
case 17: config.harmonic_lna_level_offset = v; break;
case 18: config.adf_level_offset = v; break;
#endif
default: goto usage;
}
dirty = true;
return;
}
if (argc == 3 && get_str_index(argv[1], "output") == 0){
v = my_atof(argv[2]);
switch (mode){
case 0: config.low_level_output_offset = v; config.output_is_calibrated = true; break;
case 1: config.high_level_output_offset = v; break;
#ifdef TINYSA4
case 19: config.direct_level_output_offset = v; break;
#endif
default: goto usage;
}
dirty = true;
return;
}
usage:
shell_printf("leveloffset [%s] {output} [-20..+20]\r\n", cmd_mode_list);
}
VNA_SHELL_FUNCTION(cmd_deviceid)
{
if (argc == 0) {
shell_printf("deviceid %d\r\n", config.deviceid);
return;
} else if (argc == 1) {
if (argv[0][0] == '?')
goto usage;
float v = my_atoui(argv[0]);
config.deviceid = v;
} else {
usage:
usage_printf("deviceid [<number>]\r\n");
}
}
#ifdef __SWEEP_OUTPUT__
VNA_SHELL_FUNCTION(cmd_sweep_voltage)
{
float value;
if (argc != 1 || argv[0][0] == '?') {
usage_printf("sweep_voltage {value(0-3.3)}\r\n"\
"current value: %f\r\n", config.sweep_voltage);
return;
}
value = my_atof(argv[0]);
config.sweep_voltage = value;
}
#endif
#ifdef __NOISE_FIGURE__
VNA_SHELL_FUNCTION(cmd_nf)
{
if (argc != 1 || argv[0][0] == '?') {
//usage:
usage_printf("nf {value}\r\n"\
"%f\r\n", config.noise_figure);
return;
}
config.noise_figure = my_atof(argv[0]);
dirty = true;
}
#endif
VNA_SHELL_FUNCTION(cmd_rbw)
{
if (argc != 1 || argv[0][0] == '?') {
usage:
#ifdef TINYSA4
usage_printf("rbw 0.2..850|auto\r\n%.1FHz\r\n", actual_rbw_x10*100.0);
#else
usage_printf("rbw 2..600|auto\r\n%.1FHz\r\n", actual_rbw_x10*100.0);
#endif
return;
}
if (get_str_index(argv[0], "auto|0")>=0) {
if (setting.rbw_x10 != 0)
set_RBW(0);
} else {
float a = my_atof(argv[0]);
if (a < 0.2 ||
#ifdef TINYSA4
a>850
#else
a>600
#endif
)
goto usage;
if (setting.rbw_x10 != a*10)
set_RBW((int) ( a*10));
}
}
VNA_SHELL_FUNCTION(cmd_if)
{
char *t = "975M..979M";
if (argc != 1 || argv[0][0] == '?') {
usage:
#ifdef TINYSA4
if (hw_if)
t = "1067M..1073M";
usage_printf("usage: if {%s}\r\n%QHz\r\n", t, setting.frequency_IF);
#else
usage_printf("usage: if {433M..435M}\r\n%QHz\r\n", setting.frequency_IF);
#endif
return;
}
freq_t a = (freq_t)my_atoi(argv[0]);
freq_t f = DEFAULT_IF;
if (hw_if)
f = DEFAULT_IF_PLUS;
if (a!= 0 &&( a < (f - (freq_t)5000000) || a>(f + (freq_t)5000000)))
goto usage;
setting.auto_IF = false;
set_IF(a);
}
VNA_SHELL_FUNCTION(cmd_zero)
{
if (argc != 1 || argv[0][0] == '?') {
usage_printf("zero {level}\r\n%ddBm\r\n", config.ext_zero_level);
return;
}
config.ext_zero_level = my_atoi(argv[0]);
}
#ifdef TINYSA4
VNA_SHELL_FUNCTION(cmd_direct)
{
if (argc<1 || argc>2)
goto usage;
if (argv[0][0] == '?')
goto usage;
freq_t value = 0;
if (argc == 2) value = my_atoui(argv[1]);
// Parse direct {start|stop} {freq(Hz)}
static const char direct_cmd[] = "start|stop|on|off";
int type = get_str_index(argv[0], direct_cmd);
switch(type) {
case 0:
config.direct_start = value;
return;
case 1:
config.direct_stop = value;
return;
case 2:
config.direct = true;
return;
case 3:
config.direct = false;
return;
}
usage:
usage_printf("direct {%s} {freq(Hz)}\r\n", direct_cmd);
}
VNA_SHELL_FUNCTION(cmd_if1)
{
if (argc != 1 || argv[0][0] == '?') {
usage:
usage_printf("if1 {975M..979M}\r\n%QHz\r\n", config.frequency_IF1);
return;
} else {
freq_t a = (freq_t)my_atoui(argv[0]);
if (a!= 0 &&( a < (DEFAULT_IF - (freq_t)80000000) || a>(DEFAULT_IF + (freq_t)80000000)))
goto usage;
config.frequency_IF1 = a;
config_save();
}
}
VNA_SHELL_FUNCTION(cmd_actual_freq)
{
if (argc != 1 || argv[0][0] == '?') {
shell_printf("%D\r\n", config.setting_frequency_30mhz);
return;
} else {
set_actual_freq(my_atoui(argv[0]));
}
}
VNA_SHELL_FUNCTION(cmd_freq_correction)
{
if (argc != 1 || argv[0][0] == '?') {
shell_printf("%d ppb\r\n", (int)(((int64_t)config.setting_frequency_30mhz - (int64_t)3000000000ULL)/3));
return;
} else {
set_freq_corr(my_atoi(argv[0]));
}
}
#endif
#ifdef __DRAW_LINE__
VNA_SHELL_FUNCTION(cmd_line)
{
if (argc != 1 || argv[0][0] == '?')
goto usage;
int type = get_str_index(argv[0], "off");
switch(type) {
case -1: {
float l = my_atof(argv[0]);
setting.draw_line = true;
set_trigger_level(to_dBm(l));
set_trigger(T_AUTO);
redraw_request |= REDRAW_AREA;
}
return;
case 0:
setting.draw_line = false;
redraw_request |= REDRAW_AREA;
return;
}
usage:
usage_printf("line off|{level}\r\n");
}
#endif
#ifdef TINYSA3
VNA_SHELL_FUNCTION(cmd_actual_freq)
{
if (argc != 1 || argv[0][0] == '?') {
shell_printf("%DHz\r\n", config.setting_frequency_10mhz);
return;
} else {
set_10mhz(my_atoui(argv[0]));
}
}
#endif
VNA_SHELL_FUNCTION(cmd_trigger)
{
if (argc == 0)
goto usage;
if(argv[0][0] == '?')
goto usage;
if (( '0' <= argv[0][0] && argv[0][0] <= '9') || argv[0][0] == '-') {
float t = my_atof(argv[0]);
if (setting.trigger == T_AUTO )
set_trigger(T_NORMAL);
set_trigger_level(to_dBm(t));
goto update;
}
static const char cmd_trigger_list[] = "auto|normal|single";
if (argc == 1) {
int type = get_str_index(argv[0], cmd_trigger_list);
if (type >= 0) {
set_trigger(type);
goto update;
}
goto usage;
}
update:
redraw_request |= REDRAW_CAL_STATUS | REDRAW_AREA;
completed = true;
return;
usage:
shell_printf("trigger {value}\r\n"\
"trigger {%s}\r\n" , cmd_trigger_list);
}
VNA_SHELL_FUNCTION(cmd_selftest)
{
if (argc < 1 || argc > 2 || argv[0][0] == '?') {
usage_printf("selftest (1-3) [arg]\r\n");
return;
}
setting.test = my_atoi(argv[0]);
if (argc == 1)
setting.test_argument = 0;
else
setting.test_argument = my_atoui(argv[1]);
sweep_mode = SWEEP_SELFTEST;
}
#ifdef __SINGLE_LETTER__
static int VFO = 0;
uint32_t xtoi(char *t)
{
uint32_t v=0;
while (*t) {
if ('0' <= *t && *t <= '9')
v = v*16 + *t - '0';
else if ('a' <= *t && *t <= 'f')
v = v*16 + *t - 'a' + 10;
else if ('A' <= *t && *t <= 'F')
v = v*16 + *t - 'A' + 10;
else
return v;
t++;
}
return v;
}
#ifdef __ADF4351__
VNA_SHELL_FUNCTION(cmd_x)
{
uint32_t reg;
if (argc != 1) {
usage_printf("x value(0-FFFFFFFF)\r\n");
return;
}
reg = xtoi(argv[0]);
if ((reg & 7) == 5) {
if (reg & (1<<22))
VFO = 1;
else
VFO = 0;
// reg &= ~0xc00000; // Force led to show lock
// reg |= 0x400000;
}
ADF4351_WriteRegister32(VFO, reg);
ADF4351_Latch();
shell_printf("x=%x\r\n", reg);
}
#endif
VNA_SHELL_FUNCTION(cmd_i)
{
(void)argc;
(void)argv;
return; // Don't use!!!!
#ifdef __SI4432__
int rvalue;
SI4432_Init();
shell_printf("SI4432 init done\r\n");
if (argc == 1) {
rvalue = my_atoui(argv[0]);
set_switches(rvalue);
set_mode(rvalue);
shell_printf("SI4432 mode %d set\r\n", rvalue);
}
#endif
}
VNA_SHELL_FUNCTION(cmd_o)
{
(void) argc;
freq_t value = my_atoi(argv[0]);
if (VFO == 0)
setting.frequency_IF = value;
set_freq(VFO, value);
}
VNA_SHELL_FUNCTION(cmd_d)
{
(void) argc;
(void) argv;
int32_t a = my_atoi(argv[0]);
#if false
int32_t d;
if (argc == 2)
d = my_atoi(argv[1]);
else {
d = a;
a = 2;
}
switch (a) {
case 1:
SI4463_set_output_level(d);
break;
case 2:
ADF4351_drive (d);
break;
case 3:
ADF4351_aux_drive(d);
break;
}
// setting.lo_drive=a;
// dirty = true;
#else
setting.lo_drive=a;
dirty = true;
#endif
}
#if 0
extern int16_t adc_buf_read(uint16_t *result, uint32_t count);
VNA_SHELL_FUNCTION(cmd_g)
{
(void) argc;
(void) argv;
int32_t a = my_atoi(argv[0]);
systime_t start_of_read = chVTGetSystemTimeX();
adc_buf_read(spi_buffer, 256);
systime_t time_of_read = chVTGetSystemTimeX() - start_of_read;
shell_printf("Time: %d\r\n", time_of_read);
for (int i=0;i<20;i++)
shell_printf("[%d] = %d\r\n", (int)i, (int)(spi_buffer[i]));
}
#endif
VNA_SHELL_FUNCTION(cmd_a)
{
(void)argc;
if (argc != 1) {
shell_printf("a=%U\r\n", frequencyStart);
return;
}
freq_t value = my_atoui(argv[0]);
frequencyStart = value;
}
VNA_SHELL_FUNCTION(cmd_b)
{
(void)argc;
if (argc != 1) {
shell_printf("b=%U\r\n", frequencyStop);
return;
}
freq_t value = my_atoui(argv[0]);
frequencyStop = value;
}
VNA_SHELL_FUNCTION(cmd_t)
{
(void)argc;
(void)argv;
}
VNA_SHELL_FUNCTION(cmd_e)
{
(void)argc;
if (argc != 1) {
shell_printf("e=%d\r\n", setting.tracking);
return;
}
setting.tracking = my_atoi(argv[0]);
if (setting.tracking == -1)
setting.tracking = false;
else
setting.tracking = true;
if (argc >1)
frequencyExtra = my_atoi(argv[1]);
}
VNA_SHELL_FUNCTION(cmd_s)
{
(void)argc;
if (argc != 1) {
shell_printf("s=%d\r\n", points);
return;
}
points = my_atoi(argv[0]);
}
VNA_SHELL_FUNCTION(cmd_v)
{
if (argc != 1) {
shell_printf("%d\r\n", VFO);
return;
}
VFO = my_atoi(argv[0]) > 0 ? 1 : 0;
shell_printf("VFO %d\r\n", VFO);
}
VNA_SHELL_FUNCTION(cmd_y)
{
if (argc < 1) {
usage_printf("y {addr(0-95)} [value(0-0xFF)]\r\n");
return;
}
#ifdef __SI4432__
int lvalue = 0;
int rvalue;
rvalue = xtoi(argv[0]);
SI4432_Sel = VFO;
if (argc == 2){
lvalue = my_atoui(argv[1]);
SI4432_Write_Byte(rvalue, lvalue);
} else {
lvalue = SI4432_Read_Byte(rvalue);
shell_printf("%x\r\n", lvalue);
}
#endif
#ifdef __SI4463__
uint8_t data[16];
data[0] = xtoi(argv[0]);
for (int i=1; i < argc; i++) {
data[i] = xtoi(argv[i]);
}
SI4463_do_api(data, argc, data, 16);
for (int i=0; i<16; i++)
shell_printf("%02x ", data[i]);
shell_printf("\r\n");
#endif
}
#ifdef TINYSA4
VNA_SHELL_FUNCTION(cmd_z)
{
if (argc != 1) {
usage_printf("z 0..30000\r\n%d\r\n", SI4432_step_delay);
return;
}
if (argc == 1) {